debug invoice pdf

This commit is contained in:
Omair Saleh
2023-08-10 17:25:18 +08:00
parent 42243d7c23
commit 058d7967a2
4 changed files with 56 additions and 35 deletions
@@ -1,24 +0,0 @@
<?php
function calculateSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUp($number, $decimals)
{
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@@ -1,4 +1,3 @@
@include('./InvoiceHelpers')
@extends('layouts.base_pdf')
@section('inner_content')
<br>
@@ -83,8 +82,8 @@
</thead>
<tbody>
@php
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
$displayedSubtotal = 0;
@endphp
@@ -111,7 +110,7 @@
</tbody>
<tfoot>
@php
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
@endphp
<tr class="subtotal">
@@ -149,7 +148,7 @@
<tr>
<td colspan="4"></td>
<td class="right middle">Adjustment</td>
<td class="right middle">{{ roundUp($discrepancy,2) }}</td>
<td class="right middle">{{ roundUpDo($discrepancy,2) }}</td>
</tr>
<tr>
<td colspan="4"></td>
@@ -168,4 +167,28 @@
</tr>
</table>
</htmlpagefooter>
@php
function calculateDoSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getDoVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUpDo($number, $decimals) {
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@endphp
@endsection
@@ -1,4 +1,3 @@
@include('./InvoiceHelpers')
@extends('layouts.base_pdf')
@section('inner_content')
@@ -1,4 +1,3 @@
@include('./InvoiceHelpers')
@extends('layouts.base_pdf')
@section('inner_content')
<br>
@@ -91,8 +90,8 @@
</thead>
<tbody>
@php
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate);
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
$displayedSubtotal = 0;
@endphp
@@ -119,7 +118,7 @@
</tbody>
<tfoot>
@php
$voucherDiscount = getVoucherDiscount($voucher_redemption);
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
@endphp
<tr class="subtotal">
@@ -157,7 +156,7 @@
<tr>
<td colspan="4"></td>
<td class="right middle">Adjustment</td>
<td class="right middle">{{ roundUp($discrepancy,2) }}</td>
<td class="right middle">{{ roundUpPo($discrepancy,2) }}</td>
</tr>
<tr>
<td colspan="4"></td>
@@ -176,4 +175,28 @@
</tr>
</table>
</htmlpagefooter>
@php
function calculatePoSubtotal($po_order_transaction, $currencyRate) {
$subtotal = "0";
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
$subtotal = bcadd($subtotal, $itemTotal, 5);
}
return $subtotal;
}
function getPoVoucherDiscount($voucher_redemption) {
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
}
function roundUpPo($number, $decimals) {
$factor = pow(10, $decimals);
if ($number > 0) {
return ceil($number * $factor) / $factor;
} else {
return floor($number * $factor) / $factor;
}
}
@endphp
@endsection