mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
e7c0e17ee4
# Conflicts: # app/Classes/Modules/Segments/ControllersLogic/UpdateConstantPostcodeLogic.php # app/Classes/ValueObjects/Constants/TransactionType.php # routes/api.php # routes/web.php
158 lines
5.3 KiB
PHP
158 lines
5.3 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\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 ExportsPaymentTransactions 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',
|
|
'DebtorCode',
|
|
'ShipInfo',
|
|
'AccNo',
|
|
'DetailDescription',
|
|
'FurtherDescription',
|
|
'ProjNo',
|
|
'DeptNo',
|
|
'Qty',
|
|
'UnitPrice',
|
|
// 'marking',
|
|
// 'contact person',
|
|
// 'contact number',
|
|
// 'link',
|
|
// 'amount'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection|mixed
|
|
*/
|
|
public function query()
|
|
{
|
|
$start_date = $this->request->input('startDate', null);
|
|
if ($start_date) {
|
|
$start_date = Carbon::parse($this->request->input('startDate'))->format('Y-m-d');
|
|
}
|
|
|
|
$end_date = $this->request->input('endDate', null);
|
|
if ($end_date) {
|
|
$end_date = Carbon::parse($this->request->input('endDate'))->format('Y-m-d');
|
|
}
|
|
|
|
$query = Transaction::query();
|
|
|
|
// paidInvoiceSection
|
|
$approvalStatus = ApprovalStatus::COMPLETED;
|
|
|
|
if ($this->request->route('section') == 'pendingPaymentSection') {
|
|
// pendingPaymentSection
|
|
$approvalStatus = ApprovalStatus::APPROVED;
|
|
}
|
|
|
|
$query->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [$approvalStatus]);
|
|
|
|
if($start_date && $end_date) {
|
|
$query->whereBetween('updated_at', [
|
|
Carbon::parse($start_date)->format('Y-m-d 0:00:00'),
|
|
Carbon::parse($end_date)->format('Y-m-d 23:59:59')
|
|
]);
|
|
}
|
|
elseif($start_date && !$end_date) {
|
|
$query->whereHas('transactions', function($transaction) use ($start_date) {
|
|
$transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($start_date)->format('Y-m-d 0:00:00'));
|
|
});
|
|
|
|
}
|
|
elseif(!$start_date && $end_date) {
|
|
$query->whereHas('transactions', function($transaction) use ($end_date) {
|
|
$transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($end_date)->format('Y-m-d 0:00:00'));
|
|
});
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function map($transaction): array
|
|
{
|
|
$container = $transaction->owner->containers()->first();
|
|
$order = $transaction->owner->owner;
|
|
$company = $order->companyModule->company;
|
|
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'SHIPPING_FEE')->first();
|
|
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
|
$contact = $order->companyModule->company->contacts->first();
|
|
$userName = $order->companyModule->employees()->first();
|
|
$link = route('customer.payment-and-billing', $marking);
|
|
|
|
$furtherDescription = '';
|
|
|
|
foreach ($transaction->transactionDetails as $item){
|
|
|
|
if($item->reference === 'SHIPPING_FEE')
|
|
$furtherDescription .= str_replace('X1 Freight Service Charge<br>', '', $item->name)."\n";
|
|
elseif($item->reference === 'OVER_WEIGHT_CHARGES')
|
|
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
|
|
elseif($item->reference === 'MIN_CBM_CHARGES')
|
|
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
|
|
else
|
|
$furtherDescription .= $item->name.' '.$item->quantity.' X '.$item->price."\n";
|
|
}
|
|
|
|
return [
|
|
'<<New>>',
|
|
$transaction->created_at->format('m/d/Y H:m'),
|
|
$company->debtor,
|
|
$order->reference,
|
|
'500-0000',
|
|
'X1 Freight Service Charge',
|
|
$furtherDescription,
|
|
$container->reference,
|
|
'CIEF',
|
|
$shippingTransactionDetails->quantity,
|
|
$shippingTransactionDetails->price,
|
|
// $marking,
|
|
// $contact ? $contact->phone : '',
|
|
// $userName->name,
|
|
// $link,
|
|
// $transaction->amount
|
|
];
|
|
return [
|
|
'<<New>>',
|
|
$transaction->updated_at->format('m/d/Y H:m'),
|
|
$company->debtor,
|
|
$container->reference,
|
|
'500-0000',
|
|
'X1 Freight Service Charge',
|
|
'FurtherDescription',
|
|
$container->reference,
|
|
'M3',
|
|
'CIEF',
|
|
$shippingTransactionDetails->quantity,
|
|
$shippingTransactionDetails->price,
|
|
];
|
|
}
|
|
}
|