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>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<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="number">EDO: {{ $transaction->bill_no }}</div>
|
||||||
|
|
||||||
<div class="ref">REF: {{ $transaction->booking->marking }}</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>
|
<div> </div>
|
||||||
</td>
|
</td>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -82,8 +83,8 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@php
|
@php
|
||||||
$subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate);
|
$subtotal = "0";
|
||||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
$voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||||
$displayedSubtotal = 0;
|
$displayedSubtotal = 0;
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@@ -110,7 +111,6 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
@php
|
@php
|
||||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
|
||||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||||
@endphp
|
@endphp
|
||||||
<tr class="subtotal">
|
<tr class="subtotal">
|
||||||
@@ -148,7 +148,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
<td class="right middle">Adjustment</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>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
@@ -167,28 +167,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</htmlpagefooter>
|
</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
|
@endsection
|
||||||
|
|||||||
@@ -72,8 +72,8 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@php
|
@php
|
||||||
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
|
$subtotal = "0";
|
||||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
$voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||||
$displayedSubtotal = 0;
|
$displayedSubtotal = 0;
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@@ -100,8 +100,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
@php
|
@php
|
||||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5);
|
||||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
|
||||||
@endphp
|
@endphp
|
||||||
<tr class="subtotal">
|
<tr class="subtotal">
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
@@ -133,12 +132,12 @@
|
|||||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
$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);
|
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 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
|
@endphp
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
<td class="right middle">Adjustment</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>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
@@ -160,28 +159,4 @@
|
|||||||
Account Name: CIEF Worldwide Sdn Bhd<br>
|
Account Name: CIEF Worldwide Sdn Bhd<br>
|
||||||
Account No: 564892103405<br>
|
Account No: 564892103405<br>
|
||||||
</div>
|
</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
|
@endsection
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
<table class="buyer-seller">
|
<table class="buyer-seller">
|
||||||
<tr>
|
<tr>
|
||||||
<td width="50%" class="top">
|
<td width="50%" class="top">
|
||||||
<span class="buyer-seller-title">
|
<span class="buyer-seller-title">
|
||||||
Buyer
|
Buyer
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<div class="buyer-company">
|
<div class="buyer-company">
|
||||||
@@ -34,34 +34,34 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="buyer-company">
|
<span class="buyer-company">
|
||||||
{{ $supplier->name }}
|
{{ $supplier->name }}
|
||||||
</span>
|
</span>
|
||||||
<span class="reg">
|
<span class="reg">
|
||||||
{{-- {{ $supplier }} --}}
|
{{-- {{ $supplier }} --}}
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<span class="address">
|
<span class="address">
|
||||||
@php
|
@php
|
||||||
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
||||||
@endphp
|
@endphp
|
||||||
{{ $billingAddress->street_one }}
|
{{ $billingAddress->street_one }}
|
||||||
{{ $billingAddress->street_two }}
|
{{ $billingAddress->street_two }}
|
||||||
{{ $billingAddress->state()->first()->name }}
|
{{ $billingAddress->state()->first()->name }}
|
||||||
{{ $billingAddress->district()->first()->name }}
|
{{ $billingAddress->district()->first()->name }}
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<span class="contact-no">
|
<span class="contact-no">
|
||||||
Phone: {{ $supplier->contacts()->first()->phone }}
|
Phone: {{ $supplier->contacts()->first()->phone }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td width="50%" class="top">
|
<td width="50%" class="top">
|
||||||
<span class="buyer-seller-title">
|
<span class="buyer-seller-title">
|
||||||
Seller
|
Seller
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<span class="buyer-company">
|
<span class="buyer-company">
|
||||||
CIEF Worldwide Sdn Bhd (1134596-M)
|
CIEF Worldwide Sdn Bhd (1134596-M)
|
||||||
</span>
|
</span>
|
||||||
<div class="address">
|
<div class="address">
|
||||||
No. 72-3, Jalan Jalil 1,<br>
|
No. 72-3, Jalan Jalil 1,<br>
|
||||||
The Earth Bukit Jalil,<br>
|
The Earth Bukit Jalil,<br>
|
||||||
@@ -90,8 +90,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@php
|
@php
|
||||||
$subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate);
|
$subtotal = "0";
|
||||||
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
|
|
||||||
$displayedSubtotal = 0;
|
$displayedSubtotal = 0;
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@@ -118,8 +117,12 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
@php
|
@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
|
$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
|
@endphp
|
||||||
<tr class="subtotal">
|
<tr class="subtotal">
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
@@ -147,12 +150,7 @@
|
|||||||
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@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>
|
<tr>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
<td class="right middle">Adjustment</td>
|
<td class="right middle">Adjustment</td>
|
||||||
@@ -175,28 +173,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</htmlpagefooter>
|
</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
|
@endsection
|
||||||
|
|||||||
+6
-3
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Classes\Jobs\GenerateInvoice;
|
|
||||||
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
|
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
|
||||||
use App\Http\Controllers\Accounting\BankStatementController;
|
use App\Http\Controllers\Accounting\BankStatementController;
|
||||||
use Carbon\Carbon;
|
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();
|
$bookings = Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get();
|
||||||
|
|
||||||
foreach($bookings as $booking){
|
foreach($bookings as $booking){
|
||||||
GenerateInvoice::dispatch($booking);
|
$booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete();
|
||||||
echo 'Invoice fixing job dispatched.';
|
$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');
|
})->name('invoice.fix');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user