mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-09-01 02:44:13 +00:00
null order packing list, assign packing list
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user