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; } 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'), $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 $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 processor then calls Generate Order Steps $this->confirmOrderProcessor->execute($order->id, $contract_obligation_list, $orderRoles); return $order; } }