Fix cannot approve po probem for 1 booking reported by Sin Yee

This commit is contained in:
Dillon Ngo
2025-08-30 12:22:00 +08:00
parent 3b295df9fc
commit 42493625d0
@@ -22,6 +22,7 @@ use App\Classes\ValueObjects\Constants\KVPKey;
use App\Models\Booking;
use App\Models\SegmentConstant;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\Log;
class CreateInvoiceTransactionProcessor
@@ -214,8 +215,23 @@ class CreateInvoiceTransactionProcessor
$booking_currency_average_rate = $this->calculatesBookingCurrencyAverageRate->execute($booking, TransactionType::BILL);
$transaction = $booking->transactions()->payments()->where('status', ApprovalStatus::COMPLETED)->first()
->transactions()->where('type', TransactionType::BILL)->first();
$paymentTransaction = $booking->transactions()->payments()->where('status', ApprovalStatus::COMPLETED)->first();
$transaction = null;
if($paymentTransaction){
$transaction = $paymentTransaction->transactions()->where('type', TransactionType::BILL)->first();
}
else{ // Special handling for refund cases (When a refund is deleted via DeleteRefundTransactionLogic, a booking payment transaction is set to ApprovalStatus::APPROVED)
$temp = $booking->transactions()->payments()->where('status', ApprovalStatus::APPROVED)->first();
// Lets check if there is a refund case
$refund = $temp->transactions()->refunds()->where('status', ApprovalStatus::APPROVED)->first();
if($refund){
$transaction = $temp;
}
else{
throw new Exception("No payment found for booking '$booking->id'.");
}
}
$transaction_object = new TransactionObject(
$billNumber,