346 lines
17 KiB
PHP
346 lines
17 KiB
PHP
<?php
|
|
|
|
namespace Modules\Accounting\Http\Controllers;
|
|
|
|
use App\Http\MenuIcons;
|
|
use App\Utils\ModuleUtil;
|
|
use App\Utils\Util;
|
|
use Illuminate\Routing\Controller;
|
|
use Menu;
|
|
use Modules\Accounting\Services\InstallmentBridgeService;
|
|
|
|
class DataController extends Controller
|
|
{
|
|
/**
|
|
* Superadmin package permissions
|
|
*
|
|
* @return array
|
|
*/
|
|
public function superadmin_package()
|
|
{
|
|
return [
|
|
[
|
|
'name' => 'accounting_module',
|
|
'label' => __('accounting::lang.accounting_module'),
|
|
'default' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Adds cms menus
|
|
*
|
|
* @return null
|
|
*/
|
|
public function modifyAdminMenu()
|
|
{
|
|
$business_id = session()->get('user.business_id');
|
|
$module_util = new ModuleUtil();
|
|
|
|
$is_accounting_enabled = (bool) $module_util->hasThePermissionInSubscription($business_id, 'accounting_module');
|
|
$is_essentials_enabled = (bool) $module_util->hasThePermissionInSubscription($business_id, 'essentials_module');
|
|
|
|
$commonUtil = new Util();
|
|
$is_admin = $commonUtil->is_admin(auth()->user(), $business_id);
|
|
|
|
if (auth()->user()->can('accounting.access_accounting_module') && $is_accounting_enabled) {
|
|
Menu::modify(
|
|
'admin-sidebar-menu',
|
|
function ($menu) use ($is_essentials_enabled) {
|
|
$menu->dropdown(
|
|
__('accounting::lang.accounting'),
|
|
function ($sub) use ($is_essentials_enabled) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\AccountingController::class, 'dashboard']),
|
|
__('accounting::lang.accounting'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'dashboard']
|
|
);
|
|
|
|
if (auth()->user()->can('accounting.manage_accounts')) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\CoaController::class, 'index']),
|
|
__('accounting::lang.chart_of_accounts'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'chart-of-accounts']
|
|
);
|
|
$sub->url(
|
|
route('accounting.openingBalance'),
|
|
__('accounting::lang.opening_balance'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'opening-balance']
|
|
);
|
|
}
|
|
|
|
if (auth()->user()->can('accounting.view_journal')) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\JournalEntryController::class, 'index']),
|
|
__('accounting::lang.journal_entry'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'journal-entry']
|
|
);
|
|
}
|
|
|
|
if (auth()->user()->can('accounting.view_transfer')) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\TransferController::class, 'index']),
|
|
__('accounting::lang.transfer'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'transfer']
|
|
);
|
|
}
|
|
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\TransactionController::class, 'index']),
|
|
__('accounting::lang.transactions'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'transactions']
|
|
);
|
|
|
|
if (auth()->user()->can('accounting.manage_budget')) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\BudgetController::class, 'index']),
|
|
__('accounting::lang.budget'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'budget']
|
|
);
|
|
}
|
|
|
|
if (auth()->user()->can('accounting.map_transactions')) {
|
|
$sub->url(
|
|
route('accounting.cheques'),
|
|
__('accounting::lang.cheques'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'cheques']
|
|
);
|
|
$sub->url(
|
|
route('accounting.installments'),
|
|
__('accounting::lang.installments'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'installments']
|
|
);
|
|
$sub->url(
|
|
route('accounting.depreciation'),
|
|
__('accounting::lang.depreciation'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'depreciation']
|
|
);
|
|
$sub->url(
|
|
route('accounting.fiscalPeriods'),
|
|
__('accounting::lang.fiscal_periods'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'fiscal-periods']
|
|
);
|
|
$sub->url(
|
|
route('accounting.reconciliations'),
|
|
__('accounting::lang.bank_reconciliation'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'reconciliations']
|
|
);
|
|
$sub->url(
|
|
route('accounting.deferredDocuments'),
|
|
__('accounting::lang.deferred_documents'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'deferred-documents']
|
|
);
|
|
$sub->url(
|
|
route('accounting.bankLoans'),
|
|
__('accounting::lang.bank_loans'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'bank-loans']
|
|
);
|
|
$sub->url(
|
|
route('accounting.insurance'),
|
|
__('accounting::lang.insurance_premiums'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'insurance']
|
|
);
|
|
$sub->url(
|
|
route('accounting.payrollTaxTable'),
|
|
__('accounting::lang.payroll_tax_table'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'payroll-tax-table']
|
|
);
|
|
}
|
|
|
|
if ($is_essentials_enabled) {
|
|
$sub->url(
|
|
action([\Modules\Essentials\Http\Controllers\PayrollController::class, 'index']),
|
|
__('accounting::lang.payroll_list'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'hrm' && request()->segment(2) == 'payroll']
|
|
);
|
|
$sub->url(
|
|
action([\Modules\Essentials\Http\Controllers\PayrollController::class, 'index']),
|
|
__('accounting::lang.payslip'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'hrm' && request()->segment(2) == 'payroll']
|
|
);
|
|
}
|
|
|
|
if (auth()->user()->can('accounting.view_reports')) {
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\ReportController::class, 'index']),
|
|
__('accounting::lang.reports_hub'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'reports' && empty(request()->segment(3))]
|
|
);
|
|
$sub->url(
|
|
route('accounting.chequeReport'),
|
|
__('accounting::lang.cheque_report'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'reports' && request()->segment(3) == 'cheques']
|
|
);
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\ReportController::class, 'trialBalance']),
|
|
__('accounting::lang.trial_balance'),
|
|
['icon' => '', 'active' => request()->segment(2) == 'reports' && request()->segment(3) == 'trial-balance']
|
|
);
|
|
$sub->url(
|
|
route('accounting.profitAndLoss'),
|
|
__('accounting::lang.profit_and_loss'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'profit-and-loss']
|
|
);
|
|
$sub->url(
|
|
action([\Modules\Accounting\Http\Controllers\ReportController::class, 'balanceSheet']),
|
|
__('accounting::lang.balance_sheet'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'balance-sheet']
|
|
);
|
|
$sub->url(
|
|
route('accounting.cashFlow'),
|
|
__('accounting::lang.cash_flow'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'cash-flow']
|
|
);
|
|
$sub->url(
|
|
route('accounting.subsidiaryLedger'),
|
|
__('accounting::lang.subsidiary_ledger'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'subsidiary-ledger']
|
|
);
|
|
$sub->url(
|
|
route('accounting.glTaxReport'),
|
|
__('accounting::lang.gl_tax_report'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'gl-tax']
|
|
);
|
|
$sub->url(
|
|
route('accounting.account_receivable_ageing_report'),
|
|
__('accounting::lang.account_recievable_ageing_report'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'account-receivable-ageing-report']
|
|
);
|
|
$sub->url(
|
|
route('accounting.account_payable_ageing_report'),
|
|
__('accounting::lang.account_payable_ageing_report'),
|
|
['icon' => '', 'active' => request()->segment(3) == 'account-payable-ageing-report']
|
|
);
|
|
}
|
|
},
|
|
['icon' => MenuIcons::svg('accounting'), 'style' => config('app.env') == 'demo' ? 'background-color: #D483D9;' : '', 'active' => request()->segment(1) == 'accounting', 'data-module' => 'Accounting', 'data-menu-group' => 'finance']
|
|
)->order(50);
|
|
}
|
|
);
|
|
|
|
$menu = Menu::instance('admin-sidebar-menu');
|
|
$menu->whereTitle(__('sale.sale'), function ($sub) {
|
|
if (empty($sub)) {
|
|
return false;
|
|
}
|
|
if (auth()->user()->can('accounting.map_transactions')) {
|
|
$sub->url(
|
|
route('accounting.installments'),
|
|
__('lang_v1.register_installments'),
|
|
['icon' => '', 'active' => request()->segment(1) == 'accounting' && request()->segment(2) == 'installments']
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public function transaction_show_actions($data)
|
|
{
|
|
$transaction = $data['transaction'] ?? null;
|
|
if (! $transaction || $transaction->type !== 'sell') {
|
|
return '';
|
|
}
|
|
|
|
$module_util = new ModuleUtil();
|
|
$business_id = (int) $transaction->business_id;
|
|
|
|
if (! $module_util->hasThePermissionInSubscription($business_id, 'accounting_module')) {
|
|
return '';
|
|
}
|
|
|
|
if (! auth()->user()->can('accounting.map_transactions')) {
|
|
return '';
|
|
}
|
|
|
|
$bridgeService = app(InstallmentBridgeService::class);
|
|
$existingPlan = $bridgeService->getPlanForSell($transaction);
|
|
$isEligible = $bridgeService->isEligibleForManualInstallment($transaction);
|
|
|
|
if (! $existingPlan && ! $isEligible) {
|
|
return '';
|
|
}
|
|
|
|
return view('accounting::integrations.sell_installment_action', [
|
|
'transaction' => $transaction,
|
|
'existingPlan' => $existingPlan,
|
|
'isEligible' => $isEligible,
|
|
])->render();
|
|
}
|
|
|
|
/**
|
|
* Defines user permissions for the module.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function user_permissions()
|
|
{
|
|
return [
|
|
[
|
|
'value' => 'accounting.access_accounting_module',
|
|
'label' => __('accounting::lang.access_accounting_module'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.manage_accounts',
|
|
'label' => __('accounting::lang.manage_accounts'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.view_journal',
|
|
'label' => __('accounting::lang.view_journal'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.add_journal',
|
|
'label' => __('accounting::lang.add_journal'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.edit_journal',
|
|
'label' => __('accounting::lang.edit_journal'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.delete_journal',
|
|
'label' => __('accounting::lang.delete_journal'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.map_transactions',
|
|
'label' => __('accounting::lang.map_transactions'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.view_transfer',
|
|
'label' => __('accounting::lang.view_transfer'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.add_transfer',
|
|
'label' => __('accounting::lang.add_transfer'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.edit_transfer',
|
|
'label' => __('accounting::lang.edit_transfer'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.delete_transfer',
|
|
'label' => __('accounting::lang.delete_transfer'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.manage_budget',
|
|
'label' => __('accounting::lang.manage_budget'),
|
|
'default' => false,
|
|
],
|
|
[
|
|
'value' => 'accounting.view_reports',
|
|
'label' => __('accounting::lang.view_reports'),
|
|
'default' => false,
|
|
],
|
|
];
|
|
}
|
|
}
|