mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
f1d5de226f
- Fix a timing problem exist before upgrade from Vue 2 to Vue 3
72 lines
2.8 KiB
PHP
72 lines
2.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
|
use App\Http\Resources\TransactionWithStorageResource;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ListTransactionsLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* ListTransactionsLogic constructor.
|
|
* @param ListsTransactions $listsTransactions
|
|
*/
|
|
public function __construct(ListsTransactions $listsTransactions)
|
|
{
|
|
$this->listsTransactions = $listsTransactions;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Transactions',
|
|
'message' => 'You have successfully retrieved a list of transactions'
|
|
];
|
|
}
|
|
|
|
/** @var ListsTransactions */
|
|
private $listsTransactions;
|
|
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
|
foreach ($query->items() as $item) {
|
|
if($item instanceof \App\Models\Transaction && $item->owner && $item->owner->owner->companyModule){
|
|
$eInvoice = false;
|
|
$eInvoiceStartDate = Carbon::parse(env('E_INVOICE_START_DATE', '2025-07-01 00:00:00'));
|
|
$transactionCreatedDate = Carbon::parse($item->created_at);
|
|
$eInvoiceRequestedDate = Carbon::parse($item->owner->owner->companyModule->company->e_invoice_requested_at);
|
|
|
|
if ($transactionCreatedDate->isAfter($eInvoiceStartDate)
|
|
&&($transactionCreatedDate->isAfter($eInvoiceRequestedDate) || $transactionCreatedDate->diffInMinutes($eInvoiceRequestedDate) <= 60)
|
|
&& $item->owner->owner->companyModule->company->e_invoice === 1)
|
|
{
|
|
$eInvoice = true;
|
|
}
|
|
$item['is_einvoice_applicable'] = $eInvoice;
|
|
// $item['is_einvoice_applicable'] = $item->owner->owner->companyModule->company->e_invoice === 1;
|
|
}
|
|
}
|
|
|
|
if($request->input('storages')){
|
|
foreach ($query->items() as $item) {
|
|
$transactionId = $item['id'];
|
|
$filteredStorages = array_filter($request->input('storages'), function ($storage) use ($transactionId) {
|
|
return isset($storage['parentInvoiceId']) && $storage['parentInvoiceId'] == $transactionId;
|
|
});
|
|
$item['storages'] = $filteredStorages;
|
|
}
|
|
}
|
|
return $this->collectionResponse(TransactionWithStorageResource::collection($query));
|
|
}
|
|
}
|