From d2d92f668e7d56d462c9dc2e3d6a681274c6def9 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 8 Jan 2022 03:28:18 +0800 Subject: [PATCH] add transfer fee transaction and fixed currency_vendor_order pdf calculation --- .../CreateSupplierTransactionLogic.php | 20 ++- .../CalculatesTransactionServiceCharge.php | 6 +- .../CalculatesTransactionTransferFee.php | 17 +++ .../Constants/TransactionType.php | 2 + .../pdfs/currency_vendor_order.blade.php | 115 +++++++++++------- 5 files changed, 109 insertions(+), 51 deletions(-) create mode 100644 app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 20dfa9da..6b5110ec 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -28,6 +28,7 @@ use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; +use App\Classes\Modules\Transactions\Services\CalculatesTransactionTransferFee; use App\Classes\Modules\Transactions\Services\CalculatesTransactionServiceCharge; class CreateSupplierTransactionLogic extends AbstractControllerLogic @@ -68,6 +69,9 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var CalculatesTransactionServiceCharge */ private $calculatesTransactionServiceCharge; + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + /** @var PDF */ private $pdf; @@ -79,9 +83,10 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * @param CreatesTransaction $createsTransaction * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge + * @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee * @param PDF $pdf */ - public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, PDF $pdf) + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, PDF $pdf) { $this->fetchesCompany = $fetchesCompany; @@ -92,6 +97,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->createsFile = $createsFile; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; $this->pdf = $pdf; } @@ -102,6 +108,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate = $request->input('rate'); $transactions = collect(); + $transferFeeTransactions = collect(); foreach($request->input('payments') as $payment){ @@ -119,11 +126,20 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate, 0, $supplier->id == 2 ? 0 : $serviceCharge, null, ApprovalStatus::PENDING_VERIFICATION); $transactions[] = $this->createsTransaction->execute($payment->booking, $object); + + $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); + $trasferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount); + $object = new TransactionObject($transferFeeNumber, TransactionType::TRANSFER_FEE, 1, $supplier->id, + $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $payment->original_amount, $payment->original_amount, $payment->original_currency_id, $payment->original_currency_id, + 1, 0, $trasferFee, null, ApprovalStatus::PENDING_VERIFICATION); + + $transferFeeTransactions[] = $this->createsTransaction->execute($payment->booking, $object); } if(!count($transactions)) return $this->response([]); - $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]); + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier]); $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php index 3dbabc30..641e3903 100644 --- a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -8,12 +8,12 @@ class CalculatesTransactionServiceCharge /** * @param float $amount * @param float $rate - * @param float $transfer_fee * @param float $service_charge + * @param float $transfer_fee * @return float */ - public function execute(float $amount, float $rate, ?float $transfer_fee = 0.002, ?float $service_charge = 0.75) { - return (($amount + ($amount * $transfer_fee/100)) * (1/$rate)) * $service_charge / 100; + public function execute(float $amount, float $rate, ?float $service_charge = 0.75, ?float $transfer_fee = 0.00) { + return (($amount + $transfer_fee) * (1/$rate)) * $service_charge / 100; } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php new file mode 100644 index 00000000..14f77b84 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php @@ -0,0 +1,17 @@ + - table, th, td { - border: 1px solid black; - border-collapse: collapse; - } - th, td { - padding: 15px; - } - + +
+
- -
- - +
+ - -
{{$supplier->name}} {{\Carbon\Carbon::now('Asia/Singapore')->format('d-m-Y h:s')}}
-
-
- - + +
+
+
+ + @@ -32,50 +36,69 @@ @foreach($transactions as $transaction) - - - - - - - + + + + + + + @endforeach - -
Reference MarkingBank in Details
{{$transaction->booking->marking}}{{$transaction->booking->company->reference}}{{$transaction->currency_rate}}{{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}}Account Holder Name: {{$transaction->booking->bank->holder_name}}
{{$transaction->booking->bank->bank_name}}: {{$transaction->booking->bank->account_no}} -
Branch: {{$transaction->booking->bank->bank_branch}}
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}}
{{$transaction->booking->marking}}{{$transaction->booking->company->reference}}{{$transaction->currency_rate}}{{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}}Account Holder Name: {{$transaction->booking->bank->holder_name}}
{{$transaction->booking->bank->bank_name}}: {{$transaction->booking->bank->account_no}} +
Branch: {{$transaction->booking->bank->bank_branch}}
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} +
- - + +
+ + - + @php + $sub_total_booking_amount = number_format((float)$transactions->sum('original_amount'), 2, '.', ''); + @endphp + - + @php + $transfer_fee = number_format((float)$transferFeeTransactions->sum('service_charge'), 2, '.', ''); + @endphp + - + @php + $total_booking_amount = number_format((float) ($transactions->sum('original_amount') + $transfer_fee), 2, '.', ''); + @endphp + - + @php + $sub_total_amount = number_format((float)$transactions->sum('amount') + ($transfer_fee * 1/$transactions[0]->currency_rate), 2, '.', ''); + @endphp + - - + + @php + $service_charge = number_format((float)$sub_total_amount * 0.75 / 100, 2, '.', ''); + @endphp + - + @php + $total_amount = number_format((float)$sub_total_amount + $service_charge, 2, '.', ''); + @endphp + + + +
Sub total booking amount: RMB {{number_format((float)$transactions->sum('original_amount'), 2, '.', '')}}RMB {{$sub_total_booking_amount}}
Transfer fee (0.002%): RMB {{number_format((float)$transactions->sum('original_amount') * 0.002 / 100, 2, '.', '')}}RMB {{$transfer_fee}}
Total booking amount: RMB {{number_format((float) ($transactions->sum('original_amount') +($transactions->sum('original_amount') * 0.002 / 100)), 2, '.', '')}}RMB {{$total_booking_amount}}
Sub total amount: MYR {{number_format((float)$transactions->sum('amount'), 2, '.', '')}}MYR {{$sub_total_amount}}
Service charge ({{ $supplier->id == 2 ? 0 : '0.75%' }}): MYR {{number_format((float)$transactions->sum('service_charge'), 2, '.', '')}}Service charge ({{ $supplier->id == 2 ? '0.00' : '0.75%' }}): MYR {{$service_charge}}
Total amount: MYR {{number_format((float) ($transactions->sum('amount') + $transactions->sum('service_charge')), 2, '.', '')}}MYR {{$total_amount}}
+ + + + -
Page {PAGENO} of {nbpg}
- - - - - -
Page {PAGENO} of {nbpg}
-
+
@endsection \ No newline at end of file