Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.24% |
20 / 21 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LedgerController | |
95.24% |
20 / 21 |
|
75.00% |
3 / 4 |
11 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| cashbook | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| bankbook | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| show | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
8 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\admin; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Models\Account; |
| 7 | use App\Services\Accounting\AccountingService; |
| 8 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Support\Carbon; |
| 10 | use Illuminate\View\View; |
| 11 | |
| 12 | /** |
| 13 | * Settings → Accounting → CashBook / Bank Book. A running ledger (date, |
| 14 | * particulars, in, out, balance) for one account — the design mockup |
| 15 | * screen, wired to real data via App\Services\Accounting\AccountingService. |
| 16 | * Also carries a simple reconciliation calculator: type in the bank/cash |
| 17 | * statement balance and see the variance against the book balance — nothing |
| 18 | * is persisted, it's just a live check. |
| 19 | */ |
| 20 | class LedgerController extends Controller |
| 21 | { |
| 22 | public function __construct(private readonly AccountingService $accounting) {} |
| 23 | |
| 24 | public function cashbook(Request $request): View |
| 25 | { |
| 26 | return $this->show($request, 'cash'); |
| 27 | } |
| 28 | |
| 29 | public function bankbook(Request $request): View |
| 30 | { |
| 31 | return $this->show($request, 'bank'); |
| 32 | } |
| 33 | |
| 34 | private function show(Request $request, string $type): View |
| 35 | { |
| 36 | $accounts = Account::where('type', $type)->orderBy('name')->get(); |
| 37 | $account = $accounts->firstWhere('id', (int) $request->query('account')) ?? $accounts->first(); |
| 38 | |
| 39 | $from = $request->query('from') ? Carbon::parse($request->query('from')) : null; |
| 40 | $to = $request->query('to') ? Carbon::parse($request->query('to')) : null; |
| 41 | |
| 42 | $rows = $account ? $this->accounting->ledger($account, $from, $to) : collect(); |
| 43 | $balance = $account ? $this->accounting->balance($account) : 0.0; |
| 44 | $statementBalance = $request->query('statement_balance'); |
| 45 | |
| 46 | return view('admin.accounting.ledger.show', [ |
| 47 | 'type' => $type, |
| 48 | 'title' => $type === 'bank' ? 'Bank Book' : 'CashBook', |
| 49 | 'accounts' => $accounts, |
| 50 | 'account' => $account, |
| 51 | 'rows' => $rows, |
| 52 | 'balance' => $balance, |
| 53 | 'from' => $from, |
| 54 | 'to' => $to, |
| 55 | 'statementBalance' => $statementBalance !== null && $statementBalance !== '' ? (float) $statementBalance : null, |
| 56 | ]); |
| 57 | } |
| 58 | } |