mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-31 19:27:51 -06:00
First attempt at budgets (split by account).
This commit is contained in:
parent
cba5e226d8
commit
e332bfef7c
@ -590,4 +590,94 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReportForList(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$tagRepository = app('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||
$balance = new Balance;
|
||||
|
||||
// build a balance header:
|
||||
$header = new BalanceHeader;
|
||||
$budgets = $repository->getBudgets();
|
||||
foreach ($accounts as $account) {
|
||||
$header->addAccount($account);
|
||||
}
|
||||
|
||||
/** @var BudgetModel $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$line = new BalanceLine;
|
||||
$line->setBudget($budget);
|
||||
|
||||
// get budget amount for current period:
|
||||
$rep = $repository->getCurrentRepetition($budget, $start, $end);
|
||||
// could be null?
|
||||
$line->setRepetition($rep);
|
||||
|
||||
// loop accounts:
|
||||
foreach ($accounts as $account) {
|
||||
$balanceEntry = new BalanceEntry;
|
||||
$balanceEntry->setAccount($account);
|
||||
|
||||
// get spent:
|
||||
$spent = $this->query->spentInBudgetCorrected($account, $budget, $start, $end); // I think shared is irrelevant.
|
||||
|
||||
$balanceEntry->setSpent($spent);
|
||||
$line->addBalanceEntry($balanceEntry);
|
||||
}
|
||||
// add line to balance:
|
||||
$balance->addBalanceLine($line);
|
||||
}
|
||||
|
||||
// then a new line for without budget.
|
||||
// and one for the tags:
|
||||
// and one for "left unbalanced".
|
||||
$empty = new BalanceLine;
|
||||
$tags = new BalanceLine;
|
||||
$diffLine = new BalanceLine;
|
||||
|
||||
$tags->setRole(BalanceLine::ROLE_TAGROLE);
|
||||
$diffLine->setRole(BalanceLine::ROLE_DIFFROLE);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$spent = $this->query->spentNoBudget($account, $start, $end) * -1;
|
||||
$left = $tagRepository->coveredByBalancingActs($account, $start, $end);
|
||||
bcscale(2);
|
||||
$diff = bcsub($spent, $left);
|
||||
|
||||
// budget
|
||||
$budgetEntry = new BalanceEntry;
|
||||
$budgetEntry->setAccount($account);
|
||||
$budgetEntry->setSpent($spent);
|
||||
$empty->addBalanceEntry($budgetEntry);
|
||||
|
||||
// balanced by tags
|
||||
$tagEntry = new BalanceEntry;
|
||||
$tagEntry->setAccount($account);
|
||||
$tagEntry->setLeft($left);
|
||||
$tags->addBalanceEntry($tagEntry);
|
||||
|
||||
// difference:
|
||||
$diffEntry = new BalanceEntry;
|
||||
$diffEntry->setAccount($account);
|
||||
$diffEntry->setSpent($diff);
|
||||
$diffLine->addBalanceEntry($diffEntry);
|
||||
|
||||
}
|
||||
|
||||
$balance->addBalanceLine($empty);
|
||||
$balance->addBalanceLine($tags);
|
||||
$balance->addBalanceLine($diffLine);
|
||||
|
||||
$balance->setBalanceHeader($header);
|
||||
|
||||
return $balance;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,15 @@ interface ReportHelperInterface
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, $shared);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReportForList(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
|
@ -246,7 +246,7 @@ class ReportController extends Controller
|
||||
$expenses = $this->helper->getExpenseReportForList($start, $end, $list);
|
||||
$budgets = $this->helper->getBudgetReportForList($start, $end, $list);
|
||||
$categories = $this->helper->getCategoryReportForList($start, $end, $list);
|
||||
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
||||
$balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
||||
// $bills = $this->helper->getBillReportForList($start, $end);
|
||||
|
||||
// continue!
|
||||
|
Loading…
Reference in New Issue
Block a user