diff --git a/app/Classes/Modules/Addresses/Processors/CreateOrderAddressProcessor.php b/app/Classes/Modules/Addresses/Processors/CreateOrderAddressProcessor.php new file mode 100644 index 00000000..6db43e82 --- /dev/null +++ b/app/Classes/Modules/Addresses/Processors/CreateOrderAddressProcessor.php @@ -0,0 +1,53 @@ +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); + } + +} diff --git a/app/Classes/Modules/Addresses/Services/CreatesOrderAddress.php b/app/Classes/Modules/Addresses/Services/CreatesOrderAddress.php new file mode 100644 index 00000000..c3699761 --- /dev/null +++ b/app/Classes/Modules/Addresses/Services/CreatesOrderAddress.php @@ -0,0 +1,27 @@ +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); + + } +} diff --git a/app/Classes/Modules/Orders/DataTransferObjects/OrderRoleObject.php b/app/Classes/Modules/Orders/DataTransferObjects/OrderRoleObject.php new file mode 100644 index 00000000..d87fcda1 --- /dev/null +++ b/app/Classes/Modules/Orders/DataTransferObjects/OrderRoleObject.php @@ -0,0 +1,46 @@ +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; + } + +} diff --git a/app/Classes/Modules/Orders/Processors/CreateOrderRoleProcessor.php b/app/Classes/Modules/Orders/Processors/CreateOrderRoleProcessor.php new file mode 100644 index 00000000..0dd2240a --- /dev/null +++ b/app/Classes/Modules/Orders/Processors/CreateOrderRoleProcessor.php @@ -0,0 +1,61 @@ +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; + } +} diff --git a/app/Classes/Modules/Orders/Services/CreatesOrderRole.php b/app/Classes/Modules/Orders/Services/CreatesOrderRole.php new file mode 100644 index 00000000..387321b9 --- /dev/null +++ b/app/Classes/Modules/Orders/Services/CreatesOrderRole.php @@ -0,0 +1,27 @@ +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); + } +} diff --git a/app/Classes/Modules/Orders/Standards/Rules/CanCreateOrderRole.php b/app/Classes/Modules/Orders/Standards/Rules/CanCreateOrderRole.php new file mode 100644 index 00000000..98b4cd01 --- /dev/null +++ b/app/Classes/Modules/Orders/Standards/Rules/CanCreateOrderRole.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/app/Classes/Modules/Orders/Standards/Validators/OrderRoleValidation.php b/app/Classes/Modules/Orders/Standards/Validators/OrderRoleValidation.php new file mode 100644 index 00000000..b578fb9c --- /dev/null +++ b/app/Classes/Modules/Orders/Standards/Validators/OrderRoleValidation.php @@ -0,0 +1,43 @@ + $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 []; + } +} diff --git a/app/Classes/Modules/Unity/Processors/CreateEntitySignatureProcessor.php b/app/Classes/Modules/Unity/Processors/CreateEntitySignatureProcessor.php new file mode 100644 index 00000000..fba777ce --- /dev/null +++ b/app/Classes/Modules/Unity/Processors/CreateEntitySignatureProcessor.php @@ -0,0 +1,21 @@ +createsEntitySignature = $createsEntitySignature; + } + + public function execute(string $entity_hash_id){ + return $this->createsEntitySignature->execute($entity_hash_id); + } +} diff --git a/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php new file mode 100644 index 00000000..45dc3895 --- /dev/null +++ b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php @@ -0,0 +1,30 @@ +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; + + } +} diff --git a/database/migrations/2021_08_02_224659_modify_order_roles.php b/database/migrations/2021_08_02_224659_modify_order_roles.php new file mode 100644 index 00000000..9ef5b99e --- /dev/null +++ b/database/migrations/2021_08_02_224659_modify_order_roles.php @@ -0,0 +1,32 @@ +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() + { + // + } +}