diff --git a/app/Helpers/Collection/Budget.php b/app/Helpers/Collection/Budget.php deleted file mode 100644 index f590cb6216..0000000000 --- a/app/Helpers/Collection/Budget.php +++ /dev/null @@ -1,193 +0,0 @@ -budgetLines = new Collection; - } - - /** - * @param BudgetLine $budgetLine - * - * @return Budget - */ - public function addBudgetLine(BudgetLine $budgetLine): Budget - { - $this->budgetLines->push($budgetLine); - - return $this; - } - - /** - * @param string $add - * - * @return Budget - */ - public function addBudgeted(string $add): Budget - { - $this->budgeted = bcadd($this->budgeted, $add); - - return $this; - } - - /** - * @param string $add - * - * @return Budget - */ - public function addLeft(string $add): Budget - { - $this->left = bcadd($this->left, $add); - - return $this; - } - - /** - * @param string $add - * - * @return Budget - */ - public function addOverspent(string $add): Budget - { - $this->overspent = bcadd($this->overspent, $add); - - return $this; - } - - /** - * @param string $add - * - * @return Budget - */ - public function addSpent(string $add): Budget - { - $this->spent = bcadd($this->spent, $add); - - return $this; - } - - /** - * @return \Illuminate\Support\Collection - */ - public function getBudgetLines(): Collection - { - return $this->budgetLines; - } - - /** - * @return string - */ - public function getBudgeted(): string - { - return $this->budgeted; - } - - /** - * @param string $budgeted - * - * @return Budget - */ - public function setBudgeted(string $budgeted): Budget - { - $this->budgeted = $budgeted; - - return $this; - } - - /** - * @return string - */ - public function getLeft(): string - { - return $this->left; - } - - /** - * @param string $left - * - * @return Budget - */ - public function setLeft(string $left): Budget - { - $this->left = $left; - - return $this; - } - - /** - * @return string - */ - public function getOverspent(): string - { - return $this->overspent; - } - - /** - * @param string $overspent - * - * @return Budget - */ - public function setOverspent(string $overspent): Budget - { - $this->overspent = $overspent; - - return $this; - } - - /** - * @return string - */ - public function getSpent(): string - { - return $this->spent; - } - - /** - * @param string $spent - * - * @return Budget - */ - public function setSpent(string $spent): Budget - { - $this->spent = $spent; - - return $this; - } - - -} diff --git a/app/Helpers/Collection/BudgetLine.php b/app/Helpers/Collection/BudgetLine.php deleted file mode 100644 index 03bf59f8ff..0000000000 --- a/app/Helpers/Collection/BudgetLine.php +++ /dev/null @@ -1,161 +0,0 @@ -budget ?? new BudgetModel; - } - - /** - * @param BudgetModel $budget - * - * @return BudgetLine - */ - public function setBudget(BudgetModel $budget): BudgetLine - { - $this->budget = $budget; - - return $this; - } - - /** - * @return BudgetLimit - */ - public function getBudgetLimit(): BudgetLimit - { - return $this->budgetLimit ?? new BudgetLimit; - } - - /** - * @param BudgetLimit $budgetLimit - * - * @return BudgetLimit - */ - public function setBudgetLimit(BudgetLimit $budgetLimit): BudgetLine - { - $this->budgetLimit = $budgetLimit; - - return $this; - } - - /** - * @return string - */ - public function getBudgeted(): string - { - return $this->budgeted; - } - - /** - * @param string $budgeted - * - * @return BudgetLine - */ - public function setBudgeted(string $budgeted): BudgetLine - { - $this->budgeted = $budgeted; - - return $this; - } - - /** - * @return string - */ - public function getLeft(): string - { - return $this->left; - } - - /** - * @param string $left - * - * @return BudgetLine - */ - public function setLeft(string $left): BudgetLine - { - $this->left = $left; - - return $this; - } - - /** - * @return string - */ - public function getOverspent(): string - { - return $this->overspent; - } - - /** - * @param string $overspent - * - * @return BudgetLine - */ - public function setOverspent(string $overspent): BudgetLine - { - $this->overspent = $overspent; - - return $this; - } - - /** - * @return string - */ - public function getSpent(): string - { - return $this->spent; - } - - /** - * @param string $spent - * - * @return BudgetLine - */ - public function setSpent(string $spent): BudgetLine - { - $this->spent = $spent; - - return $this; - } - - -} diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.php index dff9d99d74..8025b0a159 100644 --- a/app/Helpers/Report/BudgetReportHelper.php +++ b/app/Helpers/Report/BudgetReportHelper.php @@ -15,8 +15,6 @@ namespace FireflyIII\Helpers\Report; use Carbon\Carbon; -use FireflyIII\Helpers\Collection\Budget as BudgetCollection; -use FireflyIII\Helpers\Collection\BudgetLine; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; @@ -48,44 +46,63 @@ class BudgetReportHelper implements BudgetReportHelperInterface * @param Carbon $end * @param Collection $accounts * - * @return BudgetCollection + * @return array */ - public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): BudgetCollection + public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): array { - $object = new BudgetCollection; - $set = $this->repository->getBudgets(); + $set = $this->repository->getBudgets(); + $array = []; /** @var Budget $budget */ foreach ($set as $budget) { $budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end); if ($budgetLimits->count() == 0) { // no budget limit(s) for this budget + $spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);// spent for budget in time range - if ($spent > 0) { - $budgetLine = new BudgetLine; - $budgetLine->setBudget($budget)->setOverspent($spent); - $object->addOverspent($spent)->addBudgetLine($budgetLine); + if (bccomp($spent, '0') === -1) { + $line = [ + 'type' => 'budget', + 'id' => $budget->id, + 'name' => $budget->name, + 'budgeted' => '0', + 'spent' => $spent, + 'left' => '0', + 'overspent' => '0', + ]; + $array[] = $line; } continue; } /** @var BudgetLimit $budgetLimit */ foreach ($budgetLimits as $budgetLimit) { // one or more repetitions for budget - $data = $this->calculateExpenses($budget, $budgetLimit, $accounts); - $budgetLine = new BudgetLine; - $budgetLine->setBudget($budget)->setBudgetLimit($budgetLimit) - ->setLeft($data['left'])->setSpent($data['expenses'])->setOverspent($data['overspent']) - ->setBudgeted(strval($budgetLimit->amount)); - - $object->addBudgeted(strval($budgetLimit->amount))->addSpent($data['spent']) - ->addLeft($data['left'])->addOverspent($data['overspent'])->addBudgetLine($budgetLine); + $data = $this->calculateExpenses($budget, $budgetLimit, $accounts); + $line = [ + 'type' => 'budget-line', + 'start' => $budgetLimit->start_date, + 'end' => $budgetLimit->end_date, + 'limit' => $budgetLimit->id, + 'id' => $budget->id, + 'name' => $budget->name, + 'budgeted' => strval($budgetLimit->amount), + 'spent' => $data['expenses'], + 'left' => $data['left'], + 'overspent' => $data['overspent'], + ]; + $array[] = $line; } } - $noBudget = $this->repository->spentInPeriodWoBudget($accounts, $start, $end); // stuff outside of budgets - $budgetLine = new BudgetLine; - $budgetLine->setOverspent($noBudget)->setSpent($noBudget); - $object->addOverspent($noBudget)->addBudgetLine($budgetLine); + $noBudget = $this->repository->spentInPeriodWoBudget($accounts, $start, $end); // stuff outside of budgets + $line = [ + 'type' => 'no-budget', + 'budgeted' => '0', + 'spent' => $noBudget, + 'left' => '0', + 'overspent' => '0', + ]; + $array[] = $line; - return $object; + return $array; } /** diff --git a/app/Helpers/Report/BudgetReportHelperInterface.php b/app/Helpers/Report/BudgetReportHelperInterface.php index 07234f9694..a64d47d39f 100644 --- a/app/Helpers/Report/BudgetReportHelperInterface.php +++ b/app/Helpers/Report/BudgetReportHelperInterface.php @@ -15,7 +15,6 @@ namespace FireflyIII\Helpers\Report; use Carbon\Carbon; -use FireflyIII\Helpers\Collection\Budget as BudgetCollection; use Illuminate\Support\Collection; /** @@ -31,9 +30,9 @@ interface BudgetReportHelperInterface * @param Carbon $end * @param Collection $accounts * - * @return BudgetCollection + * @return array */ - public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): BudgetCollection; + public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): array; /** * @param Carbon $start diff --git a/resources/views/reports/partials/budgets.twig b/resources/views/reports/partials/budgets.twig index be4b938c4b..97fef8c762 100644 --- a/resources/views/reports/partials/budgets.twig +++ b/resources/views/reports/partials/budgets.twig @@ -11,26 +11,33 @@
- {% for budgetLine in budgets.getBudgetLines %} -