From 2ae879fd512e6612a4d1553784b9c71319ad5867 Mon Sep 17 00:00:00 2001 From: Fairuz Date: Wed, 29 Sep 2021 04:38:41 +0800 Subject: [PATCH] Inbound custom cleared --- .../Containers/InboundCustomClearedLogic.php | 7 +-- .../FetchInboundCustomClearedProcessor.php | 56 +++++-------------- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php index 1df92ffa..08af0bb7 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php @@ -54,13 +54,10 @@ class InboundCustomClearedLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - //$this->canListOrders->passes(); - //$query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true])); + $query = $this->fetchInboundCustomCleared->execute(); - $d = $this->fetchInboundCustomCleared->execute(); - - return response()->json($d); + return $this->collectionResponse(ContainerResource::collection($query)); } } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchInboundCustomClearedProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchInboundCustomClearedProcessor.php index b4ea6395..f5002532 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchInboundCustomClearedProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchInboundCustomClearedProcessor.php @@ -55,49 +55,23 @@ class FetchInboundCustomClearedProcessor */ public function execute(){ - $packingLists = PackingList::query()->with(['steps' => function ($query) { + $packingLists = PackingList::query()->with(['steps' => function ($query) { $query->where('steps.status', '<>', 3); - }])->first(); - dd($packingLists); - /* - $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST) - ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::SUSPENDED])->get(); + }]) + ->where('type', PackingListType::SHIPPING_PACKING_LIST) + ->whereHas('containers', function($query) { + return $query->whereHas('transports', function($query){ + return $query->where('type', '=', TransportType::SEA)->where('status', '=', ApprovalStatus::COMPLETED)->whereHas('schedules', function($query){ + return $query->where('etd', '<', Carbon::now()); + }); + }); + })->whereDoesntHave('transports', function($query){ + return $query->where('type', '=', TransportType::LAND)->where('status', '=', ApprovalStatus::APPROVED)->whereHas('schedules', function($query){ + return $query->where('etd', '<', Carbon::now()); + }); + })->get(); - foreach($packingLists as $packingList){ - try { - $filter = '["PoNumber:=%js%\"'.$packingList->reference.'\"\u0000"]'; - - $shippingPackingListsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"CreatedOn asc","Filter":'.$filter.'}}'), ''); - - $shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest); - - $shippingPackingList = $shippingPackingLists->Rows[0]; - - if(!$shippingPackingList[9] && !$shippingPackingList[10]) { - continue; - } - - $packingList->status = ApprovalStatus::COMPLETED; - $packingList->save(); - - $deliveryDate = Carbon::parse($shippingPackingList[9] ? $shippingPackingList[9]:$shippingPackingList[10]); - $transportObject = new TransportObject(TransportType::LAND, null, null, $deliveryDate, $deliveryDate, ApprovalStatus::APPROVED); - $transport = $this->createsTransport->execute($transportObject, $packingList); - $this->createsSchedule->execute($transport, new ScheduleObject($deliveryDate, $deliveryDate, ApprovalStatus::APPROVED)); - - $deliveryStep = $packingList->steps()->where('reference', '=', 'LAST_MILE_DELIVERY')->first(); - $signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture; - $this->updatesContractObligations->execute($signature, $deliveryStep->obligation_hash_id); - $deliveryStep->update(['status' => ApprovalStatus::COMPLETED]); - - } catch (GuzzleException $exception) { - continue; - } - - }*/ - - - return []; + return $packingLists ; }