mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Remove unused code.
This commit is contained in:
@@ -74,14 +74,9 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
$line = $this->createBalanceLine($budgetLimit, $accounts);
|
$line = $this->createBalanceLine($budgetLimit, $accounts);
|
||||||
$balance->addBalanceLine($line);
|
$balance->addBalanceLine($line);
|
||||||
}
|
}
|
||||||
Log::debug('Create rest of the things.');
|
|
||||||
$noBudgetLine = $this->createNoBudgetLine($accounts, $start, $end);
|
$noBudgetLine = $this->createNoBudgetLine($accounts, $start, $end);
|
||||||
$coveredByTagLine = $this->createTagsBalanceLine($accounts, $start, $end);
|
|
||||||
$leftUnbalancedLine = $this->createLeftUnbalancedLine($noBudgetLine, $coveredByTagLine);
|
|
||||||
|
|
||||||
$balance->addBalanceLine($noBudgetLine);
|
$balance->addBalanceLine($noBudgetLine);
|
||||||
$balance->addBalanceLine($coveredByTagLine);
|
|
||||||
$balance->addBalanceLine($leftUnbalancedLine);
|
|
||||||
$balance->setBalanceHeader($header);
|
$balance->setBalanceHeader($header);
|
||||||
|
|
||||||
Log::debug('Clear unused budgets.');
|
Log::debug('Clear unused budgets.');
|
||||||
@@ -93,53 +88,6 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
return $balance;
|
return $balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method collects all transfers that are part of a "balancing act" tag
|
|
||||||
* and groups the amounts of those transfers by their destination account.
|
|
||||||
*
|
|
||||||
* This is used to indicate which expenses, usually outside of budgets, have been
|
|
||||||
* corrected by transfers from a savings account.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function allCoveredByBalancingActs(Collection $accounts, Carbon $start, Carbon $end): Collection
|
|
||||||
{
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
|
||||||
$set = auth()->user()->tags()
|
|
||||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
|
||||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
|
||||||
->leftJoin(
|
|
||||||
'transactions AS t_source', function (JoinClause $join) {
|
|
||||||
$join->on('transaction_journals.id', '=', 't_source.transaction_journal_id')->where('t_source.amount', '<', 0);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
->leftJoin(
|
|
||||||
'transactions AS t_destination', function (JoinClause $join) {
|
|
||||||
$join->on('transaction_journals.id', '=', 't_destination.transaction_journal_id')->where('t_destination.amount', '>', 0);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
->where('tags.tagMode', 'balancingAct')
|
|
||||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
|
||||||
->whereNull('transaction_journals.deleted_at')
|
|
||||||
->whereIn('t_source.account_id', $ids)
|
|
||||||
->whereIn('t_destination.account_id', $ids)
|
|
||||||
->groupBy('t_destination.account_id')
|
|
||||||
->get(
|
|
||||||
[
|
|
||||||
't_destination.account_id',
|
|
||||||
DB::raw('SUM(t_destination.amount) AS sum'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,40 +116,6 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
return $line;
|
return $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param BalanceLine $noBudgetLine
|
|
||||||
* @param BalanceLine $coveredByTagLine
|
|
||||||
*
|
|
||||||
* @return BalanceLine
|
|
||||||
*/
|
|
||||||
private function createLeftUnbalancedLine(BalanceLine $noBudgetLine, BalanceLine $coveredByTagLine): BalanceLine
|
|
||||||
{
|
|
||||||
$line = new BalanceLine;
|
|
||||||
$line->setRole(BalanceLine::ROLE_DIFFROLE);
|
|
||||||
$noBudgetEntries = $noBudgetLine->getBalanceEntries();
|
|
||||||
$tagEntries = $coveredByTagLine->getBalanceEntries();
|
|
||||||
|
|
||||||
foreach ($noBudgetEntries as $entry) {
|
|
||||||
$account = $entry->getAccount();
|
|
||||||
$tagEntry = $tagEntries->filter(
|
|
||||||
function (BalanceEntry $current) use ($account) {
|
|
||||||
return $current->getAccount()->id === $account->id;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if ($tagEntry->first()) {
|
|
||||||
// found corresponding entry. As we should:
|
|
||||||
$newEntry = new BalanceEntry;
|
|
||||||
$newEntry->setAccount($account);
|
|
||||||
$spent = bcadd($tagEntry->first()->getLeft(), $entry->getSpent());
|
|
||||||
$newEntry->setSpent($spent);
|
|
||||||
$line->addBalanceEntry($newEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $line;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
@@ -227,41 +141,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
return $empty;
|
return $empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return BalanceLine
|
|
||||||
*/
|
|
||||||
private function createTagsBalanceLine(Collection $accounts, Carbon $start, Carbon $end): BalanceLine
|
|
||||||
{
|
|
||||||
$tags = new BalanceLine;
|
|
||||||
$tagsLeft = $this->allCoveredByBalancingActs($accounts, $start, $end);
|
|
||||||
|
|
||||||
$tags->setRole(BalanceLine::ROLE_TAGROLE);
|
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$leftEntry = $tagsLeft->filter(
|
|
||||||
function (Tag $tag) use ($account) {
|
|
||||||
return $tag->account_id === $account->id;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$left = '0';
|
|
||||||
if (!is_null($leftEntry->first())) {
|
|
||||||
$left = $leftEntry->first()->sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// balanced by tags
|
|
||||||
$tagEntry = new BalanceEntry;
|
|
||||||
$tagEntry->setAccount($account);
|
|
||||||
$tagEntry->setLeft($left);
|
|
||||||
$tags->addBalanceEntry($tagEntry);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Balance $balance
|
* @param Balance $balance
|
||||||
|
Reference in New Issue
Block a user