From 873384a34b063d22d427dbca581977f9c280c9e3 Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Sat, 8 Nov 2014 19:11:51 +0100 Subject: [PATCH] Built the 'show'-view for budgets. --- app/controllers/BudgetController.php | 148 +--------- app/controllers/GoogleTableController.php | 85 +++++- app/controllers/PiggybankController.php | 276 +----------------- app/models/LimitRepetition.php | 52 ++-- app/routes.php | 7 +- app/views/budgets/show.blade.php | 79 +++++ public/assets/javascript/firefly/budgets.js | 29 +- .../javascript/firefly/gcharts.options.js | 4 +- 8 files changed, 231 insertions(+), 449 deletions(-) diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 26c1b3ead2..8636aee2ab 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -8,6 +8,9 @@ use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\MessageBag; +/** + * Class BudgetController + */ class BudgetController extends BaseController { @@ -141,7 +144,16 @@ class BudgetController extends BaseController App::abort(500); } - return View::make('budgets.show'); + if (is_null($repetition)) { + // get all other repetitions: + $limits = $budget->limits()->orderBy('startdate', 'DESC')->get(); + + } else { + // get nothing? i dunno + $limits = [$repetition->limit]; + } + + return View::make('budgets.show', compact('limits', 'budget', 'repetition')); } /** @@ -185,85 +197,6 @@ class BudgetController extends BaseController } -// /** -// * @return $this|\Illuminate\View\View -// */ -// public function indexByBudget() -// { -// View::share('subTitleIcon', 'fa-folder-open'); -// -// $budgets = $this->_repository->get(); -// -// return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', new Carbon) -// ->with('subTitle', 'Grouped by budget'); -// -// } -// -// /** -// * @return $this -// */ -// public function indexByDate() -// { -// View::share('subTitleIcon', 'fa-calendar'); -// -// // get a list of dates by getting all repetitions: -// $set = $this->_repository->get(); -// $budgets = $this->_budgets->organizeByDate($set); -// -// return View::make('budgets.indexByDate')->with('budgets', $budgets) -// ->with('subTitle', 'Grouped by date'); -// -// -// } -// -// /** -// * Three use cases for this view: -// * -// * - Show everything. -// * - Show a specific repetition. -// * - Show everything shows NO repetition. -// * -// * @param Budget $budget -// * @param LimitRepetition $repetition -// * -// * @return int -// */ -// public function show(Budget $budget, \LimitRepetition $repetition = null) -// { -// $useSessionDates = Input::get('useSession') == 'true' ? true : false; -// $view = null; -// $title = null; -// \Log::debug('Is envelope true? ' . (Input::get('noenvelope') == 'true')); -// switch (true) { -// case (!is_null($repetition)): -// $data = $this->_budgets->organizeRepetition($repetition); -// $view = 1; -// $title = $budget->name . ', ' . $repetition->periodShow() . ', ' . mf( -// $repetition->limit->amount, -// false -// ); -// break; -// case (Input::get('noenvelope') == 'true'): -// $data = $this->_budgets->outsideRepetitions($budget); -// $view = 2; -// $title = $budget->name . ', transactions outside an envelope'; -// break; -// default: -// $data = $this->_budgets->organizeRepetitions($budget, $useSessionDates); -// $view = $useSessionDates ? 3 : 4; -// $title = $useSessionDates ? $budget->name . ' in session period' : $budget->name; -// break; -// } -// -// return View::make('budgets.show') -// ->with('budget', $budget) -// ->with('repetitions', $data) -// ->with('view', $view) -// ->with('highlight', Input::get('highlight')) -// ->with('useSessionDates', $useSessionDates) -// ->with('subTitle', 'Overview for ' . $title); -// } -// /** * @return \Illuminate\Http\RedirectResponse */ @@ -306,7 +239,7 @@ class BudgetController extends BaseController break; } } -// + /** * @param Budget $budget * @@ -350,56 +283,5 @@ class BudgetController extends BaseController return Redirect::route('budgets.edit', $budget->id)->withInput(); break; } - -// $budget = $this->_repository->update($budget, Input::all()); -// if ($budget->validate()) { -// Event::fire('budgets.update', [$budget]); -// Session::flash('success', 'Budget "' . $budget->name . '" updated.'); -// -// if (Input::get('from') == 'date') { -// return Redirect::route('budgets.index'); -// } else { -// return Redirect::route('budgets.index.budget'); -// } -// } else { -// Session::flash('error', 'Could not update budget: ' . $budget->errors()->first()); -// -// return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($budget->errors()); -// } -// } - -// public function nobudget($view = 'session') { -// switch($view) { -// default: -// throw new FireflyException('Cannot show transactions without a budget for view "'.$view.'".'); -// break; -// case 'session': -// $start = Session::get('start'); -// $end = Session::get('end'); -// break; -// } -// -// // Add expenses that have no budget: -// $set = \Auth::user()->transactionjournals()->whereNotIn( -// 'transaction_journals.id', function ($query) use ($start, $end) { -// $query->select('transaction_journals.id')->from('transaction_journals') -// ->leftJoin( -// 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', -// 'transaction_journals.id' -// ) -// ->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id') -// ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) -// ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) -// ->where('components.class', 'Budget'); -// } -// )->before($end)->after($start)->get(); -// -// return View::make('budgets.nobudget') -// ->with('view', $view) -// ->with('transactions',$set) -// ->with('subTitle', 'Transactions without a budget'); -// } - - -} \ No newline at end of file +} \ No newline at end of file diff --git a/app/controllers/GoogleTableController.php b/app/controllers/GoogleTableController.php index d464fdab02..8f51270363 100644 --- a/app/controllers/GoogleTableController.php +++ b/app/controllers/GoogleTableController.php @@ -57,11 +57,91 @@ class GoogleTableController extends BaseController } + /** + * @param Budget $budget + * @param LimitRepetition $repetition + */ + public function transactionsByBudget(Budget $budget, LimitRepetition $repetition = null) + { + /** @var \Grumpydictator\Gchart\GChart $chart */ + $chart = App::make('gchart'); + $chart->addColumn('ID', 'number'); + $chart->addColumn('ID_Edit', 'string'); + $chart->addColumn('ID_Delete', 'string'); + $chart->addColumn('Date', 'date'); + $chart->addColumn('Description_URL', 'string'); + $chart->addColumn('Description', 'string'); + $chart->addColumn('Amount', 'number'); + $chart->addColumn('From_URL', 'string'); + $chart->addColumn('From', 'string'); + $chart->addColumn('To_URL', 'string'); + $chart->addColumn('To', 'string'); + $chart->addColumn('Budget_URL', 'string'); + $chart->addColumn('Budget', 'string'); + $chart->addColumn('Category_URL', 'string'); + $chart->addColumn('Category', 'string'); + + if (is_null($repetition)) { + $journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get(); + } else { + $journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])-> + after($repetition->startdate)->before($repetition->enddate)->orderBy('date', 'DESC')->get(); + } + /** @var TransactionJournal $transaction */ + foreach ($journals as $journal) { + $date = $journal->date; + $descriptionURL = route('transactions.show', $journal->id); + $description = $journal->description; + /** @var Transaction $transaction */ + foreach ($journal->transactions as $transaction) { + if (floatval($transaction->amount) > 0) { + $amount = floatval($transaction->amount); + $to = $transaction->account->name; + $toURL = route('accounts.show', $transaction->account->id); + } else { + $from = $transaction->account->name; + $fromURL = route('accounts.show', $transaction->account->id); + } + + } + if (isset($journal->budgets[0])) { + $budgetURL = route('budgets.show', $journal->budgets[0]->id); + $budget = $journal->budgets[0]->name; + } else { + $budgetURL = ''; + $budget = ''; + } + + if (isset($journal->categories[0])) { + $categoryURL = route('categories.show', $journal->categories[0]->id); + $category = $journal->categories[0]->name; + } else { + $categoryURL = ''; + $category = ''; + } + + + $id = $journal->id; + $edit = route('transactions.edit', $journal->id); + $delete = route('transactions.delete', $journal->id); + $chart->addRow( + $id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, + $category + ); + } + + + $chart->generate(); + return Response::json($chart->getData()); + + } + /** * @param Account $account */ public function transactionsByAccount(Account $account) { + /** @var \Grumpydictator\Gchart\GChart $chart */ $chart = App::make('gchart'); $chart->addColumn('ID', 'number'); $chart->addColumn('ID_Edit', 'string'); @@ -118,8 +198,8 @@ class GoogleTableController extends BaseController $categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id); $category = $transaction->transactionJournal->categories[0]->name; } else { - $budgetURL = ''; - $budget = ''; + $categoryURL = ''; + $category = ''; } @@ -137,7 +217,6 @@ class GoogleTableController extends BaseController $fromURL = $opposingAccountURI; } - $budcat = 'Budcat'; $id = $transaction->transactionJournal->id; $edit = route('transactions.edit', $transaction->transactionJournal->id); $delete = route('transactions.delete', $transaction->transactionJournal->id); diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index deff70795d..78b6c49ec0 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -39,28 +39,6 @@ class PiggybankController extends BaseController ->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus'); } - - -// /** -// * @return $this -// */ -// public function createRepeated() -// { -// throw new NotImplementedException; -// /** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */ -// $toolkit = App::make('Firefly\Helper\Toolkit\Toolkit'); -// -// $periods = Config::get('firefly.piggybank_periods'); -// $list = $this->_accounts->getActiveDefault(); -// $accounts = $toolkit->makeSelectList($list); -// -// View::share('title', 'Repeated expenses'); -// View::share('subTitle', 'Create new'); -// View::share('mainTitleIcon', 'fa-rotate-right'); -// -// return View::make('piggybanks.create-repeated')->with('accounts', $accounts)->with('periods', $periods); -// } - /** * @param Piggybank $piggyBank * @@ -126,82 +104,8 @@ class PiggybankController extends BaseController 'mainTitleIcon', 'fa-sort-amount-asc' ) ->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil'); - //throw new NotImplementedException; -// /** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */ -// $toolkit = App::make('Firefly\Helper\Toolkit\Toolkit'); -// -// $list = $this->_accounts->getActiveDefault(); -// $accounts = $toolkit->makeSelectList($list); -// $periods = Config::get('firefly.piggybank_periods'); -// -// -// View::share('subTitle', 'Edit "' . $piggyBank->name . '"'); -// -// -// if ($piggyBank->repeats == 1) { -// View::share('title', 'Repeated expenses'); -// View::share('mainTitleIcon', 'fa-rotate-left'); -// -// return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts) -// ->with('periods', $periods); -// } else { -// // piggy bank. -// View::share('title', 'Piggy banks'); -// View::share('mainTitleIcon', 'fa-sort-amount-asc'); -// -// return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts) -// ->with('periods', $periods); -// } - - } -// /** -// * @param Piggybank $piggyBank -// * -// * @return \Illuminate\Http\RedirectResponse -// * @throws Firefly\Exception\FireflyException -// */ -// public function modMoney(Piggybank $piggyBank) -// { -// throw new NotImplementedException; -// $amount = floatval(Input::get('amount')); -// switch (Input::get('what')) { -// default: -// throw new FireflyException('No such action'); -// break; -// case 'add': -// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account); -// if (round($amount, 2) <= round(min($maxAdd, $piggyBank->targetamount), 2)) { -// Session::flash('success', 'Amount updated!'); -// $this->_repository->modifyAmount($piggyBank, $amount); -// Event::fire('piggybanks.modifyAmountAdd', [$piggyBank, $amount]); -// } else { -// Session::flash('warning', 'Could not!'); -// } -// break; -// case 'remove': -// $rep = $piggyBank->currentRelevantRep(); -// $maxRemove = $rep->currentamount; -// if (round($amount, 2) <= round($maxRemove, 2)) { -// Session::flash('success', 'Amount updated!'); -// $this->_repository->modifyAmount($piggyBank, ($amount * -1)); -// Event::fire('piggybanks.modifyAmountRemove', [$piggyBank, ($amount * -1)]); -// } else { -// Session::flash('warning', 'Could not!'); -// } -// break; -// } -// if ($piggyBank->repeats == 1) { -// $route = 'piggybanks.index.repeated'; -// -// } else { -// $route = 'piggybanks.index.piggybanks'; -// } -// return Redirect::route($route); -// } - - /** * @param Piggybank $piggybank * @@ -316,122 +220,13 @@ class PiggybankController extends BaseController } } return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc'); - - //throw new NotImplementedException; -// $countRepeating = $this->_repository->countRepeating(); -// $countNonRepeating = $this->_repository->countNonrepeating(); -// -// $piggybanks = $this->_repository->get(); -// -// // get the accounts with each piggy bank and check their balance; Fireflyy might needs to -// // show the user a correction. -// -// $accounts = []; -// /** @var \Piggybank $piggybank */ -// foreach ($piggybanks as $piggybank) { -// $account = $piggybank->account; -// $id = $account->id; -// if (!isset($accounts[$id])) { -// $account->leftOnAccount = $this->_repository->leftOnAccount($account); -// $accounts[$id] = [ -// 'account' => $account, -// 'left' => $this->_repository->leftOnAccount($account), -// 'tosave' => $piggybank->targetamount, -// 'saved' => $piggybank->currentRelevantRep()->currentamount -// ]; -// } else { -// $accounts[$id]['tosave'] += $piggybank->targetamount; -// $accounts[$id]['saved'] += $piggybank->currentRelevantRep()->currentamount; -// } -// } -// -// View::share('title', 'Piggy banks'); -// View::share('subTitle', 'Save for big expenses'); -// View::share('mainTitleIcon', 'fa-sort-amount-asc'); -// -// return View::make('piggybanks.index')->with('piggybanks', $piggybanks) -// ->with('countRepeating', $countRepeating) -// ->with('countNonRepeating', $countNonRepeating) -// ->with('accounts', $accounts); } -// /** -// * @param Piggybank $piggyBank -// * -// * @return $this -// */ -// public function removeMoney(Piggybank $piggyBank) -// { -// $what = 'remove'; -// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account); -// $maxRemove = $piggyBank->currentRelevantRep()->currentamount; -// -// return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with( -// 'maxRemove', $maxRemove -// )->with('piggybank', $piggyBank); -// } -// /** -// * @return $this -// */ -// public function repeated() -// { -// $countRepeating = $this->_repository->countRepeating(); -// $countNonRepeating = $this->_repository->countNonrepeating(); -// -// $piggybanks = $this->_repository->get(); -// -// // get the accounts with each piggy bank and check their balance; Fireflyy might needs to -// // show the user a correction. -// -// $accounts = []; -// /** @var \Piggybank $piggybank */ -// foreach ($piggybanks as $piggybank) { -// $account = $piggybank->account; -// $id = $account->id; -// if (!isset($accounts[$id])) { -// $account->leftOnAccount = $this->_repository->leftOnAccount($account); -// $accounts[$id] = ['account' => $account, 'left' => $this->_repository->leftOnAccount($account)]; -// } -// } -// -// View::share('title', 'Repeated expenses'); -// View::share('subTitle', 'Save for returning bills'); -// View::share('mainTitleIcon', 'fa-rotate-left'); -// -// -// return View::make('piggybanks.index')->with('piggybanks', $piggybanks) -// ->with('countRepeating', $countRepeating) -// ->with('countNonRepeating', $countNonRepeating) -// ->with('accounts', $accounts); -// } - -// /** -// * @param Piggybank $piggyBank -// * -// * @return $this -// * @throws NotImplementedException -// */ public function show(Piggybank $piggyBank) { throw new NotImplementedException; -// $leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account); -// $balance = $piggyBank->account->balance(); -// -// View::share('subTitle', $piggyBank->name); -// -// if ($piggyBank->repeats == 1) { -// // repeated expense. -// View::share('title', 'Repeated expenses'); -// View::share('mainTitleIcon', 'fa-rotate-left'); -// } else { -// // piggy bank. -// View::share('title', 'Piggy banks'); -// View::share('mainTitleIcon', 'fa-sort-amount-asc'); -// } -// -// return View::make('piggybanks.show')->with('piggyBank', $piggyBank)->with('leftOnAccount', $leftOnAccount) -// ->with('balance', $balance); + } /** @@ -477,58 +272,8 @@ class PiggybankController extends BaseController return Redirect::route('piggybanks.create')->withInput(); break; } -// $data = Input::all(); -// unset($data['_token']); -// -// // extend the data array with the settings needed to create a piggy bank: -// $data['repeats'] = 0; -// $data['rep_times'] = 1; -// $data['rep_every'] = 1; -// $data['order'] = 0; -// -// $piggyBank = $this->_repository->store($data); -// if (!is_null($piggyBank->id)) { -// Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!'); -// Event::fire('piggybanks.store', [$piggyBank]); -// -// return Redirect::route('piggybanks.index.piggybanks'); -// -// -// } else { -// Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first()); -// -// return Redirect::route('piggybanks.create.piggybank')->withInput()->withErrors($piggyBank->errors()); -// } - } -// /** -// * @return $this|\Illuminate\Http\RedirectResponse -// */ -// public function storeRepeated() -// { -// -// $data = Input::all(); -// unset($data['_token']); -// -// // extend the data array with the settings needed to create a repeated: -// $data['repeats'] = 1; -// $data['order'] = 0; -// -// $piggyBank = $this->_repository->store($data); -// if ($piggyBank->id) { -// Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!'); -// Event::fire('piggybanks.store', [$piggyBank]); -// return Redirect::route('piggybanks.index.repeated'); -// -// } else { -// Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first()); -// -// return Redirect::route('piggybanks.create.repeated')->withInput()->withErrors($piggyBank->errors()); -// } -// -// } - /** * @param Piggybank $piggyBank * @@ -575,21 +320,4 @@ class PiggybankController extends BaseController } -} - -// /** -// * @param Piggybank $piggyBank -// * -// * @return $this -// */ -// public function addMoney(Piggybank $piggyBank) -// { -// throw new NotImplementedException; -// $what = 'add'; -// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account); -// $maxRemove = null; -// -// return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with( -// 'maxRemove', $maxRemove -// )->with('piggybank', $piggyBank); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index 943512aed4..0c4188bbb7 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -5,14 +5,14 @@ use LaravelBook\Ardent\Ardent as Ardent; /** * LimitRepetition * - * @property integer $id + * @property integer $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $limit_id + * @property integer $limit_id * @property \Carbon\Carbon $startdate * @property \Carbon\Carbon $enddate - * @property float $amount - * @property-read \Limit $limit + * @property float $amount + * @property-read \Limit $limit * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereId($value) * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\LimitRepetition whereUpdatedAt($value) @@ -39,29 +39,27 @@ class LimitRepetition extends Ardent return ['created_at', 'updated_at', 'startdate', 'enddate']; } + public function spentInRepetition() { + $sum = \DB::table('transactions') + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id') + ->leftJoin('limits', 'limits.component_id', '=', 'components.id') + ->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id') + ->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d')) + ->where('transactions.amount', '>', 0) + ->where('limit_repetitions.id', '=', $this->id)->sum('transactions.amount'); + return floatval($sum); + } + /** * How much money is left in this? */ public function leftInRepetition() { - $left = floatval($this->amount); + return floatval($this->amount - $this->spentInRepetition()); - // budget: - $budget = $this->limit->budget; - - /** @var \Firefly\Storage\Limit\EloquentLimitRepository $limits */ - $limits = App::make('Firefly\Storage\Limit\EloquentLimitRepository'); - $set = $limits->getTJByBudgetAndDateRange($budget, $this->startdate, $this->enddate); - - foreach ($set as $journal) { - foreach ($journal->transactions as $t) { - if ($t->amount < 0) { - $left += floatval($t->amount); - } - } - } - - return $left; } /** @@ -85,8 +83,10 @@ class LimitRepetition extends Ardent } switch ($this->repeat_freq) { default: - throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq - . '"!'); + throw new \Firefly\Exception\FireflyException( + 'No date formats for frequency "' . $this->repeat_freq + . '"!' + ); break; case 'daily': return $this->startdate->format('Ymd') . '-5'; @@ -119,8 +119,10 @@ class LimitRepetition extends Ardent } switch ($this->repeat_freq) { default: - throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq - . '"!'); + throw new \Firefly\Exception\FireflyException( + 'No date formats for frequency "' . $this->repeat_freq + . '"!' + ); break; case 'daily': return $this->startdate->format('j F Y'); diff --git a/app/routes.php b/app/routes.php index 72486627ee..ff19a498ee 100644 --- a/app/routes.php +++ b/app/routes.php @@ -173,6 +173,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('/table/budget/{budget}/{limitrepetition?}/transactions', ['uses' => 'GoogleTableController@transactionsByBudget']); Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']); @@ -209,9 +210,9 @@ Route::group( Route::get('/piggybanks', ['uses' => 'PiggybankController@index', 'as' => 'piggybanks.index']); Route::get('/piggybanks/add/{piggybank}', ['uses' => 'PiggybankController@add']); Route::get('/piggybanks/remove/{piggybank}', ['uses' => 'PiggybankController@remove']); - Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']); + Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit', 'as' => 'piggybanks.edit']); Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create', 'as' => 'piggybanks.create']); - Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']); + Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete', 'as' => 'piggybanks.delete']); // Route::get('/repeated',['uses' => 'PiggybankController@repeated','as' => 'piggybanks.index.repeated']); @@ -263,7 +264,7 @@ Route::group( // user controller Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']); - Route::post('budgets/amount/{budget}',['uses' => 'BudgetController@amount']); + Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']); } diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php index 73fd354ac8..71d6418e42 100644 --- a/app/views/budgets/show.blade.php +++ b/app/views/budgets/show.blade.php @@ -1,9 +1,88 @@ @extends('layouts.default') @section('content') +
+
+
+
+ Some stuff? +
+
+ Some stuff? +
+
+ +
+
+ Transactions +
+
+
+
+
+
+
+ @foreach($limits as $limit) + @foreach($limit->limitrepetitions as $rep) +
+ +
+
+
+ Amount: {{mf($rep->amount)}} +
+
+ Spent: {{mf($rep->spentInRepetition())}} +
+
+
+
+ spentInRepetition() > $rep->amount; + ?> + @if($overspent) + amount / $rep->spentInRepetition()*100; + ?> +
+
+
+
+ @else + spentInRepetition() / $rep->amount*100; + ?> +
+
+
+
+ @endif +
+
+
+
+ @endforeach + @endforeach + + +
+
@stop @section('scripts') + + + +{{HTML::script('assets/javascript/firefly/gcharts.options.js')}} +{{HTML::script('assets/javascript/firefly/gcharts.js')}} +{{HTML::script('assets/javascript/firefly/budgets.js')}} @stop \ No newline at end of file diff --git a/public/assets/javascript/firefly/budgets.js b/public/assets/javascript/firefly/budgets.js index 68d880c4ee..881948aa16 100644 --- a/public/assets/javascript/firefly/budgets.js +++ b/public/assets/javascript/firefly/budgets.js @@ -2,10 +2,19 @@ $(function () { updateRanges(); $('input[type="range"]').change(updateSingleRange); $('input[type="range"]').on('input', updateSingleRange); - $('input[type="number"]').on('change',updateSingleRange); - $('input[type="number"]').on('input',updateSingleRange); + $('input[type="number"]').on('change', updateSingleRange); + $('input[type="number"]').on('input', updateSingleRange); $('.updateIncome').on('click', updateIncome); + + if (typeof(googleTable) == 'function') { + if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') { + googleTable('table/budget/' + budgetID + '/0/transactions', 'transactions'); + } else if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') { + googleTable('table/budget/' + budgetID + '/' + repetitionID + '/transactions', 'transactions'); + } + } + }); @@ -19,10 +28,10 @@ function updateSingleRange(e) { console.log('Spent vs budgeted: ' + spent + ' vs ' + value) // update small display: - if(value > 0) { + if (value > 0) { // show the input: - $('#budget-info-' + id +' span').show(); - $('#budget-info-' + id +' input').show(); + $('#budget-info-' + id + ' span').show(); + $('#budget-info-' + id + ' input').show(); // update the text: $('#budget-description-' + id).text('Budgeted: '); @@ -35,8 +44,8 @@ function updateSingleRange(e) { } else { console.log('Set to zero!'); // hide the input: - $('#budget-info-' + id +' span').hide(); - $('#budget-info-' + id +' input').hide(); + $('#budget-info-' + id + ' span').hide(); + $('#budget-info-' + id + ' input').hide(); // update the text: $('#budget-description-' + id).html('No budget'); @@ -51,14 +60,14 @@ function updateSingleRange(e) { $.post('budgets/amount/' + id, {amount: value}).success(function (data) { console.log('Budget ' + data.name + ' updated!'); // update the link if relevant: - $('#budget-link-' + id).attr('href','budgets/show/' + id + '/' + data.repetition); + $('#budget-link-' + id).attr('href', 'budgets/show/' + id + '/' + data.repetition); }); - if(input.attr('type') == 'number') { + if (input.attr('type') == 'number') { // update the range-input: $('#budget-range-' + id).val(value); } else { // update the number-input: - $('#budget-info-' + id +' input').val(value); + $('#budget-info-' + id + ' input').val(value); } // update or hide the bar, whichever is necessary. diff --git a/public/assets/javascript/firefly/gcharts.options.js b/public/assets/javascript/firefly/gcharts.options.js index db138b0c14..acba8a81bb 100644 --- a/public/assets/javascript/firefly/gcharts.options.js +++ b/public/assets/javascript/firefly/gcharts.options.js @@ -117,5 +117,7 @@ var defaultSankeyChartOptions = { height: 400 } var defaultTableOptions = { - allowHtml: true + allowHtml: true, + page: 'enable', + pageSize: 50 }; \ No newline at end of file