Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
16.13% |
5 / 31 |
|
62.50% |
5 / 8 |
CRAP | |
0.00% |
0 / 1 |
| ProductionOutputReport | |
16.13% |
5 / 31 |
|
62.50% |
5 / 8 |
82.39 | |
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 | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| rows | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| summary | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Reports\Manufacturing; |
| 4 | |
| 5 | use App\Models\ProductionOrder; |
| 6 | use App\Reports\Report; |
| 7 | use Illuminate\Support\Collection; |
| 8 | |
| 9 | class ProductionOutputReport extends Report |
| 10 | { |
| 11 | public function key(): string |
| 12 | { |
| 13 | return 'production-output'; |
| 14 | } |
| 15 | |
| 16 | public function label(): string |
| 17 | { |
| 18 | return 'Production Output'; |
| 19 | } |
| 20 | |
| 21 | public function group(): string |
| 22 | { |
| 23 | return 'Manufacturing'; |
| 24 | } |
| 25 | |
| 26 | public function feature(): ?string |
| 27 | { |
| 28 | return 'manufacturing'; |
| 29 | } |
| 30 | |
| 31 | public function description(): ?string |
| 32 | { |
| 33 | return 'Every completed production order in range — planned vs actual quantity and unit cost.'; |
| 34 | } |
| 35 | |
| 36 | public function columns(): array |
| 37 | { |
| 38 | return [ |
| 39 | ['key' => 'number', 'label' => 'Order'], |
| 40 | ['key' => 'product', 'label' => 'Product'], |
| 41 | ['key' => 'completed_at', 'label' => 'Completed'], |
| 42 | ['key' => 'planned_qty', 'label' => 'Planned', 'align' => 'right'], |
| 43 | ['key' => 'actual_qty', 'label' => 'Actual', 'align' => 'right'], |
| 44 | ['key' => 'unit_cost', 'label' => 'Unit Cost', 'align' => 'right', 'render' => fn ($r) => $r->unit_cost !== null ? money($r->unit_cost) : '—'], |
| 45 | ]; |
| 46 | } |
| 47 | |
| 48 | public function rows(array $filters): Collection |
| 49 | { |
| 50 | return ProductionOrder::query() |
| 51 | ->where('status', 'Completed') |
| 52 | ->whereDate('completed_at', '>=', $filters['from']) |
| 53 | ->whereDate('completed_at', '<=', $filters['to']) |
| 54 | ->with('bom.product') |
| 55 | ->latest('completed_at') |
| 56 | ->get() |
| 57 | ->map(fn (ProductionOrder $o) => (object) [ |
| 58 | 'number' => $o->number, |
| 59 | 'product' => $o->bom->product->name ?? '—', |
| 60 | 'completed_at' => optional($o->completed_at)->format('d M, Y'), |
| 61 | 'planned_qty' => rtrim(rtrim((string) $o->planned_qty, '0'), '.'), |
| 62 | 'actual_qty' => $o->actual_qty !== null ? rtrim(rtrim((string) $o->actual_qty, '0'), '.') : '—', |
| 63 | 'unit_cost' => $o->unit_cost !== null ? (float) $o->unit_cost : null, |
| 64 | ]); |
| 65 | } |
| 66 | |
| 67 | public function summary(Collection $rows, array $filters): array |
| 68 | { |
| 69 | return [ |
| 70 | 'Completed Orders' => number_format($rows->count()), |
| 71 | ]; |
| 72 | } |
| 73 | } |