'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 CreatesTransactionDetail */ private $createsTransactionDetail; /** @var CreatesDocument */ private $createsDocument; /** @var CreatesFiles */ private $createsFile; public function __construct( FetchesPackingList $fetchesPackingList, FetchesSegmentConstant $fetchesSegmentConstant, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, CreatesDocument $createsDocument, CreatesFiles $createsFile ) { $this->fetchesPackingList = $fetchesPackingList; $this->fetchesSegmentConstant = $fetchesSegmentConstant; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->createsTransactionDetail = $createsTransactionDetail; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; } 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 ); $invoice_transaction = $this->createsTransaction->execute($packing_list, $object); $object_detail = new TransactionDetailObject( $invoice_transaction->bill_no, $invoice_transaction->bill_no, 1, $invoice_transaction->amount, $invoice_transaction->amount ); $transaction_detail = $this->createsTransactionDetail->execute($invoice_transaction, $object_detail); $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice_transaction]); $document_object = new DocumentObject( DocumentType::SHIPPING_INVOICE, [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], '', ApprovalStatus::COMPLETED, 'shipping_invoice' ); /** @var Document $document */ $document = $this->createsDocument->execute($invoice_transaction, $document_object); $this->createsFile->execute($document, $document_object); // dd('yess'); return $this->response([]); } }