null order packing list, assign packing list

This commit is contained in:
glovetleong
2022-01-26 17:32:14 +08:00
parent 96131c5b33
commit 0a8109ae9e
10 changed files with 319 additions and 32 deletions
@@ -0,0 +1,147 @@
<?php
namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\PackingLists\Services\UpdatesPackingListOwner;
use App\Classes\Modules\Transports\Services\UpdatesTransportStatus;
use App\Classes\Modules\Unity\Services\CreatesContract;
use App\Classes\Modules\Unity\Processors\ActivateContractProcessor;
use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor;
use App\Classes\Modules\Unity\Processors\AssignContractEntityProcessor;
use App\Classes\Modules\PackingLists\Services\UpdatesPackingListContractReference;
use App\Classes\Modules\Steps\Services\CreatesStep;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Http\Resources\PackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AssignPackingListOrderLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -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 ;
@@ -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;
}
@@ -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);
@@ -0,0 +1,31 @@
<?php
namespace App\Classes\Modules\PackingLists\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Interfaces\Packable;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Models\PackingList;
class CreatesNullOrderPackingList extends AbstractUpdateRecord
{
/**
* @param PackingListObject $object
* @param Packable $packable
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(PackingListObject $object) {
$model = new PackingList();
$model->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);
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Classes\Modules\PackingLists\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\PackingList;
class UpdatesPackingListContractReference extends AbstractUpdateRecord
{
/**
* @param PackingList $model
* @param int $status
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(PackingList $model, string $reference_contract) {
$model->reference_contract = $reference_contract;
return $this->handler($model);
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Classes\Modules\PackingLists\Services;
use App\Classes\General\Interfaces\Packable;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Models\PackingList;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
class UpdatesPackingListOwner extends AbstractUpdateRelationshipRecord
{
/**
* @param PackingList $model
* @param int $status
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(PackingList $model, Packable $packable) {
$model->status = ApprovalStatus::APPROVED;
return $this->handler($packable->packingLists(), $model);
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Classes\Modules\Transports\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\Transport;
class updatesTransportStatus extends AbstractUpdateRecord
{
/**
* @param Transport $model
* @param int $status
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Transport $model, int $status) {
$model->status = $status;
return $this->handler($model);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\PackingLists;
use App\Classes\Modules\PackingLists\ControllersLogic\AssignPackingListOrderLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AssignPackingListOrderController
{
/**
* @param Request $request
* @param AssignPackingListOrderLogic $logic
* @return JsonResponse
*/
public function assign(Request $request, AssignPackingListOrderLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+2
View File
@@ -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');