'Create Supplier Transactions', 'message' => 'You have successfully created currency supplier transactions' ]; } /** @var FetchesPackingList */ private $fetchesPackingList; /** @var FetchesSegmentConstant */ private $fetchesSegmentConstant; /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; /** @var CreatesTransaction */ private $createsTransaction; // /** @var FetchesTransaction */ // private $fetchesTransaction; // /** @var UpdatesTransactionStatus */ // private $updatesTransactionStatus; // /** @var CreatesDocument */ // private $createsDocument; // /** @var CreatesFiles */ // private $createsFile; // /** @var PDF */ // private $pdf; /** * CreateSupplierTransactionLogic constructor. * @param FetchesPackingList $fetchesPackingList * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesTransaction $createsTransaction * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus * @param PDF $pdf */ public function __construct( FetchesPackingList $fetchesPackingList, FetchesSegmentConstant $fetchesSegmentConstant, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction // UpdatesTransactionStatus $updatesTransactionStatus, // CreatesDocument $createsDocument, // CreatesFiles $createsFile, // PDF $pdf ) { $this->fetchesPackingList = $fetchesPackingList; $this->fetchesSegmentConstant = $fetchesSegmentConstant; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; // $this->updatesTransactionStatus = $updatesTransactionStatus; // $this->createsDocument = $createsDocument; // $this->createsFile = $createsFile; // $this->pdf = $pdf; } public function logic(Request $request) : JsonResponse { $packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]); $cbm = $packing_list->packages->sum(function($package) { return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); }); $order = $packing_list->owner()->first(); $address = $order->addresses()->first(); $base_price_constant = $this->fetchesSegmentConstant->execute(['id' => 1]); $warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 2]); $state_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 3]); $center_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 4]); $outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 5]); $base_price = 0; $warehouse_rate = 0; $state_rate = 0; $state_select = []; $with_out = false; if ($base_price_constant) { $base_price = $base_price_constant->value->price; } if ($warehouse_rate_constant) { $package_warehouse = $order->OrderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->reference; foreach ($warehouse_rate_constant->value->config as $key_warehouse => $row_warehouse) { if ($row_warehouse->warehouse_name == $package_warehouse) { $warehouse_rate = $row_warehouse->rate; } } } if ($state_rate_constant) { foreach ($state_rate_constant->value->config as $key_state => $row_state) { if ($row_state->status_id == $address->state_id) { $state_select = $row_state; } } } if ($outstation_postcode_constant) { foreach ($outstation_postcode_constant->value as $key_out => $row_out) { if($row_out == $address->postcode) { $with_out = true; } } } if (!empty($state_select)) { $state_rate = $state_select->rate; if ($with_out) { $state_rate = $state_select->rate + $state_select->outstation_rate; } } $price_cbm = $base_price + $warehouse_rate + $state_rate; $total_cbm = $price_cbm * $cbm; $billNumber = $this->generatesTransactionBillNumber->execute('SHIP-'); $object = new TransactionObject( $billNumber, TransactionType::SHIPPING_INVOICE, 1, $order->company_module_id, 1, PaymentMethodType::CASH, $total_cbm, $total_cbm, 1, 1, 0, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION ); $transactions = $this->createsTransaction->execute($packing_list, $object); return $this->response([]); } }