diff --git a/app/Classes/Modules/Exports/Services/ExportsContainerPackingList.php b/app/Classes/Modules/Exports/Services/ExportsContainerPackingList.php new file mode 100644 index 00000000..2371962b --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsContainerPackingList.php @@ -0,0 +1,92 @@ +id = $id; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + return Container::find($this->id)->packingLists(); + } + + /** + * @param Company $container + * + * @return array + */ + public function map($packing_list): array + { + $order = $packing_list->owner()->first(); + $address = $order->addresses()->first(); + $company = $order->companyModule()->first(); + $connection = $company->inviters()->withPivot('invitee_reference')->first(); + $marking = $connection ? $connection->pivot->invitee_reference:''; + + $quantity = 0; + $cbm = 0; + foreach ($packing_list->packages()->get() as $key => $row) { + $quantity += $row->quantity; + $cbm += (($row->width / 100) * ($row->height / 100) * ($row->length / 100)) * $row->quantity; + } + + $status = ''; + if ($packing_list->transports()->count() > 0) { + $status = 'Delivery'; + } + elseif ($packing_list->status == ApprovalStatus::SUSPENDED) { + $status = 'On Hold'; + } + elseif ($packing_list->status != ApprovalStatus::SUSPENDED) { + $status = 'Release'; + } + + return [ + $marking, + $order->reference, + $quantity, + $cbm, + $status, + $address->contacts()->first() ? $address->contacts()->first()->phone : 'n/a', + $address->contacts()->first() ? $address->contacts()->first()->reference : 'n/a', + $address->street_one . ' ' . $address->street_two . ' ' . $address->district->name . ' ' . $address->post_code . ' ' . $address->state->name . ' ' . $address->country->name, + $address->remarks()->first() ? $address->remarks()->first()->content : 'n/a', + $packing_list->transports()->first() ? $packing_list->transports()->current_schedule->eta : 'n/a' + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Orders/Processors/ApproveChangeOrderAddressProcessor.php b/app/Classes/Modules/Orders/Processors/ApproveChangeOrderAddressProcessor.php index c7d17487..b53b6643 100644 --- a/app/Classes/Modules/Orders/Processors/ApproveChangeOrderAddressProcessor.php +++ b/app/Classes/Modules/Orders/Processors/ApproveChangeOrderAddressProcessor.php @@ -6,7 +6,9 @@ use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Orders\Standards\Rules\CanApproveChangeOrderAddress; use App\Classes\Modules\Orders\Services\UpdatesOrdersAddress; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\OrderRoleTypes; use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor; +use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor; use Illuminate\Http\Request; @@ -27,12 +29,13 @@ class ApproveChangeOrderAddressProcessor * @param FetchesAddress $fetchesAddress * @param UpdatesOrdersAddress $updatesOrdersAddress */ - public function __construct(CanApproveChangeOrderAddress $canApproveChangeOrderAddress, FetchesAddress $fetchesAddress, UpdatesOrdersAddress $updatesOrdersAddress, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor) + public function __construct(CanApproveChangeOrderAddress $canApproveChangeOrderAddress, FetchesAddress $fetchesAddress, UpdatesOrdersAddress $updatesOrdersAddress, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) { $this->canApproveChangeOrderAddress = $canApproveChangeOrderAddress; $this->fetchesAddress = $fetchesAddress; $this->updatesOrdersAddress = $updatesOrdersAddress; $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; + $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; } @@ -55,7 +58,14 @@ class ApproveChangeOrderAddressProcessor if($status === ApprovalStatus::APPROVED){ $address->owner->addresses()->update(['status' => ApprovalStatus::EXPIRED]); - $this->updateDoFromVTPortalProcessor->execute($address); + + $appointee = $address->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id; + if ($appointee == 2 ) { + $this->updateDoFromYDPortalProcessor->execute($address); + } + elseif ($appointee == 2302 ) { + $this->updateDoFromVTPortalProcessor->execute($address); + } } $address = $this->updatesOrdersAddress->execute($address, $status); diff --git a/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php b/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php new file mode 100644 index 00000000..ca0ced31 --- /dev/null +++ b/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php @@ -0,0 +1,85 @@ +fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal; + $this->fetchesAddress = $fetchesAddress; + } + + /** + * @param $address + * @return array + * @throws GuzzleException + * @throws InternalServerErrorException + */ + public function execute($address) { + try { + $order = $address->owner()->orderBy('id', 'desc')->first(); + $packing_list = $order->packingLists() + ->where('type', PackingListType::SHIPPING_PACKING_LIST) + ->where('status', '!=', ApprovalStatus::SUSPENDED) + ->orderBy('id', 'desc')->get(); + + foreach ($packing_list as $key => $row) { + $contact = $address->contacts()->first(); + $remark = $address->remarks()->first(); + + $remark = $remark ? $remark->content : 'URGENT!!! PLEASE CALL BEFORE ONE DAY DELIVERY.'; + $phone = $contact ? $contact->phone : null; + $reference = $contact ? $contact->reference : null; + + $yd_do_update = $this->fetchesDataFRomYDPortal->clientRequest( + 'http://www.yd-wl.com/api/UpdateOrderAddress.ashx', + 'POST', + [ + 'expressno' => $row->reference, + 'customers_name' => $reference, + 'cellphone' => $phone, + 'postcode' => $address->postcode, + 'streetAddress' => $address->street_one . ' ' . $address->street_two . ' '. $address->district->name.' '. $address->post_code.' '.$address->state->name.' '.$address->country->name + + ], ''); + $yd_do_update = $this->fetchesDataFRomYDPortal->getResponseBody($yd_do_update); + } + + } catch (\Exception $exception){ + throw new InternalServerErrorException('failed to approve address due to an error related to VT portal'); + } + } +} 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/ControllersLogic/ListPackingListsLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php index a1e485ce..7d4a9531 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/ListPackingListsLogic.php @@ -6,6 +6,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\ListsPackingLists; use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists; +use App\Http\Resources\PackingListNullOrderResource; use App\Http\Resources\PackingListResource; use ErrorException; use Illuminate\Http\JsonResponse; @@ -55,7 +56,12 @@ class ListPackingListsLogic extends AbstractControllerLogic $query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters'))); - return $this->collectionResponse(PackingListResource::collection($query)); + if ($request->input('null_order')) { + return $this->collectionResponse(PackingListNullOrderResource::collection($query)); + } + else { + return $this->collectionResponse(PackingListResource::collection($query)); + } } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/UpdatePackingListStatusLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/UpdatePackingListStatusLogic.php index 9bf1735a..13141435 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/UpdatePackingListStatusLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/UpdatePackingListStatusLogic.php @@ -10,6 +10,7 @@ use App\Classes\Modules\PackingLists\Services\UpdatesPackingListStatus; use App\Classes\Modules\PackingLists\Standards\Rules\CanUpdatePackingList; use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject; use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor; +use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor; use App\Http\Resources\PackingListResource; use ErrorException; use Illuminate\Http\JsonResponse; @@ -38,16 +39,20 @@ class UpdatePackingListStatusLogic extends AbstractControllerLogic /** @var UpdateDoFromVTPortalProcessor */ private $updateDoFromVTPortalProcessor; + /** @var UpdateDoFromYDPortalProcessor */ + private $updateDoFromYDPortalProcessor; + /** * UpdatePackingListStatusLogic constructor. * @param FetchesPackingList $fetchesPackingList * @param UpdatesPackingListStatus $updatesPackingListStatus */ - public function __construct(FetchesPackingList $fetchesPackingList, UpdatesPackingListStatus $updatesPackingListStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor) + public function __construct(FetchesPackingList $fetchesPackingList, UpdatesPackingListStatus $updatesPackingListStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) { $this->fetchesPackingList = $fetchesPackingList; $this->updatesPackingListStatus = $updatesPackingListStatus; $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; + $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; } /** @@ -64,7 +69,14 @@ class UpdatePackingListStatusLogic extends AbstractControllerLogic $packing_list = $this->updatesPackingListStatus->execute($packingList, $request->route('status')); $address = $packing_list->owner()->first()->addresses()->first(); - $this->updateDoFromVTPortalProcessor->execute($address); + $appointee = $address->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id; + + if ($appointee == 2 ) { + $this->updateDoFromYDPortalProcessor->execute($address); + } + elseif ($appointee == 2302 ) { + $this->updateDoFromVTPortalProcessor->execute($address); + } return $this->resourceResponse(new PackingListResource($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/FetchContainersStatusUpdateFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php index d1e69706..b1daeeb9 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php @@ -83,6 +83,7 @@ class FetchContainersStatusUpdateFromVTPortalProcessor if(!$containerDetails->Rows){ continue; } + $containerDetails = $containerDetails->Rows[0]; if(!$eta = $containerDetails[3]){ diff --git a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php index a95afb3d..4094cedc 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; @@ -30,11 +31,11 @@ use App\Classes\ValueObjects\Constants\PackageType; use App\Classes\ValueObjects\Constants\PackingListType; use App\Classes\ValueObjects\Constants\TransportType; use App\Models\Container; -use App\Models\Order; use App\Models\PackingList; use App\Models\Transport; use Carbon\Carbon; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class FetchOrderListsFromYdPortalProcessor { @@ -130,172 +131,198 @@ class FetchOrderListsFromYdPortalProcessor * @param Carbon|null $start * @param Carbon|null $end * @return void - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException * @throws \GuzzleHttp\Exception\GuzzleException */ public function execute(?Carbon $start = null, ?Carbon $end = null) { - db::beginTransaction(); + try { + $start = $start ? $start : Carbon::now()->subMonths(2); - $start = $start ? $start : Carbon::now()->subMonths(2); + $startLimit = Carbon::parse('01-12-2021'); - $startLimit = Carbon::parse('01-12-2021'); + if($start->isBefore($startLimit)){ + $start = $startLimit; + } - if($start->isBefore($startLimit)){ - $start = $startLimit; - } + $end = $end ? $end : Carbon::now(); - $end = $end ? $end : Carbon::now(); - - $orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [ - 'begintime' => $start->timestamp, - 'endtime' => $end->timestamp, - ]); - - $rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest); - - foreach($rows->data as $row){ - $containerReference = null; - $loadingDate = null; - $unstuffingDate = null; - $etd = null; - $eta = null; - - $trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [ - 'trakingno' => $row->expressno + $orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [ + 'begintime' => $start->timestamp, + 'endtime' => $end->timestamp, ]); - $rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest); - foreach ($rows->data as $trackingRow) { - if($trackingRow->tracking === '货物已送达仓库准备入库中'){ - $receiveDate = Carbon::parse($trackingRow->trackingtime); - } - if (strpos($trackingRow->tracking, '货物装柜完成。') !== false) { - $tracking = explode(':', $trackingRow->tracking); - $containerReference = explode('预计到港时间', $tracking[1])[0]; - $loadingDate = Carbon::parse($trackingRow->trackingtime); - $etd = Carbon::parse($tracking[2])->subDays(5); - $eta = Carbon::parse($tracking[2]); - } + $rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest); + + foreach($rows->data as $row){ + DB::beginTransaction(); - if($trackingRow->tracking === '货物已进目的港仓库'){ - $unstuffingDate = Carbon::parse($trackingRow->trackingtime); - } - } + $containerReference = null; + $loadingDate = null; + $unstuffingDate = null; + $etd = null; + $eta = null; - $customerno = preg_split('/(-|\/)/', $row->customerno); + $trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [ + 'trakingno' => $row->expressno + ]); + $rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest); + foreach ($rows->data as $trackingRow) { + if($trackingRow->tracking === '货物已送达仓库准备入库中'){ + $receiveDate = Carbon::parse($trackingRow->trackingtime); + } - if (!array_key_exists(2, $customerno)){ - if (!array_key_exists(1, $customerno)){ - continue; - } - $customerno[2] = substr($customerno[1], -9); - } + if (strpos($trackingRow->tracking, '货物装柜完成。') !== false) { + $tracking = explode(':', $trackingRow->tracking); + $containerReference = explode('预计到港时间', $tracking[1])[0]; + $loadingDate = Carbon::parse($trackingRow->trackingtime); + $etd = Carbon::parse($tracking[2])->subDays(5); + $eta = Carbon::parse($tracking[2]); + } - - $orderNumber = $customerno[2]; - - try { - $order = $this->fetchesOrder->execute(['reference' => $orderNumber]); - } catch (ResourceNotFoundException $exception) { - continue; - } - - $packingListReference = $row->expressno; - - try{ - $packingList = $this->fetchesPackingList->execute(['reference' => $row->expressno]); - } catch (ResourceNotFoundException $exception){ - - $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(); - - $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); - - 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); - } - } - - if($containerReference) { - try { - $container = $this->fetchesContainer->execute(['reference' => $containerReference]); - } catch (ResourceNotFoundException $exception){ - $originWarehouse = $this->fetchesCompanyModule->execute(['id' => $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id]); - $containerObject = new ContainerObject($containerReference, '', '', ContainerTypes::FORTY_FEET_DRY_CONTAINER, $loadingDate, ApprovalStatus::PENDING_VERIFICATION); - /** @var Container $container */ - $container = $this->createContainerProcessor->execute($containerObject, $originWarehouse); - - $container->packingLists()->attach($packingList); - - $transport = $container->transports()->first(); - - if(!$transport){ - $transportObject = new TransportObject(TransportType::SEA, null, null, $etd, null, ApprovalStatus::APPROVED); - /** @var Transport $transport */ - $transport = $this->createsTransport->execute($transportObject, $container); - $this->createsSchedule->execute($transport, new ScheduleObject($etd, $eta, ApprovalStatus::APPROVED)); + if($trackingRow->tracking === '货物已进目的港仓库'){ + $unstuffingDate = Carbon::parse($trackingRow->trackingtime); } } - if($unstuffingDate && $container->status !== ApprovalStatus::COMPLETED){ - $container->update(['status' => ApprovalStatus::COMPLETED]); - $container->transports()->first()->update(['drop_date' => $unstuffingDate, 'status' => ApprovalStatus::COMPLETED]); + $customerno = preg_split('/(-|\/)/', $row->customerno); + + if (!array_key_exists(2, $customerno)){ + if (!array_key_exists(1, $customerno)){ + continue; + } + $customerno[2] = substr($customerno[1], -9); + } + + + $orderNumber = $customerno[2]; + $allow_contract = true; + try { + $order = $this->fetchesOrder->execute(['reference' => $orderNumber]); + } catch (ResourceNotFoundException $exception) { + $order = $this->fetchesCompanyModule->execute(['id' => 1]); + $allow_contract = false; + } + + $packingListReference = $row->expressno; + + try{ + $packingList = $this->fetchesPackingList->execute(['reference' => $row->expressno]); + } catch (ResourceNotFoundException $exception){ + + if (!$allow_contract) { + $appointee_id = 2037; + } + else { + $appointee_id = $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); + + /** @var PackingList $warehouseReceiveList */ + $warehouseReceiveList = $this->createPackingListProcessor->execute($warehouseReceiveObject, $order); + + $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); + + if ($allow_contract) { + + $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, $appointee_id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION , !$allow_contract ? null : $contractReference); /** @var PackingList $packingList */ - foreach($container->packingLists as $packingList){ + $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); - if($packingList->status === ApprovalStatus::PENDING_VERIFICATION){ - $packingList->status = ApprovalStatus::APPROVED; - $packingList->save(); + 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); + + $package = $this->createPackageProcessor->execute($packageObject, $warehouseReceiveList); + $package = $this->createPackageProcessor->execute($packageObject, $packingList); + } + } + + if($containerReference) { + try { + $container = $this->fetchesContainer->execute(['reference' => $containerReference]); + } catch (ResourceNotFoundException $exception){ + + if (!$allow_contract) { + $appointee_id = 2037; + } + else { + $appointee_id = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id; } - $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]); + $originWarehouse = $this->fetchesCompanyModule->execute(['id' => $appointee_id]); + + $containerObject = new ContainerObject($containerReference, '', '', ContainerTypes::FORTY_FEET_DRY_CONTAINER, $loadingDate, ApprovalStatus::PENDING_VERIFICATION); + /** @var Container $container */ + $container = $this->createContainerProcessor->execute($containerObject, $originWarehouse); + + $container->packingLists()->attach($packingList); + + $transport = $container->transports()->first(); + + if(!$transport){ + $transportObject = new TransportObject(TransportType::SEA, null, null, $etd, null, ApprovalStatus::APPROVED); + /** @var Transport $transport */ + $transport = $this->createsTransport->execute($transportObject, $container); + $this->createsSchedule->execute($transport, new ScheduleObject($etd, $eta, ApprovalStatus::APPROVED)); + } + } + + if($unstuffingDate && $container->status !== ApprovalStatus::COMPLETED){ + $container->update(['status' => ApprovalStatus::COMPLETED]); + $container->transports()->first()->update(['drop_date' => $unstuffingDate, 'status' => ApprovalStatus::COMPLETED]); + + /** @var PackingList $packingList */ + foreach($container->packingLists as $packingList){ + + if($packingList->status === ApprovalStatus::PENDING_VERIFICATION){ + $packingList->status = ApprovalStatus::APPROVED; + $packingList->save(); + } + + $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]); + } } } } + DB::commit(); + dump('added'); } - - + } catch (\Exception $exception) { + Log::debug($exception); } - db::commit(); + } } 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/Console/Commands/CurlYdOrderListCommand.php b/app/Console/Commands/CurlYdOrderListCommand.php index 5f913cd1..318139e8 100644 --- a/app/Console/Commands/CurlYdOrderListCommand.php +++ b/app/Console/Commands/CurlYdOrderListCommand.php @@ -2,11 +2,10 @@ namespace App\Console\Commands; -use App\Models\State; +use App\Classes\Jobs\FetchOrdersFromYDPortalJob; use App\Http\Helpers\General; use Illuminate\Console\Command; -use App\Jobs\CurlYdOrderListJob; class CurlYdOrderListCommand extends Command { @@ -42,6 +41,6 @@ class CurlYdOrderListCommand extends Command */ public function handle() { - return CurlYdOrderListJob::dispatch(); + return FetchOrdersFromYDPortalJob::dispatch(); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8e61b5ce..de764786 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -27,6 +27,16 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + $schedule->command('command:curlVTCommand') + ->dailyAt('09:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlvt.log'); + + $schedule->command('command:curlYdOrderListCommand') + ->dailyAt('09:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlyd.log'); + $schedule->command('command:curlVTCommand') ->dailyAt('11:00') ->withoutOverlapping() @@ -48,12 +58,22 @@ class Kernel extends ConsoleKernel ->appendOutputTo (storage_path().'/logs/curlyd.log'); $schedule->command('command:curlVTCommand') - ->dailyAt('17:00') + ->dailyAt('16:00') ->withoutOverlapping() ->appendOutputTo (storage_path().'/logs/curlvt.log'); $schedule->command('command:curlYdOrderListCommand') - ->dailyAt('17:00') + ->dailyAt('16:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlyd.log'); + + $schedule->command('command:curlVTCommand') + ->dailyAt('18:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlvt.log'); + + $schedule->command('command:curlYdOrderListCommand') + ->dailyAt('18:00') ->withoutOverlapping() ->appendOutputTo (storage_path().'/logs/curlyd.log'); } diff --git a/app/Http/Controllers/Exports/ExportContainerPackingListController.php b/app/Http/Controllers/Exports/ExportContainerPackingListController.php new file mode 100644 index 00000000..6e5d845d --- /dev/null +++ b/app/Http/Controllers/Exports/ExportContainerPackingListController.php @@ -0,0 +1,19 @@ +headers->set('Authorization', 'Bearer '.$token); + $exportsContainerPackingList->setId($request->route('id')); + return $exportsContainerPackingList->download('customer-container-packing-list.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } +} diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index 80701563..d4e050b5 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -16,4 +16,4 @@ class ExportCustomersToExcelController $request->headers->set('Authorization', 'Bearer '.$token); return $exportsCustomers->download('customer-latest-order-date.csv', Excel::CSV, ['Content-Type' => 'text/csv']); } -} \ No newline at end of file +} 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/app/Http/Resources/OrderResource.php b/app/Http/Resources/OrderResource.php index 78b1b0a1..d2c72930 100644 --- a/app/Http/Resources/OrderResource.php +++ b/app/Http/Resources/OrderResource.php @@ -43,7 +43,7 @@ class OrderResource extends JsonResource 'delivered_packages' => PackingListResource::collection( $this->deliveredPackages()->get() ), - 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->get()), + 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get()), ]; }), 'remarks' => RemarkResource::collection($this->remarks), diff --git a/app/Http/Resources/PackingListNullOrderResource.php b/app/Http/Resources/PackingListNullOrderResource.php new file mode 100644 index 00000000..63af1466 --- /dev/null +++ b/app/Http/Resources/PackingListNullOrderResource.php @@ -0,0 +1,29 @@ +packingLists()->first(); + + return [ + 'id' => $this->id, + 'claimant_id' => $this->claimant_id, + 'reference' => $this->reference, + 'status' => $this->status, + 'type' => $this->type, + ]; + } +} diff --git a/app/Http/Resources/PackingListResource.php b/app/Http/Resources/PackingListResource.php index b1355331..53823417 100644 --- a/app/Http/Resources/PackingListResource.php +++ b/app/Http/Resources/PackingListResource.php @@ -20,7 +20,7 @@ class PackingListResource extends JsonResource $packages = $replica ? $replica->packages : $this->packages; - if(Auth()->user()->type === RoleTypes::SHADOW_ADMIN) { + if(in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) || in_array(Auth()->user()->id, [1914, 1919])) { $packages = $this->packages; } diff --git a/app/Http/Resources/ScheduleResource.php b/app/Http/Resources/ScheduleResource.php index 64532420..d22386b4 100644 --- a/app/Http/Resources/ScheduleResource.php +++ b/app/Http/Resources/ScheduleResource.php @@ -3,6 +3,7 @@ namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; +use Carbon\Carbon; class ScheduleResource extends JsonResource { @@ -18,6 +19,10 @@ class ScheduleResource extends JsonResource 'id' => $this->id, 'etd' => $this->etd ? $this->etd->format('d-m-Y') : 'n/a', 'eta' => $this->eta ? $this->eta->format('d-m-Y') : 'n/a', + 'billing_days_left' => [ + 'value' => (Carbon::parse($this->eta)->subDays(7)->gt(Carbon::now())) ? '+' : '-' , + 'duration' => Carbon::parse($this->eta)->subDays(7)->diffInDays(Carbon::now()), + ], 'status' => $this->status, ]; } diff --git a/app/Job/CurlYdOrderListJob.php b/app/Job/CurlYdOrderListJob.php deleted file mode 100644 index 378ada24..00000000 --- a/app/Job/CurlYdOrderListJob.php +++ /dev/null @@ -1,38 +0,0 @@ -make(FetchOrderListsFromYdPortalProcessor::class))->execute(); - } -} diff --git a/app/Models/Order.php b/app/Models/Order.php index 763e064e..5aabfd44 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -107,7 +107,7 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable return $schedule->dispatched() ->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); } - ); + )->whereHas('packages'); } public function inTransitPackages() @@ -122,7 +122,7 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable ->whereDoesntHave('containers', function($container) { return $container->where('containers.status', ApprovalStatus::COMPLETED); } - ); + )->whereHas('packages'); } public function destinationWarehousePackages() @@ -137,7 +137,7 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable function($schedule) { return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); } - ); + )->whereHas('packages'); } public function deliveredPackages() diff --git a/resources/assets/vue/components/containers/elements/ContainerComponent.vue b/resources/assets/vue/components/containers/elements/ContainerComponent.vue index f894385c..0aa0aa45 100644 --- a/resources/assets/vue/components/containers/elements/ContainerComponent.vue +++ b/resources/assets/vue/components/containers/elements/ContainerComponent.vue @@ -22,10 +22,22 @@
ETD
{{item.transport ? item.transport.current_schedule.etd : 'n/a'}}
-ETA
{{item.transport ? item.transport.current_schedule.eta : 'n/a'}}
Days Ago
++ {{item.transport.current_schedule.billing_days_left.value}} + {{item.transport.current_schedule.billing_days_left.duration}} + days +
+Packages
{{ item.packing_lists.reduce((total, obj) => total + obj.packages.reduce((total, obj) => obj.quantity + total, 0), 0) }}
@@ -60,6 +72,11 @@