2017-12-09 21:49:19 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* MonthReportGenerator.php
|
2020-01-28 08:45:28 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-12-09 21:49:19 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-12-09 21:49:19 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2017-12-09 21:49:19 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-12-09 21:49:19 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-12-09 21:49:19 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-12-09 21:49:19 +01:00
|
|
|
*/
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace FireflyIII\Generator\Report\Account;
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2018-08-04 17:30:06 +02:00
|
|
|
use Log;
|
|
|
|
|
use Throwable;
|
2017-12-09 21:49:19 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class MonthReportGenerator.
|
2018-08-24 07:18:33 +02:00
|
|
|
*
|
|
|
|
|
* @codeCoverageIgnore
|
2017-12-09 21:49:19 +01:00
|
|
|
*/
|
|
|
|
|
class MonthReportGenerator implements ReportGeneratorInterface
|
|
|
|
|
{
|
2020-10-31 08:00:44 +01:00
|
|
|
private Collection $accounts;
|
|
|
|
|
private Carbon $end;
|
|
|
|
|
private Collection $expense;
|
|
|
|
|
private Carbon $start;
|
2017-12-09 21:49:19 +01:00
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Generate the report.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function generate(): string
|
|
|
|
|
{
|
2018-04-02 14:42:07 +02:00
|
|
|
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
|
2020-03-17 14:57:04 +01:00
|
|
|
$doubleIds = implode(',', $this->expense->pluck('id')->toArray());
|
2017-12-10 08:56:20 +01:00
|
|
|
$reportType = 'account';
|
|
|
|
|
$preferredPeriod = $this->preferredPeriod();
|
2018-08-04 17:30:06 +02:00
|
|
|
try {
|
2022-01-29 14:11:12 +01:00
|
|
|
$result = view('reports.double.report', compact('accountIds', 'reportType', 'doubleIds', 'preferredPeriod'))
|
2019-09-03 22:35:41 +02:00
|
|
|
->with('start', $this->start)->with('end', $this->end)
|
2020-03-17 14:57:04 +01:00
|
|
|
->with('doubles', $this->expense)
|
|
|
|
|
->render();
|
2022-10-31 05:40:59 +01:00
|
|
|
} catch (Throwable $e) {
|
2019-09-03 17:30:45 +02:00
|
|
|
Log::error(sprintf('Cannot render reports.double.report: %s', $e->getMessage()));
|
|
|
|
|
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
2018-08-04 17:30:06 +02:00
|
|
|
}
|
2017-12-09 21:49:19 +01:00
|
|
|
|
2018-08-04 17:30:06 +02:00
|
|
|
return $result;
|
2017-12-09 21:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-29 14:58:06 +02:00
|
|
|
/**
|
|
|
|
|
* Return the preferred period.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function preferredPeriod(): string
|
|
|
|
|
{
|
|
|
|
|
return 'day';
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-09 21:49:19 +01:00
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set accounts.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Collection $accounts
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
$this->accounts = $accounts;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set budgets.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Collection $budgets
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set categories.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Collection $categories
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setCategories(Collection $categories): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set end date.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Carbon $date
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
$this->end = $date;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set expense collection.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Collection $expense
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setExpense(Collection $expense): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
$this->expense = $expense;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set start date.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Carbon $date
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
$this->start = $date;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-07 07:18:49 +02:00
|
|
|
* Set collection of tags.
|
|
|
|
|
*
|
2017-12-09 21:49:19 +01:00
|
|
|
* @param Collection $tags
|
|
|
|
|
*
|
|
|
|
|
* @return ReportGeneratorInterface
|
|
|
|
|
*/
|
|
|
|
|
public function setTags(Collection $tags): ReportGeneratorInterface
|
|
|
|
|
{
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
}
|