diff --git a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php index ca471bd0..57361f52 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php +++ b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php @@ -32,12 +32,12 @@ class UpdatePerfexCRMPrelude implements ShouldQueue /** * UpdatePerfexCRMPrelude constructor. - * @param $packingList + * @param PackingList $packingList * @param Transaction $transaction * @param UpdatePerfexCRMObject $updatePerfexCRMObject * @param bool|null $shouldCreateInvoice */ - public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false) + public function __construct(?PackingList $packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false) { $this->packingList = $packingList; $this->transaction = $transaction; @@ -47,6 +47,16 @@ class UpdatePerfexCRMPrelude implements ShouldQueue public function handle() { + Log::info('packingList: ' . json_encode($this->packingList)); + Log::info('packingList owner: ' . json_encode($this->packingList->owner)); + Log::info('transaction: ' . json_encode($this->transaction)); + Log::info('updatePerfexCRMObject get tasks: ' . json_encode($this->updatePerfexCRMObject->getTasks())); + Log::info('shouldCreateInvoice: ' . json_encode($this->shouldCreateInvoice)); + + if(env('APP_ENV') !== 'production'){ + return; + } + if(is_null($this->packingList)){ $this->packingList = $this->transaction->owner->owner; } diff --git a/app/Classes/Modules/Orders/ControllersLogic/FetchOrderPackagesLogic.php b/app/Classes/Modules/Orders/ControllersLogic/FetchOrderPackagesLogic.php new file mode 100644 index 00000000..f53c4f74 --- /dev/null +++ b/app/Classes/Modules/Orders/ControllersLogic/FetchOrderPackagesLogic.php @@ -0,0 +1,60 @@ + 'Retrieved Order Packages', + 'message' => 'You have successfully retrieved an order packages' + ]; + } + + /** @var CanFetchOrder */ + private $canFetchOrder; + + /** @var FetchesOrder */ + private $fetchesOrder; + + /** + * FetchOrderPackagesLogic constructor. + * @param CanFetchOrder $canFetchOrder + * @param FetchesOrder $fetchesOrder + */ + public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder) + { + $this->canFetchOrder = $canFetchOrder; + $this->fetchesOrder = $fetchesOrder; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canFetchOrder->passes(); + + $query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]); + + return $this->resourceResponse(new OrderPackagesBaseResource($query)); + + } + +} diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php index aa35da9e..a3af079e 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php @@ -68,21 +68,32 @@ class ListPackingListsLogic extends AbstractControllerLogic } else{ $filters = json_decode($request->input('filters'), true); - if(isset($filters['include_packages'])){ - //'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included - foreach ($query->items() as $item) { + $useNew = false; + foreach ($query->items() as $item) { + if(isset($filters['include_packages'])){ + //'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included $item['include_packages'] = $filters['include_packages']; + $useNew = true; } - } - if(isset($filters['include_receive_packing_list'])){ - //'include_receive_packing_list' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included - foreach ($query->items() as $item) { + if(isset($filters['include_receive_packing_list'])){ + //'include_receive_packing_list' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included $item['include_receive_packing_list'] = $filters['include_receive_packing_list']; + $useNew = true; } + + if(isset($filters['include_shipping_transaction'])){ + $item['include_shipping_transaction'] = $filters['include_shipping_transaction']; + $useNew = true; + } + + if(isset($filters['include_suspended_invoice'])){ + $item['include_suspended_invoice'] = $filters['include_suspended_invoice']; + $useNew = true; + } } - if(isset($filters['include_packages']) || isset($filters['include_receive_packing_list']) ){ + if($useNew){ return $this->collectionResponse(PackingListBaseResource::collection($query)); } diff --git a/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php b/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php index 17e559c9..2bba3192 100644 --- a/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php +++ b/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php @@ -142,4 +142,43 @@ class UpdatePerfexCRMObject implements DataTransferObject { $this->invoiceId = $invoiceId; } + + public function toArray(): array + { + return [ + 'companyName' => $this->companyName, + 'companyReference' => $this->companyReference, + 'contactName' => $this->contactName, + 'contactEmail' => $this->contactEmail, + 'bookingMarking' => $this->bookingMarking, + 'projectName' => $this->projectName, + 'projectStatus' => $this->projectStatus, + 'invoiceId' => $this->invoiceId, + 'milestoneNames' => $this->milestoneNames, + 'tasks' => $this->tasks, + ]; + } + + public function toJson(): string + { + return json_encode($this->toArray()); + } + + public static function fromJson(string $json): self + { + $data = json_decode($json, true); + + return new self( + $data['companyName'], + $data['companyReference'], + $data['contactName'], + $data['contactEmail'], + $data['bookingMarking'], + $data['projectName'], + $data['projectStatus'], + $data['invoiceId'], + $data['milestoneNames'], + $data['tasks'] + ); + } } diff --git a/app/Classes/Modules/PerfexCRM/Processors/PackingListToPerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/PackingListToPerfexCRMProcessor.php index de63ee76..5c992804 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/PackingListToPerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/PackingListToPerfexCRMProcessor.php @@ -9,6 +9,7 @@ use App\Models\PackingList; use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus; use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages; use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus; +use App\Models\DelayedJob; use Illuminate\Support\Facades\Log; class PackingListToPerfexCRMProcessor @@ -92,6 +93,29 @@ class PackingListToPerfexCRMProcessor private function dispatchUpdateJob(PackingList $packingList, UpdatePerfexCRMObject $updatePerfexCRMObject) { + try { + /** + * UpdatePerfexCRMPrelude constructor. + * @param $packingList + * @param Transaction $transaction + * @param UpdatePerfexCRMObject $updatePerfexCRMObject + * @param bool|null $shouldCreateInvoice + */ + DelayedJob::create([ + 'job_class' => UpdatePerfexCRMPrelude::class, + 'parameters' => json_encode([ + 'packingList' => $packingList, + 'transaction' => null, + 'updatePerfexCRMObject' => $updatePerfexCRMObject->toArray(), + 'shouldCreateInvoice' => false, + ]), + 'execute_at' => now()->addMinute(1), + ]); + + } catch (\Exception $e) { + Log::info('An unexpected error occurred when DelayedJob::create: ' . $e->getMessage()); + } + UpdatePerfexCRMPrelude::dispatch($packingList, null, $updatePerfexCRMObject, false); } diff --git a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php index b31505a5..ea0708e6 100644 --- a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php @@ -66,6 +66,8 @@ class CheckStorageInvoiceTransactionProcessor /** @var DeletesBillplzBill */ private $deletesBillplzBill; + private $defaultPricePerCBM = 3; + /** * @param FetchesOrder $fetchesOrder * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber @@ -90,6 +92,20 @@ class CheckStorageInvoiceTransactionProcessor $this->updatesTransactionStatus = $updatesTransactionStatus; $this->deletesGroup = $deletesGroup; $this->deletesBillplzBill = $deletesBillplzBill; + + $targetDate = Carbon::create(2024, 9, 22, 0, 0, 0, 'Asia/Kuala_Lumpur'); + $nowMalaysia = Carbon::now('Asia/Kuala_Lumpur'); + LogHelper::channel('storage_invoices')->info('targetDateMalaysia: ' . $targetDate->toIso8601String()); + LogHelper::channel('storage_invoices')->info('nowMalaysia: ' . $nowMalaysia->toIso8601String()); + + if ($nowMalaysia->greaterThanOrEqualTo($targetDate)) { + LogHelper::channel('storage_invoices')->info('true'); + $this->defaultPricePerCBM = 6; + } + else{ + LogHelper::channel('storage_invoices')->info('false'); + $this->defaultPricePerCBM = 6; + } } /** @@ -176,11 +192,12 @@ class CheckStorageInvoiceTransactionProcessor } private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $eta){ - $pricePerCBM = 3; + $pricePerCBM = $this->defaultPricePerCBM; $resultNumberOfDaysFree = 10; $dt1 = $eta->copy()->addDay()->startOfDay(); $dt2 = Carbon::now()->copy()->addDay()->startOfDay(); $interval = Carbon::parse($dt2)->diff($dt1); + LogHelper::channel('storage_invoices')->info('eta: '.json_encode($eta)); LogHelper::channel('storage_invoices')->info('dt1: '.json_encode($dt1)); LogHelper::channel('storage_invoices')->info('dt2: '.json_encode($dt2)); @@ -222,6 +239,8 @@ class CheckStorageInvoiceTransactionProcessor $this->createStorageInvoiceTransactionDetails($storageInvoice, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded, $taxPercentage); } else if($storageInvoice){ + $amount = $storageInvoice->amount; + //Additional handling for giving selected storage invoice a waiver if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){ $pricePerCBM = 0; @@ -236,6 +255,15 @@ class CheckStorageInvoiceTransactionProcessor $intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1); $resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree; $price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded; + + try{ + $auditPricePerCbm = floor($amount / ($cbm * $resultNumberOfDaysExceeded)); + LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm); + $pricePerCBM = $auditPricePerCbm; + } + catch(\Exception $ex){ + LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex); + } } if (Carbon::now()->isAfter($dateToCompare)) { @@ -244,7 +272,6 @@ class CheckStorageInvoiceTransactionProcessor $price_cbm = $price_cbm + $total_tax; } - $amount = $storageInvoice->amount; $epsilon = 0.0001; // Tolerance for the comparison LogHelper::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id); LogHelper::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status); @@ -296,7 +323,7 @@ class CheckStorageInvoiceTransactionProcessor } private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $eta){ - $pricePerCBM = 3; + $pricePerCBM = $this->defaultPricePerCBM; $resultNumberOfDaysFree = 10; $dt1 = $eta->copy()->addDay()->startOfDay(); $resultStartDate = $dt1->format('Y-m-d'); @@ -317,10 +344,6 @@ class CheckStorageInvoiceTransactionProcessor if($storageInvoice){ $storageInvoiceId = $storageInvoice->id; - if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){ - $pricePerCBM = 0; - } - $transactionDetailsItems = $transaction->transactionDetails()->get(); $cbm = 0.00; foreach ($transactionDetailsItems as $tdItem){ @@ -331,6 +354,20 @@ class CheckStorageInvoiceTransactionProcessor $cbm = $cbm + $quantity; } + if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){ + $pricePerCBM = 0; + } + else{ + try{ + $auditPricePerCbm = floor($storageInvoice->amount / ($cbm * $resultNumberOfDaysExceeded)); + LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm); + $pricePerCBM = $auditPricePerCbm; + } + catch(\Exception $ex){ + LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex); + } + } + if($storageInvoiceId !== 0){ $result = [ 'parentInvoiceId' => $transaction->id, diff --git a/app/Console/Commands/V2/ProcessDelayedJobsV2Command.php b/app/Console/Commands/V2/ProcessDelayedJobsV2Command.php new file mode 100644 index 00000000..8f19a1e5 --- /dev/null +++ b/app/Console/Commands/V2/ProcessDelayedJobsV2Command.php @@ -0,0 +1,71 @@ +limit(150) + ->get(); + + $count = 0; + foreach ($jobs as $index => $delayedJob) { + $jobClass = $delayedJob->job_class; + if($jobClass === UpdatePerfexCRMPrelude::class){ + $params = json_decode($delayedJob->parameters, true); + + Log::info('ProcessDelayedJobsV2Command packingList : ' . json_encode($params['packingList'])); + Log::info('ProcessDelayedJobsV2Command packingList id : ' . json_encode($params['packingList']['id'])); + Log::info('ProcessDelayedJobsV2Command transaction : ' . json_encode($params['transaction'])); + Log::info('ProcessDelayedJobsV2Command updatePerfexCRMObject : ' . json_encode($params['updatePerfexCRMObject'])); + Log::info('ProcessDelayedJobsV2Command shouldCreateInvoice : ' . json_encode($params['shouldCreateInvoice'])); + + $updatePerfexCRMObject = UpdatePerfexCRMObject::fromJson(json_encode($params['updatePerfexCRMObject'])); + $packingList = PackingList::where('id', $params['packingList']['id'])->first(); + + $singleDelayedJob = new $jobClass( + $packingList, + $params['transaction'], + $updatePerfexCRMObject, + $params['shouldCreateInvoice'] + ); + + $delayInSeconds = intdiv($index, 2) * 10 ; + dispatch($singleDelayedJob)->delay(now()->addSeconds($delayInSeconds)); + $delayedJob->delete(); + $count++; + } + + } + Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count); + } +} diff --git a/app/Console/Commands/V2/ProcessYDPortalDataV2Command.php b/app/Console/Commands/V2/ProcessYDPortalDataV2Command.php index 6d521a65..facd3ef3 100644 --- a/app/Console/Commands/V2/ProcessYDPortalDataV2Command.php +++ b/app/Console/Commands/V2/ProcessYDPortalDataV2Command.php @@ -44,24 +44,25 @@ class ProcessYDPortalDataV2Command extends Command $jobs = []; $jobs = array_merge($jobs, $this->fetchPackingListsFromYdPortalV2CommandJobs()); $jobs = array_merge($jobs, $this->fetchContainersFromYdPortalV2CommandJobs()); - $jobsWithDelay1 = $this->fetchContainersUpdatesFromYdPortalV2CommandJob(); - $jobsWithDelay2 = $this->fetchDeliveryUpdatesFromYdPortalV2CommandJobs(); + $jobs2 = $this->fetchContainersUpdatesFromYdPortalV2CommandJob(); + $jobs3 = $this->fetchDeliveryUpdatesFromYdPortalV2CommandJobs(); // The following job is intentionally excluded ////$jobs = array_merge($jobs, $this->fetchOrderListsFromYdPortalV2CommandJob()); // Bus::chain($jobs)->dispatch(); - foreach ($jobs as $job) { - dispatch($job); + foreach ($jobs as $index => $job) { + dispatch($job)->delay(now()->addSeconds($index * 2)); } - foreach ($jobsWithDelay1 as $index => $job) { + foreach ($jobs2 as $index => $job) { dispatch($job)->delay(now()->addSeconds($index * 1)); } - foreach ($jobsWithDelay2 as $index => $job) { - dispatch($job)->delay(now()->addSeconds($index * 1)); + foreach ($jobs3 as $index => $job) { + $delayInSeconds = intdiv($index, 2); + dispatch($job)->delay(now()->addSeconds($delayInSeconds)); } } @@ -146,7 +147,7 @@ class ProcessYDPortalDataV2Command extends Command $count = 0; foreach ($packingLists as $packingList) { - if ($count >= 500) { + if ($count >= 1000) { break; } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 52f80904..e2811174 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -34,6 +34,10 @@ class Kernel extends ConsoleKernel ->everyFiveMinutes() ->withoutOverlapping(); + $schedule->command('process-delayed-jobs-command') + ->everyFiveMinutes() + ->withoutOverlapping(); + $schedule->command('housekeeping-s3-files-command') ->dailyAt('01:00') ->withoutOverlapping(); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3d292064..ec4dba30 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -7,6 +7,7 @@ use App\Classes\ValueObjects\Response\ApiResponseObject; use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException; +use Illuminate\Support\Facades\Log; use Throwable; class Handler extends ExceptionHandler @@ -36,6 +37,13 @@ class Handler extends ExceptionHandler */ public function report(Throwable $exception) { + if (env('LOG_STACK_TRACE', false)) { + Log::error($exception->getMessage(), [ + 'exception' => $exception, + 'stack_trace' => $exception->getTraceAsString(), + ]); + } + parent::report($exception); } diff --git a/app/Http/Controllers/Orders/FetchOrderPackagesController.php b/app/Http/Controllers/Orders/FetchOrderPackagesController.php new file mode 100644 index 00000000..2902887b --- /dev/null +++ b/app/Http/Controllers/Orders/FetchOrderPackagesController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Resources/OrderPackagesBaseResource.php b/app/Http/Resources/OrderPackagesBaseResource.php new file mode 100644 index 00000000..099901d4 --- /dev/null +++ b/app/Http/Resources/OrderPackagesBaseResource.php @@ -0,0 +1,99 @@ +id; + + $origin_warehouse_packages = $this->originWarehousePackages()->get(); + foreach ($origin_warehouse_packages as $item) { + $item['include_shipping_transaction'] = false; + $item['include_suspended_invoice'] = false; + $item['include_packages'] = true; + $item['include_receive_packing_list'] = true; + $item['include_order_in_packages'] = true; + } + + $in_transit_packages = $this->inTransitPackages()->get(); + foreach ($in_transit_packages as $item) { + $item['include_shipping_transaction'] = false; + $item['include_suspended_invoice'] = false; + $item['include_packages'] = true; + $item['include_receive_packing_list'] = true; + $item['include_order_in_packages'] = true; + } + + $destination_warehouse_packages = $this->destinationWarehousePackages()->get(); + foreach ($destination_warehouse_packages as $item) { + $item['include_shipping_transaction'] = false; + $item['include_suspended_invoice'] = false; + $item['include_packages'] = true; + $item['include_receive_packing_list'] = true; + $item['include_order_in_packages'] = true; + } + + $delivered_packages = $this->deliveredPackages()->get(); + foreach ($delivered_packages as $item) { + $item['include_shipping_transaction'] = false; + $item['include_suspended_invoice'] = false; + $item['include_packages'] = true; + $item['include_receive_packing_list'] = true; + $item['include_order_in_packages'] = true; + } + + $received_packages = $this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get(); + foreach ($received_packages as $item) { + $item['include_shipping_transaction'] = false; + $item['include_suspended_invoice'] = false; + $item['include_packages'] = true; + $item['include_receive_packing_list'] = true; + $item['include_order_in_packages'] = true; + } + + + return [ + 'id' => $this->id, + 'reference' => $this->reference, + 'reference_contract' => (int) $this->type, + 'type' => (int) $this->type, + 'status' => (int) $this->status, + //'company_module' => new CompanyModuleResource($this->companyModule), + //'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee), + // 'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()), + // 'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()), + 'parcels' => $this->whenLoaded('packingLists', function() use ($origin_warehouse_packages, $in_transit_packages, $destination_warehouse_packages, $delivered_packages, $received_packages) { + return [ + 'origin_warehouse_packages' => PackingListBaseResource::collection($origin_warehouse_packages), + 'in_transit_packages' => PackingListBaseResource::collection($in_transit_packages), + 'destination_warehouse_packages' => PackingListBaseResource::collection($destination_warehouse_packages), + 'delivered_packages' => PackingListBaseResource::collection($delivered_packages), + 'received_packages' => PackingListBaseResource::collection($received_packages), + ]; + }), + // 'invoices' => $this->whenLoaded('packingLists', function() use ($orderId) { + // return TransactionResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get()); + // }), + //'remarks' => RemarkResource::collection($this->remarks), + 'created_at' => $this->created_at->format('d-m-Y') + ]; + + } +} diff --git a/app/Http/Resources/PackageBaseResource.php b/app/Http/Resources/PackageBaseResource.php index 19e4a159..5b1d14ff 100644 --- a/app/Http/Resources/PackageBaseResource.php +++ b/app/Http/Resources/PackageBaseResource.php @@ -16,7 +16,7 @@ class PackageBaseResource extends JsonResource */ public function toArray($request) { - return [ + $data = [ 'id' => $this->id, 'type' => $this->type, 'description' => $this->description, @@ -28,11 +28,15 @@ class PackageBaseResource extends JsonResource 'cbm' => (($this->width / 100) * ($this->height / 100) * ($this->length / 100)) * $this->quantity, 'reference' => $this->packingList->reference, 'status' => $this->status, - // $this->mergeWhen($originalPackingList->owner instanceof Order, [ - // 'order' => New OrderResource($originalPackingList->owner) - // ]), // 'container' => new ContainerResource($originalPackingList->containers()->first()), // 'transport' => new TransportResource($originalPackingList->transports()->first()) ]; + + if($this->include_order) { + $originalPackingList = $this->packingList->owner instanceof PackingList ? $this->packingList->owner : $this->packingList; + $data['order'] = new OrderResource($originalPackingList->owner); + } + + return $data; } } diff --git a/app/Http/Resources/PackingListBaseResource.php b/app/Http/Resources/PackingListBaseResource.php index 862bff62..f41905fe 100644 --- a/app/Http/Resources/PackingListBaseResource.php +++ b/app/Http/Resources/PackingListBaseResource.php @@ -25,12 +25,15 @@ class PackingListBaseResource extends JsonResource $receive_packing_list = null; if($this->include_packages){ $packages = !$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages; + foreach ($packages as $item) { + $item['include_order'] = $this->include_order_in_packages; + } } if($this->include_receive_packing_list){ $receive_packing_list = $this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first())); } - return [ + $data = [ 'id' => $this->id, 'claimant_id' => $this->claimant_id, 'reference' => $this->reference, @@ -43,9 +46,17 @@ class PackingListBaseResource extends JsonResource $this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]), - 'shipping_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()), - 'suspended_invoice' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()), // 'suspended_invoices' => TransactionResource::collection($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->get()), ]; + + if($this->include_shipping_transaction){ + $data['shipping_transaction'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()); + } + if($this->include_suspended_invoice){ + $data['suspended_invoice'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()); + } + + return $data; + } } diff --git a/app/Models/DelayedJob.php b/app/Models/DelayedJob.php new file mode 100644 index 00000000..7727c679 --- /dev/null +++ b/app/Models/DelayedJob.php @@ -0,0 +1,19 @@ +id(); + $table->string('job_class'); + $table->json('parameters'); + $table->timestamp('execute_at'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs_delayed'); + } +} diff --git a/resources/assets/vue/components/orders/sections/OrderPackageV2SectionComponent.vue b/resources/assets/vue/components/orders/sections/OrderPackageV2SectionComponent.vue index e4c7fe2d..7ee7c061 100644 --- a/resources/assets/vue/components/orders/sections/OrderPackageV2SectionComponent.vue +++ b/resources/assets/vue/components/orders/sections/OrderPackageV2SectionComponent.vue @@ -333,7 +333,7 @@ methods: { fetchCompany(){ this.isLoading = true; - this.submit(route('api.order.show', this.order_number), 'get', this.section, false, false) + this.submit(route('api.order.packages', this.order_number), 'get', this.section, false, false) }, successHandler(response){ this.dataLoaded = true; diff --git a/resources/assets/vue/components/paymentsBilling/sections/AdminPaymentsBillingSectionComponent.vue b/resources/assets/vue/components/paymentsBilling/sections/AdminPaymentsBillingSectionComponent.vue index a4e2ec89..0cbc46e3 100644 --- a/resources/assets/vue/components/paymentsBilling/sections/AdminPaymentsBillingSectionComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/sections/AdminPaymentsBillingSectionComponent.vue @@ -102,23 +102,23 @@
- +
- +
- +
- +
diff --git a/routes/order.php b/routes/order.php index 998ef517..27c67ec0 100644 --- a/routes/order.php +++ b/routes/order.php @@ -21,4 +21,5 @@ Route::group(['prefix' => 'order', 'as' => 'order.', 'namespace' => 'Orders'], f Route::put('/assign-remark/{id}', 'AssignOrderRemarkController@create')->name('assign.remark'); Route::get('/{id}/shipping-cost', 'ShippingCostController@calculate')->name('shipping.cost'); + Route::get('/packages/{id}', 'FetchOrderPackagesController@fetch')->name('packages'); });