Code cleanup.

This commit is contained in:
James Cole
2018-04-02 14:42:07 +02:00
parent f96f38b172
commit 7d02d0f762
55 changed files with 200 additions and 281 deletions

View File

@@ -43,12 +43,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
/**
* @return string
*
* @throws \Throwable
*/
public function generate(): string
{
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$expenseIds = join(',', $this->expense->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$expenseIds = implode(',', $this->expense->pluck('id')->toArray());
$reportType = 'account';
$preferredPeriod = $this->preferredPeriod();

View File

@@ -45,7 +45,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
/**
* @return string
* @throws \Throwable
*/
public function generate(): string
{
@@ -61,7 +60,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
$reportType = 'audit';
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date',
'interest_date', 'book_date', 'process_date',
// three new optional fields.
@@ -173,7 +172,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals = $journals->reverse();
$dayBeforeBalance = Steam::balance($account, $date);
$startBalance = $dayBeforeBalance;
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
$currency = $currencyRepos->find((int)$account->getMeta('currency_id'));
/** @var Transaction $transaction */
foreach ($journals as $transaction) {
@@ -193,9 +192,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
$return = [
'journals' => $journals->reverse(),
'exists' => $journals->count() > 0,
'end' => $this->end->formatLocalized(strval(trans('config.month_and_day'))),
'end' => $this->end->formatLocalized((string)trans('config.month_and_day')),
'endBalance' => Steam::balance($account, $this->end),
'dayBefore' => $date->formatLocalized(strval(trans('config.month_and_day'))),
'dayBefore' => $date->formatLocalized((string)trans('config.month_and_day')),
'dayBeforeBalance' => $dayBeforeBalance,
];

View File

@@ -63,12 +63,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
/**
* @return string
* @throws \Throwable
*/
public function generate(): string
{
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$budgetIds = join(',', $this->budgets->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$budgetIds = implode(',', $this->budgets->pluck('id')->toArray());
$expenses = $this->getExpenses();
$accountSummary = $this->summarizeByAccount($expenses);
$budgetSummary = $this->summarizeByBudget($expenses);
@@ -200,8 +199,8 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
];
/** @var Transaction $transaction */
foreach ($collection as $transaction) {
$jrnlBudId = intval($transaction->transaction_journal_budget_id);
$transBudId = intval($transaction->transaction_budget_id);
$jrnlBudId = (int)$transaction->transaction_journal_budget_id;
$transBudId = (int)$transaction->transaction_budget_id;
$budgetId = max($jrnlBudId, $transBudId);
$result[$budgetId] = $result[$budgetId] ?? '0';
$result[$budgetId] = bcadd($transaction->transaction_amount, $result[$budgetId]);

View File

@@ -64,12 +64,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
/**
* @return string
* @throws \Throwable
*/
public function generate(): string
{
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$categoryIds = join(',', $this->categories->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$categoryIds = implode(',', $this->categories->pluck('id')->toArray());
$reportType = 'category';
$expenses = $this->getExpenses();
$income = $this->getIncome();
@@ -240,8 +239,8 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$result = [];
/** @var Transaction $transaction */
foreach ($collection as $transaction) {
$jrnlCatId = intval($transaction->transaction_journal_category_id);
$transCatId = intval($transaction->transaction_category_id);
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
$transCatId = (int)$transaction->transaction_category_id;
$categoryId = max($jrnlCatId, $transCatId);
$result[$categoryId] = $result[$categoryId] ?? '0';
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);

View File

@@ -42,14 +42,14 @@ class MonthReportGenerator implements ReportGeneratorInterface
/**
* @return string
*
* @throws \Throwable
*/
public function generate(): string
{
/** @var ReportHelperInterface $helper */
$helper = app(ReportHelperInterface::class);
$bills = $helper->getBillReport($this->start, $this->end, $this->accounts);
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$reportType = 'default';
// continue!

View File

@@ -41,12 +41,12 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
/**
* @return string
*
* @throws \Throwable
*/
public function generate(): string
{
// and some id's, joined:
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$reportType = 'default';
// continue!

View File

@@ -41,12 +41,12 @@ class YearReportGenerator implements ReportGeneratorInterface
/**
* @return string
*
* @throws \Throwable
*/
public function generate(): string
{
// and some id's, joined:
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$reportType = 'default';
// continue!

View File

@@ -35,9 +35,7 @@ class Support
*/
public function getTopExpenses(): Collection
{
$transactions = $this->getExpenses()->sortBy('transaction_amount');
return $transactions;
return $this->getExpenses()->sortBy('transaction_amount');
}
/**
@@ -45,9 +43,7 @@ class Support
*/
public function getTopIncome(): Collection
{
$transactions = $this->getIncome()->sortByDesc('transaction_amount');
return $transactions;
return $this->getIncome()->sortByDesc('transaction_amount');
}
/**
@@ -78,13 +74,13 @@ class Support
}
++$result[$opposingId]['count'];
$result[$opposingId]['sum'] = bcadd($result[$opposingId]['sum'], $transaction->transaction_amount);
$result[$opposingId]['average'] = bcdiv($result[$opposingId]['sum'], strval($result[$opposingId]['count']));
$result[$opposingId]['average'] = bcdiv($result[$opposingId]['sum'], (string)$result[$opposingId]['count']);
}
// sort result by average:
$average = [];
foreach ($result as $key => $row) {
$average[$key] = floatval($row['average']);
$average[$key] = (float)$row['average'];
}
array_multisort($average, $sortFlag, $result);

View File

@@ -65,12 +65,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
/**
* @return string
* @throws \Throwable
*/
public function generate(): string
{
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
$tagTags = join(',', $this->tags->pluck('tag')->toArray());
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$tagTags = implode(',', $this->tags->pluck('tag')->toArray());
$reportType = 'tag';
$expenses = $this->getExpenses();
$income = $this->getIncome();