E-Invoice - Fix a problem where nothing shows after clicking 'Confim Booking' to pay remainder of booking

This commit is contained in:
Dillon Ngo
2025-07-14 14:48:25 +08:00
parent 6dec15c1ac
commit 1aee476649
2 changed files with 39 additions and 5 deletions
@@ -7,6 +7,7 @@ use App\Classes\Modules\Transactions\Services\FetchesGroup;
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\GroupResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -63,7 +64,7 @@ class DeleteGroupLogic extends AbstractControllerLogic
$payment = $bill->owner;
$group->transactions()->detach($bill->id);
$trns = $payment->transactions()->where('type', 3)->with('groupTransaction')->get();
$trns = $payment->transactions()->where('type', TransactionType::BILL)->with('groupTransaction')->get();
if(count($trns) <= 1){
$this->updatesTransactionStatus->execute($payment, ApprovalStatus::APPROVED);
}
@@ -4,6 +4,8 @@ namespace App\Classes\Modules\Transactions\Services;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
@@ -15,15 +17,25 @@ class CalculatesTransactionExpiryDateTime
/** @var FetchesCompanyPaymentAttemptLimit */
private $fetchesCompanyPaymentAttemptLimit;
/** @var CalculatesBookingOutstanding */
private $calculatesBookingOutstanding;
/** @var CalculatesBookingPaidAmount */
private $calculatesBookingPaidAmount;
/**
* CalculatesTransactionExpiryDateTime constructor.
* @param FetchesBooking $fetchesBooking
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
* @param CalculatesBookingPaidAmount $calculatesBookingPaidAmount
*/
public function __construct(FetchesBooking $fetchesBooking, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit)
public function __construct(FetchesBooking $fetchesBooking, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding, CalculatesBookingPaidAmount $calculatesBookingPaidAmount)
{
$this->fetchesBooking = $fetchesBooking;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
$this->calculatesBookingPaidAmount = $calculatesBookingPaidAmount;
}
@@ -33,13 +45,22 @@ class CalculatesTransactionExpiryDateTime
*/
public function execute(int $bookingId)
{
$isExpired = false;
$booking = $this->fetchesBooking->execute(['id' => $bookingId]);
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
$createdAt = Carbon::parse($booking->created_at);
Log::info("1. Booking created at {$createdAt}.");
$bookingExpiresAt = $createdAt->addMinutes($paymentAttemptLimit);
$newBookingExpiresAt = $this->getNewBookingExpiresAt($booking, $bookingExpiresAt, $paymentAttemptLimit);
$newBookingExpiresAt = $this->getNewBookingExpiresAt2($booking, $paymentAttemptLimit) ?? $newBookingExpiresAt; //Overuled all previous expiry datetime
$returnDateTime = $newBookingExpiresAt ? $newBookingExpiresAt : $bookingExpiresAt;
return $returnDateTime;
}
private function getNewBookingExpiresAt($booking, $bookingExpiresAt, $paymentAttemptLimit){
$isExpired = false;
Log::info("1. Booking expires at {$bookingExpiresAt}. (original)");
$newBookingExpiresAt = null;
$now = Carbon::now();
@@ -85,7 +106,19 @@ class CalculatesTransactionExpiryDateTime
Log::info("Booking expired and no valid pending payments for booking ID: {$booking->id}");
}
// }
$returnDateTime = $newBookingExpiresAt ? $newBookingExpiresAt : $bookingExpiresAt;
return $returnDateTime;
return $newBookingExpiresAt;
}
private function getNewBookingExpiresAt2($booking, $paymentAttemptLimit){
$newBookingExpiresAt = null;
$amountOutstanding = $this->calculatesBookingOutstanding->execute($booking);
$amountPaid = $this->calculatesBookingPaidAmount->execute($booking);
if($amountPaid > 0.01 && $amountOutstanding > 0){
$newBookingExpiresAt = Carbon::now()->addMinutes($paymentAttemptLimit);
Log::info("3. Overule booking expired: {$newBookingExpiresAt}");
}
return $newBookingExpiresAt;
}
}