Features: - Implement two fee types: entrance fee and annual fee (both NT$1,000) - Add 50% discount for disability certificate holders - Add disability certificate upload in member profile - Integrate disability verification into cashier approval workflow - Add membership fee settings in system admin Document permissions: - Fix hard-coded role logic in Document model - Use permission-based authorization instead of role checks Additional features: - Add announcements, general ledger, and trial balance modules - Add income management and accounting entries - Add comprehensive test suite with factories - Update UI translations to Traditional Chinese 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
3.2 KiB
PHP
88 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AccountingEntry;
|
|
use App\Models\ChartOfAccount;
|
|
use Illuminate\Http\Request;
|
|
|
|
class GeneralLedgerController extends Controller
|
|
{
|
|
/**
|
|
* Display the general ledger
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$accounts = ChartOfAccount::where('is_active', true)
|
|
->orderBy('account_code')
|
|
->get();
|
|
|
|
$selectedAccountId = $request->input('account_id');
|
|
$startDate = $request->input('start_date', now()->startOfYear()->format('Y-m-d'));
|
|
$endDate = $request->input('end_date', now()->format('Y-m-d'));
|
|
|
|
$entries = null;
|
|
$selectedAccount = null;
|
|
$openingBalance = 0;
|
|
$debitTotal = 0;
|
|
$creditTotal = 0;
|
|
$closingBalance = 0;
|
|
|
|
if ($selectedAccountId) {
|
|
$selectedAccount = ChartOfAccount::findOrFail($selectedAccountId);
|
|
|
|
// Get opening balance (all entries before start date)
|
|
$openingDebit = AccountingEntry::where('chart_of_account_id', $selectedAccountId)
|
|
->where('entry_date', '<', $startDate)
|
|
->where('entry_type', AccountingEntry::ENTRY_TYPE_DEBIT)
|
|
->sum('amount');
|
|
|
|
$openingCredit = AccountingEntry::where('chart_of_account_id', $selectedAccountId)
|
|
->where('entry_date', '<', $startDate)
|
|
->where('entry_type', AccountingEntry::ENTRY_TYPE_CREDIT)
|
|
->sum('amount');
|
|
|
|
// Calculate opening balance based on account type
|
|
if (in_array($selectedAccount->account_type, ['asset', 'expense'])) {
|
|
// Assets and Expenses: Debit increases, Credit decreases
|
|
$openingBalance = $openingDebit - $openingCredit;
|
|
} else {
|
|
// Liabilities, Equity, Income: Credit increases, Debit decreases
|
|
$openingBalance = $openingCredit - $openingDebit;
|
|
}
|
|
|
|
// Get entries for the period
|
|
$entries = AccountingEntry::with(['financeDocument', 'chartOfAccount'])
|
|
->where('chart_of_account_id', $selectedAccountId)
|
|
->whereBetween('entry_date', [$startDate, $endDate])
|
|
->orderBy('entry_date')
|
|
->orderBy('id')
|
|
->get();
|
|
|
|
// Calculate totals for the period
|
|
$debitTotal = $entries->where('entry_type', AccountingEntry::ENTRY_TYPE_DEBIT)->sum('amount');
|
|
$creditTotal = $entries->where('entry_type', AccountingEntry::ENTRY_TYPE_CREDIT)->sum('amount');
|
|
|
|
// Calculate closing balance
|
|
if (in_array($selectedAccount->account_type, ['asset', 'expense'])) {
|
|
$closingBalance = $openingBalance + $debitTotal - $creditTotal;
|
|
} else {
|
|
$closingBalance = $openingBalance + $creditTotal - $debitTotal;
|
|
}
|
|
}
|
|
|
|
return view('admin.general-ledger.index', compact(
|
|
'accounts',
|
|
'selectedAccount',
|
|
'entries',
|
|
'startDate',
|
|
'endDate',
|
|
'openingBalance',
|
|
'debitTotal',
|
|
'creditTotal',
|
|
'closingBalance'
|
|
));
|
|
}
|
|
}
|