E-Invoice - Updated business logic for refund / return (credit note) without updating booking amount

This commit is contained in:
Dillon Ngo
2025-09-05 15:45:28 +08:00
parent 27b297c0ed
commit 4ff703bd75
4 changed files with 30 additions and 8 deletions
@@ -75,10 +75,13 @@ class UpdateBookingAmountWithPOLogic extends AbstractControllerLogic
$booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]);
$outstandingAmount = $this->calculatesBookingOutstanding->execute($booking);
$bookingAttribute = $booking->attributesKVP()->where('key', "BOOKING_AMOUNT_UPDATE")->first();
$paidAmount = floatval($this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id)) - floatval($this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id));
$refundAmount = $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
$paidAmount = floatval($this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id)) - floatval($refundAmount);
if($paidAmount > 0 && $outstandingAmount > 0 && !$bookingAttribute){
throw new MalformedRequestException('Purchase Order at this point can only be edited after editing the booking amount');
if($refundAmount != $outstandingAmount){
throw new MalformedRequestException('Purchase Order at this point can only be edited after editing the booking amount');
}
}
if($bookingAttribute){
@@ -125,9 +125,9 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic
$this->updatesTransactionStatus->execute($po_transaction, (float) number_format($po_transaction->amount, 2, '.', '') === (float) number_format((float)$booking->fix_amount - $refundTransaction->original_amount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION);
}
$request['fix_amount'] = $booking->fix_amount - $refundTransaction->original_amount;
$request->route()->setParameter('id', $booking->id);
$this->updateBookingAmountLogic->execute($request);
// $request['fix_amount'] = $booking->fix_amount - $refundTransaction->original_amount;
// $request->route()->setParameter('id', $booking->id);
// $this->updateBookingAmountLogic->execute($request);
}
if ($supplierRefundTransaction) {
+4 -1
View File
@@ -39,6 +39,8 @@ class BookingResource extends JsonResource
$eInvoice = true;
}
$outStandingAmountWithRefund = floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id));
return [
'id' => $this->id,
'company' => new CompanyResource($this->company),
@@ -48,7 +50,8 @@ class BookingResource extends JsonResource
'amount' => $this->fix_amount,
'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)),
'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
// 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) + floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
'outstanding_amount_with_refund' => $outStandingAmountWithRefund > 0 ? $outStandingAmountWithRefund : 0,
'refunded_amount' => floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)),
'fixed_currency' => new CurrencyResource($this->fixedCurrency),
'convertible_currency' => new CurrencyResource($this->convertibleCurrency),
@@ -100,7 +100,7 @@
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.paid_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
<div class="row align-items-end m-b-10 ">
<div class="row align-items-end m-b-10">
<div class="col">
<div class="font-heading all-caps fs-12">Floating Amount:</div>
</div>
@@ -108,7 +108,15 @@
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.floating_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
<div class="row align-items-end bold text-danger">
<div class="row align-items-end bold text-danger" v-if="this.data.refunded_amount">
<div class="col">
<div class="font-heading all-caps fs-12">OutStanding Total:</div>
</div>
<div class="col-auto text-right">
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.outstanding_amount_with_refund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
<div class="row align-items-end bold m-t-10 text-danger" v-else>
<div class="col">
<div class="font-heading all-caps fs-12">OutStanding Total:</div>
</div>
@@ -116,6 +124,14 @@
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
<div class="row align-items-end bold m-t-10 text-danger" v-if="this.data.refunded_amount">
<div class="col">
<div class="font-heading all-caps fs-12">Refunded Total:</div>
</div>
<div class="col-auto text-right">
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.refunded_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
</div>
</div>
<div class="row m-t-20" v-if="data.company.employee.status === 2 && data.company.status === 2 && (Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100) > 0">
<div class="col">
<button id="payment-btn" class="btn btn-sm all-caps b-rad-none btn-success btn-block" @click="makePayment()">Make Payment</button>