diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index e1834cd7c1..1ffb912259 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -245,7 +245,7 @@ class CategoryController extends Controller
*
* @return View
*/
- public function showWithDate(Category $category, string $date)
+ public function showByDate(Category $category, string $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
@@ -263,7 +263,7 @@ class CategoryController extends Controller
$journals->setPath('categories/show/' . $category->id . '/' . $date);
- return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
+ return view('categories.show-by-date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
}
/**
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index be6110534b..a2ff4338c7 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -155,11 +155,13 @@ class CategoryController extends Controller
/**
* @param CRI $repository
* @param Category $category
+ * @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
- * @param Collection $accounts
+ *
+ * @return \Illuminate\Http\JsonResponse|mixed
*/
- public function reportPeriod(CRI $repository, Category $category, Carbon $start, Carbon $end, Collection $accounts)
+ public function reportPeriod(CRI $repository, Category $category, Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -171,8 +173,9 @@ class CategoryController extends Controller
return $cache->get();
}
- $report = $repository->getCategoryPeriodReport(new Collection([$category]), $accounts, $start, $end, true);
- $periods = Navigation::listOfPeriods($start, $end);
+ $expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
+ $income = $repository->periodIncome(new Collection([$category]), $accounts, $start, $end);
+ $periods = Navigation::listOfPeriods($start, $end);
// join them:
@@ -180,8 +183,46 @@ class CategoryController extends Controller
foreach (array_keys($periods) as $period) {
$nice = $periods[$period];
$result[$nice] = [
- 'earned' => $report['income'][$category->id]['entries'][$period] ?? '0',
- 'spent' => $report['expense'][$category->id]['entries'][$period] ?? '0',
+ 'earned' => $income[$category->id]['entries'][$period] ?? '0',
+ 'spent' => $expenses[$category->id]['entries'][$period] ?? '0',
+ ];
+ }
+ $data = $this->generator->reportPeriod($result);
+
+ return Response::json($data);
+ }
+
+ /**
+ * @param CRI $repository
+ * @param Category $category
+ * @param Collection $accounts
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return \Illuminate\Http\JsonResponse|mixed
+ */
+ public function reportPeriodNoCategory(CRI $repository, Collection $accounts, Carbon $start, Carbon $end)
+ {
+ $cache = new CacheProperties;
+ $cache->addProperty($start);
+ $cache->addProperty($end);
+ $cache->addProperty('no-category-period-chart');
+ $cache->addProperty($accounts->pluck('id')->toArray());
+ if ($cache->has()) {
+
+ return $cache->get();
+ }
+ $expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
+ $income = $repository->periodIncomeNoCategory($accounts, $start, $end);
+ $periods = Navigation::listOfPeriods($start, $end);
+
+ // join them:
+ $result = [];
+ foreach (array_keys($periods) as $period) {
+ $nice = $periods[$period];
+ $result[$nice] = [
+ 'earned' => $income['entries'][$period] ?? '0',
+ 'spent' => $expenses['entries'][$period] ?? '0',
];
}
$data = $this->generator->reportPeriod($result);
diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php
index 7284638f27..7d6405d494 100644
--- a/app/Http/Controllers/Report/CategoryController.php
+++ b/app/Http/Controllers/Report/CategoryController.php
@@ -60,14 +60,13 @@ class CategoryController extends Controller
}
/**
- *
+ * @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
- * @param Collection $accounts
*
- * @return string
+ * @return mixed|string
*/
- public function expenseReport(Carbon $start, Carbon $end, Collection $accounts)
+ public function expenses(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -100,7 +99,7 @@ class CategoryController extends Controller
*
* @return string
*/
- public function incomeReport(Carbon $start, Carbon $end, Collection $accounts)
+ public function income(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 7c002558a2..65b46ad44c 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -23,6 +23,7 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\User;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
+use Log;
use Navigation;
/**
@@ -258,6 +259,10 @@ class CategoryRepository implements CategoryRepositoryInterface
// loop transactions:
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
+ // if positive, skip:
+ if (bccomp($transaction->transaction_amount, '0') === 1) {
+ continue;
+ }
$categoryId = max(intval($transaction->transaction_journal_category_id), intval($transaction->transaction_category_id));
$date = $transaction->date->format($carbonFormat);
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $transaction->transaction_amount);
@@ -278,7 +283,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
- $collector->setAccounts($accounts)->setRange($start, $end);
+ $collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->enableInternalFilter();
$collector->withoutCategory();
$transactions = $collector->getJournals();
@@ -289,6 +294,10 @@ class CategoryRepository implements CategoryRepositoryInterface
];
foreach ($transactions as $transaction) {
+ // if positive, skip:
+ if (bccomp($transaction->transaction_amount, '0') === 1) {
+ continue;
+ }
$date = $transaction->date->format($carbonFormat);
if (!isset($result['entries'][$date])) {
@@ -334,6 +343,10 @@ class CategoryRepository implements CategoryRepositoryInterface
// loop transactions:
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
+ // if negative, skip:
+ if (bccomp($transaction->transaction_amount, '0') === -1) {
+ continue;
+ }
$categoryId = max(intval($transaction->transaction_journal_category_id), intval($transaction->transaction_category_id));
$date = $transaction->date->format($carbonFormat);
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $transaction->transaction_amount);
@@ -351,10 +364,11 @@ class CategoryRepository implements CategoryRepositoryInterface
*/
public function periodIncomeNoCategory(Collection $accounts, Carbon $start, Carbon $end): array
{
+ Log::debug('Now in periodIncomeNoCategory()');
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
- $collector->setAccounts($accounts)->setRange($start, $end);
+ $collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])->enableInternalFilter();
$collector->withoutCategory();
$transactions = $collector->getJournals();
@@ -363,8 +377,13 @@ class CategoryRepository implements CategoryRepositoryInterface
'name' => strval(trans('firefly.no_category')),
'sum' => '0',
];
-
+ Log::debug('Looping transactions..');
foreach ($transactions as $transaction) {
+
+ // if negative, skip:
+ if (bccomp($transaction->transaction_amount, '0') === -1) {
+ continue;
+ }
$date = $transaction->date->format($carbonFormat);
if (!isset($result['entries'][$date])) {
@@ -372,6 +391,8 @@ class CategoryRepository implements CategoryRepositoryInterface
}
$result['entries'][$date] = bcadd($result['entries'][$date], $transaction->transaction_amount);
}
+ Log::debug('Done looping transactions..');
+ Log::debug('Finished periodIncomeNoCategory()');
return $result;
}
diff --git a/public/js/ff/categories/show-by-date.js b/public/js/ff/categories/show-by-date.js
new file mode 100644
index 0000000000..931316b0d7
--- /dev/null
+++ b/public/js/ff/categories/show-by-date.js
@@ -0,0 +1,4 @@
+$(function () {
+ "use strict";
+ columnChart(specific, 'period-specific-period');
+});
\ No newline at end of file
diff --git a/public/js/ff/categories/show.js b/public/js/ff/categories/show.js
index fd6f59934c..4d668bad25 100644
--- a/public/js/ff/categories/show.js
+++ b/public/js/ff/categories/show.js
@@ -1,19 +1,5 @@
-/* globals $, categoryID, columnChart, categoryDate */
$(function () {
"use strict";
- if (typeof categoryID !== 'undefined') {
- // more splits:
- if ($('#all').length > 0) {
- columnChart('chart/category/' + categoryID + '/all', 'all');
- }
- if ($('#period').length > 0) {
- columnChart('chart/category/' + categoryID + '/period', 'period');
- }
-
- }
- if (typeof categoryID !== 'undefined' && typeof categoryDate !== 'undefined') {
- columnChart('chart/category/' + categoryID + '/period/' + categoryDate, 'period-specific-period');
- }
-
-
+ columnChart(all, 'all');
+ columnChart(current, 'period');
});
\ No newline at end of file
diff --git a/public/js/ff/categories/show_with_date.js b/public/js/ff/categories/show_with_date.js
deleted file mode 100644
index 8bf673924b..0000000000
--- a/public/js/ff/categories/show_with_date.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/* globals $, categoryID, columnChart, categoryDate */
-$(function () {
- "use strict";
- if (typeof categoryID !== 'undefined') {
- // more splits:
- if ($('#all').length > 0) {
- columnChart('chart/category/' + categoryID + '/all', 'all');
- }
- if ($('#period').length > 0) {
- columnChart('chart/category/' + categoryID + '/period', 'period');
- }
-
- }
- if (typeof categoryID !== 'undefined' && typeof categoryDate !== undefined) {
- columnChart('chart/category/' + categoryID + '/period/' + categoryDate, 'period-specific-period');
- }
-
-
-});
\ No newline at end of file
diff --git a/public/js/ff/reports/category/month.js b/public/js/ff/reports/category/month.js
index b9786d68fc..cdbe5420b2 100644
--- a/public/js/ff/reports/category/month.js
+++ b/public/js/ff/reports/category/month.js
@@ -8,31 +8,25 @@
* See the LICENSE file for details.
*/
-// it's hard coded, but what you're gonna do?
-var catInUri = 'chart/category/' + accountIds + '/' + categoryIds + '/' + startDate + '/' + endDate + '/OTHERS/income';
-var catOutUri = 'chart/category/' + accountIds + '/' + categoryIds + '/' + startDate + '/' + endDate + '/OTHERS/expense';
-var accInUri = 'chart/account/' + accountIds + '/' + categoryIds + '/' + startDate + '/' + endDate + '/OTHERS/income';
-var accOutUri = 'chart/account/' + accountIds + '/' + categoryIds + '/' + startDate + '/' + endDate + '/OTHERS/expense';
-
$(function () {
"use strict";
drawChart();
$('#categories-in-pie-chart-checked').on('change', function () {
- redrawPieChart('categories-in-pie-chart', catInUri);
+ redrawPieChart('categories-in-pie-chart', categoryIncomeUri);
});
$('#categories-out-pie-chart-checked').on('change', function () {
- redrawPieChart('categories-out-pie-chart', catOutUri);
+ redrawPieChart('categories-out-pie-chart', categoryExpenseUri);
});
$('#accounts-in-pie-chart-checked').on('change', function () {
- redrawPieChart('accounts-in-pie-chart', accInUri);
+ redrawPieChart('accounts-in-pie-chart', accountIncomeUri);
});
$('#accounts-out-pie-chart-checked').on('change', function () {
- redrawPieChart('accounts-out-pie-chart', accOutUri);
+ redrawPieChart('accounts-out-pie-chart', accountExpenseUri);
});
});
@@ -42,13 +36,13 @@ function drawChart() {
"use strict";
// month view:
- stackedColumnChart('chart/category-report-in-out/' + accountIds + '/' + categoryIds + '/' + startDate + '/' + endDate, 'in-out-chart');
+ stackedColumnChart(mainUri, 'in-out-chart');
// draw pie chart of income, depending on "show other transactions too":
- redrawPieChart('categories-in-pie-chart', catInUri);
- redrawPieChart('categories-out-pie-chart', catOutUri);
- redrawPieChart('accounts-in-pie-chart', accInUri);
- redrawPieChart('accounts-out-pie-chart', accOutUri);
+ redrawPieChart('categories-in-pie-chart', categoryIncomeUri);
+ redrawPieChart('categories-out-pie-chart', categoryExpenseUri);
+ redrawPieChart('accounts-in-pie-chart', accountIncomeUri);
+ redrawPieChart('accounts-out-pie-chart', accountExpenseUri);
}
diff --git a/public/js/ff/reports/default/all.js b/public/js/ff/reports/default/all.js
index 15ccb296cd..f5c968f05f 100644
--- a/public/js/ff/reports/default/all.js
+++ b/public/js/ff/reports/default/all.js
@@ -108,8 +108,7 @@ function clickCategoryChart(e) {
var link = $(e.target);
var categoryId = link.data('category');
- // this url is different from the one below. this is something that must be fixed
- var URL = 'chart/category/' + categoryId + '/report-period/' + startDate + '/' + endDate + '/' + accountIds;
+ var URL = 'chart/category/report-period/' + categoryId + '/' + accountIds + '/' + startDate + '/' + endDate;
var container = 'category_chart';
columnChart(URL, container);
return false;
diff --git a/public/js/ff/reports/default/year.js b/public/js/ff/reports/default/year.js
index 96e2d64167..10f305b8f6 100644
--- a/public/js/ff/reports/default/year.js
+++ b/public/js/ff/reports/default/year.js
@@ -5,7 +5,6 @@ $(function () {
drawChart();
loadAjaxPartial('budgetPeriodReport', budgetPeriodReportUri);
-
loadAjaxPartial('categoryExpense', categoryExpenseUri);
loadAjaxPartial('categoryIncome', categoryIncomeUri);
});
diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig
index 0b76b53819..d849fa50d4 100644
--- a/resources/views/accounts/edit.twig
+++ b/resources/views/accounts/edit.twig
@@ -77,7 +77,3 @@
{{ Form.close|raw }}
{% endblock %}
-
-{% block scripts %}
-
-{% endblock %}
\ No newline at end of file
diff --git a/resources/views/categories/show-by-date.twig b/resources/views/categories/show-by-date.twig
index 2514b08214..c2ffe6c1b0 100644
--- a/resources/views/categories/show-by-date.twig
+++ b/resources/views/categories/show-by-date.twig
@@ -40,12 +40,11 @@
{% endblock %}
{% block scripts %}
-
+
{% endblock %}
diff --git a/resources/views/categories/show.twig b/resources/views/categories/show.twig
index f6b18c08b4..9ff1006823 100644
--- a/resources/views/categories/show.twig
+++ b/resources/views/categories/show.twig
@@ -73,7 +73,8 @@
{% endblock %}
{% block scripts %}
diff --git a/resources/views/reports/category/month.twig b/resources/views/reports/category/month.twig
index 49556850ac..33f0d43ff9 100644
--- a/resources/views/reports/category/month.twig
+++ b/resources/views/reports/category/month.twig
@@ -369,6 +369,13 @@
var endDate = '{{ end.format('Ymd') }}';
var accountIds = '{{ accountIds }}';
var categoryIds = '{{ categoryIds }}';
+
+ // chart uri's
+ var categoryIncomeUri = '{{ route('chart.category.category-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
+ var categoryExpenseUri = '{{ route('chart.category.category-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
+ var accountIncomeUri = '{{ route('chart.category.account-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
+ var accountExpenseUri = '{{ route('chart.category.account-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
+ var mainUri = '{{ route('chart.category.main', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd')]) }}';
diff --git a/routes/web.php b/routes/web.php
index e62354c0f8..e3014bd0b6 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -242,9 +242,9 @@ Route::group(
* Chart\Bill Controller
*/
Route::group(
- ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/bill','as' => 'chart.bill.'], function () {
- Route::get('frontpage', ['uses' => 'BillController@frontpage' ,'as' => 'frontpage']);
- Route::get('single/{bill}', ['uses' => 'BillController@single','as' => 'single']);
+ ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/bill', 'as' => 'chart.bill.'], function () {
+ Route::get('frontpage', ['uses' => 'BillController@frontpage', 'as' => 'frontpage']);
+ Route::get('single/{bill}', ['uses' => 'BillController@single', 'as' => 'single']);
}
);
@@ -253,14 +253,14 @@ Route::group(
* Chart\Budget Controller
*/
Route::group(
- ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/budget','as' => 'chart.budget.'], function () {
+ ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/budget', 'as' => 'chart.budget.'], function () {
Route::get('frontpage', ['uses' => 'BudgetController@frontpage']);
Route::get('period/0/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@periodNoBudget']);
Route::get('period/{budget}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@period']);
- Route::get('budget/{budget}/{limitrepetition}', ['uses' => 'BudgetController@budgetLimit', 'as' => 'budget-limit']);
- Route::get('budget/{budget}', ['uses' => 'BudgetController@budget', 'as' => 'budget']);
+ Route::get('budget/{budget}/{limitrepetition}', ['uses' => 'BudgetController@budgetLimit', 'as' => 'budget-limit']);
+ Route::get('budget/{budget}', ['uses' => 'BudgetController@budget', 'as' => 'budget']);
}
);
@@ -269,20 +269,36 @@ Route::group(
* Chart\Category Controller
*/
Route::group(
- ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/category'], function () {
+ ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/category', 'as' => 'chart.category.'], function () {
Route::get('frontpage', ['uses' => 'CategoryController@frontpage']);
- Route::get('period/{category}', ['uses' => 'CategoryController@currentPeriod']);
- Route::get('period/{category}/{date}', ['uses' => 'CategoryController@specificPeriod']);
- Route::get('all/{category}', ['uses' => 'CategoryController@all']);
+
+ Route::get('period/{category}', ['uses' => 'CategoryController@currentPeriod', 'as' => 'current']);
+ Route::get('period/{category}/{date}', ['uses' => 'CategoryController@specificPeriod', 'as' => 'specific']);
+ Route::get('all/{category}', ['uses' => 'CategoryController@all', 'as' => 'all']);
+ Route::get('report-period/0/{accountList}/{start_date}/{end_date}', ['uses' => 'CategoryController@reportPeriodNoCategory']);
Route::get('report-period/{category}/{accountList}/{start_date}/{end_date}', ['uses' => 'CategoryController@reportPeriod']);
// these charts are used in reports (category reports):
- Route::get('category/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', ['uses' => 'CategoryReportController@categoryIncome']);
- Route::get('category/expense/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', ['uses' => 'CategoryReportController@categoryExpense']);
- Route::get('account/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', ['uses' => 'CategoryReportController@accountIncome']);
- Route::get('account/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', ['uses' => 'CategoryReportController@accountExpense']);
- Route::get('report-in-out/{accountList}/{categoryList}/{start_date}/{end_date}', ['uses' => 'CategoryReportController@mainChart']);
+ Route::get(
+ 'category/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}',
+ ['uses' => 'CategoryReportController@categoryIncome', 'as' => 'category-income']
+ );
+ Route::get(
+ 'category/expense/{accountList}/{categoryList}/{start_date}/{end_date}/{others}',
+ ['uses' => 'CategoryReportController@categoryExpense', 'as' => 'category-expense']
+ );
+ Route::get(
+ 'account/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}',
+ ['uses' => 'CategoryReportController@accountIncome', 'as' => 'account-income']
+ );
+ Route::get(
+ 'account/expense/{accountList}/{categoryList}/{start_date}/{end_date}/{others}',
+ ['uses' => 'CategoryReportController@accountExpense', 'as' => 'account-expense']
+ );
+
+ Route::get('report-in-out/{accountList}/{categoryList}/{start_date}/{end_date}',
+ ['uses' => 'CategoryReportController@mainChart', 'as' => 'main']);
}
);
@@ -292,6 +308,7 @@ Route::group(
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/piggy-bank'], function () {
+ // continue here.
Route::get('{piggyBank}', ['uses' => 'PiggyBankController@history']);
}
);
@@ -473,6 +490,8 @@ Route::group(
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Report', 'prefix' => 'report-data/category', 'as' => 'report-data.category.'], function () {
+
+
Route::get('operations/{accountList}/{start_date}/{end_date}', ['uses' => 'CategoryController@operations', 'as' => 'operations']);
Route::get('income/{accountList}/{start_date}/{end_date}', ['uses' => 'CategoryController@income', 'as' => 'income']);
Route::get('expenses/{accountList}/{start_date}/{end_date}', ['uses' => 'CategoryController@expenses', 'as' => 'expenses']);