From 80bc4eb0fdb5356f896db66158356b176ff72a95 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Thu, 12 Aug 2021 13:52:09 +0800 Subject: [PATCH] fix myr fixed invoice bug --- .../Bookings/Services/CalculatesBookingPaidAmount.php | 7 ++----- .../Services/CalculatesBookingPayableAmount.php | 7 +++++-- .../Processors/CreateInvoiceTransactionProcessor.php | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php index 0f8af523..42ce7589 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php @@ -11,11 +11,8 @@ use Carbon\Carbon; class CalculatesBookingPaidAmount { - public function execute(Booking $booking, int $type){ - return $type === 1 ? - $booking->transactions()->payments()->complete() - ->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') : - $booking->transactions()->payments()->complete()->sum('original_amount'); + public function execute(Booking $booking){ + return $booking->transactions()->payments()->complete()->sum('original_amount'); } } \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingPayableAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingPayableAmount.php index 33151018..a068cbbe 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingPayableAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingPayableAmount.php @@ -11,8 +11,11 @@ use Carbon\Carbon; class CalculatesBookingPayableAmount { - public function execute(Booking $booking){ - return $booking->transactions()->payments()->complete()->sum('original_amount'); + public function execute(Booking $booking, int $type){ + return $type === 1 ? + $booking->transactions()->payments()->complete() + ->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') : + $booking->transactions()->payments()->complete()->sum('original_amount'); } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php index d6f8fb87..ad9e5344 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php @@ -108,16 +108,16 @@ class CreateInvoiceTransactionProcessor return; } - $payment_amount = $this->calculatesBookingPaidAmount->execute($booking, $booking->fix_currency_id); + $payable_amount = $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id); $booking_amount = $booking->fix_amount; // confirm that booking amount has been fully paid - if (!(abs(((float) $booking_amount - (float) $payment_amount)/(float) $payment_amount) < 0.009)) { + if ((float) $booking_amount > $payable_amount) { return; } // confirm that all payments has been transferred - if($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPayableAmount->execute($booking)){ + if($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)){ return; } @@ -157,7 +157,7 @@ class CreateInvoiceTransactionProcessor $transaction->receiver, $transaction->recipient_bank_account_id, $transaction->payment_method, - $payment_amount, + $payable_amount, $booking_amount, $transaction->currency_id, $transaction->original_currency_id, @@ -218,7 +218,7 @@ class CreateInvoiceTransactionProcessor $transaction->receiver, $transaction->recipient_bank_account_id, $transaction->payment_method, - $payment_amount, + $payable_amount, $booking_amount, $transaction->currency_id, $transaction->original_currency_id,