61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
use App\Models\SalesOrderModel;
|
|
use App\Models\JobcardModel;
|
|
|
|
class InvNoHelper
|
|
{
|
|
|
|
|
|
|
|
public static function generateInvoiceNumber()
|
|
{
|
|
|
|
$SalesOrderModel = new SalesOrderModel();
|
|
$JobcardModel = new JobcardModel();
|
|
|
|
|
|
$Sales = $SalesOrderModel->orderBy('sales_order_id', 'DESC')->first();
|
|
$SaleslastFiveDigits = $Sales && isset($Sales['inv_no']) ? substr($Sales['inv_no'], -5) : 0;
|
|
|
|
$Jobs = $JobcardModel->orderBy('job_card_id', 'DESC')->first();
|
|
$JobslastFiveDigits = $Jobs && isset($Jobs['inv_no']) ? substr($Jobs['inv_no'], -5) : 0;
|
|
|
|
|
|
|
|
$largerNumber = max((int)$SaleslastFiveDigits, (int)$JobslastFiveDigits);
|
|
$formattedCount = str_pad($largerNumber+1, 5, '0', STR_PAD_LEFT);
|
|
$currentFinancialYear = SELF::getCurrentFinancialYear();
|
|
$invoiceNumber = 'MECH-' . $currentFinancialYear. '/' . $formattedCount;
|
|
|
|
|
|
return $invoiceNumber;
|
|
|
|
}
|
|
|
|
public static function getCurrentFinancialYear() {
|
|
// Get the current month and year
|
|
$currentMonth = date('n');
|
|
$currentYear = date('Y');
|
|
|
|
// Determine the start date of the financial year
|
|
if ($currentMonth >= 4) {
|
|
$startYear = $currentYear;
|
|
} else {
|
|
$startYear = $currentYear - 1;
|
|
}
|
|
|
|
// Determine the end date of the financial year
|
|
$endYear = $startYear + 1;
|
|
|
|
// Format the financial year string
|
|
$financialYear = $startYear . '-' . substr($endYear, -2);
|
|
|
|
return $financialYear;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
?>
|