mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Code cleanup.
This commit is contained in:
@@ -34,10 +34,6 @@ class ChartJsGenerator implements GeneratorInterface
|
||||
* Expects data as:.
|
||||
*
|
||||
* key => [value => x, 'currency_symbol' => 'x']
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiCurrencyPieChart(array $data): array
|
||||
{
|
||||
@@ -99,10 +95,6 @@ class ChartJsGenerator implements GeneratorInterface
|
||||
* ]
|
||||
*
|
||||
* // it's five.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiSet(array $data): array
|
||||
{
|
||||
@@ -148,10 +140,6 @@ class ChartJsGenerator implements GeneratorInterface
|
||||
* Expects data as:.
|
||||
*
|
||||
* key => value
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $data): array
|
||||
{
|
||||
@@ -189,11 +177,6 @@ class ChartJsGenerator implements GeneratorInterface
|
||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:.
|
||||
*
|
||||
* 'label-of-entry' => value
|
||||
*
|
||||
* @param string $setLabel
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function singleSet(string $setLabel, array $data): array
|
||||
{
|
||||
|
@@ -28,11 +28,6 @@ namespace FireflyIII\Generator\Chart\Basic;
|
||||
*/
|
||||
interface GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiCurrencyPieChart(array $data): array;
|
||||
|
||||
/**
|
||||
@@ -62,10 +57,6 @@ interface GeneratorInterface
|
||||
* ]
|
||||
*
|
||||
* // it's five.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiSet(array $data): array;
|
||||
|
||||
@@ -73,10 +64,6 @@ interface GeneratorInterface
|
||||
* Expects data as:.
|
||||
*
|
||||
* key => value
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $data): array;
|
||||
|
||||
@@ -84,11 +71,6 @@ interface GeneratorInterface
|
||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:.
|
||||
*
|
||||
* 'label-of-entry' => value
|
||||
*
|
||||
* @param string $setLabel
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function singleSet(string $setLabel, array $data): array;
|
||||
}
|
||||
|
@@ -27,12 +27,9 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
@@ -44,7 +41,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Generate the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -53,37 +49,26 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
$doubleIds = implode(',', $this->expense->pluck('id')->toArray());
|
||||
$reportType = 'account';
|
||||
$preferredPeriod = $this->preferredPeriod();
|
||||
|
||||
try {
|
||||
$result = view('reports.double.report', compact('accountIds', 'reportType', 'doubleIds', 'preferredPeriod'))
|
||||
->with('start', $this->start)->with('end', $this->end)
|
||||
->with('doubles', $this->expense)
|
||||
->render();
|
||||
} catch (Throwable $e) {
|
||||
->render()
|
||||
;
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.double.report: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the preferred period.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function preferredPeriod(): string
|
||||
{
|
||||
return 'day';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -94,10 +79,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set budgets.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -106,10 +87,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set categories.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -118,10 +95,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set end date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -132,10 +105,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set expense collection.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -146,10 +115,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set start date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -160,13 +125,17 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set collection of tags.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the preferred period.
|
||||
*/
|
||||
protected function preferredPeriod(): string
|
||||
{
|
||||
return 'day';
|
||||
}
|
||||
}
|
||||
|
@@ -25,15 +25,11 @@ namespace FireflyIII\Generator\Report\Account;
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
/**
|
||||
* Returns the preferred period.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function preferredPeriod(): string
|
||||
{
|
||||
|
@@ -25,15 +25,11 @@ namespace FireflyIII\Generator\Report\Account;
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
/**
|
||||
* Returns the preferred period.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function preferredPeriod(): string
|
||||
{
|
||||
|
@@ -31,8 +31,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
@@ -46,15 +44,15 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
$auditData = [];
|
||||
$dayBefore = clone $this->start;
|
||||
$dayBefore->subDay();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($this->accounts as $account) {
|
||||
// balance the day before:
|
||||
@@ -92,14 +90,17 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
'payment_date',
|
||||
'invoice_date',
|
||||
];
|
||||
|
||||
try {
|
||||
$result = view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow'))
|
||||
->with('start', $this->start)->with('end', $this->end)->with('accounts', $this->accounts)
|
||||
->render();
|
||||
} catch (Throwable $e) {
|
||||
->render()
|
||||
;
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.audit.report: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -109,12 +110,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Get the audit report.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function getAuditReport(Account $account, Carbon $date): array
|
||||
{
|
||||
@@ -129,7 +126,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation()
|
||||
->withBudgetInformation()->withCategoryInformation()->withBillInformation();
|
||||
->withBudgetInformation()->withCategoryInformation()->withBillInformation()
|
||||
;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = array_reverse($journals, true);
|
||||
$dayBeforeBalance = app('steam')->balance($account, $date);
|
||||
@@ -180,10 +178,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Account collection setter.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -194,10 +188,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Budget collection setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -206,10 +196,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Category collection setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -218,10 +204,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* End date setter.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -232,10 +214,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Expenses collection setter.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -245,10 +223,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Start date collection setter.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -259,10 +233,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Tags collection setter.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Audit;
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class MultiYearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Audit;
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class YearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -29,13 +29,10 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
* TODO include info about tags.
|
||||
*
|
||||
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
@@ -56,13 +53,13 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
|
||||
$budgetIds = implode(',', $this->budgets->pluck('id')->toArray());
|
||||
|
||||
try {
|
||||
$result = view(
|
||||
'reports.budget.month',
|
||||
@@ -71,11 +68,13 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
->with('start', $this->start)->with('end', $this->end)
|
||||
->with('budgets', $this->budgets)
|
||||
->with('accounts', $this->accounts)
|
||||
->render();
|
||||
} catch (Throwable $e) {
|
||||
->render()
|
||||
;
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.account.report: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -84,10 +83,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused category setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -96,10 +91,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the end date of the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -110,10 +101,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused expense setter.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -122,10 +109,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date of the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -136,20 +119,34 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused tags setter.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved budgets.
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
$this->budgets = $budgets;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved accounts.
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expenses.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExpenses(): array
|
||||
{
|
||||
@@ -162,42 +159,15 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->setBudgets($this->budgets);
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->setBudgets($this->budgets)
|
||||
;
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$this->expenses = $journals;
|
||||
|
||||
return $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved budgets.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
$this->budgets = $budgets;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Budget;
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class MultiYearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Budget;
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class YearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -29,13 +29,10 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
* TODO include info about tags
|
||||
*
|
||||
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
@@ -58,7 +55,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -73,21 +69,19 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
->with('start', $this->start)->with('end', $this->end)
|
||||
->with('categories', $this->categories)
|
||||
->with('accounts', $this->accounts)
|
||||
->render();
|
||||
} catch (Throwable $e) {
|
||||
->render()
|
||||
;
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.category.month: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty budget setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -96,10 +90,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the end date for this report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -110,10 +100,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the expenses involved in this report.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -122,10 +108,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date for this report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -136,20 +118,34 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused tag setter.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the categories involved in this report.
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
$this->categories = $categories;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved accounts.
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expenses for this report.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExpenses(): array
|
||||
{
|
||||
@@ -162,8 +158,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setCategories($this->categories)->withAccountInformation();
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setCategories($this->categories)->withAccountInformation()
|
||||
;
|
||||
|
||||
$transactions = $collector->getExtractedJournals();
|
||||
$this->expenses = $transactions;
|
||||
@@ -171,38 +168,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the categories involved in this report.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
$this->categories = $categories;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the involved accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the income for this report.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncome(): array
|
||||
{
|
||||
@@ -214,8 +181,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->setCategories($this->categories)->withAccountInformation();
|
||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->setCategories($this->categories)->withAccountInformation()
|
||||
;
|
||||
|
||||
$transactions = $collector->getExtractedJournals();
|
||||
$this->income = $transactions;
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Category;
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class MultiYearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Category;
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class YearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -28,20 +28,12 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class ReportGeneratorFactory.
|
||||
*
|
||||
|
||||
*/
|
||||
class ReportGeneratorFactory
|
||||
{
|
||||
/**
|
||||
* Static report generator class.
|
||||
*
|
||||
* @param string $type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function reportGenerator(string $type, Carbon $start, Carbon $end): ReportGeneratorInterface
|
||||
@@ -66,6 +58,7 @@ class ReportGeneratorFactory
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('Cannot generate report. There is no "%s"-report for period "%s".', $type, $period));
|
||||
}
|
||||
}
|
||||
|
@@ -33,71 +33,41 @@ interface ReportGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Generate the report.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate(): string;
|
||||
|
||||
/**
|
||||
* Set the involved accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): self;
|
||||
|
||||
/**
|
||||
* Set the involved budgets.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): self;
|
||||
|
||||
/**
|
||||
* Set the involved categories.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): self;
|
||||
|
||||
/**
|
||||
* Set the end date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): self;
|
||||
|
||||
/**
|
||||
* Set the expense accounts.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): self;
|
||||
|
||||
/**
|
||||
* Set the start date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): self;
|
||||
|
||||
/**
|
||||
* Set the tags.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): self;
|
||||
}
|
||||
|
@@ -27,26 +27,24 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
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
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -56,20 +54,17 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
try {
|
||||
return view('reports.default.month', compact('accountIds', 'reportType'))->with('start', $this->start)->with('end', $this->end)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.default.month: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = 'Could not render report view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the accounts involved in the report.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -80,10 +75,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused budget setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -92,10 +83,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused category setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -104,10 +91,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the end date of the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -118,10 +101,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the expenses used in this report.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -130,10 +109,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date of this report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -144,10 +119,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the tags used in this report.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
|
@@ -27,26 +27,24 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
/** @var Collection The accounts involved. */
|
||||
private $accounts;
|
||||
|
||||
/** @var Carbon The end date. */
|
||||
private $end;
|
||||
|
||||
/** @var Carbon The start date. */
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -60,20 +58,17 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
'reports.default.multi-year',
|
||||
compact('accountIds', 'reportType')
|
||||
)->with('start', $this->start)->with('end', $this->end)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.default.multi-year: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the accounts used in the report.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -84,10 +79,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Sets the budgets used in the report.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -96,10 +87,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Sets the categories used in the report.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -108,10 +95,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Sets the end date used in the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -122,10 +105,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused setter for expenses.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -134,10 +113,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date of the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -148,10 +123,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the tags for the report.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
|
@@ -27,26 +27,24 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
/** @var Collection The accounts involved. */
|
||||
private $accounts;
|
||||
|
||||
/** @var Carbon The end date. */
|
||||
private $end;
|
||||
|
||||
/** @var Carbon The start date. */
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -60,10 +58,11 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
'reports.default.year',
|
||||
compact('accountIds', 'reportType')
|
||||
)->with('start', $this->start)->with('end', $this->end)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.account.report: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = 'Could not render report view.';
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -72,10 +71,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -86,10 +81,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused budget setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -98,10 +89,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused categories setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -110,10 +97,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the end date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -124,10 +107,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the expenses used.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -136,10 +115,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -150,10 +125,6 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused tags setter.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
|
@@ -27,12 +27,9 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
@@ -53,7 +50,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
/**
|
||||
* Generate the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function generate(): string
|
||||
@@ -68,10 +64,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
'reports.tag.month',
|
||||
compact('accountIds', 'reportType', 'tagIds')
|
||||
)->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$result = sprintf('Could not render report view: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($result, 0, $e);
|
||||
}
|
||||
|
||||
@@ -80,10 +77,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
@@ -94,10 +87,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused budget setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
@@ -106,10 +95,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Unused category setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
@@ -118,10 +103,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the end date of the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -132,10 +113,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the expenses in this report.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setExpense(Collection $expense): ReportGeneratorInterface
|
||||
{
|
||||
@@ -144,10 +121,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the start date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
@@ -158,10 +131,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* Set the tags used in this report.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): ReportGeneratorInterface
|
||||
{
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Tag;
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class MultiYearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -25,9 +25,5 @@ namespace FireflyIII\Generator\Report\Tag;
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator.
|
||||
*
|
||||
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
}
|
||||
class YearReportGenerator extends MonthReportGenerator {}
|
||||
|
@@ -31,35 +31,15 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface MessageGeneratorInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function generateMessages(): void;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getVersion(): int;
|
||||
|
||||
/**
|
||||
* @param Collection $objects
|
||||
*/
|
||||
public function setObjects(Collection $objects): void;
|
||||
|
||||
/**
|
||||
* @param int $trigger
|
||||
*/
|
||||
public function setTrigger(int $trigger): void;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void;
|
||||
|
||||
/**
|
||||
* @param Collection $webhooks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setWebhooks(Collection $webhooks): void;
|
||||
}
|
||||
|
@@ -37,7 +37,6 @@ use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -52,18 +51,12 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
private int $version = 0;
|
||||
private Collection $webhooks;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->objects = new Collection();
|
||||
$this->webhooks = new Collection();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function generateMessages(): void
|
||||
{
|
||||
app('log')->debug(__METHOD__);
|
||||
@@ -79,20 +72,40 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
$this->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getVersion(): int
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
public function setObjects(Collection $objects): void
|
||||
{
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
public function setTrigger(int $trigger): void
|
||||
{
|
||||
$this->trigger = $trigger;
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setWebhooks(Collection $webhooks): void
|
||||
{
|
||||
$this->webhooks = $webhooks;
|
||||
}
|
||||
|
||||
private function getWebhooks(): Collection
|
||||
{
|
||||
return $this->user->webhooks()->where('active', true)->where('trigger', $this->trigger)->get(['webhooks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function run(): void
|
||||
{
|
||||
app('log')->debug('Now in StandardMessageGenerator::run');
|
||||
|
||||
/** @var Webhook $webhook */
|
||||
foreach ($this->webhooks as $webhook) {
|
||||
$this->runWebhook($webhook);
|
||||
@@ -101,14 +114,13 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function runWebhook(Webhook $webhook): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in runWebhook(#%d)', $webhook->id));
|
||||
|
||||
/** @var Model $object */
|
||||
foreach ($this->objects as $object) {
|
||||
$this->generateMessage($webhook, $object);
|
||||
@@ -116,11 +128,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param Model $model
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function generateMessage(Webhook $webhook, Model $model): void
|
||||
{
|
||||
@@ -148,9 +157,11 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
case TransactionGroup::class:
|
||||
/** @var TransactionGroup $model */
|
||||
// @var TransactionGroup $model
|
||||
$basicMessage['user_id'] = $model->user->id;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -162,11 +173,15 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
case WebhookResponse::NONE->value:
|
||||
$basicMessage['content'] = [];
|
||||
|
||||
break;
|
||||
|
||||
case WebhookResponse::TRANSACTIONS->value:
|
||||
$transformer = new TransactionGroupTransformer();
|
||||
|
||||
try {
|
||||
$basicMessage['content'] = $transformer->transformObject($model);
|
||||
} catch (FireflyException $e) {
|
||||
@@ -177,7 +192,9 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WebhookResponse::ACCOUNTS->value:
|
||||
$accounts = $this->collectAccounts($model);
|
||||
foreach ($accounts as $account) {
|
||||
@@ -189,22 +206,10 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
$this->storeMessage($webhook, $basicMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getVersion(): int
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function collectAccounts(TransactionGroup $transactionGroup): Collection
|
||||
{
|
||||
$accounts = new Collection();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||
/** @var Transaction $transaction */
|
||||
@@ -216,12 +221,6 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
return $accounts->unique();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param array $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function storeMessage(Webhook $webhook, array $message): void
|
||||
{
|
||||
$webhookMessage = new WebhookMessage();
|
||||
@@ -233,36 +232,4 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
$webhookMessage->save();
|
||||
app('log')->debug(sprintf('Stored new webhook message #%d', $webhookMessage->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $objects
|
||||
*/
|
||||
public function setObjects(Collection $objects): void
|
||||
{
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $trigger
|
||||
*/
|
||||
public function setTrigger(int $trigger): void
|
||||
{
|
||||
$this->trigger = $trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setWebhooks(Collection $webhooks): void
|
||||
{
|
||||
$this->webhooks = $webhooks;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user