akaunting 3.0 (the last dance)
This commit is contained in:
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use ConsoleTVs\Charts\Classes\Chartjs\Chart;
|
||||
|
||||
class Chartjs extends Chart
|
||||
{
|
||||
/**
|
||||
* Initializes the chart.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
@ -2,13 +2,8 @@
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Application;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Process\Exception\LogicException;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Exception\RuntimeException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Throwable;
|
||||
|
||||
@ -31,7 +26,7 @@ class Console
|
||||
if (static::isValidOutput($output)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception | InvalidArgumentException | LogicException | ProcessFailedException | RuntimeException | Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
$output = $e->getMessage();
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,10 @@ class Installer
|
||||
$requirements[] = trans('install.requirements.extension', ['extension' => 'FileInfo']);
|
||||
}
|
||||
|
||||
if (!extension_loaded('intl')) {
|
||||
$requirements[] = trans('install.requirements.extension', ['extension' => 'Intl']);
|
||||
}
|
||||
|
||||
if (!extension_loaded('gd')) {
|
||||
$requirements[] = trans('install.requirements.extension', ['extension' => 'GD']);
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ class Overrider
|
||||
}
|
||||
|
||||
// Locale
|
||||
if (session('locale') == '') {
|
||||
$locale = (user()->locale) ?? setting('default.locale');
|
||||
if (! session('locale')) {
|
||||
$locale = user()->locale ?? setting('default.locale');
|
||||
|
||||
app()->setLocale($locale);
|
||||
}
|
||||
|
||||
// Set app url dynamically if empty
|
||||
if (!config('app.url')) {
|
||||
if (! config('app.url')) {
|
||||
config(['app.url' => url('/')]);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace App\Utilities;
|
||||
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\DateTime;
|
||||
use Date;
|
||||
use App\Utilities\Date;
|
||||
|
||||
class Recurring
|
||||
{
|
||||
@ -16,11 +16,11 @@ class Recurring
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
// @todo cache recurrings
|
||||
if (!$item->recurring || !empty($item->parent_id)) {
|
||||
if (! $item->recurring || !empty($item->parent_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($item->recurring->getRecurringSchedule(false) as $schedule) {
|
||||
foreach ($item->recurring->getRecurringSchedule() as $schedule) {
|
||||
$issued = Date::parse($item->$issued_date_field);
|
||||
$start = $schedule->getStart();
|
||||
$start_date = Date::parse($start->format('Y-m-d'));
|
||||
|
@ -31,7 +31,7 @@ class Reports
|
||||
});
|
||||
|
||||
foreach ($list as $class) {
|
||||
if (!class_exists($class) || ($check_permission && !static::canRead($class))) {
|
||||
if (! class_exists($class) || ($check_permission && static::cannotRead($class))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ class Reports
|
||||
$model = Report::where('class', $model)->first();
|
||||
}
|
||||
|
||||
if ((!$model instanceof Report) || !class_exists($model->class)) {
|
||||
if ((! $model instanceof Report) || ! class_exists($model->class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -61,11 +61,21 @@ class Reports
|
||||
return (static::isModuleEnabled($class) && static::canRead($class));
|
||||
}
|
||||
|
||||
public static function cannotShow($class)
|
||||
{
|
||||
return ! static::canShow($class);
|
||||
}
|
||||
|
||||
public static function canRead($class)
|
||||
{
|
||||
return user()->can(static::getPermission($class));
|
||||
}
|
||||
|
||||
public static function cannotRead($class)
|
||||
{
|
||||
return ! static::canRead($class);
|
||||
}
|
||||
|
||||
public static function getPermission($class)
|
||||
{
|
||||
$arr = explode('\\', $class);
|
||||
@ -93,7 +103,7 @@ class Reports
|
||||
|
||||
public static function isModuleEnabled($class)
|
||||
{
|
||||
if (!$alias = static::getModuleAlias($class)) {
|
||||
if (! $alias = static::getModuleAlias($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -104,6 +114,11 @@ class Reports
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isModuleDisabled($class)
|
||||
{
|
||||
return ! static::isModuleEnabled($class);
|
||||
}
|
||||
|
||||
public static function isModule($class)
|
||||
{
|
||||
$arr = is_array($class) ? $class : explode('\\', $class);
|
||||
@ -111,9 +126,14 @@ class Reports
|
||||
return (strtolower($arr[0]) == 'modules');
|
||||
}
|
||||
|
||||
public static function isNotModule($class)
|
||||
{
|
||||
return ! static::isModule($class);
|
||||
}
|
||||
|
||||
public static function getModuleAlias($class)
|
||||
{
|
||||
if (!static::isModule($class)) {
|
||||
if (static::isNotModule($class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
57
app/Utilities/Str.php
Normal file
57
app/Utilities/Str.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str as IStr;
|
||||
|
||||
class Str
|
||||
{
|
||||
public static function getInitials($value, $length = 2)
|
||||
{
|
||||
$words = new Collection(explode(' ', $value));
|
||||
|
||||
// if name contains single word, use first N character
|
||||
if ($words->count() === 1) {
|
||||
$initial = static::getInitialFromOneWord($value, $words, $length);
|
||||
} else {
|
||||
$initial = static::getInitialFromMultipleWords($words, $length);
|
||||
}
|
||||
|
||||
$initial = strtoupper($initial);
|
||||
|
||||
if (language()->direction() == 'rtl') {
|
||||
$initial = collect(mb_str_split($initial))->reverse()->implode('');
|
||||
}
|
||||
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public static function getInitialFromOneWord($value, $words, $length)
|
||||
{
|
||||
$initial = (string) $words->first();
|
||||
|
||||
if (strlen($value) >= $length) {
|
||||
$initial = IStr::substr($value, 0, $length);
|
||||
}
|
||||
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public static function getInitialFromMultipleWords($words, $length)
|
||||
{
|
||||
// otherwise, use initial char from each word
|
||||
$initials = new Collection();
|
||||
|
||||
$words->each(function ($word) use ($initials) {
|
||||
$initials->push(IStr::substr($word, 0, 1));
|
||||
});
|
||||
|
||||
return static::selectInitialFromMultipleInitials($initials, $length);
|
||||
}
|
||||
|
||||
public static function selectInitialFromMultipleInitials($initials, $length)
|
||||
{
|
||||
return $initials->slice(0, $length)->implode('');
|
||||
}
|
||||
}
|
@ -8,23 +8,22 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Widgets
|
||||
{
|
||||
public static $core_widgets = [
|
||||
'App\Widgets\Receivables',
|
||||
'App\Widgets\Payables',
|
||||
'App\Widgets\CashFlow',
|
||||
'App\Widgets\ProfitLoss',
|
||||
'App\Widgets\ExpensesByCategory',
|
||||
'App\Widgets\AccountBalance',
|
||||
'App\Widgets\Currencies',
|
||||
];
|
||||
|
||||
public static function getClasses($alias = 'core', $check_permission = true)
|
||||
{
|
||||
$classes = $list = [];
|
||||
|
||||
if (in_array($alias, ['core', 'all'])) {
|
||||
$list = [
|
||||
'App\Widgets\TotalIncome',
|
||||
'App\Widgets\TotalExpenses',
|
||||
'App\Widgets\TotalProfit',
|
||||
'App\Widgets\CashFlow',
|
||||
'App\Widgets\IncomeByCategory',
|
||||
'App\Widgets\ExpensesByCategory',
|
||||
'App\Widgets\AccountBalance',
|
||||
'App\Widgets\LatestIncome',
|
||||
'App\Widgets\LatestExpenses',
|
||||
'App\Widgets\Currencies',
|
||||
];
|
||||
$list = static::$core_widgets;
|
||||
}
|
||||
|
||||
Module::enabled()->each(function ($module) use (&$list, $alias) {
|
||||
@ -57,7 +56,7 @@ class Widgets
|
||||
if (is_string($model)) {
|
||||
$class_name = $model;
|
||||
|
||||
if (!class_exists($class_name)) {
|
||||
if (! class_exists($class_name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -76,7 +75,7 @@ class Widgets
|
||||
$model->settings = $class->getDefaultSettings();
|
||||
}
|
||||
} else {
|
||||
if ((!$model instanceof Widget) || !class_exists($model->class)) {
|
||||
if ((! $model instanceof Widget) || ! class_exists($model->class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -100,11 +99,21 @@ class Widgets
|
||||
return (static::isModuleEnabled($class) && static::canRead($class));
|
||||
}
|
||||
|
||||
public static function cannotShow($class)
|
||||
{
|
||||
return ! static::canShow($class);
|
||||
}
|
||||
|
||||
public static function canRead($class)
|
||||
{
|
||||
return user()->can(static::getPermission($class));
|
||||
}
|
||||
|
||||
public static function cannotRead($class)
|
||||
{
|
||||
return ! static::canRead($class);
|
||||
}
|
||||
|
||||
public static function getPermission($class)
|
||||
{
|
||||
$arr = explode('\\', $class);
|
||||
@ -132,7 +141,7 @@ class Widgets
|
||||
|
||||
public static function isModuleEnabled($class)
|
||||
{
|
||||
if (!$alias = static::getModuleAlias($class)) {
|
||||
if (! $alias = static::getModuleAlias($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -143,6 +152,11 @@ class Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isModuleDisabled($class)
|
||||
{
|
||||
return ! static::isModuleEnabled($class);
|
||||
}
|
||||
|
||||
public static function isModule($class)
|
||||
{
|
||||
$arr = is_array($class) ? $class : explode('\\', $class);
|
||||
@ -150,9 +164,14 @@ class Widgets
|
||||
return (strtolower($arr[0]) == 'modules');
|
||||
}
|
||||
|
||||
public static function isNotModule($class)
|
||||
{
|
||||
return ! static::isModule($class);
|
||||
}
|
||||
|
||||
public static function getModuleAlias($class)
|
||||
{
|
||||
if (!static::isModule($class)) {
|
||||
if (static::isNotModule($class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -160,4 +179,25 @@ class Widgets
|
||||
|
||||
return Str::kebab($arr[1]);
|
||||
}
|
||||
|
||||
public static function getCoreWidgets()
|
||||
{
|
||||
return static::$core_widgets;
|
||||
}
|
||||
|
||||
public static function setCoreWidgets($widgets)
|
||||
{
|
||||
static::$core_widgets = $widgets;
|
||||
}
|
||||
|
||||
public static function optimizeCoreWidgets()
|
||||
{
|
||||
$core_widgets = collect(static::getCoreWidgets());
|
||||
|
||||
$core_widgets->pop();
|
||||
|
||||
$core_widgets->push('App\Widgets\BankFeeds');
|
||||
|
||||
static::setCoreWidgets($core_widgets->all());
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,7 @@ if (!function_exists('user')) {
|
||||
*/
|
||||
function user()
|
||||
{
|
||||
// Get user from api/web
|
||||
if (request()->isApi()) {
|
||||
$user = app('Dingo\Api\Auth\Auth')->user();
|
||||
} else {
|
||||
$user = auth()->user();
|
||||
}
|
||||
|
||||
return $user;
|
||||
return auth()->user();
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +26,7 @@ if (!function_exists('user_id')) {
|
||||
*/
|
||||
function user_id()
|
||||
{
|
||||
return optional(user())->id;
|
||||
return user()?->id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +106,7 @@ if (!function_exists('company_id')) {
|
||||
*/
|
||||
function company_id()
|
||||
{
|
||||
return optional(company())->id;
|
||||
return company()?->id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,6 +151,26 @@ if (!function_exists('cache_prefix')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('array_values_recursive')) {
|
||||
/**
|
||||
* Get array values recursively.
|
||||
*/
|
||||
function array_values_recursive(array $array): array
|
||||
{
|
||||
$flat = [];
|
||||
|
||||
foreach($array as $value) {
|
||||
if (is_array($value)) {
|
||||
$flat = array_merge($flat, array_values_recursive($value));
|
||||
} else {
|
||||
$flat[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $flat;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('running_in_queue')) {
|
||||
/**
|
||||
* Detect if application is running in queue.
|
||||
@ -169,3 +182,29 @@ if (!function_exists('running_in_queue')) {
|
||||
return defined('APP_RUNNING_IN_QUEUE') ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('simple_icons')) {
|
||||
/**
|
||||
* Get the simple icon content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function simple_icons(string $name): string
|
||||
{
|
||||
$path = base_path('vendor/simple-icons/simple-icons/icons/' . $name . '.svg');
|
||||
|
||||
return file_get_contents($path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('default_currency')) {
|
||||
/**
|
||||
* Get the default currency code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function default_currency(): string
|
||||
{
|
||||
return setting('default.currency');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user