mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
109 lines
3.6 KiB
PHP
109 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Exports\Services;
|
|
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Group;
|
|
use App\Models\Transaction;
|
|
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 Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
|
|
class ExportsGroupTransactions implements
|
|
FromQuery,
|
|
WithHeadings,
|
|
WithHeadingRow,
|
|
WithMapping,
|
|
ShouldAutoSize
|
|
{
|
|
use Exportable;
|
|
|
|
private $request;
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
$this->request = $request;
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'DocNo',
|
|
'DocDate',
|
|
'PaymentDate',
|
|
'DebtorCode',
|
|
'Ref',
|
|
'ShipInfo',
|
|
'AccNo',
|
|
'DetailDescription',
|
|
'FurtherDescription',
|
|
'ProjNo',
|
|
'DeptNo',
|
|
'Qty',
|
|
'UnitPrice',
|
|
'TaxType',
|
|
'TaxableAmt',
|
|
'TaxRate'
|
|
];
|
|
}
|
|
|
|
public function query()
|
|
{
|
|
$start_date = $this->parseDate($this->request->input('startDate'));
|
|
$end_date = $this->parseDate($this->request->input('endDate'));
|
|
|
|
return Group::when($start_date && $end_date, function ($query) use ($start_date, $end_date) {
|
|
$query->whereBetween('created_at', [
|
|
$start_date->startOfDay(),
|
|
$end_date->endOfDay()
|
|
]);
|
|
})
|
|
->when($start_date && !$end_date, function ($query) use ($start_date) {
|
|
$query->where('created_at', '>=', $start_date->startOfDay());
|
|
})
|
|
->when(!$start_date && $end_date, function ($query) use ($end_date) {
|
|
$query->where('created_at', '<=', $end_date->endOfDay());
|
|
});
|
|
}
|
|
|
|
private function parseDate($date)
|
|
{
|
|
return $date ? Carbon::parse($date)->startOfDay() : null;
|
|
}
|
|
|
|
public function map($transaction): array
|
|
{
|
|
$company = $transaction->receiverCompany;
|
|
return [
|
|
'<<New>>', //'DocNo',
|
|
'', //'DocDate',
|
|
$transaction->created_at->format('m/d/Y H:m'), //'PaymentDate',
|
|
$company->debtor, //'DebtorCode',
|
|
$company->referece, //'Ref',
|
|
$company->referece, //'ShipInfo',
|
|
'500-0000', //'AccNo',
|
|
'X1 Freight Service Charge', //'DetailDescription',
|
|
'FurtherDescription', //'FurtherDescription',
|
|
'M3', //'ProjNo',
|
|
'CIEF', //'DeptNo',
|
|
'', //'Qty',
|
|
'', //'UnitPrice',
|
|
'', //'TaxType',
|
|
floatval($transaction->tax) > 0 ? number_format($transaction->tax, 2) : '0.00', //'TaxableAmt',
|
|
'', //'TaxRate'
|
|
];
|
|
}
|
|
|
|
private function getTaxType($tax_percentage)
|
|
{
|
|
return floatval($tax_percentage) > 0 ? 'SV-6' : '';
|
|
}
|
|
}
|