diff --git a/app/Generator/Report/Standard/MonthReportGenerator.php b/app/Generator/Report/Standard/MonthReportGenerator.php index 05bf049cc4..17e4d7c745 100644 --- a/app/Generator/Report/Standard/MonthReportGenerator.php +++ b/app/Generator/Report/Standard/MonthReportGenerator.php @@ -24,7 +24,6 @@ namespace FireflyIII\Generator\Report\Standard; use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; -use FireflyIII\Helpers\Report\ReportHelperInterface; use Illuminate\Support\Collection; use Log; use Throwable; @@ -50,17 +49,11 @@ class MonthReportGenerator implements ReportGeneratorInterface */ public function generate(): string { - /** @var ReportHelperInterface $helper */ - $helper = app(ReportHelperInterface::class); - $bills = $helper->getBillReport($this->start, $this->end, $this->accounts); $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); $reportType = 'default'; try { - return view( - 'reports.default.month', - compact('bills', 'accountIds', 'reportType') - )->with('start', $this->start)->with('end', $this->end)->render(); + return view('reports.default.month', compact('accountIds', 'reportType'))->with('start', $this->start)->with('end', $this->end)->render(); } catch (Throwable $e) { Log::error(sprintf('Cannot render reports.default.month: %s', $e->getMessage())); $result = 'Could not render report view.'; diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 85dcde11ca..83a3d47589 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -66,20 +66,61 @@ class ReportHelper implements ReportHelperInterface * * Excludes bills which have not had a payment on the mentioned accounts. * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * * @param Carbon $start * @param Carbon $end * @param Collection $accounts * - * @return BillCollection + * @return array */ - public function getBillReport(Carbon $start, Carbon $end, Collection $accounts): BillCollection + public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array { /** @var BillRepositoryInterface $repository */ $repository = app(BillRepositoryInterface::class); $bills = $repository->getBillsForAccounts($accounts); + $report = [ + 'bills' => [], + ]; + + /** @var Bill $bill */ + foreach ($bills as $bill) { + $expectedDates = $repository->getPayDatesInRange($bill, $start, $end); + $billId = $bill->id; + $currency = $bill->transactionCurrency; + $current = [ + 'id' => $bill->id, + 'name' => $bill->name, + 'active' => $bill->active, + 'amount_min' => $bill->amount_min, + 'amount_max' => $bill->amount_max, + 'currency_id' => $bill->transaction_currency_id, + 'currency_code' => $currency->code, + 'currency_name' => $currency->name, + 'currency_symbol' => $currency->symbol, + 'currency_decimal_places' => $currency->decimal_places, + 'expected_dates' => $expectedDates->toArray(), + 'paid_moments' => [], + ]; + + /** @var Carbon $start */ + foreach ($expectedDates as $expectedStart) { + $expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null); + + // is paid in this period maybe? + /** @var GroupCollectorInterface $collector */ + $collector = app(GroupCollectorInterface::class); + $collector->setAccounts($accounts)->setRange($expectedStart, $expectedEnd)->setBill($bill); + $current['paid_moments'][] = $collector->getExtractedJournals(); + } + + // append to report: + $report['bills'][$billId] = $current; + } + + return $report; + echo '
';
+        print_r($report);
+        exit;
+
 
         $collection = new BillCollection;
         $collection->setStartDate($start);
diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php
index 703aa149a9..5830764cad 100644
--- a/app/Helpers/Report/ReportHelperInterface.php
+++ b/app/Helpers/Report/ReportHelperInterface.php
@@ -41,9 +41,9 @@ interface ReportHelperInterface
      * @param Carbon     $end
      * @param Collection $accounts
      *
-     * @return BillCollection
+     * @return array
      */
-    public function getBillReport(Carbon $start, Carbon $end, Collection $accounts): BillCollection;
+    public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array;
 
     /**
      * Generate a list of months.
diff --git a/app/Http/Controllers/Report/BalanceController.php b/app/Http/Controllers/Report/BalanceController.php
index f9032ac989..25ac0f23cf 100644
--- a/app/Http/Controllers/Report/BalanceController.php
+++ b/app/Http/Controllers/Report/BalanceController.php
@@ -54,7 +54,7 @@ class BalanceController extends Controller
         $cache->addProperty('balance-report');
         $cache->addProperty($accounts->pluck('id')->toArray());
         if ($cache->has()) {
-            //return $cache->get(); // @codeCoverageIgnore
+            return $cache->get(); // @codeCoverageIgnore
         }
         $helper  = app(BalanceReportHelperInterface::class);
         $report = $helper->getBalanceReport($accounts, $start, $end);
diff --git a/app/Http/Controllers/Report/BillController.php b/app/Http/Controllers/Report/BillController.php
new file mode 100644
index 0000000000..ca5d88cf73
--- /dev/null
+++ b/app/Http/Controllers/Report/BillController.php
@@ -0,0 +1,73 @@
+.
+ */
+
+namespace FireflyIII\Http\Controllers\Report;
+
+
+use Carbon\Carbon;
+use FireflyIII\Helpers\Report\ReportHelperInterface;
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Support\CacheProperties;
+use Illuminate\Support\Collection;
+use Log;
+use Throwable;
+
+/**
+ * Class BillController
+ */
+class BillController extends Controller
+{
+    /**
+     * @param Collection $accounts
+     * @param Carbon     $start
+     * @param Carbon     $end
+     */
+    public function overview(Collection $accounts, Carbon $start, Carbon $end)
+    {   // chart properties for cache:
+        $cache = new CacheProperties;
+        $cache->addProperty($start);
+        $cache->addProperty($end);
+        $cache->addProperty('bill-report');
+        $cache->addProperty($accounts->pluck('id')->toArray());
+        if ($cache->has()) {
+            //return $cache->get(); // @codeCoverageIgnore
+        }
+
+
+        /** @var ReportHelperInterface $helper */
+        $helper = app(ReportHelperInterface::class);
+        $report = $helper->getBillReport($accounts, $start, $end);
+
+
+//        try {
+            $result = view('reports.partials.bills', compact('report'))->render();
+            // @codeCoverageIgnoreStart
+//        } catch (Throwable $e) {
+//            Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
+//            $result = 'Could not render view.';
+//        }
+        // @codeCoverageIgnoreEnd
+        $cache->store($result);
+
+        return $result;
+
+    }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php
index fe01dd7ac7..4cc0ac2cda 100644
--- a/app/Http/Controllers/Report/BudgetController.php
+++ b/app/Http/Controllers/Report/BudgetController.php
@@ -57,17 +57,17 @@ class BudgetController extends Controller
         $cache->addProperty('budget-report');
         $cache->addProperty($accounts->pluck('id')->toArray());
         if ($cache->has()) {
-            //return $cache->get(); // @codeCoverageIgnore
+            return $cache->get(); // @codeCoverageIgnore
         }
         $helper  = app(BudgetReportHelperInterface::class);
         $budgets = $helper->getBudgetReport($start, $end, $accounts);
-        //try {
+        try {
             $result = view('reports.partials.budgets', compact('budgets'))->render();
             // @codeCoverageIgnoreStart
-//        } catch (Throwable $e) {
-//            Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
-//            $result = 'Could not render view.';
-//        }
+        } catch (Throwable $e) {
+            Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
+            $result = 'Could not render view.';
+        }
         // @codeCoverageIgnoreEnd
         $cache->store($result);
 
diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php
index cd0d169443..d018f5f3c6 100644
--- a/app/Http/Controllers/Report/CategoryController.php
+++ b/app/Http/Controllers/Report/CategoryController.php
@@ -164,7 +164,7 @@ class CategoryController extends Controller
         $cache->addProperty('category-report');
         $cache->addProperty($accounts->pluck('id')->toArray());
         if ($cache->has()) {
-            //return $cache->get(); // @codeCoverageIgnore
+            return $cache->get(); // @codeCoverageIgnore
         }
 
         /** @var CategoryRepositoryInterface $repository */
diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.php
index 171f81659b..4b0c22d6ce 100644
--- a/app/Http/Controllers/Report/ExpenseController.php
+++ b/app/Http/Controllers/Report/ExpenseController.php
@@ -253,7 +253,7 @@ class ExpenseController extends Controller
         $cache->addProperty($accounts->pluck('id')->toArray());
         $cache->addProperty($expense->pluck('id')->toArray());
         if ($cache->has()) {
-            //return $cache->get(); // @codeCoverageIgnore
+            return $cache->get(); // @codeCoverageIgnore
         }
         $combined = $this->combineAccounts($expense);
         $all      = new Collection;
@@ -305,7 +305,7 @@ class ExpenseController extends Controller
         $cache->addProperty($accounts->pluck('id')->toArray());
         $cache->addProperty($expense->pluck('id')->toArray());
         if ($cache->has()) {
-            //return $cache->get(); // @codeCoverageIgnore
+            return $cache->get(); // @codeCoverageIgnore
         }
         $combined = $this->combineAccounts($expense);
         $all      = new Collection;
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index ba17f478ac..9f58772a1c 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -238,8 +238,8 @@ class ReportController extends Controller
             trans(
                 'firefly.report_default',
                 [
-                    'start' => $start->formatLocalized($this->monthFormat),
-                    'end'   => $end->formatLocalized($this->monthFormat),
+                    'start' => $start->formatLocalized($this->monthAndDayFormat),
+                    'end'   => $end->formatLocalized($this->monthAndDayFormat),
                 ]
             )
         );
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 228193dd05..56ea6f377c 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -192,13 +192,13 @@ class BillRepository implements BillRepositoryInterface
         $set    = $this->user->bills()
                              ->leftJoin(
                                  'transaction_journals',
-                                 function (JoinClause $join) {
+                                 static function (JoinClause $join) {
                                      $join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
                                  }
                              )
                              ->leftJoin(
                                  'transactions',
-                                 function (JoinClause $join) {
+                                 static function (JoinClause $join) {
                                      $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
                                  }
                              )
diff --git a/public/v1/js/ff/reports/default/all.js b/public/v1/js/ff/reports/default/all.js
index 0993d18654..9436704fcc 100644
--- a/public/v1/js/ff/reports/default/all.js
+++ b/public/v1/js/ff/reports/default/all.js
@@ -31,5 +31,6 @@ $(function () {
     loadAjaxPartial('incomeReport', incomeReportUri);
     loadAjaxPartial('expenseReport', expenseReportUri);
     loadAjaxPartial('incomeVsExpenseReport', incExpReportUri);
+    loadAjaxPartial('billReport', billReportUri);
 
 });
diff --git a/resources/lang/en_US/form.php b/resources/lang/en_US/form.php
index 661ac8b976..4711ac9308 100644
--- a/resources/lang/en_US/form.php
+++ b/resources/lang/en_US/form.php
@@ -255,5 +255,7 @@ return [
 
     'withdrawal_destination_id' => 'Destination account',
     'deposit_source_id'         => 'Source account',
+    'expected_on'               => 'Expected on',
+    'paid'                      => 'Paid',
 
 ];
diff --git a/resources/views/v1/reports/default/month.twig b/resources/views/v1/reports/default/month.twig
index cd963c0572..d3d9a5a16d 100644
--- a/resources/views/v1/reports/default/month.twig
+++ b/resources/views/v1/reports/default/month.twig
@@ -102,8 +102,7 @@
                 

{{ 'categories'|_ }}

-
-
+
{# loading indicator #}
@@ -111,11 +110,6 @@
-
-
- -
-
@@ -134,10 +128,19 @@
- {% include 'reports/partials/bills' %} - +
+
+

{{ 'bills'|_ }}

+
+
+ {# loading indicator #} +
+ +
+
+ {#{% include 'reports/partials/bills' %}#} {% endblock %} {% block styles %} @@ -166,6 +169,7 @@ var incomeReportUri = '{{ route('report-data.operations.income', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; var expenseReportUri = '{{ route('report-data.operations.expenses', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; var incExpReportUri = '{{ route('report-data.operations.operations', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var billReportUri = '{{ route('report-data.bills.overview', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; // uri's for charts: var accountChartUri = '{{ route('chart.account.report', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; diff --git a/resources/views/v1/reports/partials/balance.twig b/resources/views/v1/reports/partials/balance.twig index 69a7cbc112..807328fcdf 100644 --- a/resources/views/v1/reports/partials/balance.twig +++ b/resources/views/v1/reports/partials/balance.twig @@ -20,10 +20,15 @@ {% for account in report.accounts %} {% if budget.spent[account.id] %} - - {{ formatAmountBySymbol(budget.spent[account.id].spent, budget.spent[account.id].currency_symbol, budget.spent[account.id].currency_decimal_places) }} - + + {{ formatAmountBySymbol(budget.spent[account.id].spent, budget.spent[account.id].currency_symbol, budget.spent[account.id].currency_decimal_places) }} + + {% else %} + {% if report.accounts[account.id].sum != 0 %} +   + {% endif %} {% endif %} + {% endfor %} {% for sum in report.sums[budget.budget_id] %} diff --git a/resources/views/v1/reports/partials/bills.twig b/resources/views/v1/reports/partials/bills.twig index f6a90b5081..d9fbad38a6 100644 --- a/resources/views/v1/reports/partials/bills.twig +++ b/resources/views/v1/reports/partials/bills.twig @@ -1,19 +1,51 @@ -
-
-

{{ 'bills'|_ }}

-
-
- - + + + {% for bill in report.bills %} + {% if bill.expected_dates|length > 0 and bill.paid_moments|length > 0 and bill.active %} + + + + + + + + {% endif %} + {% endfor %} + + {% for line in bills.getBills %}
{{ trans('form.name') }} {{ trans('form.amount') }}{{ trans('form.expected_on') }}{{ trans('form.paid') }}
+ {{ bill.name }} + + {{ formatAmountBySymbol(bill.amount_min, bill.currency_symbol, bill.currency_decimal_places) }} + + {{ formatAmountBySymbol(bill.amount_max, bill.currency_symbol, bill.currency_decimal_places) }} + + {% for date in bill.expected_dates %} + {{ date.formatLocalized(monthAndDayFormat) }}
+ {% endfor %} +
+ {% set hitCount = 0 %} + {% for journals in bill.paid_moments %} + {% for journal in journals %} + {% set hitCount = hitCount+1 %} + {{ journal.description }}, + {{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places) }} +
+ {% endfor %} + {% endfor %} + {% if hitCount == 0 %} + {{ 'notCharged'|_ }} + {% endif %} +
@@ -50,5 +82,3 @@ {% endfor %}
-
-
diff --git a/routes/web.php b/routes/web.php index 174d7fb86d..624b4520e6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -701,6 +701,16 @@ Route::group( } ); +/** + * Report Data Bill Controller + */ +Route::group( + ['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Report', 'prefix' => 'report-data/bill', 'as' => 'report-data.bills.'], + static function () { + Route::get('overview/{accountList}/{start_date}/{end_date}', ['uses' => 'BillController@overview', 'as' => 'overview']); + } +); + /** * Report Data Expense / Revenue Account Controller */