2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
2021-04-16 00:59:43 +03:00
|
|
|
use App\Models\Common\Company;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Traits\DateTime;
|
2020-03-25 20:21:42 +03:00
|
|
|
use App\Utilities\Date;
|
2019-12-31 02:20:10 +03:00
|
|
|
use App\Utilities\Widgets;
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
if (!function_exists('user')) {
|
|
|
|
/**
|
|
|
|
* Get the authenticated user.
|
|
|
|
*
|
|
|
|
* @return \App\Models\Auth\User
|
|
|
|
*/
|
|
|
|
function user()
|
|
|
|
{
|
|
|
|
// Get user from api/web
|
2021-01-19 14:12:54 +03:00
|
|
|
if (request()->isApi()) {
|
2019-11-16 10:21:14 +03:00
|
|
|
$user = app('Dingo\Api\Auth\Auth')->user();
|
|
|
|
} else {
|
|
|
|
$user = auth()->user();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 17:31:44 +01:00
|
|
|
if (!function_exists('company_date_format')) {
|
|
|
|
/**
|
|
|
|
* Format the given date based on company settings.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function company_date_format()
|
|
|
|
{
|
|
|
|
$date_time = new class() {
|
|
|
|
use DateTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
return $date_time->getCompanyDateFormat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
if (!function_exists('company_date')) {
|
|
|
|
/**
|
|
|
|
* Format the given date based on company settings.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function company_date($date)
|
|
|
|
{
|
2021-02-23 22:11:35 +03:00
|
|
|
return Date::parse($date)->format(company_date_format());
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|
2019-12-31 02:20:10 +03:00
|
|
|
|
|
|
|
if (!function_exists('show_widget')) {
|
|
|
|
/**
|
2020-01-04 11:49:59 +03:00
|
|
|
* Show a widget.
|
2019-12-31 02:20:10 +03:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-01-04 11:49:59 +03:00
|
|
|
function show_widget()
|
2019-12-31 02:20:10 +03:00
|
|
|
{
|
2020-01-04 11:49:59 +03:00
|
|
|
$arguments = func_get_args();
|
|
|
|
|
|
|
|
$model = array_shift($arguments);
|
|
|
|
|
|
|
|
return Widgets::show($model, ...$arguments);
|
2019-12-31 02:20:10 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 22:11:12 +03:00
|
|
|
|
2021-04-16 00:59:43 +03:00
|
|
|
if (!function_exists('company')) {
|
|
|
|
/**
|
|
|
|
* Get current/any company model.
|
|
|
|
*
|
|
|
|
* @param int|null $id
|
|
|
|
*
|
|
|
|
* @return Company|null
|
|
|
|
*/
|
|
|
|
function company($id = null)
|
|
|
|
{
|
|
|
|
$company = null;
|
|
|
|
|
|
|
|
if (is_null($id)) {
|
|
|
|
$company = Company::getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($id)) {
|
|
|
|
$company = Company::find($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $company;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('company_id')) {
|
|
|
|
/**
|
|
|
|
* Get id of current company.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function company_id()
|
|
|
|
{
|
|
|
|
return optional(company())->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('should_queue')) {
|
|
|
|
/**
|
|
|
|
* Check if queue is enabled.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function should_queue() {
|
|
|
|
return config('queue.default') != 'sync';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 22:11:12 +03:00
|
|
|
if (!function_exists('cache_prefix')) {
|
|
|
|
/**
|
|
|
|
* Cache system added company_id prefix.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function cache_prefix() {
|
2021-04-16 00:59:43 +03:00
|
|
|
return company_id() . '_';
|
2020-08-06 22:11:12 +03:00
|
|
|
}
|
|
|
|
}
|