From a81dd8abe57cd7c07b7dfe55c5ea0b6a9dee5791 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 24 Aug 2015 20:11:04 +0200 Subject: [PATCH 01/66] Send search engine spiders away, as suggested in issue #105 --- public/robots.txt | 2 +- resources/twig/layout/default.twig | 2 ++ resources/twig/layout/empty.twig | 1 + resources/twig/layout/guest.twig | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/robots.txt b/public/robots.txt index eb0536286f..77470cb39f 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,2 +1,2 @@ User-agent: * -Disallow: +Disallow: / \ No newline at end of file diff --git a/resources/twig/layout/default.twig b/resources/twig/layout/default.twig index 457e635618..5c268b2270 100644 --- a/resources/twig/layout/default.twig +++ b/resources/twig/layout/default.twig @@ -2,6 +2,7 @@ + Firefly {% if title != "Firefly" %} // {{ title }} @@ -12,6 +13,7 @@ {% endif %} + diff --git a/resources/twig/layout/empty.twig b/resources/twig/layout/empty.twig index cc9529d6c2..7fd5ef6c46 100644 --- a/resources/twig/layout/empty.twig +++ b/resources/twig/layout/empty.twig @@ -2,6 +2,7 @@ + Firefly III diff --git a/resources/twig/layout/guest.twig b/resources/twig/layout/guest.twig index 7636b67f66..43da3fc880 100644 --- a/resources/twig/layout/guest.twig +++ b/resources/twig/layout/guest.twig @@ -2,6 +2,7 @@ + Firefly III From 425552988a76b94c1b41c1c23483d63c92d62506 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 28 Aug 2015 06:19:50 +0200 Subject: [PATCH 02/66] Fix month report so transfers from a shared account to another shared account do not count as income. --- app/Helpers/Report/ReportQuery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 5e8834374c..9aba295126 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -164,6 +164,7 @@ class ReportQuery implements ReportQueryInterface function (Builder $q) { $q->where('transaction_types.type', 'Transfer'); $q->where('acm_from.data', '=', '"sharedAsset"'); + $q->where('acm_to.data','!=','"sharedAsset"'); } ); } From e5b88be5fab5978300ac2c8b5cd60095c923af1b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 29 Aug 2015 06:48:12 +0200 Subject: [PATCH 03/66] Fix a bug where an transfer to and from a shared asset would count as an expense/income. --- app/Helpers/Report/ReportQuery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 9aba295126..5c98a171d4 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -50,6 +50,7 @@ class ReportQuery implements ReportQueryInterface function (Builder $q) { // and transfers from a shared account. $q->where('transaction_types.type', 'Transfer'); $q->where('acm_to.data', '=', '"sharedAsset"'); + $q->where('acm_from.data', '!=', '"sharedAsset"'); } ); } From c3958ed3c40d765d07533dbc7e6838ab2fd46bd4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 29 Aug 2015 07:20:53 +0200 Subject: [PATCH 04/66] Fixed some bugs that caused inconsistencies in the monthly reports. --- app/Helpers/Collection/Expense.php | 5 ++--- app/Helpers/Collection/Income.php | 4 ++-- app/Helpers/Report/ReportHelper.php | 4 ++-- app/Helpers/Report/ReportQuery.php | 9 --------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index 68ac2baf05..22f189329f 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -33,11 +33,10 @@ class Expense */ public function addOrCreateExpense(TransactionJournal $entry) { - $accountId = $entry->account_id; if (!$this->expenses->has($accountId)) { $newObject = new stdClass; - $newObject->amount = strval(round($entry->amount, 2)); + $newObject->amount = strval(round($entry->actual_amount, 2)); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; @@ -45,7 +44,7 @@ class Expense } else { bcscale(2); $existing = $this->expenses->get($accountId); - $existing->amount = bcadd($existing->amount, $entry->amount); + $existing->amount = bcadd($existing->amount, $entry->actual_amount); $existing->count++; $this->expenses->put($accountId, $existing); } diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index 1d34e2bb57..5a80b7a9b1 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -38,7 +38,7 @@ class Income $accountId = $entry->account_id; if (!$this->incomes->has($accountId)) { $newObject = new stdClass; - $newObject->amount = strval(round($entry->amount, 2)); + $newObject->amount = strval(round($entry->actual_amount, 2)); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; @@ -46,7 +46,7 @@ class Income } else { bcscale(2); $existing = $this->incomes->get($accountId); - $existing->amount = bcadd($existing->amount, $entry->amount); + $existing->amount = bcadd($existing->amount, $entry->actual_amount); $existing->count++; $this->incomes->put($accountId, $existing); } diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index bccc191c87..8281b99629 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -350,7 +350,7 @@ class ReportHelper implements ReportHelperInterface $object = new Expense; $set = $this->query->expenseInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->amount); + $object->addToTotal($entry->actual_amount); $object->addOrCreateExpense($entry); } @@ -371,7 +371,7 @@ class ReportHelper implements ReportHelperInterface $object = new Income; $set = $this->query->incomeInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->amount); + $object->addToTotal($entry->actual_amount); $object->addOrCreateIncome($entry); } diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 5c98a171d4..de7c08158b 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -70,15 +70,6 @@ class ReportQuery implements ReportQueryInterface } } ); - $data = $data->filter( - function (TransactionJournal $journal) { - if ($journal->amount != 0) { - return $journal; - } - - return null; - } - ); return $data; } From 3d00e20238bb792536a57a529bb6f69b28349eb2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 29 Aug 2015 08:35:11 +0200 Subject: [PATCH 05/66] Fixed a translation. --- resources/twig/partials/reports/accounts.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/twig/partials/reports/accounts.twig b/resources/twig/partials/reports/accounts.twig index 287236801a..89c051d859 100644 --- a/resources/twig/partials/reports/accounts.twig +++ b/resources/twig/partials/reports/accounts.twig @@ -8,7 +8,7 @@ {{ 'name'|_ }} {{ 'balanceStart'|_ }} - {{ 'balanceStart'|_ }} + {{ 'balanceEnd'|_ }} {{ 'difference'|_ }} From c9bab3e5c353a3e2d66270bf51e9ccae1ce0531e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 29 Aug 2015 08:43:18 +0200 Subject: [PATCH 06/66] Tag list show sum. --- resources/twig/tags/show.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/twig/tags/show.twig b/resources/twig/tags/show.twig index b775275e31..fbced572a2 100644 --- a/resources/twig/tags/show.twig +++ b/resources/twig/tags/show.twig @@ -87,7 +87,7 @@
- {% include 'list/journals.twig' with {'journals': tag.transactionjournals} %} + {% include 'list/journals.twig' with {'journals': tag.transactionjournals, 'showPageSum' : true} %}
From 204e521ba40fd8a0df255ac344404bf4978de95e Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 8 Sep 2015 19:36:54 +0200 Subject: [PATCH 07/66] Fixed sorting for contracts. --- app/Models/Bill.php | 4 ++-- app/Repositories/Bill/BillRepository.php | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Models/Bill.php b/app/Models/Bill.php index e1196585c0..c976459a11 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -39,8 +39,8 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereSkip($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereNameEncrypted($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatchEncrypted($value) - * @property-read \Carbon\Carbon $nextExpectedMatch - * @property-read \Carbon\Carbon $lastFoundMatch + * @property \Carbon\Carbon $nextExpectedMatch + * @property \Carbon\Carbon $lastFoundMatch */ class Bill extends Model { diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index b86eefe26c..eb43b0cf83 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -97,7 +97,10 @@ class BillRepository implements BillRepositoryInterface $set = $set->sortBy( function (Bill $bill) { - return strtolower($bill->name); + + $int = $bill->active == 1 ? 0 : 1; + + return $int.strtolower($bill->name); } ); From 3699a7ba9aa330e70b82d2b8cc781e0df2cfa37d Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 8 Sep 2015 19:38:04 +0200 Subject: [PATCH 08/66] Some cleaning up. --- app/Repositories/Bill/BillRepository.php | 2 +- resources/lang/nl/firefly.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index eb43b0cf83..21a86f10c5 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -100,7 +100,7 @@ class BillRepository implements BillRepositoryInterface $int = $bill->active == 1 ? 0 : 1; - return $int.strtolower($bill->name); + return $int . strtolower($bill->name); } ); diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index a75df006e9..30749b773a 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -34,7 +34,7 @@ return [ 'new_expense_account' => 'Nieuwe crediteur', 'new_revenue_account' => 'Nieuwe debiteur', 'new_budget' => 'Nieuw budget', - 'new_bill' => 'Nieuwe rekening', + 'new_bill' => 'Nieuw contract', // tags 'store_new_tag' => 'Sla tag op', From b3333cc2d362f05dfa9781338664b8f2b2587eb6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 13 Sep 2015 07:32:39 +0200 Subject: [PATCH 09/66] Experimental fix for issue #109. --- app/Http/Controllers/Chart/CategoryController.php | 2 +- app/Repositories/Shared/ComponentRepository.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 840bc68aed..e95d4ccb38 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -65,7 +65,7 @@ class CategoryController extends Controller while ($start <= $end) { $currentEnd = Navigation::endOfPeriod($start, $range); - $spent = $repository->balanceInPeriod($category, $start, $currentEnd); + $spent = $repository->balanceInPeriod($category, $start, $currentEnd, true); $entries->push([clone $start, $spent]); $start = Navigation::addPeriod($start, $range, 0); diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index 584856fa3d..1d879a6b69 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -40,7 +40,7 @@ class ComponentRepository if ($shared === true) { // shared is true: always ignore transfers between accounts! $sum = $object->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start) - ->get(['transaction_journals.*'])->sum('amount'); + ->get(['transaction_journals.*'])->sum('actual_amount'); } else { // do something else, SEE budgets. // get all journals in this month where the asset account is NOT shared. From 8ad40389f2367363db8f7036795b40b747920046 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 13 Sep 2015 07:34:58 +0200 Subject: [PATCH 10/66] Corrected the field used for bug #109 --- app/Repositories/Shared/ComponentRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index 1d879a6b69..00096e564f 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -40,7 +40,7 @@ class ComponentRepository if ($shared === true) { // shared is true: always ignore transfers between accounts! $sum = $object->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start) - ->get(['transaction_journals.*'])->sum('actual_amount'); + ->get(['transaction_journals.*'])->sum('correct_amount'); } else { // do something else, SEE budgets. // get all journals in this month where the asset account is NOT shared. From fa586dba7e51b0cfe1ebe7434f5d19b7494c0dd4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 13 Sep 2015 07:35:53 +0200 Subject: [PATCH 11/66] Also include all types. --- app/Repositories/Shared/ComponentRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index 00096e564f..632ce9db63 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -39,7 +39,7 @@ class ComponentRepository } if ($shared === true) { // shared is true: always ignore transfers between accounts! - $sum = $object->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start) + $sum = $object->transactionjournals()->transactionTypes(['Withdrawal', 'Deposit', 'Opening balance'])->before($end)->after($start) ->get(['transaction_journals.*'])->sum('correct_amount'); } else { // do something else, SEE budgets. From 51c7d4fb1b86e68a42a1a04faf4f4fa583e54d96 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 13 Sep 2015 07:40:37 +0200 Subject: [PATCH 12/66] Properly show spent and earned. #109 --- .../Controllers/Chart/CategoryController.php | 5 +- .../Category/CategoryRepository.php | 61 +++++++++++++++++++ .../Category/CategoryRepositoryInterface.php | 22 +++++++ 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index e95d4ccb38..f7d735aef6 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -65,8 +65,9 @@ class CategoryController extends Controller while ($start <= $end) { $currentEnd = Navigation::endOfPeriod($start, $range); - $spent = $repository->balanceInPeriod($category, $start, $currentEnd, true); - $entries->push([clone $start, $spent]); + $spent = $repository->spentInPeriod($category, $start, $currentEnd); + $earned = $repository->earnedInPeriod($category, $start, $currentEnd); + $entries->push([clone $start, $spent, $earned]); $start = Navigation::addPeriod($start, $range, 0); } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index b5494c5dcf..a1825a049c 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -8,6 +8,7 @@ use Crypt; use FireflyIII\Models\Category; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Shared\ComponentRepository; +use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; /** @@ -262,4 +263,64 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito return $query->get(['transaction_journals.*'])->sum('correct_amount'); } + + /** + * @param Category $category + * @param \Carbon\Carbon $start + * @param \Carbon\Carbon $end + * + * @param bool $shared + * + * @return string + */ + public function spentInPeriod(Category $category, Carbon $start, Carbon $end) + { + $cache = new CacheProperties; // we must cache this. + $cache->addProperty($category->id); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('spentInPeriod'); + + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + + $sum = $category->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start)->get(['transaction_journals.*'])->sum( + 'correct_amount' + ); + + $cache->store($sum); + + return $sum; + } + + /** + * @param Category $category + * @param \Carbon\Carbon $start + * @param \Carbon\Carbon $end + * + * @param bool $shared + * + * @return string + */ + public function earnedInPeriod(Category $category, Carbon $start, Carbon $end) + { + $cache = new CacheProperties; // we must cache this. + $cache->addProperty($category->id); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('spentInPeriod'); + + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + + $sum = $category->transactionjournals()->transactionTypes(['Deposit'])->before($end)->after($start)->get(['transaction_journals.*'])->sum( + 'correct_amount' + ); + + $cache->store($sum); + + return $sum; + } } diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index b7364e518b..2f2e3d1edc 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -97,6 +97,28 @@ interface CategoryRepositoryInterface */ public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false); + /** + * @param Category $category + * @param \Carbon\Carbon $start + * @param \Carbon\Carbon $end + * + * @param bool $shared + * + * @return string + */ + public function spentInPeriod(Category $category, Carbon $start, Carbon $end); + + /** + * @param Category $category + * @param \Carbon\Carbon $start + * @param \Carbon\Carbon $end + * + * @param bool $shared + * + * @return string + */ + public function earnedInPeriod(Category $category, Carbon $start, Carbon $end); + /** * * Corrected for tags. From 3d15a4ca6d7c1365feb675b97cd6cc8762de3439 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 14 Sep 2015 17:20:20 +0200 Subject: [PATCH 13/66] I need unit tests again. #109 --- app/Http/Controllers/Chart/BudgetController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index d5036356d8..b0f3c79f97 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -156,7 +156,7 @@ class BudgetController extends Controller foreach ($budgets as $budget) { $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); if ($repetitions->count() == 0) { - $expenses = $repository->balanceInPeriod($budget, $start, $end, true); + $expenses = $repository->balanceInPeriod($budget, $start, $end, true) * -1; $allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]); continue; } From a838dc163dcbab592ba0fa24d0785130d5d2dfb6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 14 Sep 2015 17:22:31 +0200 Subject: [PATCH 14/66] I need unit tests again. #109 --- app/Http/Controllers/Chart/BudgetController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index b0f3c79f97..7e171df804 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -162,7 +162,7 @@ class BudgetController extends Controller } /** @var LimitRepetition $repetition */ foreach ($repetitions as $repetition) { - $expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, true); + $expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, true) * -1; // $left can be less than zero. // $overspent can be more than zero ( = overspending) From 45293fbd427beb95e47f612f002e324800dcc16c Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:00:14 +0200 Subject: [PATCH 15/66] Fixes for #109. --- .../ChartJsCategoryChartGenerator.php | 13 ++-- app/Http/Controllers/CategoryController.php | 65 +++++++++++++++- .../Controllers/Chart/CategoryController.php | 1 - app/Http/routes.php | 1 + .../Category/CategoryRepository.php | 34 ++++++++- .../Category/CategoryRepositoryInterface.php | 15 ++++ app/Support/Navigation.php | 7 +- resources/twig/categories/show.twig | 29 ++++++- resources/twig/categories/show_with_date.twig | 75 +++++++++++++++++++ resources/twig/emails/registered-html.twig | 2 +- resources/twig/emails/registered.twig | 2 +- 11 files changed, 228 insertions(+), 16 deletions(-) create mode 100644 resources/twig/categories/show_with_date.twig diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php index 621a51ee13..196a5ecd2f 100644 --- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php +++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php @@ -45,14 +45,11 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator foreach ($entries as $entry) { $data['labels'][] = $entry[0]->formatLocalized($format); - $amount = round($entry[1], 2); - if ($amount > 0) { - $data['datasets'][0]['data'][] = null; - $data['datasets'][1]['data'][] = $amount; - } else { - $data['datasets'][0]['data'][] = $amount * -1; - $data['datasets'][1]['data'][] = null; - } + $spent = round($entry[1], 2); + $earned = round($entry[2], 2); + + $data['datasets'][0]['data'][] = $spent == 0 ? null : $spent; + $data['datasets'][1]['data'][] = $earned == 0 ? null : $earned; } return $data; diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 7580f30a78..10725adce6 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -5,8 +5,11 @@ use Carbon\Carbon; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use FireflyIII\Support\CacheProperties; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Collection; use Input; +use Navigation; use Preferences; use Session; use URL; @@ -139,6 +142,30 @@ class CategoryController extends Controller return view('categories.noCategory', compact('list', 'subTitle')); } + /** + * @param CategoryRepositoryInterface $repository + * @param Category $category + * + * @return \Illuminate\View\View + */ + public function showWithDate(CategoryRepositoryInterface $repository, Category $category, $date) + { + $carbon = new Carbon($date); + $range = Preferences::get('viewRange', '1M')->data; + $start = Navigation::startOfPeriod($carbon, $range); + $end = Navigation::endOfPeriod($carbon, $range); + + $hideCategory = true; // used in list. + $page = intval(Input::get('page')); + + $set = $repository->getJournalsInRange($category, $page, $start, $end); + $count = $repository->countJournalsInRange($category, $start, $end); + $journals = new LengthAwarePaginator($set, $count, 50, $page); + $journals->setPath('categories/show/' . $category->id . '/' . $date); + + return view('categories.show_with_date', compact('category', 'journals', 'hideCategory')); + } + /** * @param CategoryRepositoryInterface $repository * @param Category $category @@ -156,7 +183,43 @@ class CategoryController extends Controller $journals = new LengthAwarePaginator($set, $count, 50, $page); $journals->setPath('categories/show/' . $category->id); - return view('categories.show', compact('category', 'journals', 'hideCategory', 'totalSum', 'periodSum')); + // list of ranges for list of periods: + + // oldest transaction in category: + $start = $repository->getFirstActivityDate($category); + $range = Preferences::get('viewRange', '1M')->data; + $start = Navigation::startOfPeriod($start, $range); + $end = Navigation::endOfX(new Carbon, $range); + $entries = new Collection; + + // chart properties for cache: + $cache = new CacheProperties(); + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('category-show'); + $cache->addProperty($category->id); + if ($cache->has()) { + $entries = $cache->get(); + } else { + + while ($end >= $start) { + $end = Navigation::startOfPeriod($end, $range); + $currentEnd = Navigation::endOfPeriod($end, $range); + + // here do something. + $spent = $repository->spentInPeriod($category, $end, $currentEnd); + $earned = $repository->earnedInPeriod($category, $end, $currentEnd); + $dateStr = $end->format('Y-m-d'); + $dateName = Navigation::periodShow($end, $range); + $entries->push([$dateStr, $dateName, $spent, $earned]); + + $end = Navigation::subtractPeriod($end, $range, 1); + + } + $cache->store($entries); + } + + return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum')); } /** diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index f7d735aef6..374072ea6a 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -69,7 +69,6 @@ class CategoryController extends Controller $earned = $repository->earnedInPeriod($category, $start, $currentEnd); $entries->push([clone $start, $spent, $earned]); $start = Navigation::addPeriod($start, $range, 0); - } $data = $this->generator->all($entries); diff --git a/app/Http/routes.php b/app/Http/routes.php index 0471e559b9..cd1a57bd18 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -244,6 +244,7 @@ Route::group( Route::get('/categories/edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'categories.edit']); Route::get('/categories/delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'categories.delete']); Route::get('/categories/show/{category}', ['uses' => 'CategoryController@show', 'as' => 'categories.show']); + Route::get('/categories/show/{category}/{date}', ['uses' => 'CategoryController@showWithDate', 'as' => 'categories.show.date']); Route::get('/categories/list/noCategory', ['uses' => 'CategoryController@noCategory', 'as' => 'categories.noCategory']); Route::post('/categories/store', ['uses' => 'CategoryController@store', 'as' => 'categories.store']); Route::post('/categories/update/{category}', ['uses' => 'CategoryController@update', 'as' => 'categories.update']); diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index a1825a049c..c0e838c50d 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -309,7 +309,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito $cache->addProperty($category->id); $cache->addProperty($start); $cache->addProperty($end); - $cache->addProperty('spentInPeriod'); + $cache->addProperty('earnedInPeriod'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore @@ -323,4 +323,36 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito return $sum; } + + /** + * @param Category $category + * @param int $page + * + * @return Collection + */ + public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end) + { + $offset = $page > 0 ? $page * 50 : 0; + + return $category->transactionJournals() + ->after($start) + ->before($end) + ->withRelevantData()->take(50)->offset($offset) + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get( + ['transaction_journals.*'] + ); + } + + /** + * @param Category $category + * + * @return int + */ + public function countJournalsInRange(Category $category, Carbon $start, Carbon $end) + { + return $category->transactionJournals()->before($end)->after($start)->count(); + } } diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index 2f2e3d1edc..06e40064a0 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -20,6 +20,13 @@ interface CategoryRepositoryInterface */ public function countJournals(Category $category); + /** + * @param Category $category + * + * @return int + */ + public function countJournalsInRange(Category $category, Carbon $start, Carbon $end); + /** * @param Category $category * @@ -57,6 +64,14 @@ interface CategoryRepositoryInterface */ public function getJournals(Category $category, $page); + /** + * @param Category $category + * @param int $page + * + * @return Collection + */ + public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end); + /** * This method returns the sum of the journals in the category, optionally * limited by a start or end date. diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index d22b0250e6..773addd142 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -106,13 +106,14 @@ class Navigation * * @return Carbon */ - public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate) + public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate = null) { $functionMap = [ 'daily' => 'endOfDay', 'week' => 'endOfWeek', 'weekly' => 'endOfWeek', 'month' => 'endOfMonth', + '1M' => 'endOfMonth', 'monthly' => 'endOfMonth', 'quarter' => 'lastOfQuarter', 'quarterly' => 'lastOfQuarter', @@ -128,7 +129,7 @@ class Navigation } - if ($currentEnd > $maxDate) { + if (!is_null($maxDate) && $currentEnd > $maxDate) { return clone $maxDate; } @@ -149,6 +150,7 @@ class Navigation 'week' => 'Week %W, %Y', 'weekly' => 'Week %W, %Y', 'quarter' => '%B %Y', + '1M' => '%B %Y', 'month' => '%B %Y', 'monthly' => '%B %Y', 'year' => '%Y', @@ -224,6 +226,7 @@ class Navigation 'week' => 'subWeeks', 'weekly' => 'subWeeks', 'month' => 'subMonths', + '1M' => 'subMonths', 'monthly' => 'subMonths', 'year' => 'subYears', 'yearly' => 'subYears', diff --git a/resources/twig/categories/show.twig b/resources/twig/categories/show.twig index 38e95fee51..88803214ca 100644 --- a/resources/twig/categories/show.twig +++ b/resources/twig/categories/show.twig @@ -38,7 +38,7 @@
-
+
@@ -49,6 +49,33 @@
+
+ {% for entry in entries %} +
+ +
+ + {% if entry[2] != 0 %} + + + + + {% endif %} + {% if entry[3] != 0 %} + + + + + {% endif %} +
{{ 'spent'|_ }}{{ entry[2]|formatAmount }}
{{ 'earned'|_ }}{{ entry[3]|formatAmount }}
+
+
+ + {% endfor %} +
{% endblock %} diff --git a/resources/twig/categories/show_with_date.twig b/resources/twig/categories/show_with_date.twig new file mode 100644 index 0000000000..50efe41d60 --- /dev/null +++ b/resources/twig/categories/show_with_date.twig @@ -0,0 +1,75 @@ +{% extends "./layout/default.twig" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category) }} +{% endblock %} + +{% block content %} +
+
+
+
+

{{ 'overview'|_ }} (month)

+
+
+ {% if Config.get('firefly.chart') == 'google' %} +
+ {% endif %} + {% if Config.get('firefly.chart') == 'chartjs' %} + + {% endif %} +
+
+
+
+
+
+

{{ 'overview'|_ }} (all)

+
+
+ {% if Config.get('firefly.chart') == 'google' %} +
+ {% endif %} + {% if Config.get('firefly.chart') == 'chartjs' %} + + {% endif %} +
+
+
+
+ +
+
+ +
+
+

{{ 'transactions'|_ }}

+
+
+ {% include 'list/journals' %} +
+
+
+
+ +{% endblock %} +{% block scripts %} + + + {% if Config.get('firefly.chart') == 'google' %} + + + {% endif %} + {% if Config.get('firefly.chart') == 'chartjs' %} + + + {% endif %} + + +{% endblock %} diff --git a/resources/twig/emails/registered-html.twig b/resources/twig/emails/registered-html.twig index a776c2299a..6a2728beeb 100644 --- a/resources/twig/emails/registered-html.twig +++ b/resources/twig/emails/registered-html.twig @@ -19,7 +19,7 @@
  • If you have forgotten your password already, please reset it using - the password reset tool. + the password reset tool.
  • There is a help-icon in the top right corner of each page. If you need help, click it! diff --git a/resources/twig/emails/registered.twig b/resources/twig/emails/registered.twig index bd8aae7d70..07c2a3efde 100644 --- a/resources/twig/emails/registered.twig +++ b/resources/twig/emails/registered.twig @@ -12,7 +12,7 @@ Firefly III: {{ address }} Password reset: -{{ address }}password/email +{{ address }}/password/email Documentation: https://github.com/JC5/firefly-iii/wiki/First-use From 0bde72d3df0cfff39e8f784f054bc56814ec69c2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:04:22 +0200 Subject: [PATCH 16/66] Spent should not be negative for the chart. --- app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php index 196a5ecd2f..6d26478e21 100644 --- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php +++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php @@ -48,7 +48,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator $spent = round($entry[1], 2); $earned = round($entry[2], 2); - $data['datasets'][0]['data'][] = $spent == 0 ? null : $spent; + $data['datasets'][0]['data'][] = $spent == 0 ? null : $spent * -1; $data['datasets'][1]['data'][] = $earned == 0 ? null : $earned; } From 968ec0853faae292baca4681e7ec94248fa94aa9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:06:06 +0200 Subject: [PATCH 17/66] Fixed the chart. Forgot an argument. --- app/Http/Controllers/Chart/CategoryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 374072ea6a..8f1931665f 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -148,7 +148,7 @@ class CategoryController extends Controller while ($start <= $end) { $spent = $repository->spentOnDaySumCorrected($category, $start); - $entries->push([clone $start, $spent]); + $entries->push([clone $start, $spent, 0]); $start->addDay(); } From cb985f58975314a5ec007bfb615426a770ff2266 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:08:10 +0200 Subject: [PATCH 18/66] Make sure the month chart can show the spent / earned. --- app/Http/Controllers/Chart/CategoryController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 8f1931665f..45556136ab 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -146,9 +146,14 @@ class CategoryController extends Controller while ($start <= $end) { - $spent = $repository->spentOnDaySumCorrected($category, $start); + $spent = $repository->spentOnDaySumCorrected($category, $start); + $earned = 0; + if ($spent < 0) { + $earned = $spent * -1; + $spent = 0; + } - $entries->push([clone $start, $spent, 0]); + $entries->push([clone $start, $spent, $earned]); $start->addDay(); } From 0a8f4017bdb1a247df187e88ab096c3a4cfdcc99 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:18:50 +0200 Subject: [PATCH 19/66] Fix some chart things. Again. --- .../Controllers/Chart/CategoryController.php | 2 +- app/Repositories/Category/CategoryRepository.php | 16 +++++++++++++++- .../Category/CategoryRepositoryInterface.php | 11 +++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 45556136ab..c28194764c 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -147,7 +147,7 @@ class CategoryController extends Controller while ($start <= $end) { $spent = $repository->spentOnDaySumCorrected($category, $start); - $earned = 0; + $earned = $repository->earnedOnDaySumCorrected($category, $start); if ($spent < 0) { $earned = $spent * -1; $spent = 0; diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index c0e838c50d..3212a5121a 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -200,7 +200,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito */ public function spentOnDaySumCorrected(Category $category, Carbon $date) { - return $category->transactionjournals()->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); } /** @@ -355,4 +355,18 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito { return $category->transactionJournals()->before($end)->after($start)->count(); } + + /** + * + * Corrected for tags. + * + * @param Category $category + * @param Carbon $date + * + * @return float + */ + public function earnedOnDaySumCorrected(Category $category, Carbon $date) + { + return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + } } diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index 06e40064a0..e424927fc8 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -145,6 +145,17 @@ interface CategoryRepositoryInterface */ public function spentOnDaySumCorrected(Category $category, Carbon $date); + /** + * + * Corrected for tags. + * + * @param Category $category + * @param Carbon $date + * + * @return float + */ + public function earnedOnDaySumCorrected(Category $category, Carbon $date); + /** * @param array $data * From 72b5895217effa33646577562534b5f424a62008 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:25:17 +0200 Subject: [PATCH 20/66] Added a subtitle to the category view. --- app/Http/Controllers/CategoryController.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 10725adce6..29c82ef1f6 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -150,20 +150,21 @@ class CategoryController extends Controller */ public function showWithDate(CategoryRepositoryInterface $repository, Category $category, $date) { - $carbon = new Carbon($date); - $range = Preferences::get('viewRange', '1M')->data; - $start = Navigation::startOfPeriod($carbon, $range); - $end = Navigation::endOfPeriod($carbon, $range); + $carbon = new Carbon($date); + $range = Preferences::get('viewRange', '1M')->data; + $start = Navigation::startOfPeriod($carbon, $range); + $end = Navigation::endOfPeriod($carbon, $range); + $subTitle = $category->name; $hideCategory = true; // used in list. $page = intval(Input::get('page')); - $set = $repository->getJournalsInRange($category, $page, $start, $end); - $count = $repository->countJournalsInRange($category, $start, $end); - $journals = new LengthAwarePaginator($set, $count, 50, $page); + $set = $repository->getJournalsInRange($category, $page, $start, $end); + $count = $repository->countJournalsInRange($category, $start, $end); + $journals = new LengthAwarePaginator($set, $count, 50, $page); $journals->setPath('categories/show/' . $category->id . '/' . $date); - return view('categories.show_with_date', compact('category', 'journals', 'hideCategory')); + return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle')); } /** @@ -180,6 +181,7 @@ class CategoryController extends Controller $count = $repository->countJournals($category); $totalSum = $repository->journalsSum($category); $periodSum = $repository->journalsSum($category, Session::get('start'), Session::get('end')); + $subTitle = $category->name; $journals = new LengthAwarePaginator($set, $count, 50, $page); $journals->setPath('categories/show/' . $category->id); @@ -219,7 +221,7 @@ class CategoryController extends Controller $cache->store($entries); } - return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum')); + return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum', 'subTitle')); } /** From 491298e1cb035a679bb0927ae66577fc03c4e968 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:33:45 +0200 Subject: [PATCH 21/66] Some fixes in titles and bread crumbs. --- app/Http/Controllers/CategoryController.php | 2 +- app/Http/breadcrumbs.php | 13 +++++++++++++ resources/twig/categories/show_with_date.twig | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 29c82ef1f6..f5088208fa 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -164,7 +164,7 @@ class CategoryController extends Controller $journals = new LengthAwarePaginator($set, $count, 50, $page); $journals->setPath('categories/show/' . $category->id . '/' . $date); - return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle')); + return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle','carbon')); } /** diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 6e7d3c6537..5d360aaf4c 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -154,6 +154,19 @@ Breadcrumbs::register( } ); +Breadcrumbs::register( + 'categories.show.date', function (Generator $breadcrumbs, Category $category, Carbon $date) { + + // get current period preference. + $range = Preferences::get('viewRange', '1M')->data; + + $breadcrumbs->parent('categories.index'); + $breadcrumbs->push(e($category->name), route('categories.show', [$category->id])); + $breadcrumbs->push(Navigation::periodShow($date, $range), route('categories.show.date', [$category->id, $date->format('Y-m-d')])); + +} +); + Breadcrumbs::register( 'categories.noCategory', function (Generator $breadcrumbs, $subTitle) { $breadcrumbs->parent('categories.index'); diff --git a/resources/twig/categories/show_with_date.twig b/resources/twig/categories/show_with_date.twig index 50efe41d60..0d136db2e2 100644 --- a/resources/twig/categories/show_with_date.twig +++ b/resources/twig/categories/show_with_date.twig @@ -1,10 +1,11 @@ {% extends "./layout/default.twig" %} {% block breadcrumbs %} - {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category) }} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category, carbon) }} {% endblock %} {% block content %} +
    From fcc3af61365aeaaa898978952341099aedc58b24 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:38:36 +0200 Subject: [PATCH 22/66] Fixed something. --- app/Http/Controllers/Chart/CategoryController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index c28194764c..09d120183a 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -148,11 +148,6 @@ class CategoryController extends Controller while ($start <= $end) { $spent = $repository->spentOnDaySumCorrected($category, $start); $earned = $repository->earnedOnDaySumCorrected($category, $start); - if ($spent < 0) { - $earned = $spent * -1; - $spent = 0; - } - $entries->push([clone $start, $spent, $earned]); $start->addDay(); } From e12d13c8389c16167ba1f18f6b0f39ec9955a9ed Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 16:43:34 +0200 Subject: [PATCH 23/66] Fixed a negative chart. --- app/Http/Controllers/Chart/BudgetController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 7e171df804..0e017fd380 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -68,7 +68,7 @@ class BudgetController extends Controller $end->subDay(); $chartDate = clone $end; $chartDate->startOfMonth(); - $spent = $repository->balanceInPeriod($budget, $first, $end); + $spent = $repository->balanceInPeriod($budget, $first, $end) * -1; $entries->push([$chartDate, $spent]); $first = Navigation::addPeriod($first, $range, 0); } From 38bc38bf267eb7a6da941bb599fb8fef44e1669f Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 17:28:42 +0200 Subject: [PATCH 24/66] Add some period things. --- app/Support/Navigation.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 773addd142..50e0faf2b3 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -109,14 +109,18 @@ class Navigation public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate = null) { $functionMap = [ + '1D' => 'endOfDay', 'daily' => 'endOfDay', + '1W' => 'endOfWeek', 'week' => 'endOfWeek', 'weekly' => 'endOfWeek', 'month' => 'endOfMonth', '1M' => 'endOfMonth', 'monthly' => 'endOfMonth', + '3M' => 'lastOfQuarter', 'quarter' => 'lastOfQuarter', 'quarterly' => 'lastOfQuarter', + '1Y' => 'endOfYear', 'year' => 'endOfYear', 'yearly' => 'endOfYear', ]; @@ -146,13 +150,17 @@ class Navigation public function periodShow(Carbon $date, $repeatFrequency) { $formatMap = [ + '1D' => '%e %B %Y', 'daily' => '%e %B %Y', + '1W' => 'Week %W, %Y', 'week' => 'Week %W, %Y', 'weekly' => 'Week %W, %Y', + '3M' => '%B %Y', 'quarter' => '%B %Y', '1M' => '%B %Y', 'month' => '%B %Y', 'monthly' => '%B %Y', + '1Y' => '%Y', 'year' => '%Y', 'yearly' => '%Y', @@ -220,10 +228,12 @@ class Navigation public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1) { $date = clone $theDate; - + // 1D 1W 1M 3M 6M 1Y $functionMap = [ + '1D' => 'subDays', 'daily' => 'subDays', 'week' => 'subWeeks', + '1W' => 'subWeeks', 'weekly' => 'subWeeks', 'month' => 'subMonths', '1M' => 'subMonths', From 73cfbbd2ba623e48ae86562a7750cc0d8b692565 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 19:28:39 +0200 Subject: [PATCH 25/66] Fix some things so the date range has a better display. --- .../Chart/Category/ChartJsCategoryChartGenerator.php | 11 ++++++----- app/Http/Controllers/Chart/CategoryController.php | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php index 6d26478e21..c5ff681ca1 100644 --- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php +++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php @@ -25,8 +25,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator { // language: - $language = Preferences::get('language', 'en')->data; - $format = Config::get('firefly.' . $dateFormat . '.' . $language); + //$language = Preferences::get('language', 'en')->data; + + //$format = Config::get('firefly.' . $dateFormat . '.' . $language); $data = [ 'count' => 2, @@ -44,9 +45,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator ]; foreach ($entries as $entry) { - $data['labels'][] = $entry[0]->formatLocalized($format); - $spent = round($entry[1], 2); - $earned = round($entry[2], 2); + $data['labels'][] = $entry[1];//$entry[0]->formatLocalized($format); + $spent = round($entry[2], 2); + $earned = round($entry[3], 2); $data['datasets'][0]['data'][] = $spent == 0 ? null : $spent * -1; $data['datasets'][1]['data'][] = $earned == 0 ? null : $earned; diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 09d120183a..52e9d1fa4b 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -67,7 +67,8 @@ class CategoryController extends Controller $currentEnd = Navigation::endOfPeriod($start, $range); $spent = $repository->spentInPeriod($category, $start, $currentEnd); $earned = $repository->earnedInPeriod($category, $start, $currentEnd); - $entries->push([clone $start, $spent, $earned]); + $date = Navigation::periodShow($start, $range); + $entries->push([clone $start, $date, $spent, $earned]); $start = Navigation::addPeriod($start, $range, 0); } @@ -148,7 +149,8 @@ class CategoryController extends Controller while ($start <= $end) { $spent = $repository->spentOnDaySumCorrected($category, $start); $earned = $repository->earnedOnDaySumCorrected($category, $start); - $entries->push([clone $start, $spent, $earned]); + $date = Navigation::periodShow($start, '1D'); + $entries->push([clone $start, $date, $spent, $earned]); $start->addDay(); } From 66dbd48b765c2398a9185f54b97eec07cc682b21 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 19:36:03 +0200 Subject: [PATCH 26/66] Fix something with the dates. --- resources/twig/categories/show.twig | 50 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/resources/twig/categories/show.twig b/resources/twig/categories/show.twig index 88803214ca..ca4f09bfe8 100644 --- a/resources/twig/categories/show.twig +++ b/resources/twig/categories/show.twig @@ -50,31 +50,33 @@
    - {% for entry in entries %} -
    - -
    - - {% if entry[2] != 0 %} - - - - - {% endif %} - {% if entry[3] != 0 %} - - - - - {% endif %} -
    {{ 'spent'|_ }}{{ entry[2]|formatAmount }}
    {{ 'earned'|_ }}{{ entry[3]|formatAmount }}
    -
    -
    + {% for entry in entries %} + {% if entry[2] != 0 or entry[3] != 0 %} +
    + +
    + + {% if entry[2] != 0 %} + + + + + {% endif %} + {% if entry[3] != 0 %} + + + + + {% endif %} +
    {{ 'spent'|_ }}{{ entry[2]|formatAmount }}
    {{ 'earned'|_ }}{{ entry[3]|formatAmount }}
    +
    +
    + {% endif %} - {% endfor %} + {% endfor %}
    From e2790ca6c11c4c0a1f5e27382f503b89c88e5757 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 20:13:43 +0200 Subject: [PATCH 27/66] Try to limit the collection returned to the user. --- app/Http/Controllers/Chart/CategoryController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 52e9d1fa4b..360aeb26d0 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -71,6 +71,10 @@ class CategoryController extends Controller $entries->push([clone $start, $date, $spent, $earned]); $start = Navigation::addPeriod($start, $range, 0); } + // limit the set to the last 40: + $entries = $entries->reverse(); + $entries = $entries->slice(0, 40); + $entries = $entries->reverse(); $data = $this->generator->all($entries); $cache->store($data); From 5953f691d12f377d4e86aa8eaabdc1fee459f479 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 20:15:38 +0200 Subject: [PATCH 28/66] More should fit. --- app/Http/Controllers/Chart/CategoryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 360aeb26d0..efe4419f85 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -73,7 +73,7 @@ class CategoryController extends Controller } // limit the set to the last 40: $entries = $entries->reverse(); - $entries = $entries->slice(0, 40); + $entries = $entries->slice(0, 48); $entries = $entries->reverse(); $data = $this->generator->all($entries); From 466e81d56ae046eb41920a5ccce6f1547fd2e86e Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 20:25:22 +0200 Subject: [PATCH 29/66] Fixed some sorting. --- public/js/accounts.js | 4 ++++ public/js/piggy-banks.js | 11 ++++------- resources/twig/list/journals.twig | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/public/js/accounts.js b/public/js/accounts.js index 7d390f74f5..14f5054583 100644 --- a/public/js/accounts.js +++ b/public/js/accounts.js @@ -13,6 +13,7 @@ var fixHelper = function (e, ui) { $(function () { "use strict"; if (typeof(lineChart) === "function" && typeof accountID !== 'undefined') { + lineChart('chart/account/' + accountID, 'overview-chart'); } @@ -26,6 +27,8 @@ $(function () { handle: '.handle' } ).disableSelection(); + } else { + console.log('its null'); } }); @@ -34,6 +37,7 @@ $(function () { function sortStop(event, ui) { "use strict"; var current = $(ui.item); + console.log('sort stop'); var thisDate = current.data('date'); var originalBG = current.css('backgroundColor'); diff --git a/public/js/piggy-banks.js b/public/js/piggy-banks.js index 36c14e20bc..4b8aa3ab6b 100644 --- a/public/js/piggy-banks.js +++ b/public/js/piggy-banks.js @@ -1,15 +1,12 @@ /* globals $, lineChart, token, piggyBankID */ // Return a helper with preserved width of cells -var fixHelper = function (e, tr) { +var fixHelper = function (e, ui) { "use strict"; - var $originals = tr.children(); - var $helper = tr.clone(); - $helper.children().each(function (index) { - // Set helper cell sizes to match the original sizes - $(this).width($originals.eq(index).width()); + ui.children().each(function () { + $(this).width($(this).width()); }); - return $helper; + return ui; }; $(function () { diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index aa739484bb..f3cae8d9ca 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -1,6 +1,6 @@ {{ journals.render|raw }} - +
    From cdc0e3cfd85177bdbd5b73a2575b3843971ceece Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Sep 2015 20:40:24 +0200 Subject: [PATCH 30/66] Some cleaning up. --- .../Events/ConnectJournalToPiggyBank.php | 2 +- app/Helpers/Collection/Expense.php | 4 +- app/Helpers/Collection/Income.php | 4 +- app/Helpers/Report/ReportHelper.php | 4 +- .../Controllers/TransactionController.php | 2 +- app/Models/TransactionJournal.php | 40 +++++-------------- .../Category/CategoryRepository.php | 10 ++--- .../Shared/ComponentRepository.php | 4 +- app/Support/Twig/Journal.php | 2 +- resources/twig/list/journals.twig | 8 +--- 10 files changed, 27 insertions(+), 53 deletions(-) diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index cc75dca89f..d4c9cef764 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -53,7 +53,7 @@ class ConnectJournalToPiggyBank } bcscale(2); - $amount = $journal->actual_amount; + $amount = $journal->amount_positive; // if piggy account matches source account, the amount is positive if ($piggyBank->account_id == $journal->source_account->id) { $amount = $amount * -1; diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index 22f189329f..e165feb365 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -36,7 +36,7 @@ class Expense $accountId = $entry->account_id; if (!$this->expenses->has($accountId)) { $newObject = new stdClass; - $newObject->amount = strval(round($entry->actual_amount, 2)); + $newObject->amount = strval(round($entry->amount_positive, 2)); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; @@ -44,7 +44,7 @@ class Expense } else { bcscale(2); $existing = $this->expenses->get($accountId); - $existing->amount = bcadd($existing->amount, $entry->actual_amount); + $existing->amount = bcadd($existing->amount, $entry->amount_positive); $existing->count++; $this->expenses->put($accountId, $existing); } diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index 5a80b7a9b1..9d1389dfcb 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -38,7 +38,7 @@ class Income $accountId = $entry->account_id; if (!$this->incomes->has($accountId)) { $newObject = new stdClass; - $newObject->amount = strval(round($entry->actual_amount, 2)); + $newObject->amount = strval(round($entry->amount_positive, 2)); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; @@ -46,7 +46,7 @@ class Income } else { bcscale(2); $existing = $this->incomes->get($accountId); - $existing->amount = bcadd($existing->amount, $entry->actual_amount); + $existing->amount = bcadd($existing->amount, $entry->amount_positive); $existing->count++; $this->incomes->put($accountId, $existing); } diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 8281b99629..97090de7da 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -350,7 +350,7 @@ class ReportHelper implements ReportHelperInterface $object = new Expense; $set = $this->query->expenseInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->actual_amount); + $object->addToTotal($entry->amount_positive); $object->addOrCreateExpense($entry); } @@ -371,7 +371,7 @@ class ReportHelper implements ReportHelperInterface $object = new Income; $set = $this->query->incomeInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->actual_amount); + $object->addToTotal($entry->amount_positive); $object->addOrCreateIncome($entry); } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index aa53a87ba1..ef8c33d0dc 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -179,7 +179,7 @@ class TransactionController extends Controller $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; } - $preFilled['amount'] = $journal->actual_amount; + $preFilled['amount'] = $journal->amount_positive; if ($journal->transactionType->type == 'Withdrawal') { $preFilled['account_id'] = $journal->source_account->id; diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index a2b1fc3f8b..3248980fb3 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -69,6 +69,7 @@ use Watson\Validating\ValidatingTrait; * @property string $name * @property-read string $symbol * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments + * @property-read mixed $amount_positive */ class TransactionJournal extends Model { @@ -120,7 +121,7 @@ class TransactionJournal extends Model /** * @return string */ - public function getActualAmountAttribute() + public function getAmountPositiveAttribute() { $amount = '0'; /** @var Transaction $t */ @@ -146,18 +147,11 @@ class TransactionJournal extends Model } bcscale(2); - $set = $this->transactions->sortByDesc('amount'); - $amount = $set->first()->amount; - - if (intval($this->tag_count) === 1) { - // get amount for single tag: - $amount = $this->amountByTag($this->tags()->first(), $amount); - } - - if (intval($this->tag_count) > 1) { - // get amount for either tag. - $amount = $this->amountByTags($amount); - + $type = $this->transactionType->type; + $transaction = $this->transactions->sortByDesc('amount')->first(); + $amount = $transaction->amount; + if ($type == 'Withdrawal') { + $amount = $amount * -1; } $cache->store($amount); @@ -176,7 +170,7 @@ class TransactionJournal extends Model if ($this->transactionType->type == 'Withdrawal') { $others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get(); foreach ($others as $other) { - $amount = bcsub($amount, $other->actual_amount); + $amount = bcsub($amount, $other->amount_positive); } return $amount; @@ -199,7 +193,7 @@ class TransactionJournal extends Model if ($this->transactionType->type == 'Withdrawal') { $transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first(); if ($transfer) { - $amount = bcsub($amount, $transfer->actual_amount); + $amount = bcsub($amount, $transfer->amount_positive); return $amount; } @@ -260,22 +254,6 @@ class TransactionJournal extends Model return $amount; } - /** - * @return string - */ - public function getCorrectAmountAttribute() - { - - switch ($this->transactionType->type) { - case 'Deposit': - return $this->transactions()->where('amount', '>', 0)->first()->amount; - case 'Withdrawal': - return $this->transactions()->where('amount', '<', 0)->first()->amount; - } - - return $this->transactions()->where('amount', '>', 0)->first()->amount; - } - /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\HasMany diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 3212a5121a..035f1079ed 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -200,7 +200,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito */ public function spentOnDaySumCorrected(Category $category, Carbon $date) { - return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount'); } /** @@ -260,7 +260,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito $query->before($end); } - return $query->get(['transaction_journals.*'])->sum('correct_amount'); + return $query->get(['transaction_journals.*'])->sum('amount'); } @@ -286,7 +286,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito } $sum = $category->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start)->get(['transaction_journals.*'])->sum( - 'correct_amount' + 'amount' ); $cache->store($sum); @@ -316,7 +316,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito } $sum = $category->transactionjournals()->transactionTypes(['Deposit'])->before($end)->after($start)->get(['transaction_journals.*'])->sum( - 'correct_amount' + 'amount' ); $cache->store($sum); @@ -367,6 +367,6 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito */ public function earnedOnDaySumCorrected(Category $category, Carbon $date) { - return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('amount'); } } diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index 632ce9db63..7edbb7bfb3 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -40,7 +40,7 @@ class ComponentRepository if ($shared === true) { // shared is true: always ignore transfers between accounts! $sum = $object->transactionjournals()->transactionTypes(['Withdrawal', 'Deposit', 'Opening balance'])->before($end)->after($start) - ->get(['transaction_journals.*'])->sum('correct_amount'); + ->get(['transaction_journals.*'])->sum('amount'); } else { // do something else, SEE budgets. // get all journals in this month where the asset account is NOT shared. @@ -52,7 +52,7 @@ class ComponentRepository 'account_meta', function (JoinClause $join) { $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); } - )->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('correct_amount'); + )->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('amount'); } $cache->store($sum); diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 1be638061d..62c07048de 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -181,7 +181,7 @@ class Journal extends Twig_Extension if ($tag->tagMode == 'balancingAct') { // return tag formatted for a "balancing act", even if other // tags are present. - $amount = app('amount')->format($journal->actual_amount, false); + $amount = app('amount')->format($journal->amount_positive, false); $string = ' ' . $tag->tag . ''; diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index f3cae8d9ca..ddc9c6e64c 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -40,7 +40,7 @@ {% else %} - {% set _sum = _sum + journal.correct_amount %} + {% set _sum = _sum + journal.amount %} - +
    Invalid journal: Found {{ journal.transactions|length }} transaction(s)
    - {% if not hideTags %} - {{ relevantTags(journal)|raw }} - {% else %} - {{ journal.correct_amount|formatAmount }} - {% endif %} + {{ journal.amount|formatAmount }}
    {{ 'spent'|_ }}{{ budget.spent|formatAmount }}{{ (budget.spent*-1)|formatAmountPlain }}
@@ -180,7 +179,7 @@ {% block scripts %}