<?php

/**
 * Accounting module routes (scaffold — controllers defined, logic TBD).
 * @var \CodeIgniter\Router\RouteCollection $routes
 */
$routes->group('accounting', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\AccountingDashboardController::index', ['filter' => 'permission:accounting.view']);
});

// --- Ledger ---
$routes->group('accounting/chart-of-accounts', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ChartOfAccountController::index', ['filter' => 'permission:chart_of_accounts.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\ChartOfAccountController::createForm', ['filter' => 'permission:chart_of_accounts.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\ChartOfAccountController::store', ['filter' => 'permission:chart_of_accounts.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\ChartOfAccountController::show/$1', ['filter' => 'permission:chart_of_accounts.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\ChartOfAccountController::editForm/$1', ['filter' => 'permission:chart_of_accounts.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\ChartOfAccountController::update/$1', ['filter' => 'permission:chart_of_accounts.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\ChartOfAccountController::activate/$1', ['filter' => 'permission:chart_of_accounts.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\ChartOfAccountController::deactivate/$1', ['filter' => 'permission:chart_of_accounts.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\ChartOfAccountController::destroy/$1', ['filter' => 'permission:chart_of_accounts.delete']);
});

$routes->group('accounting/journal-entries', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\JournalEntryController::index', ['filter' => 'permission:journal_entries.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\JournalEntryController::createForm', ['filter' => 'permission:journal_entries.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\JournalEntryController::store', ['filter' => 'permission:journal_entries.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\JournalEntryController::show/$1', ['filter' => 'permission:journal_entries.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\JournalEntryController::editForm/$1', ['filter' => 'permission:journal_entries.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\JournalEntryController::update/$1', ['filter' => 'permission:journal_entries.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\JournalEntryController::post/$1', ['filter' => 'permission:journal_entries.post']);
    $routes->post('(:num)/unpost', '\Modules\Accounting\Controllers\JournalEntryController::unpost/$1', ['filter' => 'permission:journal_entries.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\JournalEntryController::destroy/$1', ['filter' => 'permission:journal_entries.delete']);
});

$routes->group('settings/fiscal-years', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\FiscalYearController::index', ['filter' => 'permission:fiscal_years.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\FiscalYearController::createForm', ['filter' => 'permission:fiscal_years.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\FiscalYearController::store', ['filter' => 'permission:fiscal_years.create']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\FiscalYearController::editForm/$1', ['filter' => 'permission:fiscal_years.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\FiscalYearController::update/$1', ['filter' => 'permission:fiscal_years.edit']);
    $routes->post('(:num)/close', '\Modules\Accounting\Controllers\FiscalYearController::close/$1', ['filter' => 'permission:fiscal_years.edit']);
    $routes->post('(:num)/reopen', '\Modules\Accounting\Controllers\FiscalYearController::reopen/$1', ['filter' => 'permission:fiscal_years.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\FiscalYearController::destroy/$1', ['filter' => 'permission:fiscal_years.delete']);
});

$routes->get('accounting/fiscal-years', static function () {
    return redirect()->to('/settings/fiscal-years');
}, ['filter' => 'auth']);
$routes->get('accounting/fiscal-years/(:any)', static function ($path) {
    return redirect()->to('/settings/fiscal-years/' . $path);
}, ['filter' => 'auth']);

// --- Receivables (AR) ---
$routes->group('accounting/customer-invoices', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\CustomerInvoiceController::index', ['filter' => 'permission:customer_invoices.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\CustomerInvoiceController::createForm', ['filter' => 'permission:customer_invoices.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\CustomerInvoiceController::store', ['filter' => 'permission:customer_invoices.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\CustomerInvoiceController::show/$1', ['filter' => 'permission:customer_invoices.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\CustomerInvoiceController::editForm/$1', ['filter' => 'permission:customer_invoices.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\CustomerInvoiceController::update/$1', ['filter' => 'permission:customer_invoices.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\CustomerInvoiceController::post/$1', ['filter' => 'permission:customer_invoices.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\CustomerInvoiceController::cancel/$1', ['filter' => 'permission:customer_invoices.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\CustomerInvoiceController::destroy/$1', ['filter' => 'permission:customer_invoices.delete']);
});

$routes->group('accounting/receipts', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ReceiptController::index', ['filter' => 'permission:receipts.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\ReceiptController::createForm', ['filter' => 'permission:receipts.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\ReceiptController::store', ['filter' => 'permission:receipts.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\ReceiptController::show/$1', ['filter' => 'permission:receipts.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\ReceiptController::editForm/$1', ['filter' => 'permission:receipts.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\ReceiptController::update/$1', ['filter' => 'permission:receipts.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\ReceiptController::post/$1', ['filter' => 'permission:receipts.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\ReceiptController::cancel/$1', ['filter' => 'permission:receipts.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\ReceiptController::destroy/$1', ['filter' => 'permission:receipts.delete']);
});

$routes->group('accounting/credit-notes', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\CreditNoteController::index', ['filter' => 'permission:credit_notes.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\CreditNoteController::createForm', ['filter' => 'permission:credit_notes.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\CreditNoteController::store', ['filter' => 'permission:credit_notes.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\CreditNoteController::show/$1', ['filter' => 'permission:credit_notes.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\CreditNoteController::editForm/$1', ['filter' => 'permission:credit_notes.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\CreditNoteController::update/$1', ['filter' => 'permission:credit_notes.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\CreditNoteController::post/$1', ['filter' => 'permission:credit_notes.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\CreditNoteController::cancel/$1', ['filter' => 'permission:credit_notes.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\CreditNoteController::destroy/$1', ['filter' => 'permission:credit_notes.delete']);
});

$routes->group('accounting/customer-statements', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\CustomerStatementController::index', ['filter' => 'permission:customer_statements.view']);
});

$routes->group('accounting/receivables-aging', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ReceivablesAgingController::index', ['filter' => 'permission:receivables_aging.view']);
});

// --- Payables (AP) ---
$routes->group('accounting/supplier-bills', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\SupplierBillController::index', ['filter' => 'permission:supplier_bills.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\SupplierBillController::createForm', ['filter' => 'permission:supplier_bills.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\SupplierBillController::store', ['filter' => 'permission:supplier_bills.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\SupplierBillController::show/$1', ['filter' => 'permission:supplier_bills.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\SupplierBillController::editForm/$1', ['filter' => 'permission:supplier_bills.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\SupplierBillController::update/$1', ['filter' => 'permission:supplier_bills.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\SupplierBillController::post/$1', ['filter' => 'permission:supplier_bills.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\SupplierBillController::cancel/$1', ['filter' => 'permission:supplier_bills.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\SupplierBillController::destroy/$1', ['filter' => 'permission:supplier_bills.delete']);
});

$routes->group('accounting/payments', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\PaymentController::index', ['filter' => 'permission:payments.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\PaymentController::createForm', ['filter' => 'permission:payments.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\PaymentController::store', ['filter' => 'permission:payments.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\PaymentController::show/$1', ['filter' => 'permission:payments.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\PaymentController::editForm/$1', ['filter' => 'permission:payments.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\PaymentController::update/$1', ['filter' => 'permission:payments.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\PaymentController::post/$1', ['filter' => 'permission:payments.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\PaymentController::cancel/$1', ['filter' => 'permission:payments.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\PaymentController::destroy/$1', ['filter' => 'permission:payments.delete']);
});

$routes->group('accounting/debit-notes', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\DebitNoteController::index', ['filter' => 'permission:debit_notes.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\DebitNoteController::createForm', ['filter' => 'permission:debit_notes.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\DebitNoteController::store', ['filter' => 'permission:debit_notes.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\DebitNoteController::show/$1', ['filter' => 'permission:debit_notes.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\DebitNoteController::editForm/$1', ['filter' => 'permission:debit_notes.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\DebitNoteController::update/$1', ['filter' => 'permission:debit_notes.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\DebitNoteController::post/$1', ['filter' => 'permission:debit_notes.post']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\DebitNoteController::cancel/$1', ['filter' => 'permission:debit_notes.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\DebitNoteController::destroy/$1', ['filter' => 'permission:debit_notes.delete']);
});

$routes->group('accounting/supplier-statements', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\SupplierStatementController::index', ['filter' => 'permission:supplier_statements.view']);
});

$routes->group('accounting/payables-aging', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\PayablesAgingController::index', ['filter' => 'permission:payables_aging.view']);
});

$routes->group('settings/cost-centers', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\CostCenterController::index', ['filter' => 'permission:cost_centers.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\CostCenterController::createForm', ['filter' => 'permission:cost_centers.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\CostCenterController::store', ['filter' => 'permission:cost_centers.create']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\CostCenterController::editForm/$1', ['filter' => 'permission:cost_centers.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\CostCenterController::update/$1', ['filter' => 'permission:cost_centers.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\CostCenterController::activate/$1', ['filter' => 'permission:cost_centers.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\CostCenterController::deactivate/$1', ['filter' => 'permission:cost_centers.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\CostCenterController::destroy/$1', ['filter' => 'permission:cost_centers.delete']);
});

$routes->get('accounting/cost-centers', static function () {
    return redirect()->to('/settings/cost-centers');
}, ['filter' => 'auth']);
$routes->get('accounting/cost-centers/(:any)', static function ($path) {
    return redirect()->to('/settings/cost-centers/' . $path);
}, ['filter' => 'auth']);

// --- Banking ---
$routes->group('accounting/bank-accounts', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\BankAccountController::index', ['filter' => 'permission:bank_accounts.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\BankAccountController::createForm', ['filter' => 'permission:bank_accounts.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\BankAccountController::store', ['filter' => 'permission:bank_accounts.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\BankAccountController::show/$1', ['filter' => 'permission:bank_accounts.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\BankAccountController::editForm/$1', ['filter' => 'permission:bank_accounts.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\BankAccountController::update/$1', ['filter' => 'permission:bank_accounts.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\BankAccountController::activate/$1', ['filter' => 'permission:bank_accounts.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\BankAccountController::deactivate/$1', ['filter' => 'permission:bank_accounts.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\BankAccountController::destroy/$1', ['filter' => 'permission:bank_accounts.delete']);
});

$routes->group('accounting/cash-accounts', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\CashAccountController::index', ['filter' => 'permission:cash_accounts.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\CashAccountController::createForm', ['filter' => 'permission:cash_accounts.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\CashAccountController::store', ['filter' => 'permission:cash_accounts.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\CashAccountController::show/$1', ['filter' => 'permission:cash_accounts.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\CashAccountController::editForm/$1', ['filter' => 'permission:cash_accounts.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\CashAccountController::update/$1', ['filter' => 'permission:cash_accounts.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\CashAccountController::activate/$1', ['filter' => 'permission:cash_accounts.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\CashAccountController::deactivate/$1', ['filter' => 'permission:cash_accounts.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\CashAccountController::destroy/$1', ['filter' => 'permission:cash_accounts.delete']);
});

$routes->group('accounting/bank-transfers', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\BankTransferController::index', ['filter' => 'permission:bank_transfers.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\BankTransferController::createForm', ['filter' => 'permission:bank_transfers.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\BankTransferController::store', ['filter' => 'permission:bank_transfers.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\BankTransferController::show/$1', ['filter' => 'permission:bank_transfers.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\BankTransferController::editForm/$1', ['filter' => 'permission:bank_transfers.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\BankTransferController::update/$1', ['filter' => 'permission:bank_transfers.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\BankTransferController::post/$1', ['filter' => 'permission:bank_transfers.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\BankTransferController::destroy/$1', ['filter' => 'permission:bank_transfers.delete']);
});

$routes->group('accounting/bank-reconciliations', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\BankReconciliationController::index', ['filter' => 'permission:bank_reconciliations.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\BankReconciliationController::createForm', ['filter' => 'permission:bank_reconciliations.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\BankReconciliationController::store', ['filter' => 'permission:bank_reconciliations.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\BankReconciliationController::show/$1', ['filter' => 'permission:bank_reconciliations.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\BankReconciliationController::editForm/$1', ['filter' => 'permission:bank_reconciliations.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\BankReconciliationController::update/$1', ['filter' => 'permission:bank_reconciliations.edit']);
    $routes->post('(:num)/complete', '\Modules\Accounting\Controllers\BankReconciliationController::complete/$1', ['filter' => 'permission:bank_reconciliations.complete']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\BankReconciliationController::destroy/$1', ['filter' => 'permission:bank_reconciliations.delete']);
});

$routes->group('accounting/cheques', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ChequeController::index', ['filter' => 'permission:cheques.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\ChequeController::createForm', ['filter' => 'permission:cheques.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\ChequeController::store', ['filter' => 'permission:cheques.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\ChequeController::show/$1', ['filter' => 'permission:cheques.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\ChequeController::editForm/$1', ['filter' => 'permission:cheques.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\ChequeController::update/$1', ['filter' => 'permission:cheques.edit']);
    $routes->post('(:num)/clear', '\Modules\Accounting\Controllers\ChequeController::clear/$1', ['filter' => 'permission:cheques.clear']);
    $routes->post('(:num)/bounce', '\Modules\Accounting\Controllers\ChequeController::bounce/$1', ['filter' => 'permission:cheques.edit']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\ChequeController::cancel/$1', ['filter' => 'permission:cheques.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\ChequeController::destroy/$1', ['filter' => 'permission:cheques.delete']);
});

// --- Assets ---
$routes->group('accounting/asset-categories', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\AssetCategoryController::index', ['filter' => 'permission:asset_categories.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\AssetCategoryController::createForm', ['filter' => 'permission:asset_categories.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\AssetCategoryController::store', ['filter' => 'permission:asset_categories.create']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\AssetCategoryController::editForm/$1', ['filter' => 'permission:asset_categories.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\AssetCategoryController::update/$1', ['filter' => 'permission:asset_categories.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\AssetCategoryController::activate/$1', ['filter' => 'permission:asset_categories.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\AssetCategoryController::deactivate/$1', ['filter' => 'permission:asset_categories.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\AssetCategoryController::destroy/$1', ['filter' => 'permission:asset_categories.delete']);
});

$routes->group('accounting/fixed-assets', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\FixedAssetController::index', ['filter' => 'permission:fixed_assets.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\FixedAssetController::createForm', ['filter' => 'permission:fixed_assets.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\FixedAssetController::store', ['filter' => 'permission:fixed_assets.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\FixedAssetController::show/$1', ['filter' => 'permission:fixed_assets.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\FixedAssetController::editForm/$1', ['filter' => 'permission:fixed_assets.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\FixedAssetController::update/$1', ['filter' => 'permission:fixed_assets.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\FixedAssetController::destroy/$1', ['filter' => 'permission:fixed_assets.delete']);
});

$routes->group('accounting/depreciation', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\DepreciationController::index', ['filter' => 'permission:depreciation.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\DepreciationController::createForm', ['filter' => 'permission:depreciation.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\DepreciationController::store', ['filter' => 'permission:depreciation.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\DepreciationController::show/$1', ['filter' => 'permission:depreciation.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\DepreciationController::editForm/$1', ['filter' => 'permission:depreciation.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\DepreciationController::update/$1', ['filter' => 'permission:depreciation.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\DepreciationController::post/$1', ['filter' => 'permission:depreciation.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\DepreciationController::destroy/$1', ['filter' => 'permission:depreciation.delete']);
});

$routes->group('accounting/asset-disposals', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\AssetDisposalController::index', ['filter' => 'permission:asset_disposals.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\AssetDisposalController::createForm', ['filter' => 'permission:asset_disposals.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\AssetDisposalController::store', ['filter' => 'permission:asset_disposals.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\AssetDisposalController::show/$1', ['filter' => 'permission:asset_disposals.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\AssetDisposalController::editForm/$1', ['filter' => 'permission:asset_disposals.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\AssetDisposalController::update/$1', ['filter' => 'permission:asset_disposals.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\AssetDisposalController::post/$1', ['filter' => 'permission:asset_disposals.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\AssetDisposalController::destroy/$1', ['filter' => 'permission:asset_disposals.delete']);
});

// --- Taxes ---
$routes->group('accounting/tax-rates', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\TaxRateController::index', ['filter' => 'permission:tax_rates.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\TaxRateController::createForm', ['filter' => 'permission:tax_rates.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\TaxRateController::store', ['filter' => 'permission:tax_rates.create']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\TaxRateController::editForm/$1', ['filter' => 'permission:tax_rates.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\TaxRateController::update/$1', ['filter' => 'permission:tax_rates.edit']);
    $routes->post('(:num)/activate', '\Modules\Accounting\Controllers\TaxRateController::activate/$1', ['filter' => 'permission:tax_rates.edit']);
    $routes->post('(:num)/deactivate', '\Modules\Accounting\Controllers\TaxRateController::deactivate/$1', ['filter' => 'permission:tax_rates.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\TaxRateController::destroy/$1', ['filter' => 'permission:tax_rates.delete']);
});

$routes->group('accounting/vat-returns', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\VatReturnController::index', ['filter' => 'permission:vat_returns.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\VatReturnController::createForm', ['filter' => 'permission:vat_returns.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\VatReturnController::store', ['filter' => 'permission:vat_returns.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\VatReturnController::show/$1', ['filter' => 'permission:vat_returns.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\VatReturnController::editForm/$1', ['filter' => 'permission:vat_returns.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\VatReturnController::update/$1', ['filter' => 'permission:vat_returns.edit']);
    $routes->post('(:num)/calculate', '\Modules\Accounting\Controllers\VatReturnController::calculate/$1', ['filter' => 'permission:vat_returns.edit']);
    $routes->post('(:num)/submit', '\Modules\Accounting\Controllers\VatReturnController::submit/$1', ['filter' => 'permission:vat_returns.submit']);
    $routes->post('(:num)/file', '\Modules\Accounting\Controllers\VatReturnController::file/$1', ['filter' => 'permission:vat_returns.submit']);
    $routes->post('(:num)/cancel', '\Modules\Accounting\Controllers\VatReturnController::cancel/$1', ['filter' => 'permission:vat_returns.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\VatReturnController::destroy/$1', ['filter' => 'permission:vat_returns.delete']);
});

$routes->group('accounting/tax-reports', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\TaxReportController::index', ['filter' => 'permission:tax_reports.view']);
});

// --- Operations (vouchers, expenses, budgets) ---
$routes->group('accounting/payment-vouchers', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\PaymentVoucherController::index', ['filter' => 'permission:payment_vouchers.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\PaymentVoucherController::createForm', ['filter' => 'permission:payment_vouchers.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\PaymentVoucherController::store', ['filter' => 'permission:payment_vouchers.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\PaymentVoucherController::show/$1', ['filter' => 'permission:payment_vouchers.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\PaymentVoucherController::editForm/$1', ['filter' => 'permission:payment_vouchers.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\PaymentVoucherController::update/$1', ['filter' => 'permission:payment_vouchers.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\PaymentVoucherController::post/$1', ['filter' => 'permission:payment_vouchers.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\PaymentVoucherController::destroy/$1', ['filter' => 'permission:payment_vouchers.delete']);
});

$routes->group('accounting/receipt-vouchers', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ReceiptVoucherController::index', ['filter' => 'permission:receipt_vouchers.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\ReceiptVoucherController::createForm', ['filter' => 'permission:receipt_vouchers.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\ReceiptVoucherController::store', ['filter' => 'permission:receipt_vouchers.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\ReceiptVoucherController::show/$1', ['filter' => 'permission:receipt_vouchers.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\ReceiptVoucherController::editForm/$1', ['filter' => 'permission:receipt_vouchers.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\ReceiptVoucherController::update/$1', ['filter' => 'permission:receipt_vouchers.edit']);
    $routes->post('(:num)/post', '\Modules\Accounting\Controllers\ReceiptVoucherController::post/$1', ['filter' => 'permission:receipt_vouchers.post']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\ReceiptVoucherController::destroy/$1', ['filter' => 'permission:receipt_vouchers.delete']);
});

$routes->group('accounting/expenses', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\ExpenseController::index', ['filter' => 'permission:expenses.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\ExpenseController::createForm', ['filter' => 'permission:expenses.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\ExpenseController::store', ['filter' => 'permission:expenses.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\ExpenseController::show/$1', ['filter' => 'permission:expenses.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\ExpenseController::editForm/$1', ['filter' => 'permission:expenses.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\ExpenseController::update/$1', ['filter' => 'permission:expenses.edit']);
    $routes->post('(:num)/approve', '\Modules\Accounting\Controllers\ExpenseController::approve/$1', ['filter' => 'permission:expenses.approve']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\ExpenseController::destroy/$1', ['filter' => 'permission:expenses.delete']);
});

$routes->group('accounting/budgets', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\BudgetController::index', ['filter' => 'permission:budgets.view']);
    $routes->get('create', '\Modules\Accounting\Controllers\BudgetController::createForm', ['filter' => 'permission:budgets.create']);
    $routes->post('/', '\Modules\Accounting\Controllers\BudgetController::store', ['filter' => 'permission:budgets.create']);
    $routes->get('(:num)', '\Modules\Accounting\Controllers\BudgetController::show/$1', ['filter' => 'permission:budgets.view']);
    $routes->get('(:num)/edit', '\Modules\Accounting\Controllers\BudgetController::editForm/$1', ['filter' => 'permission:budgets.edit']);
    $routes->post('(:num)', '\Modules\Accounting\Controllers\BudgetController::update/$1', ['filter' => 'permission:budgets.edit']);
    $routes->post('(:num)/delete', '\Modules\Accounting\Controllers\BudgetController::destroy/$1', ['filter' => 'permission:budgets.delete']);
});

// Legacy taxes route → tax rates
$routes->get('accounting/taxes', static function () {
    return redirect()->to('/accounting/tax-rates');
}, ['filter' => 'auth']);

// --- Reports ---
$routes->group('accounting/reports', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Accounting\Controllers\AccountingReportController::index', ['filter' => 'permission:accounting.reports']);
    $routes->get('trial-balance', '\Modules\Accounting\Controllers\AccountingReportController::trialBalance', ['filter' => 'permission:accounting.reports']);
    $routes->get('general-ledger', '\Modules\Accounting\Controllers\AccountingReportController::generalLedger', ['filter' => 'permission:accounting.reports']);
    $routes->get('profit-and-loss', '\Modules\Accounting\Controllers\AccountingReportController::profitAndLoss', ['filter' => 'permission:accounting.reports']);
    $routes->get('balance-sheet', '\Modules\Accounting\Controllers\AccountingReportController::balanceSheet', ['filter' => 'permission:accounting.reports']);
    $routes->get('cash-flow', '\Modules\Accounting\Controllers\AccountingReportController::cashFlow', ['filter' => 'permission:accounting.reports']);
});
