. */ declare(strict_types=1); namespace FireflyIII\Generator\Report\Standard; use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; use FireflyIII\Helpers\Report\ReportHelperInterface; use Illuminate\Support\Collection; use Log; use Throwable; /** * Class MonthReportGenerator. */ class MonthReportGenerator implements ReportGeneratorInterface { /** @var Collection The accounts involved in the report. */ private $accounts; /** @var Carbon The end date. */ private $end; /** @var Carbon The start date. */ private $start; /** * Generates the report. * * @return string */ public function generate(): string { /** @var ReportHelperInterface $helper */ $helper = app(ReportHelperInterface::class); $bills = $helper->getBillReport($this->start, $this->end, $this->accounts); $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); $reportType = 'default'; try { return view( 'reports.default.month', compact('bills', 'accountIds', 'reportType') )->with('start', $this->start)->with('end', $this->end)->render(); } catch (Throwable $e) { Log::error(sprintf('Cannot render reports.default.month: %s', $e->getMessage())); $result = 'Could not render report view.'; } return $result; } /** * Sets the accounts involved in the report. * * @param Collection $accounts * * @return ReportGeneratorInterface */ public function setAccounts(Collection $accounts): ReportGeneratorInterface { $this->accounts = $accounts; return $this; } /** * Unused budget setter. * * @param Collection $budgets * * @return ReportGeneratorInterface */ public function setBudgets(Collection $budgets): ReportGeneratorInterface { return $this; } /** * Unused category setter. * * @param Collection $categories * * @return ReportGeneratorInterface */ public function setCategories(Collection $categories): ReportGeneratorInterface { return $this; } /** * Set the end date of the report. * * @param Carbon $date * * @return ReportGeneratorInterface */ public function setEndDate(Carbon $date): ReportGeneratorInterface { $this->end = $date; return $this; } /** * Set the expenses used in this report. * * @param Collection $expense * * @return ReportGeneratorInterface */ public function setExpense(Collection $expense): ReportGeneratorInterface { return $this; } /** * Set the start date of this report. * * @param Carbon $date * * @return ReportGeneratorInterface */ public function setStartDate(Carbon $date): ReportGeneratorInterface { $this->start = $date; return $this; } /** * Set the tags used in this report. * * @param Collection $tags * * @return ReportGeneratorInterface */ public function setTags(Collection $tags): ReportGeneratorInterface { return $this; } }