mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-31 18:34:34 +00:00
Merge branch '248_order_steps_apis' into 'master'
248 order steps apis See merge request CIEFWorldwideSdnBhd/shipping-portal!30
This commit is contained in:
@@ -76,4 +76,4 @@ class CreateAddressLogic extends AbstractControllerLogic
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Processors;
|
||||
|
||||
use App\Classes\Modules\Addresses\Services\CreatesOrderAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Order;
|
||||
|
||||
class CreateOrderAddressProcessor
|
||||
{
|
||||
|
||||
/** @var CanCreateAddress */
|
||||
private $canCreateAddress;
|
||||
|
||||
/** @var CreatesAddress */
|
||||
private $createsOrderAddress;
|
||||
|
||||
private $fetchesAddress;
|
||||
|
||||
/**
|
||||
* CreateAddressProcessor constructor.
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
* @param CreatesAddress $CreatesAddress
|
||||
*/
|
||||
public function __construct(CanCreateAddress $canCreateAddress, CreatesOrderAddress $createsOrderAddress, FetchesAddress $fetchesAddress)
|
||||
{
|
||||
$this->fetchesAddress = $fetchesAddress;
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
$this->createsOrderAddress = $createsOrderAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmploymentObject $object
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(int $address_id, Order $order): Model {
|
||||
|
||||
$address = $this->fetchesAddress->getRepository()->whereIn('id',[$address_id])->first();
|
||||
|
||||
|
||||
// $this->canCreateAddress->passes($object);
|
||||
|
||||
//Fetches Address & duplicate
|
||||
|
||||
return $this->createsOrderAddress->execute($address, $order);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Models\Order;
|
||||
use App\Models\Address;
|
||||
|
||||
class CreatesOrderAddress extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
public function execute(Address $address, Order $order) {
|
||||
|
||||
$model = new Address();
|
||||
$model->street_one = $address->street_one;
|
||||
$model->street_two = $address->street_two;
|
||||
$model->country_id = $address->country_id;
|
||||
$model->state_id = $address->state_id;
|
||||
$model->district_id = $address->district_id;
|
||||
$model->postcode = $address->postcode;
|
||||
|
||||
return $this->handler($order->addresses(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,22 @@ class CompanyModuleObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $unity_hash_id;
|
||||
|
||||
/** @var string */
|
||||
private $unity_signature;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param int $companyId
|
||||
* @param int|null $type
|
||||
* @param int|null $status
|
||||
*/
|
||||
public function __construct(int $companyId, int $type, int $status, ?string $unity_hash_id)
|
||||
public function __construct(int $companyId, int $type, int $status, ?string $unity_hash_id, ?string $unity_signature)
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
$this->unity_hash_id = $unity_hash_id;
|
||||
$this->unity_signature = $unity_signature;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,4 +67,12 @@ class CompanyModuleObject implements DataTransferObject
|
||||
{
|
||||
return $this->unity_hash_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUnitySignature(): string
|
||||
{
|
||||
return $this->unity_signature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntityProcessor;
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntitySignatureProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyModuleObject;
|
||||
use App\Classes\Modules\Companies\Services\CreatesCompanyModule;
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompanyModule;
|
||||
@@ -20,15 +21,20 @@ class CreateCompanyModuleProcessor
|
||||
|
||||
private $canCreateCompanyModule;
|
||||
|
||||
private $createEntityProcessor;
|
||||
|
||||
private $createUnityEntitySignatureProcessor;
|
||||
|
||||
/**
|
||||
* CreateCompanyModuleProcessor constructor.
|
||||
* @param CreatesCompanyModule $createsCompanyModule
|
||||
*/
|
||||
public function __construct(CanCreateCompanyModule $canCreateCompanyModule, CreatesCompanyModule $createsCompanyModule, CreateEntityProcessor $createUnityEntityProcessor)
|
||||
public function __construct(CanCreateCompanyModule $canCreateCompanyModule, CreatesCompanyModule $createsCompanyModule, CreateEntityProcessor $createUnityEntityProcessor, CreateEntitySignatureProcessor $createUnityEntitySignatureProcessor)
|
||||
{
|
||||
$this->createsCompanyModule = $createsCompanyModule;
|
||||
$this->createUnityEntityProcessor = $createUnityEntityProcessor;
|
||||
$this->canCreateCompanyModule = $canCreateCompanyModule;
|
||||
$this->createUnityEntitySignatureProcessor = $createUnityEntitySignatureProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,11 +45,14 @@ class CreateCompanyModuleProcessor
|
||||
{
|
||||
$unityEntity = $this->createUnityEntityProcessor->execute($company->name);
|
||||
|
||||
$unityEntitySignature = $this->createUnityEntitySignatureProcessor->execute($unityEntity->hash_id);
|
||||
|
||||
$company_module_object = new CompanyModuleObject(
|
||||
$company->id,
|
||||
$businessType??BusinessType::IMPORTER,
|
||||
$company->status,
|
||||
$unityEntity->hash_id
|
||||
$unityEntity->hash_id,
|
||||
$unityEntitySignature->hash_id,
|
||||
);
|
||||
|
||||
$this->canCreateCompanyModule->passes($company_module_object);
|
||||
|
||||
@@ -21,6 +21,7 @@ class CreatesCompanyModule extends AbstractUpdateRecord
|
||||
$model->type = $object->getType();
|
||||
$model->status = $object->getStatus();
|
||||
$model->unity_hash_id = $object->getUnityHashId();
|
||||
$model->unity_signature = $object->getUnitySignature();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ class CompanyModuleValidation extends AbstractValidation
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'unity_hash_id' => $object->getUnityHashId()
|
||||
'unity_hash_id' => $object->getUnityHashId(),
|
||||
'unity_signature' => $object->getUnitySignature(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -25,7 +26,8 @@ class CompanyModuleValidation extends AbstractValidation
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'unity_hash_id' => 'required'
|
||||
'unity_hash_id' => 'required',
|
||||
'unity_signature' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ class OrderStepsObject implements DataTransferObject
|
||||
|
||||
private $completed_date;
|
||||
|
||||
public function __construct(int $order_id, int $appointee_id, string $reference, bool $primary, float $sequence, int $status, int $contract_status, ?string $completed_date, int $id=0)
|
||||
private $hash_id;
|
||||
|
||||
public function __construct(int $order_id, int $appointee_id, string $reference, bool $primary, float $sequence, int $status, int $contract_status, ?string $completed_date, int $id=0, ?string $hash_id)
|
||||
{
|
||||
$this->order_id = $order_id;
|
||||
$this->appointee_id = $appointee_id;
|
||||
@@ -38,6 +40,7 @@ class OrderStepsObject implements DataTransferObject
|
||||
$this->completed_date = $completed_date;
|
||||
|
||||
$this->id = $id;
|
||||
$this->hash_id = $hash_id;
|
||||
}
|
||||
|
||||
public function getOrderId(): int
|
||||
@@ -49,10 +52,12 @@ class OrderStepsObject implements DataTransferObject
|
||||
{
|
||||
return $this->appointee_id;
|
||||
}
|
||||
|
||||
public function getReference(): string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function getPrimary(): bool
|
||||
{
|
||||
return $this->primary;
|
||||
@@ -83,4 +88,8 @@ class OrderStepsObject implements DataTransferObject
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
}
|
||||
public function getHashId(): ?string
|
||||
{
|
||||
return $this->hash_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class CreateOrderStepsProcessor
|
||||
|
||||
public function execute(Model $order, string $currentStep, $appointee_id){
|
||||
|
||||
$order_steps_object = new OrderStepsObject($order->id, $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null);
|
||||
$order_steps_object = new OrderStepsObject($order->id, $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null, 0, null);
|
||||
|
||||
$this->canCreateOrderStep->passes($order_steps_object);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class GenerateOrderStepsProcessor
|
||||
$this->getUnityContractObligationsProcessor = $getUnityContractObligationsProcessor;
|
||||
}
|
||||
|
||||
public function execute(Order $order, array $contract_obligation_list=[]){
|
||||
public function execute(Order $order, array $contract_obligation_list=[], array $orderRoles=[]){
|
||||
|
||||
$obligations = $contract_obligation_list;
|
||||
|
||||
@@ -48,13 +48,15 @@ class GenerateOrderStepsProcessor
|
||||
foreach($obligations as $step){
|
||||
$orderSteps[] = new OrderStepsObject(
|
||||
$order->id,
|
||||
1,
|
||||
$orderRoles[0]->company_module_id,
|
||||
$step->name,
|
||||
true,
|
||||
$step->sequence??0,
|
||||
0,
|
||||
0,
|
||||
null
|
||||
null,
|
||||
0,
|
||||
$step->hash_id
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class UpdateOrderStepsProcessor
|
||||
|
||||
public function execute(string $currentStep){
|
||||
|
||||
$orderStepsObject = new OrderStepsObject(0,0,$currentStep, 0, 0, 1, 1, null);
|
||||
$orderStepsObject = new OrderStepsObject(0,0,$currentStep, 0, 0, 1, 1, null, 0, null);
|
||||
|
||||
$this->canUpdateOrderStep->passes($orderStepsObject);
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ class CreatesManyOrderSteps extends AbstractUpdateRecord
|
||||
'primary' => $step->getPrimary(),
|
||||
'sequence' => $step->getSequence(),
|
||||
'status' => 0,
|
||||
'contract_status' => 0
|
||||
'contract_status' => 0,
|
||||
'unity_hash_id' => $step->getHashId(),
|
||||
];
|
||||
}
|
||||
$order->orderSteps()->createMany($orderStepsModel);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class OrderRoleObject implements DataTransferObject
|
||||
{
|
||||
private $order_id;
|
||||
|
||||
private $company_module_id;
|
||||
|
||||
private $role_hash_id;
|
||||
|
||||
private $role_signature;
|
||||
|
||||
public function __construct(int $order_id, int $company_module_id, ?string $role_hash_id, ?string $role_signature)
|
||||
{
|
||||
$this->order_id = $order_id;
|
||||
$this->company_module_id = $company_module_id;
|
||||
$this->role_hash_id = $role_hash_id;
|
||||
$this->role_signature = $role_signature;
|
||||
}
|
||||
|
||||
public function getOrderId(): int
|
||||
{
|
||||
return $this->order_id;
|
||||
}
|
||||
|
||||
public function getCompanyModuleId(): int
|
||||
{
|
||||
return $this->company_module_id;
|
||||
}
|
||||
|
||||
public function getRoleHashId(): ?string
|
||||
{
|
||||
return $this->role_hash_id;
|
||||
}
|
||||
|
||||
public function getRoleSignature(): ?string
|
||||
{
|
||||
return $this->role_signature;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class ConfirmOrderProcessor
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
}
|
||||
|
||||
public function execute(int $orderId, array $contract_obligation_list = []){
|
||||
public function execute(int $orderId, array $contract_obligation_list = [], array $orderRoles=[] ){
|
||||
|
||||
$order_object = new OrderObject(0,'','',0,0, '',$orderId,0,0);
|
||||
|
||||
@@ -34,7 +34,7 @@ class ConfirmOrderProcessor
|
||||
|
||||
$order = $this->fetchesOrder->execute(['id'=>$order_object->getId()]);
|
||||
|
||||
$this->generateOrderStepsProcessor->execute($order, $contract_obligation_list);
|
||||
$this->generateOrderStepsProcessor->execute($order, $contract_obligation_list, $orderRoles);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@ use App\Classes\ValueObjects\Constants\OrderStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderSteps;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use App\Classes\Modules\Unity\Processors\CreateContractProcessor;
|
||||
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\Orders\Processors\CreateOrderRoleProcessor;
|
||||
use App\Classes\Modules\Addresses\Processors\CreateOrderAddressProcessor;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateOrderProcessor
|
||||
@@ -31,13 +34,24 @@ class CreateOrderProcessor
|
||||
|
||||
private $unityCreateContractEntity;
|
||||
|
||||
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor, ConfirmOrderProcessor $confirmOrderProcessor, CreateContractProcessor $unityCreateContract, CreateContractEntityProcessor $unityCreateContractEntity, AssignContractEntityProcessor $unityAssignContractEntity)
|
||||
private $unityActivateContract;
|
||||
|
||||
private $createOrderRoleProcessor;
|
||||
|
||||
private $createOrderAddressProcessor;
|
||||
|
||||
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor, ConfirmOrderProcessor $confirmOrderProcessor, CreateOrderRoleProcessor $createOrderRoleProcessor, CreateOrderAddressProcessor $createOrderAddressProcessor, CreateContractProcessor $unityCreateContract, CreateContractEntityProcessor $unityCreateContractEntity, AssignContractEntityProcessor $unityAssignContractEntity, ActivateContractProcessor $unityActivateContract)
|
||||
{
|
||||
$this->canCreateOrder = $canCreateOrder;
|
||||
|
||||
$this->createsOrder = $createsOrder;
|
||||
$this->createOrderRoleProcessor = $createOrderRoleProcessor;
|
||||
$this->confirmOrderProcessor = $confirmOrderProcessor;
|
||||
$this->createOrderStepsProcessor = $createOrderStepsProcessor;
|
||||
$this->createOrderAddressProcessor = $createOrderAddressProcessor;
|
||||
|
||||
$this->unityCreateContract = $unityCreateContract;
|
||||
$this->unityActivateContract = $unityActivateContract;
|
||||
$this->unityAssignContractEntity = $unityAssignContractEntity;
|
||||
$this->unityCreateContractEntity = $unityCreateContractEntity;
|
||||
}
|
||||
@@ -48,32 +62,34 @@ class CreateOrderProcessor
|
||||
|
||||
//Call Unity to create contract and get contract reference no (and all the obligations)
|
||||
$contract = $this->unityCreateContract->execute();
|
||||
|
||||
$contract_reference_no = $contract->hash_id;
|
||||
$contract_obligation_list = $contract->contract_obligation_list;
|
||||
|
||||
//$e = $this->unityCreateContractEntity->execute($request, $contract_reference_no, $contract_obligation_list);
|
||||
//Activate Contract (if not activated then cannot update status)
|
||||
$activated = $this->unityActivateContract->execute($contract_reference_no);
|
||||
|
||||
//Create Order on Shipping Platform
|
||||
$order_object = new OrderObject($request->get('company_module_id'), $contract_reference_no, '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING, 0, $request->get('address_id'), $request->get('warehouse_id'));
|
||||
$this->canCreateOrder->passes($order_object);
|
||||
$order = $this->createsOrder->execute($order_object);
|
||||
|
||||
//Add address (polymorphic)
|
||||
$this->createOrderAddressProcessor->execute($request->get('address_id'), $order);
|
||||
|
||||
//Add order roles - Allow entity to process this order
|
||||
//This processor calls Unity to create Contract Entity ID
|
||||
$orderRoles = $this->createOrderRoleProcessor->execute($request, $order->id, $contract_reference_no);
|
||||
|
||||
//Call Unity to assign contract entity to obligation
|
||||
//$r = $this->unityAssignContractEntity->execute($request, $contract_obligation_list);
|
||||
|
||||
//echo('??');
|
||||
//dd($e);
|
||||
|
||||
$order_object = new OrderObject($request->get('company_module_id'), $contract_reference_no, '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING, 0, $request->get('address_id'), $request->get('warehouse_id'));
|
||||
|
||||
$this->canCreateOrder->passes($order_object);
|
||||
|
||||
$order = $this->createsOrder->execute($order_object);
|
||||
$this->unityAssignContractEntity->execute($request, $orderRoles, $contract_obligation_list);
|
||||
|
||||
//Add processing to order step
|
||||
//Note: For processing apointee_id is CIEF Freight Forward , id is 1, reserved in company table
|
||||
$this->createOrderStepsProcessor->execute($order, OrderSteps::PROCESSING, 1);
|
||||
|
||||
//Pre-approved order, no need Admin to process it
|
||||
$this->confirmOrderProcessor->execute($order->id, $contract_obligation_list);
|
||||
|
||||
//TODO: Add order roles - Allow multiple entity to process this order
|
||||
//This processor then calls Generate Order Steps
|
||||
$this->confirmOrderProcessor->execute($order->id, $contract_obligation_list, $orderRoles);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Processors;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderRoleObject;
|
||||
use App\Classes\Modules\Orders\Services\CreatesOrderRole;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanCreateOrderRole;
|
||||
use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor;
|
||||
use App\Classes\ValueObjects\Constants\OrderStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderSteps;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateOrderRoleProcessor
|
||||
{
|
||||
private $canCreateOrderRole;
|
||||
|
||||
private $createsOrderRole;
|
||||
|
||||
private $fetchesCompany;
|
||||
|
||||
private $unityCreateContractEntity;
|
||||
|
||||
public function __construct(CanCreateOrderRole $canCreateOrderRole, CreatesOrderRole $createsOrderRole, FetchesCompany $fetchesCompany, CreateContractEntityProcessor $unityCreateContractEntity)
|
||||
{
|
||||
$this->canCreateOrderRole = $canCreateOrderRole;
|
||||
$this->createsOrderRole = $createsOrderRole;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->unityCreateContractEntity = $unityCreateContractEntity;
|
||||
}
|
||||
|
||||
public function execute(Request $request, int $orderId, string $contract_reference_no){
|
||||
|
||||
$companies = $this->fetchesCompany->getRepository()->whereIn('id',[1, $request->get('warehouse_id')])->get();
|
||||
|
||||
$cief_company = $companies[0]->id == 1 ? $companies[0] : $companies[1];
|
||||
$warehouse_company = $companies[0]->id != 1 ? $companies[0] : $companies[1];
|
||||
|
||||
$cief_company_module = $cief_company->companyModule()->first();
|
||||
$contractEntities[] = $this->unityCreateContractEntity->execute( $contract_reference_no, [$cief_company_module->unity_hash_id]);
|
||||
$contractEntities[0]->{"company_module_id"} = $cief_company_module->id;
|
||||
|
||||
$warehouse_company_module = $warehouse_company->companyModule()->first();
|
||||
$contractEntities[] = $this->unityCreateContractEntity->execute( $contract_reference_no, [$warehouse_company_module->unity_hash_id]);
|
||||
$contractEntities[1]->{"company_module_id"} = $warehouse_company_module->id;
|
||||
|
||||
foreach($contractEntities as $entity){
|
||||
$order_role_object = new OrderRoleObject($orderId, $entity->company_module_id, $entity->hash_id, $entity->entity_signature_hash_id);
|
||||
|
||||
$this->canCreateOrderRole->passes($order_role_object);
|
||||
|
||||
$this->createsOrderRole->execute($order_role_object);
|
||||
}
|
||||
|
||||
return $contractEntities;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderRoleObject;
|
||||
use App\Models\OrderRole;
|
||||
|
||||
class CreatesOrderRole extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param OrderObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(OrderRoleObject $object)
|
||||
{
|
||||
$model = new OrderRole();
|
||||
$model->order_id = $object->getOrderId();
|
||||
$model->company_module_id = $object->getCompanyModuleId();
|
||||
$model->role_hash_id = $object->getRoleHashId();
|
||||
$model->role_signature = $object->getRoleSignature();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Orders\Standards\Validators\OrderRoleValidation;
|
||||
|
||||
class CanCreateOrderRole extends AbstractRule
|
||||
{
|
||||
private $orderRoleValidation;
|
||||
|
||||
public function __construct(OrderRoleValidation $orderRoleValidation)
|
||||
{
|
||||
$this->orderRoleValidation = $orderRoleValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->orderRoleValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
|
||||
class OrderRoleValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param OrderObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'order_id' => $object->getOrderId(),
|
||||
'company_module_id' => $object->getCompanyModuleId(),
|
||||
'role_hash_id' => $object->getRoleHashId(),
|
||||
'role_signature' => $object->getRoleSignature(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(?string $type = 'POST'): array
|
||||
{
|
||||
return [
|
||||
'order_id' => 'required|exists:orders,id',
|
||||
'company_module_id' => 'required|exists:company_modules,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\ActivatesContract;
|
||||
|
||||
class ActivateContractProcessor
|
||||
{
|
||||
private $activatesContract;
|
||||
|
||||
public function __construct(ActivatesContract $activatesContract)
|
||||
{
|
||||
$this->activatesContract = $activatesContract;
|
||||
}
|
||||
|
||||
public function execute($contract_hash_id){
|
||||
return $this->activatesContract->execute($contract_hash_id);
|
||||
}
|
||||
}
|
||||
@@ -20,29 +20,15 @@ class AssignContractEntityProcessor
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
}
|
||||
|
||||
public function execute(Request $request, array $obligations){
|
||||
public function execute(Request $request, array $contractEntities, array $obligations){
|
||||
|
||||
$responses = [];
|
||||
|
||||
$companies = $this->fetchesCompany->getRepository()->whereIn('id',[1, $request->get('warehouse_id')])->get();
|
||||
|
||||
$cief_company = $companies[0]->id == 1 ? $companies[0] : $companies[1];
|
||||
|
||||
$warehouse_company = $companies[0]->id != 1 ? $companies[0] : $companies[1];
|
||||
|
||||
$cief_unity_hash_id = $cief_company->companyModule()->first()->unity_hash_id;
|
||||
|
||||
$warehouse_unity_hash_id = $warehouse_company->companyModule()->first()->unity_hash_id;
|
||||
//CIEF Contract Entity Hash ID
|
||||
$contract_entity_hash_id = $contractEntities[0]->hash_id;
|
||||
|
||||
foreach($obligations as $obligation){
|
||||
$entities_hash_id = [];
|
||||
$entities_hash_id[] = $cief_unity_hash_id;
|
||||
|
||||
if(in_array($obligation->name,['WAREHOUSE_RECEIVING','WAREHOUSE_LOAD_CONTAINER'])){
|
||||
$entities_hash_id[] = $warehouse_unity_hash_id ;
|
||||
}
|
||||
|
||||
$responses[] = $this->updatesContractEntity->execute($obligation->hash_id, $entities_hash_id);
|
||||
$responses[] = $this->updatesContractEntity->execute($obligation->hash_id, [$contract_entity_hash_id]);
|
||||
}
|
||||
|
||||
return $responses;
|
||||
|
||||
@@ -20,18 +20,7 @@ class CreateContractEntityProcessor
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
}
|
||||
|
||||
public function execute(Request $request, string $new_contract_id, array $obligations){
|
||||
|
||||
$entity_hash_ids = [];
|
||||
|
||||
$companies = $this->fetchesCompany->getRepository()->whereIn('id',[1, $request->get('warehouse_id')])->get();
|
||||
|
||||
$cief_company = $companies[0]->id == 1 ? $companies[0] : $companies[1];
|
||||
$warehouse_company = $companies[0]->id != 1 ? $companies[0] : $companies[1];
|
||||
|
||||
$entity_hash_ids[] = $cief_company->companyModule()->first()->unity_hash_id;
|
||||
$entity_hash_ids[] = $warehouse_company->companyModule()->first()->unity_hash_id;
|
||||
|
||||
public function execute(string $new_contract_id, array $entity_hash_ids){
|
||||
return $this->createsContractEntity->execute($new_contract_id, $entity_hash_ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\CreatesEntitySignature;
|
||||
|
||||
class CreateEntitySignatureProcessor
|
||||
{
|
||||
private $createsEntitySignature;
|
||||
|
||||
public function __construct(CreatesEntitySignature $createsEntitySignature)
|
||||
{
|
||||
$this->createsEntitySignature = $createsEntitySignature;
|
||||
}
|
||||
|
||||
public function execute(string $entity_hash_id){
|
||||
return $this->createsEntitySignature->execute($entity_hash_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Services;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\GetAccessToken;
|
||||
|
||||
class ActivatesContract
|
||||
{
|
||||
private $getAccessToken;
|
||||
|
||||
private $activateEntityEndpoint;
|
||||
|
||||
public function __construct(GetAccessToken $getAccessToken)
|
||||
{
|
||||
$this->activateEntityEndpoint = Config::get('unity.url').Config::get('unity.endpoint.activate_contract');
|
||||
$this->getAccessToken = $getAccessToken;
|
||||
}
|
||||
|
||||
public function execute($contract_hash_id){
|
||||
|
||||
$accessToken=$this->getAccessToken->execute();
|
||||
|
||||
$this->activateEntityEndpoint = str_replace('{hash}',$contract_hash_id,$this->activateEntityEndpoint);
|
||||
|
||||
$response = Http::withToken($accessToken)->put($this->activateEntityEndpoint)->object();
|
||||
|
||||
return (isset($response->data)) ? $response->data : null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,6 @@ class CreatesContractEntity
|
||||
|
||||
$response = Http::withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object();
|
||||
|
||||
echo($new_contract_id.'<br/>');
|
||||
|
||||
echo($this->createContractEntityEndpoint);
|
||||
dd($response );
|
||||
return (isset($response->data)) ? $response->data : null;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Services;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\GetAccessToken;
|
||||
|
||||
class CreatesEntitySignature
|
||||
{
|
||||
private $getAccessToken;
|
||||
|
||||
private $createEntitySignatureEndpoint;
|
||||
|
||||
public function __construct(GetAccessToken $getAccessToken)
|
||||
{
|
||||
$this->createEntitySignatureEndpoint = Config::get('unity.url').Config::get('unity.endpoint.create_entity_signature');
|
||||
$this->getAccessToken = $getAccessToken;
|
||||
}
|
||||
|
||||
public function execute(string $entity_hash_id){
|
||||
|
||||
$accesToken=$this->getAccessToken->execute();
|
||||
|
||||
$response = Http::withToken($accesToken)->post($this->createEntitySignatureEndpoint,['entity_id'=>[$entity_hash_id], 'type'=>'1'])->object();
|
||||
|
||||
return (isset($response->data)) ? $response->data : null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Classes\Modules\Unity\Services;
|
||||
|
||||
use Config;
|
||||
use Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class GetAccessToken
|
||||
@@ -15,31 +16,47 @@ class GetAccessToken
|
||||
|
||||
private $apiKey;
|
||||
|
||||
private $cacheName;
|
||||
|
||||
private $cacheTime;
|
||||
|
||||
private $accessToken;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->getAccessTokenEndpoint = Config::get('unity.url').Config::get('unity.endpoint.login');
|
||||
$this->username = Config::get('unity.auth.login.username');
|
||||
$this->password = Config::get('unity.auth.login.password');
|
||||
$this->apiKey = Config::get('unity.auth.api_key.key');
|
||||
$this->cacheName = 'unity_access_token';
|
||||
$this->cacheTime = Config::get('unity.access_token_cache');
|
||||
$this->accessToken = $this->getAccessToken();
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
|
||||
//Note: Cache access token base on expiry from login not ideal as token may gets overwritten if user login Unity dashboard
|
||||
//if(!empty($this->getAccessToken())) return $this->getAccessToken();
|
||||
|
||||
$accessToken='';
|
||||
if(empty($this->apiKey)){
|
||||
$response = Http::post($this->getAccessTokenEndpoint, [
|
||||
'email' => $this->username,
|
||||
'password' => $this->password ,
|
||||
])->object();
|
||||
$accessToken = $response->access_token;
|
||||
$this->accessToken = $response->access_token;
|
||||
|
||||
}else{
|
||||
$accessToken = $this->apiKey;
|
||||
$this->accessToken = $this->apiKey;
|
||||
}
|
||||
|
||||
//TODO: Throw error if access token not available
|
||||
|
||||
return $accessToken;
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
private function getAccessToken(){
|
||||
$accessToken = $this->accessToken;
|
||||
return Cache::remember($this->cacheName, $this->cacheTime, function () use ( $accessToken ) {
|
||||
return $accessToken??'';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ class UpdatesContractEntity
|
||||
|
||||
$response = Http::withToken($accessToken)->put( $this->assignEntityEndpoint,['contract_entity_id'=>$entity_hash_id])->object();
|
||||
|
||||
dd($response);
|
||||
return (isset($response->data)) ? $response->data : null;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,4 +27,8 @@ class Order extends AbstractModel
|
||||
return $this->hasMany(OrderStep::class, 'order_id');
|
||||
}
|
||||
|
||||
public function addresses(): morphMany
|
||||
{
|
||||
return $this->morphMany(Address::class, 'owner');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ class OrderStep extends AbstractModel
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = ['order_id','appointee_id','reference','primary','sequence','status','contract_status','complete_date'];
|
||||
protected $fillable = ['order_id','appointee_id','reference','primary','sequence','status','contract_status','complete_date','unity_hash_id'];
|
||||
}
|
||||
|
||||
+3
-1
@@ -10,14 +10,16 @@ return [
|
||||
'endpoint' => [
|
||||
'login' => env('UNITY_LOGIN_ENDPOINT','login'),
|
||||
'create_entity' => env('UNITY_CREATE_ENTITY_ENDPOINT','entity/store'),
|
||||
'create_entity_signature' => env('UNITY_CREATE_ENTITY_SIGNATURE_ENDPOINT','entity-signature/store'),
|
||||
'create_contract_entity' => env('UNITY_CREATE_ENTITY_ENDPOINT','contract-entity/store'),
|
||||
'get_contract_obligations' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
|
||||
'create_contract' => env('UNITY_OB_LIST_ENDPOINT','contract/generate'),
|
||||
'activate_contract' => 'contract/active/{hash}',
|
||||
'assign_entity' => env('UNITY_OB_LIST_ENDPOINT','contract-obligation/assign-contract-entity/{hash}'),
|
||||
'update_obligation_status' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
|
||||
],
|
||||
|
||||
#'default_auth' => env('UNITY_AUTH','login'),
|
||||
'access_token_cache' => env('UNITY_TOKEN_CACHE', 86400),
|
||||
|
||||
//Set API key empty if using login as auth
|
||||
'auth' => [
|
||||
|
||||
@@ -14,7 +14,8 @@ class ModifyCompanyTable extends Migration
|
||||
public function up()
|
||||
{
|
||||
Schema::table('company_modules', function (Blueprint $table) {
|
||||
$table->string('unity_hash_id',200)->nullable()->after('status');
|
||||
$table->string('unity_hash_id',200)->nullable(false)->after('status');
|
||||
$table->string('unity_signature',200)->nullable(false)->after('unity_hash_id');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ModifyOrderRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('order_roles', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
$table->string('role_hash_id',200)->nullable(true)->after('company_module_id');
|
||||
$table->string('role_signature',200)->nullable(true)->after('role_hash_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ModifyOrderSteps extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('order_steps', function (Blueprint $table) {
|
||||
$table->string('unity_hash_id',200)->nullable(true)->after('contract_status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntityProcessor;
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntitySignatureProcessor;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -17,9 +18,12 @@ class CompaniesTableSeeder extends Seeder
|
||||
|
||||
private $createEntityProcessor;
|
||||
|
||||
public function __construct(CreateEntityProcessor $createEntityProcessor)
|
||||
private $createEntitySignatureProcessor;
|
||||
|
||||
public function __construct(CreateEntityProcessor $createEntityProcessor, CreateEntitySignatureProcessor $createEntitySignatureProcessor)
|
||||
{
|
||||
$this->createEntityProcessor = $createEntityProcessor;
|
||||
$this->createEntitySignatureProcessor = $createEntitySignatureProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +61,8 @@ class CompaniesTableSeeder extends Seeder
|
||||
|
||||
$unityEntity = $this->createEntityProcessor->execute($company['name']);
|
||||
|
||||
$unityEntitySignature = $this->createEntitySignatureProcessor->execute($unityEntity->hash_id);
|
||||
|
||||
$company = Company::create($company);
|
||||
|
||||
$companyModule = [
|
||||
@@ -64,6 +70,7 @@ class CompaniesTableSeeder extends Seeder
|
||||
'type' => BusinessType::WAREHOUSE,
|
||||
'status' => ApprovalStatus::APPROVED,
|
||||
'unity_hash_id' => $unityEntity->hash_id,
|
||||
'unity_signature' => $unityEntitySignature->hash_id,
|
||||
];
|
||||
|
||||
if($company['reference']=='CIEF'){
|
||||
|
||||
@@ -2449,6 +2449,13 @@
|
||||
"summary": "Create address",
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "company_id",
|
||||
"in": "query",
|
||||
"description": "Company id",
|
||||
"required": true,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "district_id",
|
||||
"in": "query",
|
||||
|
||||
Reference in New Issue
Block a user