mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-27 08:24:06 +00:00
82 lines
2.7 KiB
PHP
82 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Exports\Services;
|
|
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Transaction;
|
|
use App\Models\Wallet;
|
|
use Maatwebsite\Excel\Concerns\Exportable;
|
|
use Maatwebsite\Excel\Concerns\FromQuery;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ExportsWalletTopUpDepositEntryReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
|
{
|
|
use Exportable;
|
|
|
|
protected $startDate;
|
|
protected $endDate;
|
|
|
|
public function __construct($startDate = null, $endDate = null) {
|
|
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
|
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'DocNo',
|
|
'DebtorCode',
|
|
'DocDate',
|
|
'Description',
|
|
'DeptNo',
|
|
'DepositPaymentMethod',
|
|
'CurrencyCode',
|
|
'PaymentMethod',
|
|
'PaymentAmt',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection|mixed
|
|
*/
|
|
public function query()
|
|
{
|
|
$type = TransactionType::TOP_UP;
|
|
$query = Transaction::query();
|
|
$query->where('owner_type', Wallet::class);
|
|
$query->where('type', $type);
|
|
$query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
|
$query->whereBetween('created_at', [$this->startDate, $this->endDate]);
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* @param Transaction $transaction
|
|
* @return array
|
|
*/
|
|
public function map($transaction): array
|
|
{
|
|
$formattedDocumentDate = Carbon::parse($transaction->created_at)->format('m/d/Y');
|
|
$owner = $transaction->owner;
|
|
$company = $owner->owner;
|
|
return [
|
|
'<<New>>', //DocNo
|
|
$company ? $company->debtor : '', //DebtorCode
|
|
$formattedDocumentDate, //DocDate
|
|
'Wallet Deposit', //Description
|
|
'C', //DeptNo
|
|
'WALLET DEPOSIT - EXC', //DepositPaymentMethod
|
|
'MYR', //CurrencyCode
|
|
'MBB', //PaymentMethod
|
|
number_format($transaction->amount, 2), //PaymentAmt
|
|
];
|
|
}
|
|
}
|