Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.77% |
30 / 31 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
| DayBookReport | |
96.77% |
30 / 31 |
|
87.50% |
7 / 8 |
10 | |
0.00% |
0 / 1 |
| key | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| label | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| group | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| feature | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| columns | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| rows | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
3.00 | |||
| summary | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Reports\Finance; |
| 4 | |
| 5 | use App\Models\Transaction; |
| 6 | use App\Reports\Report; |
| 7 | use Illuminate\Support\Collection; |
| 8 | |
| 9 | /** Every posted transaction (income/expense/transfer) across every account in the range — the full day-by-day book. */ |
| 10 | class DayBookReport extends Report |
| 11 | { |
| 12 | public function key(): string |
| 13 | { |
| 14 | return 'day-book'; |
| 15 | } |
| 16 | |
| 17 | public function label(): string |
| 18 | { |
| 19 | return 'Day Book'; |
| 20 | } |
| 21 | |
| 22 | public function group(): string |
| 23 | { |
| 24 | return 'Finance'; |
| 25 | } |
| 26 | |
| 27 | public function feature(): ?string |
| 28 | { |
| 29 | return 'accounting'; |
| 30 | } |
| 31 | |
| 32 | public function description(): ?string |
| 33 | { |
| 34 | return 'Every transaction posted across every account in the selected range.'; |
| 35 | } |
| 36 | |
| 37 | public function columns(): array |
| 38 | { |
| 39 | return [ |
| 40 | ['key' => 'date', 'label' => 'Date'], |
| 41 | ['key' => 'account', 'label' => 'Account'], |
| 42 | ['key' => 'type', 'label' => 'Type'], |
| 43 | ['key' => 'particulars', 'label' => 'Particulars'], |
| 44 | ['key' => 'amount', 'label' => 'Amount', 'align' => 'right', 'render' => fn ($r) => money($r->amount)], |
| 45 | ]; |
| 46 | } |
| 47 | |
| 48 | public function rows(array $filters): Collection |
| 49 | { |
| 50 | return Transaction::query() |
| 51 | ->with('account', 'toAccount', 'category') |
| 52 | ->whereNull('reversed_at') |
| 53 | ->whereDate('date', '>=', $filters['from']) |
| 54 | ->whereDate('date', '<=', $filters['to']) |
| 55 | ->orderBy('date')->orderBy('id') |
| 56 | ->get() |
| 57 | ->map(fn (Transaction $t) => (object) [ |
| 58 | 'date' => $t->date->format('d M, Y'), |
| 59 | 'account' => $t->type === 'transfer' |
| 60 | ? ($t->account->name ?? '—') . ' → ' . ($t->toAccount->name ?? '—') |
| 61 | : ($t->account->name ?? '—'), |
| 62 | 'type' => ucfirst($t->type), |
| 63 | 'particulars' => $t->category->name ?? ($t->party_name ?: '—'), |
| 64 | 'amount' => (float) $t->amount, |
| 65 | ]); |
| 66 | } |
| 67 | |
| 68 | public function summary(Collection $rows, array $filters): array |
| 69 | { |
| 70 | return [ |
| 71 | 'Transactions' => number_format($rows->count()), |
| 72 | ]; |
| 73 | } |
| 74 | } |