2016-11-09 14:36:54 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ReportGeneratorFactory.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-11-09 14:36:54 -06:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-11-09 14:36:54 -06:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:41:58 -06:00
|
|
|
* along with Firefly III. If not, see <http://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.
|
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
|
|
|
|
*
|
|
|
|
* @return ReportGeneratorInterface
|
2017-11-15 05:25:49 -06:00
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|