From 6013a4e94e35d230d95f7c14ea228bda5983084b Mon Sep 17 00:00:00 2001 From: omair saleh Date: Wed, 22 Dec 2021 16:15:08 +0800 Subject: [PATCH] fix transfers list --- app/Classes/General/Eloquent/Filters/WithTotalPayments.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Classes/General/Eloquent/Filters/WithTotalPayments.php b/app/Classes/General/Eloquent/Filters/WithTotalPayments.php index d93e55e2..25973ffb 100644 --- a/app/Classes/General/Eloquent/Filters/WithTotalPayments.php +++ b/app/Classes/General/Eloquent/Filters/WithTotalPayments.php @@ -5,6 +5,7 @@ namespace App\Classes\General\Eloquent\Filters; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; +use App\Models\Booking; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\DB; @@ -19,7 +20,7 @@ class WithTotalPayments implements Filter public static function apply(Builder $builder, $value) { return $builder->leftJoin('bookings', 'companies.id', '=', 'bookings.company_id')->rightJoin('transactions', function ($join) { - $join->on('bookings.id', '=', 'transactions.booking_id')->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + $join->on('bookings.id', '=', 'transactions.owner_id')->where('owner_type', '=', Booking::class)->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); })->addSelect(['companies.*', DB::raw('SUM(transactions.amount) as total_payments')])->groupBy(['companies.id']); } } \ No newline at end of file