246 lines
7.9 KiB
PHP
246 lines
7.9 KiB
PHP
<?php
|
|
|
|
use App\Models\Menuitems;
|
|
use App\Models\Menulocations;
|
|
use App\Models\Preparationclasses;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CCMS
|
|
{
|
|
// public function __construct()
|
|
// {
|
|
// $this->initDB();
|
|
// }
|
|
|
|
|
|
public static function getSiteVars()
|
|
{
|
|
$siteVars = DB::table("settings")->where('status', 1)->orderby('display_order')->first();
|
|
return $siteVars;
|
|
}
|
|
|
|
public static function createMenuLink($text, $URL)
|
|
{
|
|
$isActive = request()->fullUrl() == $URL;
|
|
$activeClass = $isActive ? 'active' : '';
|
|
?>
|
|
<li>
|
|
<a class="nav-link menu-link <?php echo $activeClass; ?>" href="<?php echo $URL; ?>"><i class="ri-file-text-line "></i> <span data-key="t-landing">
|
|
<?php echo $text; ?>
|
|
</span></a>
|
|
</li>
|
|
<?php
|
|
}
|
|
|
|
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);
|
|
}
|