E-Invoice - Update business logic for downloading E-CreditNote

This commit is contained in:
Dillon Ngo
2025-08-26 10:09:18 +08:00
parent d8ce379560
commit d63b46c0ab
5 changed files with 41 additions and 21 deletions
+11 -1
View File
@@ -4,6 +4,7 @@ namespace App\Http\Resources;
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\KVPKey;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use Carbon\Carbon;
@@ -37,6 +38,14 @@ class TransactionResource extends JsonResource
}
//Check if Transaction of type PAYMENT has an override for recipient bank - ends
$eInvoice = false;
if($booking && $this->type === TransactionType::REFUND){
$kvp = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE)->first();
if($kvp){
$eInvoice = true;
}
}
$days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1);
return [
'id' => $this->id,
@@ -72,7 +81,8 @@ class TransactionResource extends JsonResource
'remarks' => RemarkResource::collection($this->remarks),
'redemption' => new VoucherRedemptionResource($this->voucherRedemption),
'bank' => ((int) $this->type === TransactionType::PAYMENT) ? new BankResource($bank) : null, //When a transaction (of type payment) has an override recipient bank details on booking, this is NOT null
'bank_recipient_edited' => $isEditedBankRecipient
'bank_recipient_edited' => $isEditedBankRecipient,
'e_invoice' => $this->when($this->type === TransactionType::REFUND, $eInvoice),
];
}
}