58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Contracts\PaymentResourceInterface;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use App\Libraries\ParameterHelper;
|
|
|
|
class ReportTopUpExport implements FromCollection
|
|
{
|
|
|
|
private $payments;
|
|
|
|
public function __construct(PaymentResourceInterface $payments)
|
|
{
|
|
$this->payments = $payments;
|
|
}
|
|
|
|
/**
|
|
* @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->payments->report_topUp($params, true);
|
|
|
|
$data = collect([['Date & Time', 'Card Number', 'Amount']]);
|
|
|
|
if($list->count())
|
|
{
|
|
foreach ($list as $key => $value) {
|
|
$data->push( [
|
|
date('d-M-Y h:i A',strtotime($value->paid_at)),
|
|
'="' .$value->loyaltyCard->card_number. '"',
|
|
$value->amount,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|