From 47eb9262ad2923b7a6920a22e5b2a626307a10f4 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 28 Dec 2021 01:19:26 +0800 Subject: [PATCH] add packing list replica --- ...inersStatusUpdateFromVTPortalProcessor.php | 3 ++ ...hLoadedContainersFromVTPortalProcessor.php | 10 ++--- .../FetchPackingListFromVTPortalProcessor.php | 9 ++++ ...ehouseReceiveListFromVTPortalProcessor.php | 15 +++++++ .../Constants/PackingListType.php | 5 +++ app/Http/Resources/OrderResource.php | 4 +- app/Http/Resources/PackageResource.php | 7 +-- app/Http/Resources/PackingListResource.php | 11 ++++- app/Models/Order.php | 13 +++--- app/Models/Package.php | 4 +- app/Models/PackingList.php | 43 +++++++++++++++++++ .../sections/OrderProfileSectionComponent.vue | 28 ++++++------ resources/views/pages/orders/index.blade.php | 2 +- 13 files changed, 119 insertions(+), 35 deletions(-) diff --git a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php index 955d68d0..d1e69706 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php @@ -80,6 +80,9 @@ class FetchContainersStatusUpdateFromVTPortalProcessor $containerDetails = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailsRequest); + if(!$containerDetails->Rows){ + continue; + } $containerDetails = $containerDetails->Rows[0]; if(!$eta = $containerDetails[3]){ diff --git a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php index 32c17cd1..330c3200 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php @@ -195,7 +195,7 @@ class FetchLoadedContainersFromVTPortalProcessor $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', '=', RoleT::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_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); @@ -208,15 +208,15 @@ class FetchLoadedContainersFromVTPortalProcessor $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); $container->packingLists()->attach($packingList); - //Duplicate a copy for internal reference - $packingListObject = new PackingListObject($packingListReference, RoleTypes::SUPER_ADMIN, PackingListType::SHIPPING_PACKING_LIST, (int) filter_var($marking, FILTER_SANITIZE_NUMBER_INT) <= 1000 ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::SUSPENDED, $contractReference); - $packingList = $this->createPackingListProcessor->execute($packingListObject, $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); } + //Duplicate a copy for internal reference + $packingListObject = new PackingListObject($packingListReference.'_01', $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST_REPLICA, ApprovalStatus::PENDING_SUBMISSION); + $this->createPackingListProcessor->execute($packingListObject, $packingList); + } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php index 00c3e112..9a47ed50 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php @@ -63,6 +63,9 @@ class FetchPackingListFromVTPortalProcessor $packingList->packages()->delete(); + $replica = $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + if($replica) $replica->packages()->delete(); + foreach($shippingPackingLists->Rows as $shippingPackingList){ if(!$shippingPackingList[22]) { continue; @@ -70,6 +73,12 @@ class FetchPackingListFromVTPortalProcessor $packageObject = new PackageObject(PackageType::CARTON, $shippingPackingList[19], $shippingPackingList[31], $shippingPackingList[30], $shippingPackingList[29], 0, $shippingPackingList[22], ApprovalStatus::APPROVED); $this->createPackageProcessor->execute($packageObject, $packingList); + + if($replica) { + $modificationValue = 1; + $packageObject = new PackageObject(PackageType::CARTON, $shippingPackingList[19], $shippingPackingList[31] + $modificationValue, $shippingPackingList[30] + $modificationValue, $shippingPackingList[29] + $modificationValue, 0, $shippingPackingList[22], ApprovalStatus::APPROVED); + $this->createPackageProcessor->execute($packageObject, $replica); + } } DB::commit(); diff --git a/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php index d1eb8516..397dacce 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php @@ -207,6 +207,9 @@ class FetchWarehouseReceiveListFromVTPortalProcessor if(!$packingList) { $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); + $packingListObject = new PackingListObject($packingListReference.'_01', $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA, ApprovalStatus::APPROVED); + $this->createPackingListProcessor->execute($packingListObject, $packingList); + $transportObject = new TransportObject(TransportType::LAND, null, $tracking, Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED); @@ -220,15 +223,27 @@ class FetchWarehouseReceiveListFromVTPortalProcessor $this->createsSchedule->execute($transport, new ScheduleObject(Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED)); + /** @var PackingList $replica */ + $replica = $packingList->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA)->first(); $packingList->packages()->delete(); + $packageObject = new PackageObject(PackageType::CARTON, $description, $measurement, $measurement, $measurement, 0, $quantity, ApprovalStatus::APPROVED); $this->createPackageProcessor->execute($packageObject, $packingList); + if($replica){ + $replica->packages()->delete(); + $modificationValue = 1; + $packageObject = new PackageObject(PackageType::CARTON, $description, $measurement + $modificationValue, $measurement + $modificationValue, $measurement + $modificationValue, 0, $quantity, ApprovalStatus::APPROVED); + $this->createPackageProcessor->execute($packageObject, $replica); + + } + } } catch (\Exception $exception){ + dd($exception); Log::error($exception->getMessage()); } diff --git a/app/Classes/ValueObjects/Constants/PackingListType.php b/app/Classes/ValueObjects/Constants/PackingListType.php index 56f29244..bd83c6ba 100644 --- a/app/Classes/ValueObjects/Constants/PackingListType.php +++ b/app/Classes/ValueObjects/Constants/PackingListType.php @@ -14,5 +14,10 @@ final class PackingListType { public const DELIVERY_PACKING_LIST = 4; + public const WAREHOUSE_RECEIVE_LIST_REPLICA = 5; + + public const SHIPPING_PACKING_LIST_REPLICA = 6; + + } diff --git a/app/Http/Resources/OrderResource.php b/app/Http/Resources/OrderResource.php index 0c30bb62..b5bdf0ab 100644 --- a/app/Http/Resources/OrderResource.php +++ b/app/Http/Resources/OrderResource.php @@ -31,7 +31,7 @@ class OrderResource extends JsonResource 'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()), 'parcels' => $this->whenLoaded('packingLists', function() { return [ - 'origin_warehouse_packages' => PackageResource::collection( + 'origin_warehouse_packages' => PackingListResource::collection( $this->originWarehousePackages()->get() ), 'in_transit_packages' => PackageResource::collection( @@ -43,7 +43,7 @@ class OrderResource extends JsonResource 'delivered_packages' => PackageResource::collection( $this->deliveredPackages()->get() ), - 'received_packages' => PackageResource::collection($this->parcels()->warehouseReceiveList()->get()), + 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->get()), ]; }), 'remarks' => RemarkResource::collection($this->remarks), diff --git a/app/Http/Resources/PackageResource.php b/app/Http/Resources/PackageResource.php index 6e45f91f..2cd76a1b 100644 --- a/app/Http/Resources/PackageResource.php +++ b/app/Http/Resources/PackageResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Models\Order; use Illuminate\Http\Resources\Json\JsonResource; class PackageResource extends JsonResource @@ -26,9 +27,9 @@ class PackageResource extends JsonResource 'quantity' => $this->quantity, 'cbm' => (($this->width / 100) * ($this->height / 100) * ($this->length / 100)) * $this->quantity, 'status' => $this->status, - 'order' => new OrderResource($this->packingList->owner), - 'container' => new ContainerResource($this->container), - 'transport' => new TransportResource($this->transport) + 'order' => New OrderResource($this->packingList->owner instanceof Order ? $this->packingList->owner : $this->packingList->owner->owner), + 'container' => new ContainerResource($this->packingList->owner instanceof Order ? $this->container : $this->packingList->owner->containers()->first()), + 'transport' => new TransportResource($this->packingList->owner instanceof Order ? $this->transport : $this->packingList->owner->transports()->first()) ]; } } diff --git a/app/Http/Resources/PackingListResource.php b/app/Http/Resources/PackingListResource.php index 4024833d..67667ddf 100644 --- a/app/Http/Resources/PackingListResource.php +++ b/app/Http/Resources/PackingListResource.php @@ -2,6 +2,8 @@ namespace App\Http\Resources; +use App\Classes\ValueObjects\Constants\RoleTypes; +use App\Models\Order; use Illuminate\Http\Resources\Json\JsonResource; class PackingListResource extends JsonResource @@ -14,14 +16,19 @@ class PackingListResource extends JsonResource */ public function toArray($request) { + $replica = $this->packingLists()->first(); return [ 'id' => $this->id, 'claimant_id' => $this->claimant_id, 'reference' => $this->reference, 'status' => $this->status, 'transport' => new TransportResource($this->transports()->first()), - 'packages' => PackageResource::collection($this->packages), - 'order' => New OrderResource($this->owner) + 'type' => $this->type, + 'packages' => PackageResource::collection(Auth()->user()->role === RoleTypes::SUPER_ADMIN ? $this->packages : $replica ? $replica->packages : $this->packages), + 'packing_list' => new PackingListResource($replica), + $this->mergeWhen($this->owner instanceof Order, [ + 'order' => New OrderResource($this->owner) + ]) ]; } } diff --git a/app/Models/Order.php b/app/Models/Order.php index ffa0550a..763e064e 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -6,6 +6,7 @@ use App\Classes\General\Interfaces\Addressable; use App\Classes\General\Interfaces\Contactable; use App\Classes\General\Interfaces\Packable; use App\Classes\General\Interfaces\Remarkable; +use App\Classes\ValueObjects\Constants\PackingListType; use App\Classes\ValueObjects\Constants\RoleTypes; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Scopes\CustomerOrdersScope; @@ -100,7 +101,7 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable public function originWarehousePackages() { - return $this->parcels()->shippingList() + return $this->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST) ->whereDoesntHave('shippingSchedules', function($schedule) { return $schedule->dispatched() @@ -111,14 +112,14 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable public function inTransitPackages() { - return $this->parcels()->shippingList()->Shipping() + return $this->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST)->Shipping() ->whereHas('shippingSchedules', function($schedule) { return $schedule->dispatched() ->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); } ) - ->whereDoesntHave('container', function($container) { + ->whereDoesntHave('containers', function($container) { return $container->where('containers.status', ApprovalStatus::COMPLETED); } ); @@ -126,8 +127,8 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable public function destinationWarehousePackages() { - return $this->parcels()->shippingList() - ->whereHas('container', + return $this->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST) + ->whereHas('containers', function($container) { return $container->where('containers.status', ApprovalStatus::COMPLETED); } @@ -141,7 +142,7 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable public function deliveredPackages() { - return $this->parcels()->shippingList() + return $this->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST) ->whereHas('deliverySchedules', function($schedule) { return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); diff --git a/app/Models/Package.php b/app/Models/Package.php index 89ef8328..cb2bf35f 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -142,9 +142,9 @@ class Package extends AbstractModel protected static function booted() { - if (auth()->user()->type === RoleTypes::USER) { +// if (auth()->user()->type === RoleTypes::USER) { // static::addGlobalScope(new CustomerPackagesScope()); - } +// } } } diff --git a/app/Models/PackingList.php b/app/Models/PackingList.php index 21b0d692..d2594210 100644 --- a/app/Models/PackingList.php +++ b/app/Models/PackingList.php @@ -5,15 +5,21 @@ namespace App\Models; use App\Classes\General\Interfaces\Steppable; use App\Classes\General\Interfaces\Transportable; use App\Classes\General\Interfaces\Packable; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; +use Staudenmeir\EloquentHasManyDeep\HasManyDeep; +use Staudenmeir\EloquentHasManyDeep\HasRelationships; class PackingList extends AbstractModel implements Transportable, Steppable, Packable { + use HasRelationships; use SoftDeletes; protected $table = 'packing_lists'; @@ -80,4 +86,41 @@ class PackingList extends AbstractModel implements Transportable, Steppable, Pac { return $this->morphMany(PackingList::class, 'owner'); } + + /** + * @return hasManyDeep + */ + public function shippingTransports(): hasManyDeep + { + return $this->hasManyDeep(Transport::class, [ContainerPackingList::class, Container::class], ['packing_list_id', 'id', ['owner_type', 'owner_id']], ['id', 'container_id', null]); + } + + /** + * @return hasManyDeep + */ + public function shippingSchedules(): hasManyDeep + { + return $this->hasManyDeep(Schedule::class, [ContainerPackingList::class, Container::class, Transport::class], ['packing_list_id', 'id', ['owner_type', 'owner_id'], ['owner_type', 'owner_id']], ['id', 'container_id', null, null]); + } + + + /** + * @return hasManyDeep + */ + public function deliverySchedules(): hasManyDeep + { + return $this->hasManyDeep(Schedule::class, [Transport::class], [['owner_type', 'owner_id'], ['owner_type', 'owner_id']], [null, null]); + } + + /** + * @param $query + * @return mixed + */ + public function scopeShipping($query){ + return $query->whereHas('shippingSchedules', function($schedule){ + return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED); + })->whereDoesntHave('shippingTransports', function($transport){ + return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED); + }); + } } diff --git a/resources/assets/vue/components/orders/sections/OrderProfileSectionComponent.vue b/resources/assets/vue/components/orders/sections/OrderProfileSectionComponent.vue index 1332bfe6..33a69cb6 100644 --- a/resources/assets/vue/components/orders/sections/OrderProfileSectionComponent.vue +++ b/resources/assets/vue/components/orders/sections/OrderProfileSectionComponent.vue @@ -293,7 +293,7 @@
- +
@@ -310,10 +310,10 @@
-
+
-
-
+
+
@@ -343,10 +343,10 @@
-
+
-
-
+
+
@@ -376,10 +376,10 @@
-
+
-
-
+
+
@@ -409,16 +409,16 @@
-
+
-
-
+
+
-
+
diff --git a/resources/views/pages/orders/index.blade.php b/resources/views/pages/orders/index.blade.php index 056d5fbd..d4633a81 100644 --- a/resources/views/pages/orders/index.blade.php +++ b/resources/views/pages/orders/index.blade.php @@ -1,6 +1,6 @@ @extends('layouts.base_portal') @section('inner_content') -