update
This commit is contained in:
@ -33,23 +33,213 @@ class CCMS
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
// private function initDB()
|
||||
// {
|
||||
// static $initialized = false;
|
||||
// if (!$initialized) {
|
||||
|
||||
|
||||
// if (!(DB::table('users')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_users` (`name`,`email`,`username`,`password`,`status`) VALUES ('Prajwal Adhikari','prajwalbro@hotmail.com','prajwalbro@hotmail.com','$2y$10$3zlF9VeXexzWKRDPZuDio.W7RZIC3tU.cjwMoLzG8ki8bVwAQn1WW','1');");
|
||||
// }
|
||||
// if (!(DB::table('settings')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_settings` (`title`, `description`, `status`) values ('Bibhuti LMS', '', '1');");
|
||||
// }
|
||||
// if (!(DB::table('articles')->first())) {
|
||||
// DB::statement("INSERT INTO `tbl_articles` (`title`,`alias`, `text`, `status`) VALUES ('Company Profile', 'company-profile','Welcome Article', '1');");
|
||||
// }
|
||||
|
||||
// $initialized = true;
|
||||
function getRouteList()
|
||||
{
|
||||
$routes = Route::getRoutes();
|
||||
$ignoreRoutes = ['debugbar', 'login', 'register', 'logout', 'post', 'sanctum', 'ignition', 'unisharp', 'errorpage', 'form7', 'master', 'hr', 'setting', 'nepalidictonary', 'api'];
|
||||
$routeNameArr = [];
|
||||
foreach ($routes as $value) {
|
||||
if (!is_null($value)) {
|
||||
$routeName = explode('.', $value->getName());
|
||||
if (is_array($routeName) && !empty($routeName[0])) {
|
||||
if (!in_array($routeName[0], $ignoreRoutes)) {
|
||||
$routeNameArr[$routeName[0]][] = $value->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $routeNameArr;
|
||||
}
|
||||
|
||||
function generateEstimateNumber()
|
||||
{
|
||||
$lastEstimate = Estimate::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastEstimate) {
|
||||
$newEstimateNumber = intval($lastEstimate->id) + 1;
|
||||
return 'EST-' . activeFiscalYear('code') . '-' . str_pad($newEstimateNumber, 4, '0', STR_PAD_LEFT);
|
||||
|
||||
} else {
|
||||
return 'EST-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateCreditNoteNumber()
|
||||
{
|
||||
$lastCreditNote = CreditNote::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastCreditNote) {
|
||||
$newCreditNoteNumber = intval($lastCreditNote->id) + 1;
|
||||
return 'CN-' . activeFiscalYear('code') . '-' . str_pad($newCreditNoteNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CN-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateInvoiceNumber()
|
||||
{
|
||||
$lastInvoice = Invoice::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastInvoice) {
|
||||
$newInvoiceNumber = intval($lastInvoice->id) + 1;
|
||||
return 'INV-' . activeFiscalYear('code') . '-' . str_pad($newInvoiceNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'INV-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateReceivedInvoiceNumber()
|
||||
{
|
||||
$lastReceivedInvoice = ReceivedInvoice::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastReceivedInvoice) {
|
||||
$newReceivedInvoiceNumber = intval($lastReceivedInvoice->id) + 1;
|
||||
return 'RI-' . activeFiscalYear('code') . '-' . str_pad($newReceivedInvoiceNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'RI-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
function generateCashReceivedNumber()
|
||||
{
|
||||
$lastCastReceived = CashReceived::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastCastReceived) {
|
||||
$newCastReceivedNumber = intval($lastCastReceived->id) + 1;
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad($newCastReceivedNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
function generateDebitNoteNumber()
|
||||
{
|
||||
$lastDebitNote = DebitNote::withTrashed()->latest()->first();
|
||||
|
||||
if ($lastDebitNote) {
|
||||
$newDebitNoteNumber = intval($lastDebitNote->id) + 1;
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad($newDebitNoteNumber, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
return 'CR-' . activeFiscalYear('code') . '-' . str_pad(1, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (!function_exists('sendNotification')) {
|
||||
// function sendNotification($user, $notification = [])
|
||||
// {
|
||||
// \Notification::send($user, new SendNotification($notification));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
if (!function_exists('uploadImage')) {
|
||||
function uploadImage($file)
|
||||
{
|
||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||
$filePath = Storage::disk('public')->putFileAs('uploads', $file, $fileName);
|
||||
return $filePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('activeFiscalYear')) {
|
||||
function activeFiscalYear($select)
|
||||
{
|
||||
$fiscalYearModel = FiscalYear::whereStatus(11)->first();
|
||||
return $fiscalYearModel->$select ?? null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('setting')) {
|
||||
function setting($key = '')
|
||||
{
|
||||
// Cache::forget('setting');
|
||||
$setting = Cache::has('setting') ? Cache::get('setting') : Cache::rememberForever('setting', function () {
|
||||
return Setting::get()->mapWithKeys(function ($setting) {
|
||||
return [$setting->key => $setting->value];
|
||||
});;
|
||||
});
|
||||
return $setting->has($key) ? $setting[$key] : null;
|
||||
}
|
||||
}
|
||||
|
||||
function convertAmountInWords($amount): string
|
||||
{
|
||||
$units = [
|
||||
'kharab' => 100000000000,
|
||||
'arab' => 1000000000,
|
||||
'crore' => 10000000,
|
||||
'lakh' => 100000,
|
||||
'thousand' => 1000,
|
||||
'hundred' => 100,
|
||||
];
|
||||
|
||||
$words = [];
|
||||
|
||||
foreach ($units as $unit => $value) {
|
||||
if ($amount >= $value) {
|
||||
$count = floor($amount / $value);
|
||||
$remaining = $amount % $value;
|
||||
$words[] = convertCount($count) . ' ' . $unit;
|
||||
$amount = $remaining;
|
||||
}
|
||||
}
|
||||
|
||||
if ($amount > 0) {
|
||||
$words[] = convertCount($amount);
|
||||
}
|
||||
|
||||
return implode(' ', $words) . ' only /-';
|
||||
}
|
||||
|
||||
function convertCount($count)
|
||||
{
|
||||
$ones = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
|
||||
$teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
|
||||
$tens = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
|
||||
|
||||
$words = [];
|
||||
|
||||
if ($count >= 100) {
|
||||
$words[] = $ones[floor($count / 100)] . ' hundred';
|
||||
$count %= 100;
|
||||
if ($count > 0) {
|
||||
$words[] = 'and';
|
||||
}
|
||||
}
|
||||
|
||||
if ($count >= 20) {
|
||||
$tensPlace = $tens[floor($count / 10) - 2];
|
||||
$onesPlace = $count % 10;
|
||||
if ($onesPlace > 0) {
|
||||
$words[] = $tensPlace . '-' . $ones[$onesPlace];
|
||||
} else {
|
||||
$words[] = $tensPlace;
|
||||
}
|
||||
} elseif ($count >= 10) {
|
||||
$words[] = $teens[$count - 10];
|
||||
} elseif ($count > 0) {
|
||||
$words[] = $ones[$count];
|
||||
}
|
||||
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
function getAllKeys($data)
|
||||
{
|
||||
$keys = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
if (is_object($item)) {
|
||||
$item = (array) $item;
|
||||
}
|
||||
|
||||
if (is_array($item)) {
|
||||
$subKeys = getAllKeys($item);
|
||||
$keys = array_merge($keys, $subKeys);
|
||||
} else {
|
||||
$keys[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($keys);
|
||||
}
|
||||
|
Reference in New Issue
Block a user