Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FinanceReportRenderer
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 renderPreview
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Services;
4
5use App\Console\Commands\SendFinanceReport;
6
7/**
8 * FIRE-1148: thin service wrapper around SendFinanceReport's renderPreview().
9 *
10 * Why a separate service instead of having the controller call the command
11 * directly: keeps FinanceController decoupled from `App\Console\Commands\*`
12 * (controllers depending on console commands is awkward) and gives us a
13 * stable injection seam if/when the rendering logic eventually moves out
14 * of the command class entirely.
15 *
16 * The actual HTML build still happens inside SendFinanceReport via the same
17 * private buildReportHtml / buildAllRegionsReportHtml / etc. methods the
18 * cron uses — so the preview output is byte-identical to what recipients
19 * receive in the email body.
20 */
21final class FinanceReportRenderer
22{
23    public function __construct(private SendFinanceReport $command) {}
24
25    /**
26     * Returns the aggregated all-regions HTML for the given month + type
27     * ('weekly' or 'monthly'). Pass `month=null` to fall back to the
28     * command's default month resolution (current month for weekly,
29     * previous month for monthly).
30     */
31    public function renderPreview(?int $month = null, string $type = 'weekly'): string
32    {
33        return $this->command->renderPreview($month, $type);
34    }
35}