diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index bf87c445c9..78c7371aa5 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -49,7 +49,7 @@ class AccountController extends \BaseController } } - return View::make('accounts.index')->with('accounts', $list)->with('total',$total); + return View::make('accounts.index')->with('accounts', $list)->with('total', $total); } // // @@ -128,4 +128,6 @@ class AccountController extends \BaseController // } + + } diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php index af43fe323a..403f0f0b5f 100644 --- a/app/controllers/ChartController.php +++ b/app/controllers/ChartController.php @@ -23,45 +23,39 @@ class ChartController extends BaseController { list($start, $end) = tk::getDateRange(); $current = clone $start; - - // chart - $chart = App::make('gchart'); - $chart->addColumn('Day of the month', 'date'); - + $return = []; if (is_null($account)) { - // get accounts: $accounts = $this->accounts->getActiveDefault(); - foreach ($accounts as $account) { - $chart->addColumn($account->name, 'number'); + foreach ($accounts as $index => $account) { + $return[] = ['name' => $account->name, 'data' => []]; } - while ($current <= $end) { - $row = [clone $current]; // loop accounts: - foreach ($accounts as $account) { - $row[] = $account->balance(clone $current); + foreach ($accounts as $index => $account) { + $return[$index]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)]; } $current->addDay(); - $chart->addRowArray($row); } } else { + // do something experimental: $account = $this->accounts->find($account); if (is_null($account)) { return View::make('error')->with('message', 'No account found.'); } - $chart->addColumn($account->name, 'number'); - while ($current <= $end) { - $row = [clone $current, $account->balance(clone $current)]; - $current->addDay(); - $chart->addRowArray($row); - } - } + $return[0] = ['name' => $account->name, 'data' => []]; - $chart->generate(); - return $chart->getData(); + + while ($current <= $end) { + + $return[0]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)]; + $current->addDay(); + } + + } + return Response::json($return); } /** @@ -70,18 +64,18 @@ class ChartController extends BaseController public function homeBudgets() { list($start, $end) = tk::getDateRange(); + $data = [ + 'type' => 'pie', + 'name' => 'Expense: ', + 'data' => [] + ]; $result = $this->journals->homeBudgetChart($start, $end); - // create a chart: - $chart = App::make('gchart'); - $chart->addColumn('Budget', 'string'); - $chart->addColumn('Amount', 'number'); foreach ($result as $name => $amount) { - $chart->addRow($name, $amount); + $data['data'][] = [$name, $amount]; } - $chart->generate(); - return Response::json($chart->getData()); + return Response::json([$data]); } @@ -93,16 +87,16 @@ class ChartController extends BaseController list($start, $end) = tk::getDateRange(); $result = $this->journals->homeCategoryChart($start, $end); + $data = [ + 'type' => 'pie', + 'name' => 'Amount: ', + 'data' => [] + ]; - // create a chart: - $chart = App::make('gchart'); - $chart->addColumn('Category', 'string'); - $chart->addColumn('Amount', 'number'); foreach ($result as $name => $amount) { - $chart->addRow($name, $amount); + $data['data'][] = [$name, $amount]; } - $chart->generate(); - return Response::json($chart->getData()); + return Response::json([$data]); } @@ -112,18 +106,18 @@ class ChartController extends BaseController public function homeBeneficiaries() { list($start, $end) = tk::getDateRange(); + $data = [ + 'type' => 'pie', + 'name' => 'Amount: ', + 'data' => [] + ]; $result = $this->journals->homeBeneficiaryChart($start, $end); - // create a chart: - $chart = App::make('gchart'); - $chart->addColumn('Beneficiary', 'string'); - $chart->addColumn('Amount', 'number'); foreach ($result as $name => $amount) { - $chart->addRow($name, $amount); + $data['data'][] = [$name, $amount]; } - $chart->generate(); - return Response::json($chart->getData()); + return Response::json([$data]); } } \ No newline at end of file diff --git a/app/controllers/ComponentsController.php b/app/controllers/ComponentsController.php new file mode 100644 index 0000000000..edd100dcca --- /dev/null +++ b/app/controllers/ComponentsController.php @@ -0,0 +1,7 @@ +preferences->get('viewRange','week'); - - // get list setting: $pref = $this->preferences->get('frontpageAccounts', []); diff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.php new file mode 100644 index 0000000000..9e9b279396 --- /dev/null +++ b/app/controllers/JsonController.php @@ -0,0 +1,40 @@ +components = $components; + $this->accounts = $accounts; + } + + /** + * Returns a JSON list of all beneficiaries. + */ + public function beneficiaries() + { + $list = $this->accounts->getBeneficiaries(); + $return = []; + foreach ($list as $entry) { + $return[] = $entry->name; + } + + return Response::json($return); + + } + + /** + * Responds some JSON for typeahead fields. + */ + public function categories() + { + $list = $this->components->get(); + + + } + +} \ No newline at end of file diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.php index eb54fd4ac5..7f2773c3d4 100644 --- a/app/controllers/PreferencesController.php +++ b/app/controllers/PreferencesController.php @@ -20,18 +20,31 @@ class PreferencesController extends BaseController { $accounts = $this->accounts->getDefault(); + $viewRange = $this->preferences->get('viewRange','1M'); + $viewRangeValue = $viewRange->data; + // pref: $frontpage = $this->preferences->get('frontpageAccounts', []); - return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage); + return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage)->with('viewRange',$viewRangeValue); } public function postIndex() { + + // frontpage accounts $frontpageAccounts = []; foreach(Input::get('frontpageAccounts') as $id) { $frontpageAccounts[] = intval($id); } $this->preferences->set('frontpageAccounts',$frontpageAccounts); + + // view range: + $this->preferences->set('viewRange',Input::get('viewRange')); + // forget session values: + Session::forget('start'); + Session::forget('end'); + Session::forget('range'); + Session::flash('success', 'Preferences saved!'); return Redirect::route('preferences'); } diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php new file mode 100644 index 0000000000..f81868f868 --- /dev/null +++ b/app/controllers/TransactionController.php @@ -0,0 +1,26 @@ +accounts = $accounts; + + + View::share('menu','home'); + } + + public function createWithdrawal() { + + // get accounts with names and id's. + $accounts =$this->accounts->getActiveDefaultAsSelectList(); + + + return View::make('transactions.withdrawal')->with('accounts',$accounts); + } + +} \ No newline at end of file diff --git a/app/database/migrations/2014_07_09_204843_create_session_table.php b/app/database/migrations/2014_07_09_204843_create_session_table.php new file mode 100644 index 0000000000..2aac4339c2 --- /dev/null +++ b/app/database/migrations/2014_07_09_204843_create_session_table.php @@ -0,0 +1,32 @@ +string('id')->unique(); + $t->text('payload'); + $t->integer('last_activity'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('sessions'); + } + +} diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php index 088cbf828c..1d973cb490 100644 --- a/app/lib/Firefly/Helper/Toolkit/Toolkit.php +++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php @@ -17,25 +17,68 @@ class Toolkit implements ToolkitInterface public static function getDateRange() { $preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface'); - $viewRange = $preferences->get('viewRange', 'week'); + $viewRange = $preferences->get('viewRange', '1M'); - // as you can see, this method now only supports "right now": - $now = new \Carbon\Carbon; - $start = clone $now; - $end = clone $now; + // default range: + $range = $viewRange->data; + // update range if session has something: + if (!is_null(\Session::get('range'))) { + $range = \Session::get('range'); + } - switch ($viewRange->data) { - case 'week': + // update view range if the input has something: + if (!is_null(\Input::get('range'))) { + $range = \Input::get('range'); + } + + // switch $range, update range or something: + $today = new \Carbon\Carbon; + $start = clone $today; + $end = clone $today; + switch ($range) { + case 'custom': + // when range is custom AND input, we ignore $today + if (\Input::get('start') && \Input::get('end')) { + $start = new \Carbon\Carbon(\Input::get('start')); + $end = new \Carbon\Carbon(\Input::get('end')); + } else { + $start = \Session::get('start'); + $end = \Session::get('end'); + } + break; + case '1D': + $start->startOfDay(); + $end->endOfDay(); + break; + case '1W': $start->startOfWeek(); $end->endOfWeek(); break; - default: - case 'month': + case '1M': $start->startOfMonth(); $end->endOfMonth(); break; + case '3M': + $start->firstOfQuarter(); + $end->lastOfQuarter(); + break; + case '6M': + if (intval($today->format('m')) >= 7) { + $start->startOfYear()->addMonths(6); + $end->endOfYear(); + } else { + $start->startOfYear(); + $end->startOfYear()->addMonths(6); + } + break; } + // save in session: + \Session::put('start', $start); + \Session::put('end', $end); + \Session::put('range', $range); + + // and return: return [$start, $end]; diff --git a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php index 3976ba7cd4..0ba7e745c3 100644 --- a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php @@ -10,12 +10,21 @@ interface AccountRepositoryInterface public function count(); public function get(); + + public function getBeneficiaries(); + public function find($id); + public function getByIds($ids); + public function getDefault(); + public function getActiveDefault(); + public function getActiveDefaultAsSelectList(); + public function store($data); - public function storeWithInitialBalance($data,\Carbon\Carbon $date, $amount = 0); + + public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0); } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php index 8731882f8f..a9a1fa1a9e 100644 --- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php +++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php @@ -16,6 +16,16 @@ class EloquentAccountRepository implements AccountRepositoryInterface return \Auth::user()->accounts()->with('accounttype')->get(); } + public function getBeneficiaries() { + $list = \Auth::user()->accounts()->leftJoin( + 'account_types', 'account_types.id', '=', 'accounts.account_type_id' + ) + ->where('account_types.description', 'Beneficiary account')->where('accounts.active', 1) + + ->get(['accounts.*']); + return $list; + } + public function find($id) { return \Auth::user()->accounts()->where('id', $id)->first(); @@ -42,6 +52,21 @@ class EloquentAccountRepository implements AccountRepositoryInterface ->get(['accounts.*']); } + public function getActiveDefaultAsSelectList() + { + $list = \Auth::user()->accounts()->leftJoin( + 'account_types', 'account_types.id', '=', 'accounts.account_type_id' + ) + ->where('account_types.description', 'Default account')->where('accounts.active', 1) + + ->get(['accounts.*']); + $return = []; + foreach ($list as $entry) { + $return[intval($entry->id)] = $entry->name; + } + return $return; + } + public function count() { return \Auth::user()->accounts()->count(); diff --git a/app/lib/Firefly/Storage/Component/ComponentRepositoryInterface.php b/app/lib/Firefly/Storage/Component/ComponentRepositoryInterface.php index 72745564f5..7a1a801527 100644 --- a/app/lib/Firefly/Storage/Component/ComponentRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Component/ComponentRepositoryInterface.php @@ -9,6 +9,8 @@ interface ComponentRepositoryInterface public function count(); + public function get(); + public function store($data); } \ No newline at end of file diff --git a/app/lib/Firefly/Storage/Component/EloquentComponentRepository.php b/app/lib/Firefly/Storage/Component/EloquentComponentRepository.php index 138af1f028..d59a098e74 100644 --- a/app/lib/Firefly/Storage/Component/EloquentComponentRepository.php +++ b/app/lib/Firefly/Storage/Component/EloquentComponentRepository.php @@ -13,10 +13,15 @@ class EloquentComponentRepository implements ComponentRepositoryInterface public function count() { - return \Auth::user()->accounts()->count(); + return \Auth::user()->components()->count(); } + public function get() { + die('no impl'); + } + + public function store($data) { diff --git a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php index 9fa1dc839c..4b100b5629 100644 --- a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php +++ b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php @@ -145,7 +145,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito // lets make this simple. $types = []; - foreach (\TransactionType::whereIn('type', ['Deposit', 'Withdrawal'])->get() as $t) { + foreach (\TransactionType::whereIn('type', ['Withdrawal'])->get() as $t) { $types[] = $t->id; } unset($t); @@ -163,6 +163,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito ->whereIn('transaction_type_id', $types) ->get(['transaction_journals.*']); unset($types); + $result = []; foreach ($journals as $journal) { @@ -196,7 +197,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito // lets make this simple. $types = []; - foreach (\TransactionType::whereIn('type', ['Deposit', 'Withdrawal'])->get() as $t) { + foreach (\TransactionType::whereIn('type', ['Withdrawal'])->get() as $t) { $types[] = $t->id; } unset($t); diff --git a/app/models/Account.php b/app/models/Account.php index 98f5c7e038..aaa9c62e82 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -42,9 +42,9 @@ class Account extends Elegant { $date = is_null($date) ? new \Carbon\Carbon : $date; - return $this->transactions() + return floatval($this->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount'); + ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')); } public function transactions() diff --git a/app/views/accounts/list.blade.php b/app/views/accounts/list.blade.php index db906b4232..fa8e97dfe9 100644 --- a/app/views/accounts/list.blade.php +++ b/app/views/accounts/list.blade.php @@ -1,6 +1,6 @@
+ | Name | Current balance |
---|