From 139d98590422a9d8610f292c934d01ab4147ac24 Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Fri, 7 Nov 2014 11:18:06 +0100 Subject: [PATCH] All kinds of fixes and things. I should really start organizing. --- app/controllers/GoogleTableController.php | 51 ++++++ app/controllers/HomeController.php | 59 ++++++- app/lib/FireflyIII/Database/Account.php | 6 +- app/lib/FireflyIII/Database/AccountType.php | 1 - .../Database/TransactionJournal.php | 2 +- app/routes.php | 2 + app/views/accounts/asset.blade.php | 18 --- app/views/accounts/expense.blade.php | 28 ---- app/views/accounts/index.blade.php | 22 ++- app/views/accounts/list.blade.php | 26 --- app/views/accounts/revenue.blade.php | 28 ---- app/views/accounts/sankey.blade.php | 44 ------ public/assets/images/error.png | Bin 0 -> 666 bytes public/assets/javascript/firefly/accounts.js | 149 ++---------------- public/assets/javascript/firefly/gcharts.js | 14 +- public/assets/stylesheets/sbadmin/sb.css | 3 +- 16 files changed, 142 insertions(+), 311 deletions(-) delete mode 100644 app/views/accounts/asset.blade.php delete mode 100644 app/views/accounts/expense.blade.php delete mode 100644 app/views/accounts/list.blade.php delete mode 100644 app/views/accounts/revenue.blade.php delete mode 100644 app/views/accounts/sankey.blade.php create mode 100755 public/assets/images/error.png diff --git a/app/controllers/GoogleTableController.php b/app/controllers/GoogleTableController.php index 727b6af6fb..d464fdab02 100644 --- a/app/controllers/GoogleTableController.php +++ b/app/controllers/GoogleTableController.php @@ -1,11 +1,62 @@ getAssetAccounts(); + break; + case 'expense': + $list = $acct->getExpenseAccounts(); + break; + case 'revenue': + $list = $acct->getRevenueAccounts(); + break; + } + + + $chart = App::make('gchart'); + $chart->addColumn('ID', 'number'); + $chart->addColumn('ID_Edit', 'string'); + $chart->addColumn('ID_Delete', 'string'); + $chart->addColumn('Name_URL', 'string'); + $chart->addColumn('Name', 'string'); + $chart->addColumn('Balance', 'number'); + + /** @var \Account $entry */ + foreach ($list as $entry) { + $edit = route('accounts.edit', $entry->id); + $delete = route('accounts.delete', $entry->id); + $show = route('accounts.show', $entry->id); + $chart->addRow($entry->id, $edit, $delete, $show, $entry->name, $entry->balance()); + } + + $chart->generate(); + return Response::json($chart->getData()); + + + } + /** * @param Account $account */ diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 0f2a049c9d..ffd33b86cd 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -15,8 +15,8 @@ class HomeController extends BaseController protected $_journal; /** - * @param ARI $accounts - * @param PHI $preferences + * @param ARI $accounts + * @param PHI $preferences * @param TJRI $journal */ public function __construct(ARI $accounts, PHI $preferences, TJRI $journal) @@ -115,4 +115,59 @@ class HomeController extends BaseController return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly') ->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire'); } + + public function cleanup() + { + /** @var \FireflyIII\Database\TransactionJournal $jrnls */ + $jrnls = App::make('FireflyIII\Database\TransactionJournal'); + + /** @var \FireflyIII\Database\Account $acct */ + $acct = \App::make('FireflyIII\Database\Account'); + + /** @var \FireflyIII\Database\AccountType $acctType */ + $acctType = \App::make('FireflyIII\Database\AccountType'); + $rightAcctType = $acctType->findByWhat('revenue'); + + $all = $jrnls->get(); + + /** @var \TransactionJournal $entry */ + foreach ($all as $entry) { + $wrongFromType = false; + $wrongToType = false; + $transactions = $entry->transactions; + if (count($transactions) == 2) { + switch ($entry->transactionType->type) { + case 'Deposit': + /** @var \Transaction $transaction */ + foreach ($transactions as $transaction) { + if (floatval($transaction->amount) < 0) { + $accountType = $transaction->account->accountType; + if ($accountType->type == 'Beneficiary account') { + // should be a Revenue account! + $name = $transaction->account->name; + /** @var \Account $account */ + $account = \Auth::user()->accounts()->where('name', $name)->where('account_type_id', $rightAcctType->id)->first(); + if (!$account) { + $new = [ + 'name' => $name, + 'what' => 'revenue' + ]; + $account = $acct->store($new); + } + $transaction->account()->associate($account); + $transaction->save(); + } + + echo 'Paid by: ' . $transaction->account->name . ' (' . $transaction->account->accountType->type . ')
'; + } + } + break; + } + + + } + } + + + } } \ No newline at end of file diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php index d683bf9b2c..60726af53c 100644 --- a/app/lib/FireflyIII/Database/Account.php +++ b/app/lib/FireflyIII/Database/Account.php @@ -123,11 +123,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface /* * If present, process parameters for sorting: */ - if (isset($parameters['order'])) { - foreach ($parameters['order'] as $instr) { - $query->orderBy($instr['name'], $instr['dir']); - } - } + $query->orderBy('name', 'ASC'); /* * If present, process parameters for searching. diff --git a/app/lib/FireflyIII/Database/AccountType.php b/app/lib/FireflyIII/Database/AccountType.php index a08b00f385..8a4e13f1dc 100644 --- a/app/lib/FireflyIII/Database/AccountType.php +++ b/app/lib/FireflyIII/Database/AccountType.php @@ -8,7 +8,6 @@ use LaravelBook\Ardent\Ardent; use FireflyIII\Database\Ifaces\AccountTypeInterface; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; -use FireflyIII\Database\Ifaces\AccountTypeInterface; /** * Class AccountType diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index 5b37d5c2ae..ae07ca3dfe 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -289,7 +289,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData */ public function get() { - // TODO: Implement get() method. + return $this->getUser()->transactionjournals()->get(); } /** diff --git a/app/routes.php b/app/routes.php index 0444f2c99a..5a1b2b5223 100644 --- a/app/routes.php +++ b/app/routes.php @@ -128,6 +128,7 @@ Route::group( Route::get('/prev', ['uses' => 'HomeController@sessionPrev', 'as' => 'sessionPrev']); Route::get('/next', ['uses' => 'HomeController@sessionNext', 'as' => 'sessionNext']); Route::get('/jump/{range}', ['uses' => 'HomeController@rangeJump', 'as' => 'rangeJump']); + Route::get('/cleanup', ['uses' => 'HomeController@cleanup', 'as' => 'cleanup']); // account controller: Route::get('/accounts/json/{what}', ['uses' => 'AccountController@json', 'as' => 'accounts.json'])->where('what', 'revenue|asset|expense'); @@ -170,6 +171,7 @@ Route::group( // google table controller Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']); + Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']); Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']); diff --git a/app/views/accounts/asset.blade.php b/app/views/accounts/asset.blade.php deleted file mode 100644 index b64988ce02..0000000000 --- a/app/views/accounts/asset.blade.php +++ /dev/null @@ -1,18 +0,0 @@ -@extends('layouts.default') -@section('content') -
-
-

- Create a new asset account -

- @if(count($accounts) > 0) - @include('accounts.list') -

- Create a new asset account -

- @endif -
- -
- -@stop \ No newline at end of file diff --git a/app/views/accounts/expense.blade.php b/app/views/accounts/expense.blade.php deleted file mode 100644 index 0002fba73e..0000000000 --- a/app/views/accounts/expense.blade.php +++ /dev/null @@ -1,28 +0,0 @@ -@extends('layouts.default') -@section('content') -
-
-

- Bla bla expense -

-

- Bla bla bla expense -

-
-
-
-
-

- Create a new expense account -

- @if(count($accounts) > 0) - @include('accounts.list') -

- Create a new expense account -

- @endif -
- -
- -@stop \ No newline at end of file diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.php index d67f0812e1..2410bc6c8e 100644 --- a/app/views/accounts/index.blade.php +++ b/app/views/accounts/index.blade.php @@ -22,29 +22,25 @@
- - - - - - - - -
NamebalanceID
+
@stop @section('scripts') -{{HTML::script('assets/javascript/datatables/jquery.dataTables.min.js')}} -{{HTML::script('assets/javascript/datatables/dataTables.bootstrap.js')}} + + + +{{HTML::script('assets/javascript/firefly/gcharts.options.js')}} +{{HTML::script('assets/javascript/firefly/gcharts.js')}} + + @stop @section('styles') -{{HTML::style('assets/stylesheets/datatables/dataTables.bootstrap.css')}} @endsection \ No newline at end of file diff --git a/app/views/accounts/list.blade.php b/app/views/accounts/list.blade.php deleted file mode 100644 index 52bef1acf3..0000000000 --- a/app/views/accounts/list.blade.php +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - @foreach($accounts as $account) - - - - - - - @endforeach -
 NameCurrent balance
- @if($account->active == 0) - - @endif - - {{{$account->name}}}{{mf($account->balance())}} - - - - -
\ No newline at end of file diff --git a/app/views/accounts/revenue.blade.php b/app/views/accounts/revenue.blade.php deleted file mode 100644 index c5a1aed311..0000000000 --- a/app/views/accounts/revenue.blade.php +++ /dev/null @@ -1,28 +0,0 @@ -@extends('layouts.default') -@section('content') -
-
-

- Bla bla revenue -

-

- Bla bla bla revenue -

-
-
-
-
-

- Create a new revenue account -

- @if(count($accounts) > 0) - @include('accounts.list') -

- Create a new revenue account -

- @endif -
- -
- -@stop \ No newline at end of file diff --git a/app/views/accounts/sankey.blade.php b/app/views/accounts/sankey.blade.php deleted file mode 100644 index 26beb8fe60..0000000000 --- a/app/views/accounts/sankey.blade.php +++ /dev/null @@ -1,44 +0,0 @@ -@extends('layouts.default') -@section('content') - - -
- - - - -@stop -@section('scripts') - - -@stop \ No newline at end of file diff --git a/public/assets/images/error.png b/public/assets/images/error.png new file mode 100755 index 0000000000000000000000000000000000000000..628cf2dae3d419ae220c8928ac71393b480745a3 GIT binary patch literal 666 zcmV;L0%iS)P)eOSYYtbpBV}~vsBnU!_?2tr-P=|^T zED%wc9ezHgW@NMb!^uT_|SvCpFLJylbx zY%bpaTGI8IYXMN$9w<3j9VkA~NYOKEQXsj?6a9_hcwfU$acAhJhB)zb_w@MVUEy@S zX&I>K-R!bhu3?(6bHWIg$HEl7{9g>>&l_qdd+UYb(1~BCo9LptNq&8>!yoJ3Ui(i5 zRJ|XnYBklL!{@$-7=3mJ>P@1c=7Oc79e-V7yf+%lD2!I;Y&nXBZ>=B!5?CB>LvEx6 znI%n)qqi$#X#wKB(U7XP2P=+4{b@j#r%9-K(8UqtSDk>0UKzf*HM9yqMZ1D!$2MdZ zR=`U>0zhOH1XqN?nY@AQqB7)Fp4{v&dKXvb43hZKvnN8;Po;+jY*}~*Z|W9Q0W%{D z^T}Cc<|r(Su=1K=P5>Z4 zg`et&Va}tdzBS-G-ZcO)zCWpJvGQwrHZ`@wpM420ac@bI5~KkTFfGEM3sPWO8co4^fI6lPnA)Y{ef%@{+SnoUk0+dW+*{8WvF8}}l07*qoM6N<$g7cXs A&j0`b literal 0 HcmV?d00001 diff --git a/public/assets/javascript/firefly/accounts.js b/public/assets/javascript/firefly/accounts.js index 702335e3ae..2387946845 100644 --- a/public/assets/javascript/firefly/accounts.js +++ b/public/assets/javascript/firefly/accounts.js @@ -1,145 +1,20 @@ $(function () { - if (typeof(googleLineChart) == "function") { + if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined') { googleLineChart('chart/account/' + accountID, 'overview-chart'); } // - if(typeof(googleSankeyChart) == 'function') { - googleSankeyChart('chart/sankey/' + accountID + '/out','account-out-sankey'); - googleSankeyChart('chart/sankey/' + accountID + '/in','account-in-sankey'); + if (typeof(googleSankeyChart) == 'function' && typeof accountID != 'undefined') { + googleSankeyChart('chart/sankey/' + accountID + '/out', 'account-out-sankey'); + googleSankeyChart('chart/sankey/' + accountID + '/in', 'account-in-sankey'); } - if(typeof(googleTable) == 'function') { - googleTable('table/account/' + accountID + '/transactions','account-transactions'); + if (typeof(googleTable) == 'function') { + if (typeof accountID != 'undefined') { + googleTable('table/account/' + accountID + '/transactions', 'account-transactions'); + } + if (typeof what != 'undefined') { + googleTable('table/accounts/' + what, 'account-list'); + } } - - if ($('#accountTable').length == 1) { - drawDatatable(); - } - //if ($('#overviewChart').length == 1) { - // drawOverviewChart(); - //} - -}); - -function drawDatatable() { - var opt = { - serverSide: true, - ajax: URL, - paging: true, - processing: true, - columns: [ - { - name: 'name', - data: 'name', - searchable: true, - render: function (data) { - return '' + data.name + ''; - } - - }, - { - name: 'balance', - data: 'balance', - title: 'Amount (\u20AC)', - searchable: false, - sortable: true, - render: function (data) { - var amount = parseInt(data); - if (amount < 0) { - '\u20AC ' + data.toFixed(2) + '' - } - if (amount > 0) { - '\u20AC ' + data.toFixed(2) + '' - } - return '\u20AC ' + data.toFixed(2) + '' - } - }, - { - name: 'id', - data: 'id', - title: '', - render: function (data) { - return ''; - } - } - ] - }; - $('#accountTable').DataTable(opt); -} - - -function drawOverviewChart() { - $.getJSON('chart/home/account/' + accountID).success(function (data) { - var options = { - chart: { - renderTo: 'overviewChart', - type: 'spline' - }, - - series: data.series, - title: { - text: null - }, - yAxis: { - allowDecimals: false, - labels: { - formatter: function () { - if (this.value >= 1000 || this.value <= -1000) { - return '\u20AC ' + (this.value / 1000) + 'k'; - } - return '\u20AC ' + this.value; - - } - }, - title: {text: null} - }, - xAxis: { - type: 'datetime', - dateTimeLabelFormats: { - day: '%e %b', - week: '%e %b' - }, - title: { - text: null - } - }, - legend: {enabled: false}, - tooltip: { - formatter: function () { - return this.series.name + ': \u20AC ' + Highcharts.numberFormat(this.y, 2); - } - }, - plotOptions: { - line: { - shadow: true - }, - series: { - cursor: 'pointer', - negativeColor: '#FF0000', - threshold: 0, - lineWidth: 1, - marker: { - radius: 0 - }, - point: { - events: { - click: function (e) { - alert('click!'); - } - } - } - } - }, - credits: { - enabled: false - } - }; - $('#overviewChart').highcharts(options); - }); -} +}); \ No newline at end of file diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js index 367b017e9c..9b2f2c3940 100644 --- a/public/assets/javascript/firefly/gcharts.js +++ b/public/assets/javascript/firefly/gcharts.js @@ -1,4 +1,4 @@ -google.load('visualization', '1.1', {'packages': ['corechart', 'bar','sankey', 'table']}); +google.load('visualization', '1.1', {'packages': ['corechart', 'bar', 'sankey', 'table']}); function googleLineChart(URL, container) { $.getJSON(URL).success(function (data) { @@ -187,24 +187,24 @@ function googleTable(URL, container) { /* Format a string using the previous column as URL. */ - if (label == 'Description' || label == 'From' || label == 'To' || label == 'Budget' || label == 'Category') { + if (label == 'Description' || label == 'From' || label == 'Name' || label == 'To' || label == 'Budget' || label == 'Category') { URLFormatter.format(gdata, [i - 1, i], i); columnsToHide.push(i - 1); } - if(label == 'ID') { - EditButtonFormatter.format(gdata, [i+1,i+2],i); - columnsToHide.push(i+1,i+2); + if (label == 'ID') { + EditButtonFormatter.format(gdata, [i + 1, i + 2], i); + columnsToHide.push(i + 1, i + 2); } /* - Format with buttons: + Format with buttons: */ /* Format as money */ - if (label == 'Amount') { + if (label == 'Amount' || label == 'Balance') { money.format(gdata, i); } diff --git a/public/assets/stylesheets/sbadmin/sb.css b/public/assets/stylesheets/sbadmin/sb.css index 2e181df17b..7317b94229 100755 --- a/public/assets/stylesheets/sbadmin/sb.css +++ b/public/assets/stylesheets/sbadmin/sb.css @@ -9,7 +9,8 @@ body { } .google-chart-error { - border:1px red solid;height:20px; + height:30px; + background:url('../../images/error.png') no-repeat center center } #wrapper {