Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Included bills in month report. [skip ci]
James Colec9df265c9bcf
diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.phpnew file mode 100644index 0000000000..973b886482--- /dev/null+++ b/app/Helpers/Collection/Bill.php@@ -0,0 +1,55 @@+<?php++namespace FireflyIII\Helpers\Collection;+++use FireflyIII\Models\Bill as BillModel;+use Illuminate\Support\Collection;++/**+ * Class Bill+ *+ * @package FireflyIII\Helpers\Collection+ */+class Bill+{++ /**+ * @var Collection+ */+ protected $bills;++ /**+ *+ */+ public function __construct()+ {+ $this->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 filediff --git a/app/Helpers/Collection/BillLine.php b/app/Helpers/Collection/BillLine.phpnew file mode 100644index 0000000000..613121073b--- /dev/null+++ b/app/Helpers/Collection/BillLine.php@@ -0,0 +1,125 @@+<?php++namespace FireflyIII\Helpers\Collection;++use FireflyIII\Models\Bill as BillModel;++/**+ * Class BillLine+ *+ * @package FireflyIII\Helpers\Collection+ */+class BillLine+{++ /** @var bool */+ protected $active;+ /** @var float */+ protected $amount;+ /** @var BillModel */+ protected $bill;+ /** @var bool */+ protected $hit;+ /** @var float */+ protected $max;+ /** @var float */+ protected $min;++ /**+ * @return float+ */+ public function getAmount()+ {+ return $this->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 filediff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.phpindex 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 ReportHelperInterfacereturn $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 $enddiff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.phpindex 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 $enddiff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.phpindex 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.phpindex 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.phpindex 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.phpindex 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.phpindex 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.twignew file mode 100644index 0000000000..2cace68717--- /dev/null+++ b/resources/twig/partials/reports/bills.twig@@ -0,0 +1,51 @@+<div class="panel panel-default">+ <div class="panel-heading">+ <i class="fa fa-calendar-o fa-fw"></i>+ {{ 'bills'|_ }}+ </div>+ <table class="table table-bordered table-striped sortable">+ <thead>+ <tr>+ <th>{{ trans('form.name') }}</th>+ <th>{{ trans('form.amount_min') }}</th>+ <th>{{ trans('form.amount_max') }}</th>+ <th>{{ trans('form.amount') }}</th>+ <th>{{ trans('form.under') }}</th>+ </tr>+ </thead>+ <tbody>+ {% for line in bills.getBills %}+ {% if not line.isActive %}+ <tr class="text-muted">+ {% else %}+ <tr>+ {% endif %}+ <td data-value="{{ line.getBill.name }}">+ <a href="{{ route('bills.show',line.getBill.id) }}">{{ line.getBill.name }}</a>+ {% if not line.isActive %}+ ({{ 'inactive'|_|lower }})+ {% endif %}+ </td>+ <td data-value="{{ line.getMin }}">{{ line.getMin|formatAmount }}</td>+ <td data-value="{{ line.getMax }}">{{ line.getMax|formatAmount }}</td>+ {% if line.isHit %}+ <td data-value="{{ line.getAmount }}">{{ line.getAmount|formatAmount }}</td>+ {% endif %}+ {% if not line.isHit and line.isActive %}+ <td data-value="0" class="bg-success">{{ 'notCharged'|_ }}</td>+ {% endif %}+ {% if not line.isActive %}+ <td data-value="-1"> </td>+ {% endif %}+ <td data-value="{{ (line.getMax - line.getAmount) }}">+ {% if line.isActive %}+ {{ (line.getMax - line.getAmount)|formatAmount }}+ {% endif %}+ </td>++ </tr>++ {% endfor %}+ </tbody>+ </table>+</div>\ No newline at end of filediff --git a/resources/twig/reports/month.twig b/resources/twig/reports/month.twigindex d040c3e5e5..1f7439570c 100644--- a/resources/twig/reports/month.twig+++ b/resources/twig/reports/month.twig@@ -52,13 +52,8 @@</div><div class="row"><div class="col-lg-12 col-md-12 col-sm-12">- <div class="panel panel-default">- <div class="panel-heading">- <i class="fa fa-calendar-o fa-fw"></i>- {{ 'bills'|_ }}- </div>- <div class="panel-body">Body</div>- </div>+ {% include 'partials/reports/bills.twig' %}+</div></div><div class="row">