2016-11-09 14:36:54 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ReportGeneratorFactory.php
|
2020-01-28 01:45:28 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-11-09 14:36:54 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-11-09 14:36:54 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 01:40:00 -05:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:37:26 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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/>.
|
2016-11-09 14:36:54 -06:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
2016-11-09 14:36:54 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Generator\Report;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class ReportGeneratorFactory.
|
2019-02-13 10:38:41 -06:00
|
|
|
*
|
2018-08-24 00:18:33 -05:00
|
|
|
* @codeCoverageIgnore
|
2016-11-09 14:36:54 -06:00
|
|
|
*/
|
|
|
|
class ReportGeneratorFactory
|
|
|
|
{
|
|
|
|
/**
|
2018-07-07 00:18:49 -05:00
|
|
|
* Static report generator class.
|
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @param string $type
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2020-03-17 08:57:04 -05:00
|
|
|
* @throws FireflyException
|
2016-11-09 14:36:54 -06:00
|
|
|
* @return ReportGeneratorInterface
|
2017-11-15 05:25:49 -06:00
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
*/
|
|
|
|
public static function reportGenerator(string $type, Carbon $start, Carbon $end): ReportGeneratorInterface
|
|
|
|
{
|
|
|
|
$period = 'Month';
|
|
|
|
// more than two months date difference means year report.
|
|
|
|
if ($start->diffInMonths($end) > 1) {
|
|
|
|
$period = 'Year';
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:46:32 -06:00
|
|
|
// more than one year date difference means multi year report.
|
|
|
|
if ($start->diffInMonths($end) > 12) {
|
|
|
|
$period = 'MultiYear';
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:36:54 -06:00
|
|
|
$class = sprintf('FireflyIII\Generator\Report\%s\%sReportGenerator', $type, $period);
|
|
|
|
if (class_exists($class)) {
|
|
|
|
/** @var ReportGeneratorInterface $obj */
|
2017-03-05 11:15:38 -06:00
|
|
|
$obj = app($class);
|
2016-11-09 14:36:54 -06:00
|
|
|
$obj->setStartDate($start);
|
|
|
|
$obj->setEndDate($end);
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
2016-11-09 23:23:21 -06:00
|
|
|
throw new FireflyException(sprintf('Cannot generate report. There is no "%s"-report for period "%s".', $type, $period));
|
2016-11-09 14:36:54 -06:00
|
|
|
}
|
2016-12-22 12:42:45 -06:00
|
|
|
}
|