diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php
index d8bcb6ec..5d8b3836 100644
--- a/app/Http/Resources/BookingResource.php
+++ b/app/Http/Resources/BookingResource.php
@@ -49,7 +49,8 @@ class BookingResource extends JsonResource
'marking' => $this->marking,
'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)),
+ 'paid_amount_with_refund' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
+ 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::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)),
diff --git a/resources/views/pages/pdfs/e_invoice.blade.php b/resources/views/pages/pdfs/e_invoice.blade.php
index cf3069ca..a5ea0cd5 100644
--- a/resources/views/pages/pdfs/e_invoice.blade.php
+++ b/resources/views/pages/pdfs/e_invoice.blade.php
@@ -65,7 +65,7 @@
- @include('pages.pdfs.purchase_order_table')
+ @include('pages.pdfs.e_invoice_purchase_order_table')
diff --git a/resources/views/pages/pdfs/e_invoice_purchase_order_table.blade.php b/resources/views/pages/pdfs/e_invoice_purchase_order_table.blade.php
new file mode 100644
index 00000000..209ff33d
--- /dev/null
+++ b/resources/views/pages/pdfs/e_invoice_purchase_order_table.blade.php
@@ -0,0 +1,199 @@
+
+
+
+
+ | No |
+ Stock Code |
+ Description |
+ Quantity |
+ Unit Price (RM) |
+ Total Amount (RM) |
+
+
+
+ @php
+ $subtotal = "0";
+ $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
+ $displayedSubtotal = 0;
+ $currency_id = $transaction->owner->fix_currency_id;
+ @endphp
+
+ owner ?? $booking;
+ $paymentSum = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->where('status', ApprovalStatus::COMPLETED)
+ ->get()
+ ->sum(function ($transaction) {
+ return round($transaction->amount, 2);
+ });
+
+ $totalPayment = 0;
+ $average_currency_rate = $transaction->currency_rate;
+
+ $paymentSumRefund = 0;
+ if ($paymentSum){
+ $average_currency_rate = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->where('status', ApprovalStatus::COMPLETED)
+ ->get()
+ ->sum(function ($transaction) {
+ return $transaction->currency_rate;
+ }) / $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->where('status', ApprovalStatus::COMPLETED)
+ ->count();
+
+ // $refundedAmount = (App()->make(CalculatesBookingRefundAmount::class))->execute($booking, 1);
+ // $refundedServiceCharge = (App()->make(CalculatesBookingRefundServiceCharge::class))->execute($booking, 1);
+
+ $totalPayment = $paymentSum;
+ // $totalPayment = $paymentSum - $refundedAmount - $refundedServiceCharge;
+ }
+ else{
+ $paymentSumRefund = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->where('status', ApprovalStatus::REFUNDED)
+ ->get()
+ ->sum(function ($transaction) {
+ return round($transaction->amount, 2);
+ });
+ }
+ ?>
+
+ @if (!empty($po_order_transaction) && $po_order_transaction->transactionDetails)
+ @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
+ @php
+ $exactUnitPrice = ($currency_id) === 1 ? $transaction_detail->price : bcdiv($transaction_detail->price, $average_currency_rate, 7);
+ $displayUnitPrice = round($exactUnitPrice, 2);
+ @endphp
+
+ @continue($transaction_detail->product_name === 'Discount' && $displayUnitPrice < 0)
+
+ @php
+ $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
+ $displayedItemTotal = round(bcmul($displayUnitPrice, $transaction_detail->quantity, 7), 2);
+ $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
+ $subtotal = bcadd($subtotal, $itemTotal, 5);
+ @endphp
+
+ | {{ $key + 1 }} |
+ {{ $transaction_detail->product_code }} |
+ {{ $transaction_detail->product_name }} |
+ {{ $transaction_detail->quantity }} |
+
+ {{ number_format($displayUnitPrice, 2) }}
+ |
+
+ {{ number_format($displayedItemTotal, 2) }}
+ |
+
+ @endforeach
+ @else
+ @if ($paymentSumRefund)
+
+ |
+ |
+ CANCEL FULL ORDER |
+ |
+ |
+ |
+
+ @endif
+ @endif
+
+
+ @php
+ $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5);
+ if (!$totalPayment) {
+ $serviceCharge = $transaction->service_charge;
+ }
+ else {
+ $serviceCharge = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->where('status', ApprovalStatus::COMPLETED)
+ ->get()
+ ->sum(function ($transaction) {
+ return $transaction->service_charge;
+ });
+ }
+ if ($paymentSumRefund && $displayedSubtotal === 0){
+ $subtotal = bcsub($paymentSumRefund, $serviceCharge, 5);
+ $displayedSubtotal = bcsub($paymentSumRefund, $serviceCharge, 2);
+ }
+ @endphp
+
+ |
+ Subtotal |
+ {{ number_format($displayedSubtotal, 2) }} |
+
+
+ |
+ Service Charges |
+ {{ number_format($serviceCharge, 2) }} |
+
+ @if($voucher_redemption)
+
+ |
+ Voucher ({{ $voucher_redemption->voucher->code }}) |
+ {{ number_format($voucherDiscount, 2) }} |
+
+ @endif
+
+ @if($transaction->tax > 0)
+
+ |
+ Tax |
+ {{ number_format($transaction->tax, 2) }} |
+
+ @endif
+ @php
+ $displayedSubtotal = is_numeric($displayedSubtotal) ? sprintf('%F', $displayedSubtotal) : '0';
+ $serviceCharge = is_numeric($serviceCharge) ? sprintf('%F', $serviceCharge) : '0';
+ $tax = is_numeric($transaction->tax) ? sprintf('%F', $transaction->tax) : '0';
+ $voucherDiscount = is_numeric($voucherDiscount) ? sprintf('%F', $voucherDiscount) : '0';
+
+ $displayedTotal = bcadd(
+ bcadd(
+ bcadd($displayedSubtotal, $serviceCharge, 5),
+ $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, $serviceCharge, 5), $transaction->tax, 5), $voucherDiscount, 5);
+
+ if ($totalPayment) {
+ $expectedTotal = $totalPayment;
+ $discrepancy = bcsub($expectedTotal, $displayedTotal, 5);
+ $total = $totalPayment;
+ }
+
+ if($paymentSumRefund){
+ $total = $paymentSumRefund;
+ }
+ @endphp
+
+ |
+ Adjustment |
+ {{number_format($discrepancy, 5)}} |
+
+
+ |
+ Total |
+
+ {{ number_format($total, 2) }}
+ |
+
+
+