canCreateOrder = $canCreateOrder; $this->createsOrder = $createsOrder; $this->confirmOrderProcessor = $confirmOrderProcessor; $this->createStepsProcessor = $createStepsProcessor; $this->unityCreateContract = $unityCreateContract; $this->unityAssignContractEntity = $unityAssignContractEntity; $this->unityCreateContractEntity = $unityCreateContractEntity; $this->unityActivateContract = $unityActivateContract; $this->createOrderRoleProcessor = $createOrderRoleProcessor; $this->createAddress = $createAddress; $this->fetchesAddress = $fetchesAddress; } public function execute(Request $request){ $reference_no = rand(1000000, 9999999); //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; //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'), $reference_no, $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); $address = $this->fetchesAddress->execute(['id' => $order_object->getAddressId()]); $addressObject = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode,$address->reference); //Add address (polymorphic) $this->createAddress->execute($order, $addressObject); //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 $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->createStepsProcessor->execute($order, OrderSteps::PROCESSING, 1); //Pre-approved order, no need Admin to process it //This processor then calls Generate Order Steps $this->confirmOrderProcessor->execute($order->id, $contract_obligation_list, $orderRoles); return $order; } }