mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 12:34:01 +00:00
177 lines
5.8 KiB
PHP
177 lines
5.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
|
|
|
|
|
|
|
|
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
|
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
|
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
|
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
|
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
|
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
|
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Models\Document;
|
|
use App\Models\Transaction;
|
|
use Barryvdh\DomPDF\PDF;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf;
|
|
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
|
|
|
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Create Supplier Transactions',
|
|
'message' => 'You have successfully created currency supplier transactions'
|
|
];
|
|
}
|
|
|
|
/** @var FetchesPackingList */
|
|
private $fetchesPackingList;
|
|
|
|
/** @var FetchesTransaction */
|
|
private $fetchesTransaction;
|
|
|
|
/** @var UpdatesTransactionStatus */
|
|
private $updatesTransactionStatus;
|
|
|
|
/** @var CreatesTransaction */
|
|
private $createsTransaction;
|
|
|
|
/** @var CreatesDocument */
|
|
private $createsDocument;
|
|
|
|
/** @var CreatesFiles */
|
|
private $createsFile;
|
|
|
|
/** @var GeneratesTransactionBillNumber */
|
|
private $generatesTransactionBillNumber;
|
|
|
|
/** @var PDF */
|
|
private $pdf;
|
|
|
|
/**
|
|
* CreateSupplierTransactionLogic constructor.
|
|
* @param FetchesPackingList $fetchesPackingList
|
|
* @param FetchesTransaction $fetchesTransaction
|
|
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
|
* @param CreatesTransaction $createsTransaction
|
|
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
|
* @param PDF $pdf
|
|
*/
|
|
public function __construct(
|
|
FetchesPackingList $fetchesPackingList,
|
|
|
|
|
|
|
|
FetchesTransaction $fetchesTransaction,
|
|
UpdatesTransactionStatus $updatesTransactionStatus,
|
|
CreatesTransaction $createsTransaction,
|
|
CreatesDocument $createsDocument,
|
|
CreatesFiles $createsFile,
|
|
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
|
PDF $pdf
|
|
)
|
|
{
|
|
|
|
$this->fetchesPackingList = $fetchesPackingList;
|
|
|
|
|
|
|
|
$this->fetchesTransaction = $fetchesTransaction;
|
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
|
$this->createsTransaction = $createsTransaction;
|
|
$this->createsDocument = $createsDocument;
|
|
$this->createsFile = $createsFile;
|
|
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
|
$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);
|
|
});
|
|
|
|
dd($packages);
|
|
|
|
Transaction::select(DB::raw('sum(jumlah * harga) as total'))->get();
|
|
|
|
|
|
price_per_cbm = base_price + customer_rate + warehouse_rate + state_rate + outstation_rate
|
|
|
|
price_cbm = 570 myr
|
|
|
|
total cbm * price_cbm = 896.61
|
|
|
|
price_cbm, invoice total
|
|
|
|
create transaction invoice
|
|
create transaction details
|
|
|
|
shipping service (570 per cbm * 1.57 cbm)
|
|
|
|
// dd($packing_list);
|
|
|
|
|
|
// $rate = $request->input('rate');
|
|
|
|
// $transactions = collect();
|
|
|
|
// foreach($request->input('payments') as $payment){
|
|
|
|
// /** @var Transaction $payment */
|
|
// $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]);
|
|
// $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED);
|
|
// $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-');
|
|
// $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1,
|
|
// $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH,
|
|
// $payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id,
|
|
// $rate, 0, 0, null, ApprovalStatus::APPROVED);
|
|
|
|
// $transactions[] = $this->createsTransaction->execute($payment->booking, $object);
|
|
// }
|
|
|
|
// $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]);
|
|
|
|
// $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf';
|
|
|
|
// $object = new DocumentObject(
|
|
// DocumentType::CURRENCY_VENDOR_ORDER,
|
|
// [chunk_split('data:application/pdf;base64,'.base64_encode($pdf->output()))],
|
|
// '',
|
|
// ApprovalStatus::COMPLETED,
|
|
// 'currency_vendor_order'
|
|
// );
|
|
|
|
// /** @var Document $document */
|
|
// $document = $this->createsDocument->execute($supplier, $object);
|
|
// $this->createsFile->execute($document, $object);
|
|
|
|
return $this->response([]);
|
|
}
|
|
}
|