diff --git a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php index 11ee4454..2509e263 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php @@ -202,7 +202,15 @@ class FetchOrderListsFromYdPortalProcessor try{ $packingList = $this->fetchesPackingList->execute(['reference' => $row->expressno, 'type' => PackingListType::SHIPPING_PACKING_LIST]); - $packingList->packages()->withTrashed()->restore(); + + $packingList->packages()->delete(); + $replica = $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + if($replica) $replica->packages()->delete(); + + $warehouseReceiveList = $this->fetchesPackingList->execute(['reference' => $row->expressno, 'type' => PackingListType::WAREHOUSE_RECEIVE_LIST]); + $replica = $warehouseReceiveList->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA)->first(); + if($replica) $replica->packages()->delete(); + } 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 */ @@ -238,12 +246,12 @@ class FetchOrderListsFromYdPortalProcessor $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); - } + 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) { diff --git a/app/Models/PackingList.php b/app/Models/PackingList.php index 77feb7f6..1ebb2439 100644 --- a/app/Models/PackingList.php +++ b/app/Models/PackingList.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Classes\General\Interfaces\Packable; use App\Classes\General\Interfaces\Steppable; use App\Classes\General\Interfaces\Transportable; use App\Classes\ValueObjects\Constants\ApprovalStatus; @@ -15,7 +16,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; -class PackingList extends AbstractModel implements Transportable, Steppable +class PackingList extends AbstractModel implements Transportable, Steppable, Packable { use SoftDeletes; use HasRelationships;