diff --git a/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php index 3f052352..75516fdf 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php @@ -85,7 +85,7 @@ class CreateSupplierTransactionProcessor $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); - $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant ? (float) $constant->detail->amount : 0); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant); $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, @@ -97,7 +97,7 @@ class CreateSupplierTransactionProcessor $this->pushBill($billTransaction); $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); - $transferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount); + $transferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount, $constant); $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, diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php index 8ddb80c9..e04edee2 100644 --- a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -2,18 +2,38 @@ namespace App\Classes\Modules\Transactions\Services; +use App\Models\SegmentConstant; + class CalculatesTransactionServiceCharge { + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + + /** + * CalculatesTransactionServiceCharge constructor. + * @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee + */ + public function __construct(CalculatesTransactionTransferFee $calculatesTransactionTransferFee) + { + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + } + /** * @param float $amount * @param float $rate - * @param float $service_charge - * @param float $transfer_fee + * @param SegmentConstant|null $service_charge * @return float */ - public function execute(float $amount, float $rate, ?float $service_charge = 0, ?float $transfer_fee = 0.00) { - return (($amount + $transfer_fee) * (1/$rate)) * $service_charge / 100; + public function execute(float $amount, float $rate, ?SegmentConstant $service_charge) { + + if(!$service_charge) { + return 0; + } + + $transfer_fee = $this->calculatesTransactionTransferFee->execute($amount, $service_charge); + return $service_charge->detail->amount->type === 'percentage' ? (($amount + $transfer_fee) * ( (float) $service_charge->detail->amount->value /100) * (1/$rate)) : (float) $service_charge->detail->amount->value; + } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php index b5feb245..5a02a394 100644 --- a/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php @@ -2,16 +2,23 @@ namespace App\Classes\Modules\Transactions\Services; +use App\Models\SegmentConstant; + class CalculatesTransactionTransferFee { /** * @param float $amount - * @param float $transfer_fee + * @param SegmentConstant|null $service_charge * @return float */ - public function execute(float $amount, ?float $transfer_fee = 0) { - return $amount * ($transfer_fee / 100); + public function execute(float $amount, ?SegmentConstant $service_charge) { + + if(!$service_charge) { + return 0; + } + + return $service_charge->detail->transferFee->type === 'percentage' ? $amount * ((float) $service_charge->detail->transferFee->value /100) : (float) $service_charge->detail->transferFee->value; } } \ No newline at end of file diff --git a/database/seeds/UpdateTransactionBillOwnerSeeder.php b/database/seeds/UpdateTransactionBillOwnerSeeder.php index 7f04a0fc..1ced925d 100644 --- a/database/seeds/UpdateTransactionBillOwnerSeeder.php +++ b/database/seeds/UpdateTransactionBillOwnerSeeder.php @@ -1,5 +1,6 @@ get(); + $bookings = Booking::all(); - foreach ($transaction as $key => $row) { - $key = 0; - $bills = $row->booking->transactions()->bills()->where('original_amount', '=', $row->original_amount)->get(); - if(count($bills) > 1){ $key = $bills->search(function($bill)use($row){ return $bill->id === $row->id; }); } - $paymentTransaction = $row->booking->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->skip($key)->first(); + foreach ($bookings as $booking) { - $row->owner_type = Transaction::class; - $row->owner_id = $paymentTransaction->id; - $row->updated_at = $row->updated_at; - $row->update(); + $transactions = $booking->transactions()->bills()->get(); + foreach ($transactions as $row) { + $key = 0; + $bills = $booking->transactions()->bills()->where('original_amount', '=', $row->original_amount)->get(); + if(count($bills) > 1){ $key = $bills->search(function($bill)use($row){ return $bill->id === $row->id; }); } + $paymentTransaction = $booking->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->skip($key)->first(); + + $row->owner_type = Transaction::class; + $row->owner_id = $paymentTransaction->id; + $row->updated_at = $row->updated_at; + $row->update(); + } } DB::commit(); diff --git a/resources/assets/vue/components/companies/elements/SupplierComponent.vue b/resources/assets/vue/components/companies/elements/SupplierComponent.vue index b25e9ae7..f6944c4c 100644 --- a/resources/assets/vue/components/companies/elements/SupplierComponent.vue +++ b/resources/assets/vue/components/companies/elements/SupplierComponent.vue @@ -22,7 +22,7 @@ -
+
Currencies
@@ -42,7 +42,19 @@
-
{{item.service_charge ? parseFloat(item.service_charge.detail.amount).toFixed(3) : '0.000'}}%
+
{{item.service_charge ? ((Math.round((parseFloat(item.service_charge.detail.amount.value) + Number.EPSILON) * 1000) / 1000).toFixed(3)+ '' +(item.service_charge.detail.amount.type === 'percentage' ? '%' : ' MYR')) : '0.000%'}}
+
+
+
+
+
+
+
Transfer Fee
+
+
+
+
+
{{item.service_charge ? ((Math.round((parseFloat(item.service_charge.detail.transferFee.value) + Number.EPSILON) * 1000) / 1000).toFixed(3)+ '' +(item.service_charge.detail.transferFee.type === 'percentage' ? '%' : ' FEC')) : '0.000%'}}
diff --git a/resources/assets/vue/components/companies/forms/SupplierServiceChargeFormComponent.vue b/resources/assets/vue/components/companies/forms/SupplierServiceChargeFormComponent.vue index 37301e23..c6906d92 100644 --- a/resources/assets/vue/components/companies/forms/SupplierServiceChargeFormComponent.vue +++ b/resources/assets/vue/components/companies/forms/SupplierServiceChargeFormComponent.vue @@ -14,13 +14,49 @@ {{error}}
-
-
- - - +
+
+ + +
+
+
+
+ MYR +
+
+
+
+
+
+ % +
+
+
+
+
+
+ + + + +
+
+
+
+ FEC +
+
+
+
+
+
+ % +
+
+
@@ -52,20 +88,33 @@ reference: 'SERVICE_CHARGE', detail: { id: this.supplierId, - type: "percentage", - amount: 0, + amount: { + type: "percentage", + value: 0 + }, + transferFee: { + type: "percentage", + value: 0 + }, + transferCompanyId: this.supplierId }, segment_id: 1 }, + serviceChargeOptions: false, + transferFeeOptions: false, } }, validations: { parameters: { - amount: { - detail: { - amount: { - required: true - } + detail: { + amount: { + value: required + }, + transferFee: { + value: required + }, + transferCompanyId: { + required: true } } } @@ -74,8 +123,15 @@ if(this.data){ this.parameters.detail = { id: this.supplierId, - type: "percentage", - amount: parseFloat(this.data.detail.amount).toFixed(3), + amount: { + type: this.data.detail.amount.type, + value: parseFloat(this.data.detail.amount.value).toFixed(3) + }, + transferFee: { + type: this.data.detail.transferFee.type, + value: parseFloat(this.data.detail.transferFee.value).toFixed(3) + }, + transferCompanyId: this.data.detail.transferCompanyId } } }, diff --git a/resources/views/pages/pdfs/currency_vendor_order.blade.php b/resources/views/pages/pdfs/currency_vendor_order.blade.php index c19811bb..3f37cc08 100644 --- a/resources/views/pages/pdfs/currency_vendor_order.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order.blade.php @@ -57,7 +57,7 @@ RMB {{$sub_total_booking_amount}} - Transfer fee (0.002%): + Transfer fee: @php $transfer_fee = number_format((float)$transferFeeTransactions->sum('service_charge'), 2, '.', ''); @endphp