From 2cb7e2e3c6c581282c13b8a74fa914cf5e727c45 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Fri, 16 Jul 2021 17:57:37 +0800 Subject: [PATCH] fix duplicated invoices bug --- .../Services/CalculatesBookingTransferredAmount.php | 4 ++-- app/Models/Transaction.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingTransferredAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingTransferredAmount.php index 398c99e9..f83fa7ef 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingTransferredAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingTransferredAmount.php @@ -13,9 +13,9 @@ class CalculatesBookingTransferredAmount public function execute(Booking $booking, int $type){ return $type === 1 ? - $booking->transactions()->payments()->transferred() + $booking->transactions()->bills()->transferred() ->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') : - $booking->transactions()->payments()->transferred()->sum('original_amount'); + $booking->transactions()->bills()->transferred()->sum('original_amount'); } } \ No newline at end of file diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 0e39c289..002d7611 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -75,6 +75,16 @@ class Transaction extends AbstractModel implements Documentable return $query->where('type', TransactionType::PAYMENT); } + /** + * @param Builder $query + * @return Builder + */ + public function scopeBills(Builder $query) + { + return $query->where('type', TransactionType::BILL); + } + + /** * @param Builder $query * @return Builder