From f0f965421c00029438365df03d5689f34cf547de Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 22 Nov 2014 07:30:46 +0100 Subject: [PATCH] Implemented some todo's. --- app/controllers/TransactionController.php | 15 ++++++++++ app/models/Account.php | 20 ------------- app/views/reminders/show.blade.php | 1 - app/views/transactions/show.blade.php | 2 +- bootstrap/start.php | 2 ++ public/assets/javascript/firefly/gcharts.js | 31 ++++++++++----------- public/index.php | 4 +-- 7 files changed, 33 insertions(+), 42 deletions(-) diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 048c470ce5..1f5caa78f6 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -277,6 +277,21 @@ class TransactionController extends BaseController */ public function show(TransactionJournal $journal) { + $journal->transactions->each( + function(\Transaction $t) use ($journal) { + $t->before = floatval( + $t->account->transactions()->leftJoin( + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + )->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where( + 'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s') + )->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount') + ); + $t->after = $t->before + $t->amount; + } + ); + + + return View::make('transactions.show')->with('journal', $journal)->with( 'subTitle', $journal->transactionType->type . ' "' . $journal->description . '"' ); diff --git a/app/models/Account.php b/app/models/Account.php index ad6f210b67..63f6790b48 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -66,26 +66,6 @@ class Account extends Ardent { return $this->hasMany('Transaction'); } - - /** - * - * TODO remove this method in favour of something in the FireflyIII libraries. - * - * @param TransactionJournal $journal - * - * @return float - */ - public function balanceBeforeJournal(TransactionJournal $journal) - { - return floatval( - $this->transactions()->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' - )->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where( - 'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s') - )->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount') - ); - } - /** * TODO remove this method in favour of something in the FireflyIII libraries. * diff --git a/app/views/reminders/show.blade.php b/app/views/reminders/show.blade.php index 34d02d9865..0b12c927c5 100644 --- a/app/views/reminders/show.blade.php +++ b/app/views/reminders/show.blade.php @@ -19,7 +19,6 @@ @endif

- I want to do this I already did this Not this time diff --git a/app/views/transactions/show.blade.php b/app/views/transactions/show.blade.php index b4c3eb5414..3339468ef4 100644 --- a/app/views/transactions/show.blade.php +++ b/app/views/transactions/show.blade.php @@ -74,7 +74,7 @@ New balance - {{mf($t->account->balanceBeforeJournal($journal))}} → {{mf($t->account->balanceBeforeJournal($journal) + $t->amount)}} + {{mf($t->before)}} → {{mf($t->after)}} @if(!is_null($t->description)) diff --git a/bootstrap/start.php b/bootstrap/start.php index 3f375d48cf..e05212f1db 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -115,4 +115,6 @@ Event::subscribe('FireflyIII\Event\TransactionJournal'); // see if the various has-many-throughs actually get used. // set very tight rules on all models // create custom uniquely rules. +// TODO add "Create new X" button to any list there is: categories, accounts, piggies, etc. +// TODO Install PHP5 and code thing and create very small methods. return $app; diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js index 3636599c68..c0bc5dd090 100644 --- a/public/assets/javascript/firefly/gcharts.js +++ b/public/assets/javascript/firefly/gcharts.js @@ -1,9 +1,6 @@ google.load('visualization', '1.1', {'packages': ['corechart', 'bar', 'sankey', 'table']}); -/* -TODO manage the combination of default options AND custom options. - */ -function googleLineChart(URL, container) { +function googleLineChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -31,7 +28,7 @@ function googleLineChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultLineChartOptions); + chart.draw(gdata, options || defaultLineChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -41,7 +38,7 @@ function googleLineChart(URL, container) { } } -function googleBarChart(URL, container) { +function googleBarChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -69,7 +66,7 @@ function googleBarChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultBarChartOptions); + chart.draw(gdata, options || defaultBarChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -79,7 +76,7 @@ function googleBarChart(URL, container) { } } -function googleColumnChart(URL, container) { +function googleColumnChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -106,7 +103,7 @@ function googleColumnChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultColumnChartOptions); + chart.draw(gdata, options || defaultColumnChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -116,7 +113,7 @@ function googleColumnChart(URL, container) { } } -function googleStackedColumnChart(URL, container) { +function googleStackedColumnChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -143,7 +140,7 @@ function googleStackedColumnChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultStackedColumnChartOptions); + chart.draw(gdata, options || defaultStackedColumnChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -153,7 +150,7 @@ function googleStackedColumnChart(URL, container) { } } -function googleComboChart(URL, container) { +function googleComboChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -180,7 +177,7 @@ function googleComboChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultComboChartOptions); + chart.draw(gdata, options || defaultComboChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -190,7 +187,7 @@ function googleComboChart(URL, container) { } } -function googlePieChart(URL, container) { +function googlePieChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -218,7 +215,7 @@ function googlePieChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultPieChartOptions); + chart.draw(gdata, options || defaultPieChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); @@ -228,7 +225,7 @@ function googlePieChart(URL, container) { } } -function googleSankeyChart(URL, container) { +function googleSankeyChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { /* @@ -258,7 +255,7 @@ function googleSankeyChart(URL, container) { /* Draw it: */ - chart.draw(gdata, defaultSankeyChartOptions); + chart.draw(gdata, options || defaultSankeyChartOptions); }).fail(function () { $('#' + container).addClass('google-chart-error'); diff --git a/public/index.php b/public/index.php index c4f34cbfec..50f994dcdc 100644 --- a/public/index.php +++ b/public/index.php @@ -20,9 +20,7 @@ require __DIR__.'/../bootstrap/autoload.php'; -/* - * TODO: add "Create new X" button to any list there is: categories, accounts, piggies, etc. - */ + /* |--------------------------------------------------------------------------