mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
fix invoice refund service charge
This commit is contained in:
@@ -108,10 +108,12 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
// $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount'));
|
||||
// $transactionRefundCalculationObject->init();
|
||||
|
||||
// full refund
|
||||
if ((float)$request->input('amount') === (float)$transaction->original_amount) {
|
||||
$refundAmount = $transaction->original_amount / $transaction->currency_rate;
|
||||
$service_charges_to_refund = $transaction->service_charge;
|
||||
} else {
|
||||
// partial refund
|
||||
$refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7);
|
||||
|
||||
$bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending;
|
||||
|
||||
@@ -7,6 +7,8 @@ use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
@@ -42,9 +44,19 @@ class CreateInvoiceDocumentProcessor
|
||||
*/
|
||||
public function execute($transaction, $purchaseOrder, $supplier, $document_type, $voucherRedemption = null)
|
||||
{
|
||||
// calculate current Paid Amount
|
||||
$booking = $transaction->owner_type == Booking::class ? $transaction->owner : null;
|
||||
$currentPaidAmount = null;
|
||||
if ($booking) {
|
||||
$payment = $booking->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->first();
|
||||
$refundAmount = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sum('amount');
|
||||
$paymentAmount = $payment->amount;
|
||||
$currentPaidAmount = $paymentAmount - $refundAmount;
|
||||
}
|
||||
|
||||
$lowercaseDocumentType = strtolower($document_type);
|
||||
|
||||
$order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption]);
|
||||
$order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption, 'current_paid_amount' => $currentPaidAmount]);
|
||||
|
||||
if($purchaseOrder->booking->service_id === 4) {
|
||||
$purchaseOrderDocuments = $purchaseOrder->booking->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->get();
|
||||
|
||||
@@ -83,6 +83,12 @@
|
||||
{{item.original_currency.short_code}} {{(Math.round((totalRefunds + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto p-l-0" v-if="$store.getters.isSuperAdmin">
|
||||
<div class="font-heading fs-8 muted all-caps">Service Type</div>
|
||||
<div class="font-heading fs-10 bold">
|
||||
{{item.booking.service.name}} ({{item.booking.service.id}})
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto" v-if="$store.getters.isAdmin">
|
||||
<div class="font-heading fs-8 muted all-caps">Supplier</div>
|
||||
<div class="font-heading fs-10 bold">
|
||||
|
||||
@@ -53,7 +53,14 @@
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Service Charges</td>
|
||||
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
|
||||
<?php
|
||||
$serviceCharge = $transaction->service_charge;
|
||||
if (isset($current_paid_amount)) {
|
||||
$refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount;
|
||||
$serviceCharge = $serviceCharge - $refundedServiceCharge;
|
||||
}
|
||||
?>
|
||||
<td class="right">{{ number_format($serviceCharge, 2) }}</td>
|
||||
</tr>
|
||||
|
||||
@if($voucher_redemption)
|
||||
@@ -72,10 +79,10 @@
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($expectedTotal, $displayedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
|
||||
Reference in New Issue
Block a user