diff --git a/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php b/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php index f885d5d2..296d3f52 100644 --- a/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php +++ b/app/Classes/Jobs/FetchContainersStatusUpdateFromVTPortalJob.php @@ -14,7 +14,7 @@ class FetchContainersStatusUpdateFromVTPortalJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 3600; + public $timeout = 900; /** * Execute the job. diff --git a/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php b/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php index 100fd52d..49005f3e 100644 --- a/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php +++ b/app/Classes/Jobs/FetchDeliveryListFromVTPortalJob.php @@ -15,7 +15,7 @@ class FetchDeliveryListFromVTPortalJob implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 3600; + public $timeout = 900; /** * Execute the job. diff --git a/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php b/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php index 4b128d8e..af8d51ea 100644 --- a/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php +++ b/app/Classes/Jobs/FetchLoadedContainersFromVTPortalJob.php @@ -16,7 +16,7 @@ class FetchLoadedContainersFromVTPortalJob implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 3600; + public $timeout = 300; /** * Execute the job. diff --git a/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php b/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php index 05888453..adaa9dc6 100644 --- a/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php +++ b/app/Classes/Jobs/FetchPackingListFromVTPortalJob.php @@ -15,7 +15,7 @@ class FetchPackingListFromVTPortalJob implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 3600; + public $timeout = 900; /** * Execute the job. diff --git a/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php b/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php index 757a899f..bc7083ff 100644 --- a/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php +++ b/app/Classes/Jobs/FetchWarehouseReceiveListFromVTPortalJob.php @@ -16,7 +16,7 @@ class FetchWarehouseReceiveListFromVTPortalJob implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 3600; + public $timeout = 300; /** * Execute the job. diff --git a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php index ddbcd01b..18599d95 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php @@ -30,6 +30,7 @@ use App\Models\Transport; use Carbon\Carbon; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class FetchContainersStatusUpdateFromVTPortalProcessor { @@ -68,68 +69,72 @@ class FetchContainersStatusUpdateFromVTPortalProcessor */ public function execute(){ - $containers = Container::where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get(); + try { + $containers = Container::where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get(); - /** @var Container $container */ - foreach($containers as $container){ - try { - $filter = '["RefNo:=%js%\"'.$container->reference.'\"\u0000"]'; + /** @var Container $container */ + foreach($containers as $container){ + try { + $filter = '["RefNo:=%js%\"'.$container->reference.'\"\u0000"]'; - $containerDetailsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); + $containerDetailsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); - $containerDetails = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailsRequest); + $containerDetails = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailsRequest); - $containerDetails = $containerDetails->Rows[0]; + $containerDetails = $containerDetails->Rows[0]; - if(!$eta = $containerDetails[3]){ + if(!$eta = $containerDetails[3]){ + continue; + } + + $eta = Carbon::parse($eta); + + $delayDate = $containerDetails[6]; + + $containerStatus = $containerDetails[9]; + + $unstuffingDate = $containerDetails[7]; + + $transport = $container->transports()->first(); + + if(!$transport){ + $transportObject = new TransportObject(TransportType::SEA, null, null, $eta, null, ApprovalStatus::APPROVED); + /** @var Transport $transport */ + $transport = $this->createsTransport->execute($transportObject, $container); + $this->createsSchedule->execute($transport, new ScheduleObject($eta->subDays(5), $eta, ApprovalStatus::APPROVED)); + } + + if($delayDate){ + $delayDate = Carbon::parse($delayDate); + $transport = $container->transports()->first(); + if(!$transport->schedules()->where('eta', '=', $delayDate)){ + $transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]); + } + + $this->createsSchedule->execute($transport, new ScheduleObject($delayDate->subDays(5), $delayDate, ApprovalStatus::APPROVED)); + } + + if($containerStatus === 'Unstuffing'){ + $container->update(['status' => ApprovalStatus::COMPLETED]); + $container->transports()->first()->update(['drop_date' => Carbon::parse($unstuffingDate)->subDay(), 'status' => ApprovalStatus::COMPLETED]); + $container->packingLists()->update(['status' => ApprovalStatus::APPROVED]); + /** @var PackingList $packingList */ + foreach($container->packingLists as $packingList){ + $signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture; + foreach($packingList->steps()->where('reference', '!=', 'DELIVERY')->get() as $step){ + $this->updatesContractObligations->execute($signature, $step->obligation_hash_id); + $step->update(['status' => ApprovalStatus::COMPLETED]); + } + } + } + + } catch (GuzzleException $exception) { continue; } - $eta = Carbon::parse($eta); - - $delayDate = $containerDetails[6]; - - $containerStatus = $containerDetails[9]; - - $unstuffingDate = $containerDetails[7]; - - $transport = $container->transports()->first(); - - if(!$transport){ - $transportObject = new TransportObject(TransportType::SEA, null, null, $eta, null, ApprovalStatus::APPROVED); - /** @var Transport $transport */ - $transport = $this->createsTransport->execute($transportObject, $container); - $this->createsSchedule->execute($transport, new ScheduleObject($eta->subDays(5), $eta, ApprovalStatus::APPROVED)); - } - - if($delayDate){ - $delayDate = Carbon::parse($delayDate); - $transport = $container->transports()->first(); - if(!$transport->schedules()->where('eta', '=', $delayDate)){ - $transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]); - } - - $this->createsSchedule->execute($transport, new ScheduleObject($delayDate->subDays(5), $delayDate, ApprovalStatus::APPROVED)); - } - - if($containerStatus === 'Unstuffing'){ - $container->update(['status' => ApprovalStatus::COMPLETED]); - $container->transports()->first()->update(['drop_date' => Carbon::parse($unstuffingDate)->subDay(), 'status' => ApprovalStatus::COMPLETED]); - $container->packingLists()->update(['status' => ApprovalStatus::APPROVED]); - /** @var PackingList $packingList */ - foreach($container->packingLists as $packingList){ - $signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture; - foreach($packingList->steps()->where('reference', '!=', 'DELIVERY')->get() as $step){ - $this->updatesContractObligations->execute($signature, $step->obligation_hash_id); - $step->update(['status' => ApprovalStatus::COMPLETED]); - } - } - } - - } catch (GuzzleException $exception) { - continue; } - + } catch (\Exception $exception) { + Log::error($exception); } return []; diff --git a/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php index ca3a83cc..6714472b 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php @@ -19,6 +19,7 @@ use App\Models\PackingList; use App\Models\Transport; use Carbon\Carbon; use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Support\Facades\Log; class FetchDeliveryListFromVTPortalProcessor { @@ -53,44 +54,47 @@ class FetchDeliveryListFromVTPortalProcessor /** * @return array - * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(){ - $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::APPROVED)->get(); + try { + $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::APPROVED)->get(); - /** @var PackingList $packingList */ - foreach($packingLists as $packingList){ - try { - $filter = '["PoNumber:=%js%\"'.$packingList->reference.'\"\u0000"]'; + /** @var PackingList $packingList */ + 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":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); + $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":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); + + $shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest); + + foreach($shippingPackingLists->Rows as $shippingPackingList){ + if(!$shippingPackingList[9] && !$shippingPackingList[10]) { + continue; + } + + $deliveryDate = Carbon::parse($shippingPackingList[9] ? $shippingPackingList[9]:$shippingPackingList[10]); + $transportObject = new TransportObject(TransportType::LAND, null, null, $deliveryDate, $deliveryDate, ApprovalStatus::APPROVED); + /** @var Transport $transport */ + $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]); - $shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest); - foreach($shippingPackingLists->Rows as $shippingPackingList){ - if(!$shippingPackingList[9]) { - continue; } - $deliveryDate = Carbon::parse($shippingPackingList[9]); - $transportObject = new TransportObject(TransportType::LAND, null, null, $deliveryDate, $deliveryDate, ApprovalStatus::APPROVED); - /** @var Transport $transport */ - $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; } - } catch (GuzzleException $exception) { - continue; } - + } catch (\Exception $exception){ + Log::error($exception); } return []; diff --git a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php index 25eca299..2776124d 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php @@ -28,6 +28,7 @@ use App\Models\PackingList; use Carbon\Carbon; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class FetchLoadedContainersFromVTPortalProcessor { @@ -120,102 +121,103 @@ class FetchLoadedContainersFromVTPortalProcessor * @param Carbon|null $end * @return array * @throws GuzzleException - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException */ public function execute(?Carbon $start = null, ?Carbon $end = null){ DB::beginTransaction(); - $start = $start ? $start : Carbon::now()->subMonth(); + try { + $start = $start ? $start : Carbon::now()->subMonth(); - $startLimit = Carbon::parse('11-08-2021'); + $startLimit = Carbon::parse('11-08-2021'); - if($start->isBefore($startLimit)){ - $start = $startLimit; - } - - $end = $end ? $end : Carbon::now(); - $filter = '["LoadedTime:$between$%js%\"'.$start->format('Y-m-d').'T00:00:00.000\"$and$%js%\"'.$end->format('Y-m-d').'T00:00:00.000\"\u0000"]'; - - $containersRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); - - $containers = $this->fetchesDataFRomVTPortal->getResponseBody($containersRequest); - - foreach ($containers->Rows as $container){ - - $filter = '["ContainerID:=%js%'.$container[11].'"]'; - $containerDetailRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); - - $containerDetail = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailRequest); - - $containerObject = new ContainerObject($container[0], str_replace(' ', '', $container[24]), str_replace(' ', '', $container[15]), ContainerTypes::FORTY_FEET_DRY_CONTAINER, ApprovalStatus::PENDING_VERIFICATION); - - try { - $container = $this->fetchesContainer->execute(['reference' => $containerObject->getReference()]); - } catch (ResourceNotFoundException $exception){ - $warehouseId = $container[12]; - $originWarehouse = $this->fetchesCompanyModule->execute(['id' => $warehouseId === 11 ? 3 : 4]); - $container = $this->createContainerProcessor->execute($containerObject, $originWarehouse); + if($start->isBefore($startLimit)){ + $start = $startLimit; } - foreach($containerDetail->Rows as $packingList){ - $marking = explode('/', explode('CIEF/', $packingList[13])[1]); + $end = $end ? $end : Carbon::now(); + $filter = '["LoadedTime:$between$%js%\"'.$start->format('Y-m-d').'T00:00:00.000\"$and$%js%\"'.$end->format('Y-m-d').'T00:00:00.000\"\u0000"]'; - if(!array_key_exists(1, $marking)){ - continue; - } + $containersRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); - $orderNumber = $marking[1]; + $containers = $this->fetchesDataFRomVTPortal->getResponseBody($containersRequest); - if(!$packingList[22]){ - continue; - } + foreach ($containers->Rows as $container){ + + $filter = '["ContainerID:=%js%'.$container[11].'"]'; + $containerDetailRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); + + $containerDetail = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailRequest); + + $containerObject = new ContainerObject($container[0], str_replace(' ', '', $container[24]), str_replace(' ', '', $container[15]), ContainerTypes::FORTY_FEET_DRY_CONTAINER, ApprovalStatus::PENDING_VERIFICATION); try { - /** @var Order $order */ - $order = $this->fetchesOrder->execute(['reference' => $orderNumber]); + $container = $this->fetchesContainer->execute(['reference' => $containerObject->getReference()]); } catch (ResourceNotFoundException $exception){ - continue; + $warehouseId = $container[12]; + $originWarehouse = $this->fetchesCompanyModule->execute(['id' => $warehouseId === 11 ? 3 : 4]); + $container = $this->createContainerProcessor->execute($containerObject, $originWarehouse); } - $packingListReference = $packingList[16]; + foreach($containerDetail->Rows as $packingList){ + $marking = explode('/', explode('CIEF/', $packingList[13])[1]); - try{ - $this->fetchesPackingList->execute(['reference' => $packingListReference]); - } catch (ResourceNotFoundException $exception){ - $contract = $this->unityCreateContract->execute(); - $contractReference = $contract->hash_id; - $contractObligations = $contract->contract_obligation_list; - - $this->unityActivateContract->execute($contractReference); - - $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; - - $supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId); - $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]); - - $importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id); - $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]); - - $this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations); - - $packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION, $contractReference); - - /** @var PackingList $packingList */ - $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); - $container->packingLists()->attach($packingList); - - foreach($contractObligations as $obligation) { - $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); - $this->createsStep->execute($packingList, $stepObject); + if(!array_key_exists(1, $marking)){ + continue; } + $orderNumber = $marking[1]; + + if(!$packingList[22]){ + continue; + } + + try { + /** @var Order $order */ + $order = $this->fetchesOrder->execute(['reference' => $orderNumber]); + } catch (ResourceNotFoundException $exception){ + continue; + } + + $packingListReference = $packingList[16]; + + try{ + $this->fetchesPackingList->execute(['reference' => $packingListReference]); + } catch (ResourceNotFoundException $exception){ + $contract = $this->unityCreateContract->execute(); + $contractReference = $contract->hash_id; + $contractObligations = $contract->contract_obligation_list; + + $this->unityActivateContract->execute($contractReference); + + $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; + + $supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId); + $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]); + + $importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id); + $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]); + + $this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations); + + $packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION, $contractReference); + + /** @var PackingList $packingList */ + $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); + $container->packingLists()->attach($packingList); + + foreach($contractObligations as $obligation) { + $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); + $this->createsStep->execute($packingList, $stepObject); + } + + + } } } - + } catch (\Exception $exception){ + Log::error($exception); } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php index ec896e5c..d163fdb7 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php @@ -10,6 +10,7 @@ use App\Classes\ValueObjects\Constants\PackageType; use App\Classes\ValueObjects\Constants\PackingListType; use App\Models\PackingList; use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Support\Facades\Log; class FetchPackingListFromVTPortalProcessor { @@ -39,38 +40,41 @@ class FetchPackingListFromVTPortalProcessor /** * @return array - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\RequestValidationException */ public function execute(){ - $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get(); + try { + $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get(); - foreach($packingLists as $packingList){ - try { - $filter = '["PoNumber:=%js%\"'.$packingList->reference.'\"\u0000"]'; + 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":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); + $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":"ModifiedOn DESC","Filter":'.$filter.'}}'), ''); - $shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest); + $shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest); - $packingList->packages()->delete(); + $packingList->packages()->delete(); + + foreach($shippingPackingLists->Rows as $shippingPackingList){ + if(!$shippingPackingList[22]) { + continue; + } + + $packageObject = new PackageObject(PackageType::CARTON, $shippingPackingList[19], $shippingPackingList[31], $shippingPackingList[30], $shippingPackingList[29], 0, $shippingPackingList[22], ApprovalStatus::APPROVED); + $this->createPackageProcessor->execute($packageObject, $packingList); - foreach($shippingPackingLists->Rows as $shippingPackingList){ - if(!$shippingPackingList[22]) { - continue; } - - $packageObject = new PackageObject(PackageType::CARTON, $shippingPackingList[43] ? $shippingPackingList[43] : $shippingPackingList[19], $shippingPackingList[31], $shippingPackingList[30], $shippingPackingList[29], 0, $shippingPackingList[22], ApprovalStatus::APPROVED); - $this->createPackageProcessor->execute($packageObject, $packingList); - + } catch (GuzzleException $exception) { + continue; } - } catch (GuzzleException $exception) { - continue; - } + } + } catch (\Exception $exception) { + Log::error($exception); } + return []; } diff --git a/database/seeders/OrdersTableSeeder.php b/database/seeders/OrdersTableSeeder.php index c9fb6667..0e881591 100644 --- a/database/seeders/OrdersTableSeeder.php +++ b/database/seeders/OrdersTableSeeder.php @@ -21,11 +21,12 @@ class OrdersTableSeeder extends Seeder */ public function run() { - FetchWarehouseReceiveListFromVTPortalJob::dispatch(); - FetchLoadedContainersFromVTPortalJob::dispatch()->delay(now()->addMinutes(5)); - FetchPackingListFromVTPortalJob::dispatch()->delay(now()->addMinutes(10)); - FetchContainersStatusUpdateFromVTPortalJob::dispatch()->delay(now()->addMinutes(15)); - FetchDeliveryListFromVTPortalJob::dispatch()->delay(now()->addMinutes(20)); + FetchWarehouseReceiveListFromVTPortalJob::withChain([ + new FetchLoadedContainersFromVTPortalJob, + new FetchPackingListFromVTPortalJob, + new FetchContainersStatusUpdateFromVTPortalJob, + new FetchDeliveryListFromVTPortalJob + ])->dispatch(); } }