diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php new file mode 100644 index 00000000..15b852f6 --- /dev/null +++ b/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php @@ -0,0 +1,147 @@ + 'Assign Packing List Order', + 'message' => 'You have successfully created a Packing List Order' + ]; + } + + /** @var FetchesPackingList */ + private $fetchesPackingList; + + + /** @var FetchesOrder */ + private $fetchesOrder; + + /** @var UpdatesPackingListOwner */ + private $updatesPackingListOwner; + + /** @var UpdatesTransportStatus */ + private $updatesTransportStatus; + + /** @var CreatesContract */ + private $unityCreateContract; + + /** @var ActivateContractProcessor */ + private $unityActivateContract; + + /** @var CreateContractEntityProcessor */ + private $unityCreateContractEntity; + + /** @var AssignContractEntityProcessor */ + private $unityAssignContractEntity; + + /** @var UpdatesPackingListContractReference */ + private $updatesPackingListContractReference; + + /** @var CreatesStep */ + private $createsStep; + + /** + * CreateRemarkLogic constructor. + * @param CanCreateRemark $canCreateRemark + * @param CreatesPackingListRemark $createsPackingListRemark + */ + public function __construct(FetchesPackingList $fetchesPackingList, FetchesOrder $fetchesOrder, UpdatesPackingListOwner $updatesPackingListOwner, UpdatesTransportStatus $updatesTransportStatus, CreatesContract $unityCreateContract, ActivateContractProcessor $unityActivateContract, CreateContractEntityProcessor $unityCreateContractEntity, AssignContractEntityProcessor $unityAssignContractEntity, UpdatesPackingListContractReference $updatesPackingListContractReference, CreatesStep $createsStep) + { + $this->fetchesPackingList = $fetchesPackingList; + $this->fetchesOrder = $fetchesOrder; + $this->updatesPackingListOwner = $updatesPackingListOwner; + $this->updatesTransportStatus = $updatesTransportStatus; + + $this->unityCreateContract = $unityCreateContract; + $this->unityActivateContract = $unityActivateContract; + $this->unityCreateContractEntity = $unityCreateContractEntity; + $this->unityAssignContractEntity = $unityAssignContractEntity; + + $this->updatesPackingListContractReference = $updatesPackingListContractReference; + $this->createsStep = $createsStep; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $warehouse_packing_list = $this->fetchesPackingList->execute([ + 'id' => $request->route('id'), + 'type' => PackingListType::WAREHOUSE_RECEIVE_LIST, + 'status' => ApprovalStatus::REJECTED + ]); + + $order = $this->fetchesOrder->execute(['id' => $request->input('order_id')]); + + $warehouse_packing_list = $this->updatesPackingListOwner->execute($warehouse_packing_list, $order); + + + $transport = $warehouse_packing_list->transports()->first(); + $transport = $this->updatesTransportStatus->execute($transport, ApprovalStatus::APPROVED); + + $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); + + $packing_list = $this->fetchesPackingList->execute([ + 'reference' => $warehouse_packing_list->reference, + 'type' => PackingListType::SHIPPING_PACKING_LIST, + 'status' => ApprovalStatus::PENDING_VERIFICATION + ]); + + $packing_list = $this->updatesPackingListContractReference->execute($packing_list, $contractReference); + + 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($packing_list, $stepObject); + } + + return $this->resourceResponse(new PackingListResource($warehouse_packing_list)); + } +} diff --git a/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php b/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php index 13e4a83b..e1d112ed 100644 --- a/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php @@ -49,7 +49,7 @@ class CreatePackageProcessor if($replica) { $modificationValue = 1; $packageObject = new PackageObject($object->getType(), $object->getDescription(), $object->getWidth() + $modificationValue, $object->getHeight() + $modificationValue, $object->getLength() + $modificationValue, $object->getWeight(), $object->getQuantity(), $object->getStatus()); - $this->createsPackage->execute($packageObject, $replica); + $package = $this->createsPackage->execute($packageObject, $replica); } return ; diff --git a/app/Classes/Modules/PackingLists/Processors/CreatePackingListProcessor.php b/app/Classes/Modules/PackingLists/Processors/CreatePackingListProcessor.php index 3e2a861d..f0eda0cb 100644 --- a/app/Classes/Modules/PackingLists/Processors/CreatePackingListProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/CreatePackingListProcessor.php @@ -48,11 +48,13 @@ class CreatePackingListProcessor /** @var PackingList $packingList */ $packingList = $this->createsPackingList->execute($object, $packable); + $appointee_id = $packingList->owner_id == 1 ? 2037 : $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id; + $type = $object->getType() === PackingListType::SHIPPING_PACKING_LIST ? PackingListType::SHIPPING_PACKING_LIST_REPLICA : PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA; /** create packing list replica */ - $object = new PackingListObject($object->getReference().'_01', $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, $type, ApprovalStatus::PENDING_SUBMISSION); + $object = new PackingListObject($object->getReference().'_01', $appointee_id, $type, ApprovalStatus::PENDING_SUBMISSION); $this->createsPackingList->execute($object, $packingList); - + return $packingList; } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php index 4ed615eb..e1ab37d8 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php @@ -7,6 +7,7 @@ use App\Classes\Modules\Companies\Services\FetchesCompanyModule; use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal; use App\Classes\Modules\Orders\Services\FetchesOrder; + use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject; use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject; use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject; @@ -134,7 +135,6 @@ class FetchOrderListsFromYdPortalProcessor */ public function execute(?Carbon $start = null, ?Carbon $end = null) { - try { $start = $start ? $start : Carbon::now()->subMonths(2); @@ -152,7 +152,7 @@ class FetchOrderListsFromYdPortalProcessor ]); $rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest); - + foreach($rows->data as $row){ DB::beginTransaction(); @@ -195,60 +195,72 @@ class FetchOrderListsFromYdPortalProcessor $orderNumber = $customerno[2]; - + $allow_contract = true; try { $order = $this->fetchesOrder->execute(['reference' => $orderNumber]); } catch (ResourceNotFoundException $exception) { - continue; + $order = $this->fetchesCompanyModule->execute(['id' => 1]); + $allow_contract = false; } - $packingListReference = $row->expressno; try{ - $packingList = $this->fetchesPackingList->execute(['reference' => $row->expressno]); + $packingList = $this->fetchesPackingList->execute(['reference' => 123]); } catch (ResourceNotFoundException $exception){ + $appointee_id = !$allow_contract ? 2037 : $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id; + $warehouseReceiveObject = new PackingListObject($packingListReference, $appointee_id, PackingListType::WAREHOUSE_RECEIVE_LIST, $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); - $warehouseReceiveObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST, ApprovalStatus::APPROVED); /** @var PackingList $warehouseReceiveList */ $warehouseReceiveList = $this->createPackingListProcessor->execute($warehouseReceiveObject, $order); - $transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED); - $this->createsTransport->execute($transportObject, $warehouseReceiveList); - $contract = $this->unityCreateContract->execute(); + $transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + $transport = $this->createsTransport->execute($transportObject, $warehouseReceiveList); - $contractReference = $contract->hash_id; - $contractObligations = $contract->contract_obligation_list; + if ($allow_contract) { - $this->unityActivateContract->execute($contractReference); + $contract = $this->unityCreateContract->execute(); - $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; + $contractReference = $contract->hash_id; + $contractObligations = $contract->contract_obligation_list; - $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]); + $this->unityActivateContract->execute($contractReference); - $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]); + $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; - $this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations); + $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]); - $packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION , $contractReference); + $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, $appointee_id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION , !$allow_contract ? null : $contractReference); /** @var PackingList $packingList */ $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); - 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 ($allow_contract) { + 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); + } } foreach($row->deliverysize as $package) { - $packageObject = new PackageObject(PackageType::CARTON, $row->goodname, (float) $package->width, (float) $package->height, (float) $package->length, 0, (float) $package->num, ApprovalStatus::APPROVED); - $this->createPackageProcessor->execute($packageObject, $warehouseReceiveList); - $this->createPackageProcessor->execute($packageObject, $packingList); + $packageObject = new PackageObject(PackageType::CARTON, $row->goodname, (float) $package->width, (float) $package->height, (float) $package->length, 0, (float) $package->num, $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + + $package = $this->createPackageProcessor->execute($packageObject, $warehouseReceiveList); + + dd($packageObject); + $package = $this->createPackageProcessor->execute($packageObject, $packingList); } } + dd($row->deliverysize, 'yesss'); + if($containerReference) { try { $container = $this->fetchesContainer->execute(['reference' => $containerReference]); @@ -289,13 +301,12 @@ class FetchOrderListsFromYdPortalProcessor } } } - - } DB::commit(); - dump('added'); + dd('here'); + dump('added'); } } catch (\Exception $exception) { Log::debug($exception); diff --git a/app/Classes/Modules/PackingLists/Services/CreatesNullOrderPackingList.php b/app/Classes/Modules/PackingLists/Services/CreatesNullOrderPackingList.php new file mode 100644 index 00000000..fd955d44 --- /dev/null +++ b/app/Classes/Modules/PackingLists/Services/CreatesNullOrderPackingList.php @@ -0,0 +1,31 @@ +reference = $object->getReference(); + $model->claimant_id = $object->getClaimantId(); + $model->type = $object->getType(); + $model->status = $object->getStatus(); + $model->reference_contract = $object->getContractReference(); + $model->owner_type = 'App\Models\Order'; + $model->owner_id = 1; + + return $this->handler($model); + } +} diff --git a/app/Classes/Modules/PackingLists/Services/UpdatesPackingListContractReference.php b/app/Classes/Modules/PackingLists/Services/UpdatesPackingListContractReference.php new file mode 100644 index 00000000..dba4dfb3 --- /dev/null +++ b/app/Classes/Modules/PackingLists/Services/UpdatesPackingListContractReference.php @@ -0,0 +1,24 @@ +reference_contract = $reference_contract; + + return $this->handler($model); + + } +} diff --git a/app/Classes/Modules/PackingLists/Services/UpdatesPackingListOwner.php b/app/Classes/Modules/PackingLists/Services/UpdatesPackingListOwner.php new file mode 100644 index 00000000..4a6b6dfb --- /dev/null +++ b/app/Classes/Modules/PackingLists/Services/UpdatesPackingListOwner.php @@ -0,0 +1,26 @@ +status = ApprovalStatus::APPROVED; + + return $this->handler($packable->packingLists(), $model); + + } +} diff --git a/app/Classes/Modules/Transports/Services/UpdatesTransportStatus.php b/app/Classes/Modules/Transports/Services/UpdatesTransportStatus.php new file mode 100644 index 00000000..2898156a --- /dev/null +++ b/app/Classes/Modules/Transports/Services/UpdatesTransportStatus.php @@ -0,0 +1,24 @@ +status = $status; + + return $this->handler($model); + + } +} diff --git a/app/Http/Controllers/PackingLists/AssignPackingListOrderController.php b/app/Http/Controllers/PackingLists/AssignPackingListOrderController.php new file mode 100644 index 00000000..7498d863 --- /dev/null +++ b/app/Http/Controllers/PackingLists/AssignPackingListOrderController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} diff --git a/routes/packing_list.php b/routes/packing_list.php index 6716ada9..475613dd 100644 --- a/routes/packing_list.php +++ b/routes/packing_list.php @@ -17,6 +17,8 @@ Route::group(['namespace' => 'PackingLists', 'as' => 'packing_list.', 'prefix' = Route::put('/update-drop-date/{id}', 'UpdateDropDatePackingListController@update')->name('update_drop_date'); Route::put('/complete/{id}', 'CompletePackingListController@complete')->name('complete'); Route::put('/assign-remark/{id}', 'AssignPackingListRemarkController@create')->name('assign.remark'); + Route::put('/assign-order/{id}', 'AssignPackingListOrderController@assign')->name('assign.order'); + Route::group(['namespace' => 'Containers', 'prefix' => 'container', 'as' => 'container.'], function () { Route::get('/{id}/show', 'FetchContainerController@fetch')->name('show');