60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Contracts\RatingsResourceInterface;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use App\Libraries\ParameterHelper;
|
|
|
|
class ReportStationRatingsExport implements FromCollection
|
|
{
|
|
private $ratings;
|
|
|
|
public function __construct(RatingsResourceInterface $ratings)
|
|
{
|
|
$this->ratings = $ratings;
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
public function collection()
|
|
{
|
|
$request = request();
|
|
|
|
$params = [
|
|
'search' => ($request->has('_search') ? $request->get('_search') : NULL),
|
|
'page_size' => null,
|
|
'page' => null,
|
|
'date_start' => ($request->has('date_start') ? $request->get('date_start') : null),
|
|
'date_end' => ($request->has('date_end') ? $request->get('date_end') : null),
|
|
'sorting' => ParameterHelper::prepareSortingParameter($request)
|
|
];
|
|
|
|
|
|
if(ParameterHelper::validateStartEndDate($params))
|
|
{
|
|
return $this->format->unprocessableEntity('Start date must not be greater than end date');
|
|
}
|
|
|
|
$list = $this->ratings->report_stationRatings($params, true);
|
|
|
|
$data = collect([['Transaction Date & Time', 'Card Number', 'Sales Invoice', 'Station', 'Ratings']]);
|
|
|
|
if($list->count())
|
|
{
|
|
foreach ($list as $key => $value) {
|
|
$data->push( [
|
|
date('d-M-Y h:i A',strtotime($value->created_at)),
|
|
'="' .$value->loyaltyCard->card_number. '"',
|
|
$value->payment->trans_num,
|
|
$value->station->description,
|
|
$value->rate
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|