From c9df265c9bcf749993f9586be5c17f1545380f1a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 17 May 2015 17:54:13 +0200 Subject: [PATCH] Included bills in month report. [skip ci] --- app/Helpers/Collection/Bill.php | 55 ++++++++ app/Helpers/Collection/BillLine.php | 125 +++++++++++++++++++ app/Helpers/Report/ReportHelper.php | 59 ++++++++- app/Helpers/Report/ReportHelperInterface.php | 12 ++ app/Http/Controllers/ReportController.php | 4 +- resources/lang/en/firefly.php | 3 +- resources/lang/en/form.php | 1 + resources/lang/nl/firefly.php | 2 + resources/lang/nl/form.php | 1 + resources/twig/partials/reports/bills.twig | 51 ++++++++ resources/twig/reports/month.twig | 9 +- 11 files changed, 308 insertions(+), 14 deletions(-) create mode 100644 app/Helpers/Collection/Bill.php create mode 100644 app/Helpers/Collection/BillLine.php create mode 100644 resources/twig/partials/reports/bills.twig diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php new file mode 100644 index 0000000000..973b886482 --- /dev/null +++ b/app/Helpers/Collection/Bill.php @@ -0,0 +1,55 @@ +bills = new Collection; + } + + /** + * @param BillLine $bill + */ + public function addBill(BillLine $bill) + { + $this->bills->push($bill); + } + + /** + * @return Collection + */ + public function getBills() + { + $this->bills->sortBy( + function (BillLine $bill) { + $active = intval($bill->getBill()->active) == 0 ? 1 : 0; + $name = $bill->getBill()->name; + return $active.$name; + } + ); + + + return $this->bills; + } + +} \ No newline at end of file diff --git a/app/Helpers/Collection/BillLine.php b/app/Helpers/Collection/BillLine.php new file mode 100644 index 0000000000..613121073b --- /dev/null +++ b/app/Helpers/Collection/BillLine.php @@ -0,0 +1,125 @@ +amount; + } + + /** + * @param float $amount + */ + public function setAmount($amount) + { + $this->amount = $amount; + } + + /** + * @return BillModel + */ + public function getBill() + { + return $this->bill; + } + + /** + * @param BillModel $bill + */ + public function setBill($bill) + { + $this->bill = $bill; + } + + /** + * @return float + */ + public function getMax() + { + return $this->max; + } + + /** + * @param float $max + */ + public function setMax($max) + { + $this->max = $max; + } + + /** + * @return float + */ + public function getMin() + { + return $this->min; + } + + /** + * @param float $min + */ + public function setMin($min) + { + $this->min = $min; + } + + /** + * @return boolean + */ + public function isActive() + { + return $this->active; + } + + /** + * @param boolean $active + */ + public function setActive($active) + { + $this->active = $active; + } + + /** + * @return boolean + */ + public function isHit() + { + return $this->hit; + } + + /** + * @param boolean $hit + */ + public function setHit($hit) + { + $this->hit = $hit; + } + + +} \ No newline at end of file diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 5dbbbed26a..c1f3863e0e 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -9,12 +9,15 @@ use FireflyIII\Helpers\Collection\Balance; use FireflyIII\Helpers\Collection\BalanceEntry; use FireflyIII\Helpers\Collection\BalanceHeader; use FireflyIII\Helpers\Collection\BalanceLine; +use FireflyIII\Helpers\Collection\Bill as BillCollection; +use FireflyIII\Helpers\Collection\BillLine; use FireflyIII\Helpers\Collection\Budget as BudgetCollection; use FireflyIII\Helpers\Collection\BudgetLine; use FireflyIII\Helpers\Collection\Category as CategoryCollection; use FireflyIII\Helpers\Collection\Expense; use FireflyIII\Helpers\Collection\Income; use FireflyIII\Models\Account; +use FireflyIII\Models\Bill; use FireflyIII\Models\Budget as BudgetModel; use FireflyIII\Models\LimitRepetition; @@ -137,17 +140,17 @@ class ReportHelper implements ReportHelperInterface // then a new line for without budget. // and one for the tags: - $empty = new BalanceLine; - $tags = new BalanceLine; + $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); - $left = $tagRepository->coveredByBalancingActs($account, $start, $end); - $diff = $spent + $left; + $spent = $this->query->spentNoBudget($account, $start, $end); + $left = $tagRepository->coveredByBalancingActs($account, $start, $end); + $diff = $spent + $left; // budget $budgetEntry = new BalanceEntry; @@ -178,6 +181,52 @@ class ReportHelper implements ReportHelperInterface return $balance; } + /** + * This method generates a full report for the given period on all + * the users bills and their payments. + * + * @param Carbon $start + * @param Carbon $end + * @param boolean $shared + * + * @return BillCollection + */ + public function getBillReport(Carbon $start, Carbon $end, $shared) + { + /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */ + $repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface'); + $bills = $repository->getBills(); + $collection = new BillCollection; + + /** @var Bill $bill */ + foreach ($bills as $bill) { + $billLine = new BillLine; + $billLine->setBill($bill); + $billLine->setActive(intval($bill->active) == 1); + $billLine->setMin(floatval($bill->amount_min)); + $billLine->setMax(floatval($bill->amount_max)); + + // is hit in period? + $set = $repository->getJournalsInRange($bill, $start, $end); + if ($set->count() == 0) { + $billLine->setHit(false); + } else { + $billLine->setHit(true); + $amount = 0; + foreach ($set as $entry) { + $amount += $entry->amount; + } + $billLine->setAmount($amount); + } + + $collection->addBill($billLine); + + } + + return $collection; + + } + /** * @param Carbon $start * @param Carbon $end diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 863a386d6a..13bef6fb67 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -30,6 +30,18 @@ interface ReportHelperInterface */ public function getAccountReport(Carbon $date, Carbon $end, $shared); + /** + * This method generates a full report for the given period on all + * the users bills and their payments. + * + * @param Carbon $start + * @param Carbon $end + * @param boolean $shared + * + * @return Account + */ + public function getBillReport(Carbon $start, Carbon $end, $shared); + /** * @param Carbon $start * @param Carbon $end diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 7b2b3f1d4c..6ba200646b 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -90,6 +90,7 @@ class ReportController extends Controller $budgets = $this->helper->getBudgetReport($start, $end, $shared); $categories = $this->helper->getCategoryReport($start, $end, $shared); $balance = $this->helper->getBalanceReport($start, $end, $shared); + $bills = $this->helper->getBillReport($start, $end, $shared); return view( @@ -101,7 +102,8 @@ class ReportController extends Controller 'incomes', 'incomeTopLength', 'expenses', 'expenseTopLength', 'budgets', 'balance', - 'categories' + 'categories', + 'bills' ) ); diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php index 24779a33ef..9ad498b57d 100644 --- a/resources/lang/en/firefly.php +++ b/resources/lang/en/firefly.php @@ -111,7 +111,8 @@ return [ 'leftInBudget' => 'Left in budget', 'sumOfSums' => 'Sum of sums', - + 'notCharged' => 'Not charged (yet)', + 'inactive' => 'Inactive', 'difference' => 'Difference', 'in' => 'In', diff --git a/resources/lang/en/form.php b/resources/lang/en/form.php index 55dd42ae0f..5b27b1fa90 100644 --- a/resources/lang/en/form.php +++ b/resources/lang/en/form.php @@ -36,6 +36,7 @@ return [ 'remind_me' => 'Remind me', 'tag' => 'Tag', 'reminder' => 'Remind me every', + 'under' => 'Under', 'store_new_withdrawal' => 'Store new withdrawal', 'store_new_deposit' => 'Store new deposit', diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index 8e57c5e47c..67780270fa 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -112,6 +112,8 @@ return [ 'leftInBudget' => 'Over van budget', 'sumOfSums' => 'Alles bij elkaar', + 'notCharged' => '(Nog) niet betaald', + 'inactive' => 'Niet actief', 'difference' => 'Verschil', 'in' => 'In', diff --git a/resources/lang/nl/form.php b/resources/lang/nl/form.php index d213f0a0e1..b8ef6b4c49 100644 --- a/resources/lang/nl/form.php +++ b/resources/lang/nl/form.php @@ -36,6 +36,7 @@ return [ 'remind_me' => 'Help me herinneren', 'tag' => 'Tag', 'reminder' => 'Herinner me elke', + 'under' => 'Onder', 'store_new_withdrawal' => 'Nieuwe uitgave opslaan', 'store_new_deposit' => 'Nieuwe inkomsten opslaan', diff --git a/resources/twig/partials/reports/bills.twig b/resources/twig/partials/reports/bills.twig new file mode 100644 index 0000000000..2cace68717 --- /dev/null +++ b/resources/twig/partials/reports/bills.twig @@ -0,0 +1,51 @@ +
+
+ + {{ 'bills'|_ }} +
+ + + + + + + + + + + + {% for line in bills.getBills %} + {% if not line.isActive %} + + {% else %} + + {% endif %} + + + + {% if line.isHit %} + + {% endif %} + {% if not line.isHit and line.isActive %} + + {% endif %} + {% if not line.isActive %} + + {% endif %} + + + + + {% endfor %} + +
{{ trans('form.name') }}{{ trans('form.amount_min') }}{{ trans('form.amount_max') }}{{ trans('form.amount') }}{{ trans('form.under') }}
+ {{ line.getBill.name }} + {% if not line.isActive %} + ({{ 'inactive'|_|lower }}) + {% endif %} + {{ line.getMin|formatAmount }}{{ line.getMax|formatAmount }}{{ line.getAmount|formatAmount }}{{ 'notCharged'|_ }}  + {% if line.isActive %} + {{ (line.getMax - line.getAmount)|formatAmount }} + {% endif %} +
+
\ No newline at end of file diff --git a/resources/twig/reports/month.twig b/resources/twig/reports/month.twig index d040c3e5e5..1f7439570c 100644 --- a/resources/twig/reports/month.twig +++ b/resources/twig/reports/month.twig @@ -52,13 +52,8 @@
-
-
- - {{ 'bills'|_ }} -
-
Body
-
+ {% include 'partials/reports/bills.twig' %} +