mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
regenerate invoices for 2023
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Helpers;
|
||||
|
||||
class InvoiceDocumentsHelper
|
||||
{
|
||||
public static 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;
|
||||
}
|
||||
|
||||
public static function getVoucherDiscount($voucher_redemption) {
|
||||
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
}
|
||||
|
||||
public static function roundUp($number, $decimals) {
|
||||
$factor = pow(10, $decimals);
|
||||
if ($number > 0) {
|
||||
return ceil($number * $factor) / $factor;
|
||||
} else {
|
||||
return floor($number * $factor) / $factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
@php
|
||||
use App\Classes\Helpers\InvoiceDocumentsHelper;
|
||||
@endphp
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
<div class="number">EDO: {{ $transaction->bill_no }}</div>
|
||||
|
||||
<div class="ref">REF: {{ $transaction->booking->marking }}</div>
|
||||
<div class="date">Date: {{ $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->created_at }}</div>
|
||||
<div class="date">Date: {{
|
||||
$supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->created_at }}</div>
|
||||
<div> </div>
|
||||
</td>
|
||||
<tr>
|
||||
@@ -82,8 +83,8 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
||||
$subtotal = "0";
|
||||
$voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@@ -110,7 +111,6 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
@@ -148,7 +148,7 @@
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
<td class="right middle">{{ roundUpDo($discrepancy,2) }}</td>
|
||||
<td class="right middle">{{ ceil($discrepancy * 100) / 100 }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
@@ -167,28 +167,4 @@
|
||||
</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
|
||||
|
||||
@@ -72,8 +72,8 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
||||
$subtotal = "0";
|
||||
$voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@@ -100,8 +100,7 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5);
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
<td colspan="4"></td>
|
||||
@@ -133,12 +132,12 @@
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
<td class="right middle">{{ roundUp($discrepancy,2) }}</td>
|
||||
<td class="right middle">{{ roundUp($discrepancy, 2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
@@ -160,28 +159,4 @@
|
||||
Account Name: CIEF Worldwide Sdn Bhd<br>
|
||||
Account No: 564892103405<br>
|
||||
</div>
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@endphp
|
||||
@endsection
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
<table class="buyer-seller">
|
||||
<tr>
|
||||
<td width="50%" class="top">
|
||||
<span class="buyer-seller-title">
|
||||
Buyer
|
||||
</span>
|
||||
<span class="buyer-seller-title">
|
||||
Buyer
|
||||
</span>
|
||||
<br>
|
||||
|
||||
<div class="buyer-company">
|
||||
@@ -34,34 +34,34 @@
|
||||
</div>
|
||||
|
||||
<span class="buyer-company">
|
||||
{{ $supplier->name }}
|
||||
</span>
|
||||
{{ $supplier->name }}
|
||||
</span>
|
||||
<span class="reg">
|
||||
{{-- {{ $supplier }} --}}
|
||||
</span>
|
||||
{{-- {{ $supplier }} --}}
|
||||
</span>
|
||||
<br>
|
||||
<span class="address">
|
||||
@php
|
||||
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
||||
@endphp
|
||||
@php
|
||||
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
||||
@endphp
|
||||
{{ $billingAddress->street_one }}
|
||||
{{ $billingAddress->street_two }}
|
||||
{{ $billingAddress->state()->first()->name }}
|
||||
{{ $billingAddress->district()->first()->name }}
|
||||
</span>
|
||||
</span>
|
||||
<br>
|
||||
<span class="contact-no">
|
||||
Phone: {{ $supplier->contacts()->first()->phone }}
|
||||
</span>
|
||||
Phone: {{ $supplier->contacts()->first()->phone }}
|
||||
</span>
|
||||
</td>
|
||||
<td width="50%" class="top">
|
||||
<span class="buyer-seller-title">
|
||||
Seller
|
||||
</span>
|
||||
<span class="buyer-seller-title">
|
||||
Seller
|
||||
</span>
|
||||
<br>
|
||||
<span class="buyer-company">
|
||||
CIEF Worldwide Sdn Bhd (1134596-M)
|
||||
</span>
|
||||
CIEF Worldwide Sdn Bhd (1134596-M)
|
||||
</span>
|
||||
<div class="address">
|
||||
No. 72-3, Jalan Jalil 1,<br>
|
||||
The Earth Bukit Jalil,<br>
|
||||
@@ -90,8 +90,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
|
||||
$subtotal = "0";
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@@ -118,8 +117,12 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
|
||||
$voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
<td colspan="4"></td>
|
||||
@@ -147,12 +150,7 @@
|
||||
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
@endphp
|
||||
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
@@ -175,28 +173,4 @@
|
||||
</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
|
||||
|
||||
+6
-3
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Classes\Jobs\GenerateInvoice;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
|
||||
use App\Http\Controllers\Accounting\BankStatementController;
|
||||
use Carbon\Carbon;
|
||||
@@ -470,8 +469,12 @@ Route::get('/invoice/fix', function(){
|
||||
$bookings = Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get();
|
||||
|
||||
foreach($bookings as $booking){
|
||||
GenerateInvoice::dispatch($booking);
|
||||
echo 'Invoice fixing job dispatched.';
|
||||
$booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete();
|
||||
$booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete();
|
||||
$booking->status = ApprovalStatus::APPROVED;
|
||||
$booking->save();
|
||||
|
||||
(App()->make(CreateInvoiceTransactionProcessor::class))->execute($booking);
|
||||
}
|
||||
})->name('invoice.fix');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user