diff --git a/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php index bf4dde0b..2ce1d63e 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php @@ -129,21 +129,27 @@ class CreateProformaInvoiceTransactionProcessor $billNumber = $this->generatesTransactionBillNumber->execute('PROFORMA-'); - $payable_amount = $booking->transactions()->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::SUSPENDED])->payments()->sum('amount'); + $payable_amount = $booking->transactions()->payments()->where(function($query){ + return $query->where(function($query){ + return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString()); + })->orWhere(function($query){ + return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + }); + })->sum('amount'); $booking_amount = $booking->fix_amount; $transaction = $booking->transactions() ->where('type', TransactionType::PAYMENT) ->first(); - $booking_currency_average_rate = $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) / $booking->transactions()->payments()->where(function($query){ + $booking_currency_average_rate = $booking_amount / $booking->transactions()->payments()->where(function($query){ return $query->where(function($query){ return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString()); })->orWhere(function($query){ return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); }); })->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total'); - dd($booking_currency_average_rate); + dd($payable_amount, $booking_currency_average_rate); // $booking_currency_average_rate = $booking_amount / $booking->transactions()->payments()->where(function($query){ // return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>', Carbon::now())->get(); // })->orWhere(function($query){