first commit
This commit is contained in:
186
app/Http/Middleware/AdminMenu.php
Normal file
186
app/Http/Middleware/AdminMenu.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Events\AdminMenuCreated;
|
||||
use Auth;
|
||||
use Closure;
|
||||
use Menu;
|
||||
use Module;
|
||||
|
||||
class AdminMenu
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Check if logged in
|
||||
if (!Auth::check()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Setup the admin menu
|
||||
Menu::create('AdminMenu', function ($menu) {
|
||||
$menu->style('adminlte');
|
||||
|
||||
$user = Auth::user();
|
||||
$attr = ['icon' => 'fa fa-angle-double-right'];
|
||||
|
||||
// Dashboard
|
||||
$menu->add([
|
||||
'url' => '/',
|
||||
'title' => trans('general.dashboard'),
|
||||
'icon' => 'fa fa-dashboard',
|
||||
'order' => 1,
|
||||
]);
|
||||
|
||||
// Items
|
||||
if ($user->can('read-items-items')) {
|
||||
$menu->add([
|
||||
'url' => 'items/items',
|
||||
'title' => trans_choice('general.items', 2),
|
||||
'icon' => 'fa fa-cubes',
|
||||
'order' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
// Incomes
|
||||
if ($user->can(['read-incomes-invoices', 'read-incomes-revenues', 'read-incomes-customers'])) {
|
||||
$menu->dropdown(trans_choice('general.incomes', 2), function ($sub) use($user, $attr) {
|
||||
if ($user->can('read-incomes-invoices')) {
|
||||
$sub->url('incomes/invoices', trans_choice('general.invoices', 2), 1, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-incomes-revenues')) {
|
||||
$sub->url('incomes/revenues', trans_choice('general.revenues', 2), 2, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-incomes-customers')) {
|
||||
$sub->url('incomes/customers', trans_choice('general.customers', 2), 3, $attr);
|
||||
}
|
||||
}, 3, [
|
||||
'title' => trans_choice('general.incomes', 2),
|
||||
'icon' => 'fa fa-money',
|
||||
]);
|
||||
}
|
||||
|
||||
// Expences
|
||||
if ($user->can(['read-expenses-bills', 'read-expenses-payments', 'read-expenses-vendors'])) {
|
||||
$menu->dropdown(trans_choice('general.expenses', 2), function ($sub) use($user, $attr) {
|
||||
if ($user->can('read-expenses-bills')) {
|
||||
$sub->url('expenses/bills', trans_choice('general.bills', 2), 1, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-expenses-payments')) {
|
||||
$sub->url('expenses/payments', trans_choice('general.payments', 2), 2, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-expenses-vendors')) {
|
||||
$sub->url('expenses/vendors', trans_choice('general.vendors', 2), 3, $attr);
|
||||
}
|
||||
}, 4, [
|
||||
'title' => trans_choice('general.expenses', 2),
|
||||
'icon' => 'fa fa-shopping-cart',
|
||||
]);
|
||||
}
|
||||
|
||||
// Banking
|
||||
if ($user->can(['read-banking-accounts', 'read-banking-transfers', 'read-banking-transactions'])) {
|
||||
$menu->dropdown(trans('general.banking'), function ($sub) use($user, $attr) {
|
||||
if ($user->can('read-banking-accounts')) {
|
||||
$sub->url('banking/accounts', trans_choice('general.accounts', 2), 1, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-banking-transfers')) {
|
||||
$sub->url('banking/transfers', trans_choice('general.transfers', 2), 2, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-banking-transactions')) {
|
||||
$sub->url('banking/transactions', trans_choice('general.transactions', 2), 3, $attr);
|
||||
}
|
||||
}, 5, [
|
||||
'title' => trans('general.banking'),
|
||||
'icon' => 'fa fa-university',
|
||||
]);
|
||||
}
|
||||
|
||||
// Reports
|
||||
if ($user->can(['read-reports-income-summary', 'read-reports-expense-summary', 'read-reports-income-expense-summary'])) {
|
||||
$menu->dropdown(trans_choice('general.reports', 2), function ($sub) use($user, $attr) {
|
||||
if ($user->can('read-reports-income-summary')) {
|
||||
$sub->url('reports/income-summary', trans('reports.summary.income'), 1, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-reports-expense-summary')) {
|
||||
$sub->url('reports/expense-summary', trans('reports.summary.expense'), 2, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-reports-income-expense-summary')) {
|
||||
$sub->url('reports/income-expense-summary', trans('reports.summary.income_expense'), 3, $attr);
|
||||
}
|
||||
}, 6, [
|
||||
'title' => trans_choice('general.reports', 2),
|
||||
'icon' => 'fa fa-bar-chart',
|
||||
]);
|
||||
}
|
||||
|
||||
// Settings
|
||||
if ($user->can(['read-settings-settings', 'read-settings-categories', 'read-settings-currencies', 'read-settings-taxes'])) {
|
||||
$menu->dropdown(trans_choice('general.settings', 2), function ($sub) use($user, $attr) {
|
||||
if ($user->can('read-settings-settings')) {
|
||||
$sub->url('settings/settings', trans('general.general'), 1, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-settings-categories')) {
|
||||
$sub->url('settings/categories', trans_choice('general.categories', 2), 2, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-settings-currencies')) {
|
||||
$sub->url('settings/currencies', trans_choice('general.currencies', 2), 3, $attr);
|
||||
}
|
||||
|
||||
if ($user->can('read-settings-taxes')) {
|
||||
$sub->url('settings/taxes', trans_choice('general.tax_rates', 2), 4, $attr);
|
||||
}
|
||||
|
||||
// Modules
|
||||
$modules = Module::all();
|
||||
$position = 5;
|
||||
foreach ($modules as $module) {
|
||||
// Check if the module has settings
|
||||
if (empty($module->get('settings'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub->url('settings/modules/' . $module->getAlias(), $module->getName(), $position, $attr);
|
||||
|
||||
$position++;
|
||||
}
|
||||
}, 7, [
|
||||
'title' => trans_choice('general.settings', 2),
|
||||
'icon' => 'fa fa-gears',
|
||||
]);
|
||||
}
|
||||
|
||||
// Apps
|
||||
if ($user->can('read-modules-home')) {
|
||||
$menu->add([
|
||||
'url' => 'modules/home',
|
||||
'title' => trans_choice('general.modules', 2),
|
||||
'icon' => 'fa fa-rocket',
|
||||
'order' => 8,
|
||||
]);
|
||||
}
|
||||
|
||||
// Fire the event to extend the menu
|
||||
event(new AdminMenuCreated($menu));
|
||||
});
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
36
app/Http/Middleware/ApiCompany.php
Normal file
36
app/Http/Middleware/ApiCompany.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class ApiCompany
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$company_id = $request->get('company_id');
|
||||
|
||||
if (empty($company_id)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Check if user can access company
|
||||
$companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
|
||||
if (!in_array($company_id, $companies)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
31
app/Http/Middleware/CheckIfInstalled.php
Normal file
31
app/Http/Middleware/CheckIfInstalled.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class CheckIfInstalled
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// DB_DATABASE not empty means installed
|
||||
if (env('DB_DATABASE', '') != '') {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Already in the wizard
|
||||
if (starts_with($request->getPathInfo(), '/install')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Not installed, redirect to installation wizard
|
||||
redirect('install/requirements')->send();
|
||||
}
|
||||
}
|
||||
69
app/Http/Middleware/CustomerMenu.php
Normal file
69
app/Http/Middleware/CustomerMenu.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Events\CustomerMenuCreated;
|
||||
use Auth;
|
||||
use Closure;
|
||||
use Menu;
|
||||
|
||||
class CustomerMenu
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Check if logged in
|
||||
if (!Auth::check()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
Menu::create('CustomerMenu', function ($menu) {
|
||||
$menu->style('adminlte');
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Dashboard
|
||||
$menu->add([
|
||||
'url' => 'customers/',
|
||||
'title' => trans('general.dashboard'),
|
||||
'icon' => 'fa fa-dashboard',
|
||||
'order' => 1,
|
||||
]);
|
||||
|
||||
// Invoices
|
||||
$menu->add([
|
||||
'url' => 'customers/invoices',
|
||||
'title' => trans_choice('general.invoices', 2),
|
||||
'icon' => 'fa fa-wpforms',
|
||||
'order' => 2,
|
||||
]);
|
||||
|
||||
// Payments
|
||||
$menu->add([
|
||||
'url' => 'customers/payments',
|
||||
'title' => trans_choice('general.payments', 2),
|
||||
'icon' => 'fa fa-money',
|
||||
'order' => 3,
|
||||
]);
|
||||
|
||||
// Payments
|
||||
$menu->add([
|
||||
'url' => 'customers/transactions',
|
||||
'title' => trans_choice('general.transactions', 2),
|
||||
'icon' => 'fa fa-list',
|
||||
'order' => 4,
|
||||
]);
|
||||
|
||||
// Fire the event to extend the menu
|
||||
event(new CustomerMenuCreated($menu));
|
||||
});
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
|
||||
|
||||
class EncryptCookies extends BaseEncrypter
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
60
app/Http/Middleware/LoadSettings.php
Normal file
60
app/Http/Middleware/LoadSettings.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class LoadSettings
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
|
||||
if (empty($company_id)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Set the active company settings
|
||||
setting()->setExtraColumns(['company_id' => $company_id]);
|
||||
|
||||
// Timezone
|
||||
config(['app.timezone' => setting('general.timezone', 'UTC')]);
|
||||
|
||||
// Email
|
||||
$email_protocol = setting('general.email_protocol', 'mail');
|
||||
config(['mail.driver' => $email_protocol]);
|
||||
config(['mail.from.name' => setting('general.company_name')]);
|
||||
config(['mail.from.address' => setting('general.company_email')]);
|
||||
|
||||
if ($email_protocol == 'sendmail') {
|
||||
config(['mail.sendmail' => setting('general.email_sendmail_path')]);
|
||||
} elseif ($email_protocol == 'smtp') {
|
||||
config(['mail.host' => setting('general.email_smtp_host')]);
|
||||
config(['mail.port' => setting('general.email_smtp_port')]);
|
||||
config(['mail.username' => setting('general.email_smtp_username')]);
|
||||
config(['mail.password' => setting('general.email_smtp_password')]);
|
||||
config(['mail.encryption' => setting('general.email_smtp_encryption')]);
|
||||
}
|
||||
|
||||
// Session
|
||||
config(['session.driver' => setting('general.session_handler', 'file')]);
|
||||
config(['session.lifetime' => setting('general.session_lifetime', '30')]);
|
||||
|
||||
// Locale
|
||||
if (session('locale') == '') {
|
||||
//App::setLocale(setting('general.default_language'));
|
||||
//Session::put('locale', setting('general.default_language'));
|
||||
config(['app.locale' => setting('general.default_locale')]);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Closure;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
if (Auth::user()->customer) {
|
||||
return redirect('/customers');
|
||||
}
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
|
||||
|
||||
class TrimStrings extends BaseTrimmer
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user