fetchesCompanyModule = $fetchesCompanyModule; $this->createsOrderRole = $createsOrderRole; $this->fetchesCompany = $fetchesCompany; } /** * @param CompanyModule $originWarehouse * @param Order $order * @return bool * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(CompanyModule $originWarehouse, Order $order){ $address = $order->addresses()->first(); $importer = $order->companyModule; /** @var CompanyModule $destinationWarehouse */ $destinationWarehouse = $this->fetchesCompanyModule->execute(['reference' => WarehouseReferences::DESTINATION_WAREHOUSE[$address->state_id ]]); /** @var CompanyModule $freightForwarder */ $freightForwarder = $originWarehouse->company->companyModules()->freightForwarders()->first(); /** @var CompanyModule $supervisor */ $supervisor = $this->fetchesCompany->execute(['reference' => 'CIEF'])->companyModules()->freightForwarders()->first(); $roleObject = new OrderRoleObject($order, $supervisor, OrderRoleTypes::SUPERVISOR); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $importer, OrderRoleTypes::IMPORTER); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $originWarehouse, OrderRoleTypes::ORIGIN_WAREHOUSE); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $freightForwarder, OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $freightForwarder, OrderRoleTypes::DESTINATION_FREIGHT_FORWARDER); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $destinationWarehouse, OrderRoleTypes::DESTINATION_WAREHOUSE); $this->createsOrderRole->execute($roleObject); $roleObject = new OrderRoleObject($order, $freightForwarder, OrderRoleTypes::LAST_MILE_DELIVERY_DRIVER); $this->createsOrderRole->execute($roleObject); return true; $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; } }