From 5b9c2cdc135ac143415658e4e20157d1180c76f3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 24 Feb 2015 21:10:25 +0100 Subject: [PATCH] Newly converted code. --- app/Http/Controllers/PiggyBankController.php | 54 +++++++ .../Controllers/TransactionController.php | 36 +++++ app/Http/breadcrumbs.php | 29 ++-- app/Http/routes.php | 20 ++- app/Models/Account.php | 8 ++ app/Models/PiggyBank.php | 57 ++++++++ .../Account/AccountRepository.php | 18 +++ .../Account/AccountRepositoryInterface.php | 7 + app/Support/ExpandedForm.php | 65 ++++++++- app/User.php | 2 +- public/js/bootstrap3-typeahead.min.js | 1 + public/js/piggy-banks.js | 22 +++ public/js/transactions.js | 21 +++ resources/views/partials/menu.blade.php | 6 +- resources/views/piggy-banks/add.blade.php | 24 ++++ resources/views/piggy-banks/create.blade.php | 94 +++++++++++++ resources/views/piggy-banks/delete.blade.php | 37 +++++ resources/views/piggy-banks/edit.blade.php | 94 +++++++++++++ resources/views/piggy-banks/index.blade.php | 132 ++++++++++++++++++ resources/views/piggy-banks/remove.blade.php | 24 ++++ resources/views/piggy-banks/show.blade.php | 125 +++++++++++++++++ resources/views/transactions/create.blade.php | 34 ++--- 22 files changed, 864 insertions(+), 46 deletions(-) create mode 100644 public/js/bootstrap3-typeahead.min.js create mode 100644 public/js/piggy-banks.js create mode 100644 public/js/transactions.js create mode 100644 resources/views/piggy-banks/add.blade.php create mode 100644 resources/views/piggy-banks/create.blade.php create mode 100644 resources/views/piggy-banks/delete.blade.php create mode 100644 resources/views/piggy-banks/edit.blade.php create mode 100644 resources/views/piggy-banks/index.blade.php create mode 100644 resources/views/piggy-banks/remove.blade.php create mode 100644 resources/views/piggy-banks/show.blade.php diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index 0a83fb239e..81d40fb137 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -3,7 +3,14 @@ use FireflyIII\Http\Requests; use FireflyIII\Http\Controllers\Controller; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Http\Request; +use View; +use Auth; +use Illuminate\Support\Collection; +use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\Account; +use Steam; /** * Class PiggyBankController @@ -12,5 +19,52 @@ use Illuminate\Http\Request; */ class PiggyBankController extends Controller { + /** + * + */ + public function __construct() + { + View::share('title', 'Piggy banks'); + View::share('mainTitleIcon', 'fa-sort-amount-asc'); + } + + + /** + * @return $this + */ + public function index(AccountRepositoryInterface $repository) + { + /** @var Collection $piggyBanks */ + $piggyBanks = Auth::user()->piggyBanks()->where('repeats',0)->get(); + + $accounts = []; + /** @var PiggyBank $piggyBank */ + foreach ($piggyBanks as $piggyBank) { + $piggyBank->savedSoFar = floatval($piggyBank->currentRelevantRep()->currentamount); + $piggyBank->percentage = intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100); + $piggyBank->leftToSave = $piggyBank->targetamount - $piggyBank->savedSoFar; + + /* + * Fill account information: + */ + $account = $piggyBank->account; + if (!isset($accounts[$account->id])) { + $accounts[$account->id] = [ + 'name' => $account->name, + 'balance' => Steam::balance($account), + 'leftForPiggyBanks' => $repository->leftOnAccount($account), + 'sumOfSaved' => $piggyBank->savedSoFar, + 'sumOfTargets' => floatval($piggyBank->targetamount), + 'leftToSave' => $piggyBank->leftToSave + ]; + } else { + $accounts[$account->id]['sumOfSaved'] += $piggyBank->savedSoFar; + $accounts[$account->id]['sumOfTargets'] += floatval($piggyBank->targetamount); + $accounts[$account->id]['leftToSave'] += $piggyBank->leftToSave; + } + } + + return View::make('piggy-banks.index', compact('piggyBanks', 'accounts')); + } } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 0967e186f7..2ee5dc4458 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -1,8 +1,11 @@ accounts()->accountTypeIn(['Default account', 'Asset account'])->where('active', 1)->orderBy('name', 'DESC')->get() + ); + $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); + $budgets[0] = '(no budget)'; + $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); + $piggies[0] = '(no piggy bank)'; + $preFilled = Session::has('preFilled') ? Session::get('preFilled') : []; + $respondTo = ['account_id', 'account_from_id']; + $subTitle = 'Add a new ' . e($what); + + foreach ($respondTo as $r) { + if (!is_null(Input::get($r))) { + $preFilled[$r] = Input::get($r); + } + } + Session::put('preFilled', $preFilled); + + asort($piggies); + + + return view('transactions.create', compact('accounts', 'budgets', 'what', 'piggies', 'subTitle')); + } + /** * @param $what * diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 3bd399b3c5..b202f82636 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -6,6 +6,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; use FireflyIII\Models\LimitRepetition; +use FireflyIII\Models\PiggyBank; /* * Back home. @@ -141,35 +142,35 @@ Breadcrumbs::register( // piggy banks Breadcrumbs::register( - 'piggyBanks.index', function (Generator $breadcrumbs) { + 'piggy-banks.index', function (Generator $breadcrumbs) { $breadcrumbs->parent('home'); - $breadcrumbs->push('Piggy banks', route('piggyBanks.index')); + $breadcrumbs->push('Piggy banks', route('piggy-banks.index')); } ); Breadcrumbs::register( - 'piggyBanks.create', function (Generator $breadcrumbs) { - $breadcrumbs->parent('piggyBanks.index'); - $breadcrumbs->push('Create new piggy bank', route('piggyBanks.create')); + 'piggy-banks.create', function (Generator $breadcrumbs) { + $breadcrumbs->parent('piggy-banks.index'); + $breadcrumbs->push('Create new piggy bank', route('piggy-banks.create')); } ); Breadcrumbs::register( - 'piggyBanks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { - $breadcrumbs->parent('piggyBanks.show', $piggyBank); - $breadcrumbs->push('Edit ' . e($piggyBank->name), route('piggyBanks.edit', $piggyBank->id)); + 'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + $breadcrumbs->parent('piggy-banks.show', $piggyBank); + $breadcrumbs->push('Edit ' . e($piggyBank->name), route('piggy-banks.edit', $piggyBank->id)); } ); Breadcrumbs::register( - 'piggyBanks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { - $breadcrumbs->parent('piggyBanks.show', $piggyBank); - $breadcrumbs->push('Delete ' . e($piggyBank->name), route('piggyBanks.delete', $piggyBank->id)); + 'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + $breadcrumbs->parent('piggy-banks.show', $piggyBank); + $breadcrumbs->push('Delete ' . e($piggyBank->name), route('piggy-banks.delete', $piggyBank->id)); } ); Breadcrumbs::register( - 'piggyBanks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { - $breadcrumbs->parent('piggyBanks.index'); - $breadcrumbs->push(e($piggyBank->name), route('piggyBanks.show', $piggyBank->id)); + 'piggy-banks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { + $breadcrumbs->parent('piggy-banks.index'); + $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', $piggyBank->id)); } ); diff --git a/app/Http/routes.php b/app/Http/routes.php index 35290611d2..7dc48170bf 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -161,13 +161,13 @@ Route::group( * Piggy Bank Controller */ // piggy bank controller - Route::get('/piggy-banks', ['uses' => 'PiggyBankController@index', 'as' => 'piggy_banks.index']); - //Route::get('/piggy-banks/add/{piggyBank}', ['uses' => 'PiggyBankController@add']); # add money - //Route::get('/piggy-banks/remove/{piggyBank}', ['uses' => 'PiggyBankController@remove']); #remove money - //Route::get('/piggy-banks/create', ['uses' => 'PiggyBankController@create', 'as' => 'piggy_banks.create']); - //Route::get('/piggy-banks/edit/{piggyBank}', ['uses' => 'PiggyBankController@edit', 'as' => 'piggy_banks.edit']); - //Route::get('/piggy-banks/delete/{piggyBank}', ['uses' => 'PiggyBankController@delete', 'as' => 'piggy_banks.delete']); - //Route::get('/piggy-banks/show/{piggyBank}', ['uses' => 'PiggyBankController@show', 'as' => 'piggy_banks.show']); + Route::get('/piggy-banks', ['uses' => 'PiggyBankController@index', 'as' => 'piggy-banks.index']); + Route::get('/piggy-banks/add/{piggyBank}', ['uses' => 'PiggyBankController@add']); # add money + Route::get('/piggy-banks/remove/{piggyBank}', ['uses' => 'PiggyBankController@remove']); #remove money + Route::get('/piggy-banks/create', ['uses' => 'PiggyBankController@create', 'as' => 'piggy-banks.create']); + Route::get('/piggy-banks/edit/{piggyBank}', ['uses' => 'PiggyBankController@edit', 'as' => 'piggy-banks.edit']); + Route::get('/piggy-banks/delete/{piggyBank}', ['uses' => 'PiggyBankController@delete', 'as' => 'piggy-banks.delete']); + Route::get('/piggy-banks/show/{piggyBank}', ['uses' => 'PiggyBankController@show', 'as' => 'piggy-banks.show']); /** * Preferences Controller @@ -214,6 +214,12 @@ Route::group( Route::get('/transaction/edit/{tj}', ['uses' => 'TransactionController@edit', 'as' => 'transactions.edit']); Route::get('/transaction/delete/{tj}', ['uses' => 'TransactionController@delete', 'as' => 'transactions.delete']); Route::get('/transaction/show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'transactions.show']); + // transaction controller: + Route::post('/transactions/store/{what}', ['uses' => 'TransactionController@store', 'as' => 'transactions.store'])->where( + ['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers'] + ); + Route::post('/transaction/update/{tj}', ['uses' => 'TransactionController@update', 'as' => 'transactions.update']); + Route::post('/transaction/destroy/{tj}', ['uses' => 'TransactionController@destroy', 'as' => 'transactions.destroy']); //Route::get('/transaction/relate/{tj}', ['uses' => 'TransactionController@relate', 'as' => 'transactions.relate']); //Route::post('/transactions/relatedSearch/{tj}', ['uses' => 'TransactionController@relatedSearch', 'as' => 'transactions.relatedSearch']); //Route::post('/transactions/alreadyRelated/{tj}', ['uses' => 'TransactionController@alreadyRelated', 'as' => 'transactions.alreadyRelated']); diff --git a/app/Models/Account.php b/app/Models/Account.php index 5bad563764..2c6c21002e 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -94,4 +94,12 @@ class Account extends Model return $this->belongsTo('FireflyIII\User'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function piggyBanks() + { + return $this->hasMany('FireflyIII\Models\PiggyBank'); + } + } diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index f31dbcc142..187e4dd722 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -1,5 +1,7 @@ morphMany('FireflyIII\Models\Reminder', 'remindersable'); } + + /** + * Grabs the PiggyBankRepetition that's currently relevant / active + * + * @returns PiggyBankRepetition + */ + public function currentRelevantRep() + { + if ($this->currentRep) { + return $this->currentRep; + } + if ($this->repeats == 0) { + $rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']); + $this->currentRep = $rep; + + return $rep; + } else { + $query = $this->piggyBankRepetitions()->where( + function (EloquentBuilder $q) { + + $q->where( + function (EloquentBuilder $q) { + + $q->where( + function (EloquentBuilder $q) { + $today = new Carbon; + $q->whereNull('startdate'); + $q->orWhere('startdate', '<=', $today->format('Y-m-d 00:00:00')); + } + )->where( + function (EloquentBuilder $q) { + $today = new Carbon; + $q->whereNull('targetdate'); + $q->orWhere('targetdate', '>=', $today->format('Y-m-d 00:00:00')); + } + ); + } + )->orWhere( + function (EloquentBuilder $q) { + $today = new Carbon; + $q->where('startdate', '>=', $today->format('Y-m-d 00:00:00')); + $q->where('targetdate', '>=', $today->format('Y-m-d 00:00:00')); + } + ); + + } + )->orderBy('startdate', 'ASC'); + $result = $query->first(['piggy_bank_repetitions.*']); + $this->currentRep = $result; + + return $result; + } + + + } } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index d62e6c36dd..aff7831674 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -9,6 +9,7 @@ use Config; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountType; +use FireflyIII\Models\PiggyBank; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; @@ -309,4 +310,21 @@ class AccountRepository implements AccountRepositoryInterface return $journal; } + + /** + * @param Account $account + * + * @return float + */ + public function leftOnAccount(Account $account) + { + $balance = \Steam::balance($account); + /** @var PiggyBank $p */ + foreach ($account->piggybanks()->get() as $p) { + $balance -= $p->currentRelevantRep()->currentamount; + } + + return $balance; + + } } \ No newline at end of file diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 322a9f39af..619309d762 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -49,4 +49,11 @@ interface AccountRepositoryInterface * @return Account */ public function update(Account $account, array $data); + + /** + * @param Account $account + * + * @return float + */ + public function leftOnAccount(Account $account); } \ No newline at end of file diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index a7a148b2cf..af36e9fa77 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -3,6 +3,7 @@ namespace FireflyIII\Support; use FireflyIII\Models\TransactionCurrency; +use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; use Input; use Session; @@ -15,7 +16,6 @@ use View; */ class ExpandedForm { - /** * @param $name * @param null $value @@ -23,18 +23,20 @@ class ExpandedForm * * @return string */ - public function balance($name, $value = null, array $options = []) + public function amount($name, $value = null, array $options = []) { $label = $this->label($name, $options); $options = $this->expandOptionArray($name, $label, $options); $classes = $this->getHolderClasses($name); $value = $this->fillFieldValue($name, $value); $options['step'] = 'any'; - $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amount::getDefaultCurrency(); + $options['min'] = '0.01'; + $defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency(); $currencies = TransactionCurrency::orderBy('code', 'ASC')->get(); - $html = View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); + $html = View::make('form.amount', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); return $html; + } /** @@ -124,6 +126,27 @@ class ExpandedForm return $value; } + /** + * @param $name + * @param null $value + * @param array $options + * + * @return string + */ + public function balance($name, $value = null, array $options = []) + { + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $value = $this->fillFieldValue($name, $value); + $options['step'] = 'any'; + $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amount::getDefaultCurrency(); + $currencies = TransactionCurrency::orderBy('code', 'ASC')->get(); + $html = View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); + + return $html; + } + /** * @param $name * @param int $value @@ -165,6 +188,40 @@ class ExpandedForm return $html; } + /** + * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. + * + * Takes any collection and tries to make a sensible select list compatible array of it. + * + * @param Collection $set + * @param bool $addEmpty + * + * @return mixed + */ + public function makeSelectList(Collection $set, $addEmpty = false) + { + $selectList = []; + if ($addEmpty) { + $selectList[0] = '(none)'; + } + $fields = ['title', 'name', 'description']; + /** @var \Eloquent $entry */ + foreach ($set as $entry) { + $id = intval($entry->id); + $title = null; + + foreach ($fields as $field) { + if (isset($entry->$field)) { + $title = $entry->$field; + } + } + $selectList[$id] = $title; + } + + + return $selectList; + } + /** * @param $type * @param $name diff --git a/app/User.php b/app/User.php index 62447196e0..4e09c591f0 100644 --- a/app/User.php +++ b/app/User.php @@ -72,7 +72,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function piggyBanks() { - return $this->hasManyThrough('FireflyIII\Models\PiggyBank', 'Account'); + return $this->hasManyThrough('FireflyIII\Models\PiggyBank', 'FireflyIII\Models\Account'); } /** diff --git a/public/js/bootstrap3-typeahead.min.js b/public/js/bootstrap3-typeahead.min.js new file mode 100644 index 0000000000..9d3cb53ccf --- /dev/null +++ b/public/js/bootstrap3-typeahead.min.js @@ -0,0 +1 @@ +!function($){"use strict";var Typeahead=function(element,options){this.$element=$(element),this.options=$.extend({},$.fn.typeahead.defaults,options),this.matcher=this.options.matcher||this.matcher,this.sorter=this.options.sorter||this.sorter,this.select=this.options.select||this.select,this.autoSelect="boolean"==typeof this.options.autoSelect?this.options.autoSelect:!0,this.highlighter=this.options.highlighter||this.highlighter,this.updater=this.options.updater||this.updater,this.source=this.options.source,this.$menu=$(this.options.menu),this.shown=!1,this.listen(),this.showHintOnFocus="boolean"==typeof this.options.showHintOnFocus?this.options.showHintOnFocus:!1};Typeahead.prototype={constructor:Typeahead,select:function(){var val=this.$menu.find(".active").data("value");return(this.autoSelect||val)&&this.$element.val(this.updater(val)).change(),this.hide()},updater:function(item){return item},setSource:function(source){this.source=source},show:function(){var scrollHeight,pos=$.extend({},this.$element.position(),{height:this.$element[0].offsetHeight});return scrollHeight="function"==typeof this.options.scrollHeight?this.options.scrollHeight.call():this.options.scrollHeight,this.$menu.insertAfter(this.$element).css({top:pos.top+pos.height+scrollHeight,left:pos.left}).show(),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},lookup:function(query){var items;return this.query="undefined"!=typeof query&&null!==query?query:this.$element.val()||"",this.query.length"+match+""})},render:function(items){var that=this;return items=$(items).map(function(i,item){return i=$(that.options.item).data("value",item),i.find("a").html(that.highlighter(item)),i[0]}),this.autoSelect&&items.first().addClass("active"),this.$menu.html(items),this},next:function(){var active=this.$menu.find(".active").removeClass("active"),next=active.next();next.length||(next=$(this.$menu.find("li")[0])),next.addClass("active")},prev:function(){var active=this.$menu.find(".active").removeClass("active"),prev=active.prev();prev.length||(prev=this.$menu.find("li").last()),prev.addClass("active")},listen:function(){this.$element.on("focus",$.proxy(this.focus,this)).on("blur",$.proxy(this.blur,this)).on("keypress",$.proxy(this.keypress,this)).on("keyup",$.proxy(this.keyup,this)),this.eventSupported("keydown")&&this.$element.on("keydown",$.proxy(this.keydown,this)),this.$menu.on("click",$.proxy(this.click,this)).on("mouseenter","li",$.proxy(this.mouseenter,this)).on("mouseleave","li",$.proxy(this.mouseleave,this))},destroy:function(){this.$element.data("typeahead",null),this.$element.off("focus").off("blur").off("keypress").off("keyup"),this.eventSupported("keydown")&&this.$element.off("keydown"),this.$menu.remove()},eventSupported:function(eventName){var isSupported=eventName in this.$element;return isSupported||(this.$element.setAttribute(eventName,"return;"),isSupported="function"==typeof this.$element[eventName]),isSupported},move:function(e){if(this.shown){switch(e.keyCode){case 9:case 13:case 27:e.preventDefault();break;case 38:e.preventDefault(),this.prev();break;case 40:e.preventDefault(),this.next()}e.stopPropagation()}},keydown:function(e){this.suppressKeyPressRepeat=~$.inArray(e.keyCode,[40,38,9,13,27]),this.shown||40!=e.keyCode?this.move(e):this.lookup("")},keypress:function(e){this.suppressKeyPressRepeat||this.move(e)},keyup:function(e){switch(e.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 9:case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide();break;default:this.lookup()}e.stopPropagation(),e.preventDefault()},focus:function(){this.focused||(this.focused=!0,(0===this.options.minLength&&!this.$element.val()||this.options.showHintOnFocus)&&this.lookup())},blur:function(){this.focused=!1,!this.mousedover&&this.shown&&this.hide()},click:function(e){e.stopPropagation(),e.preventDefault(),this.select(),this.$element.focus()},mouseenter:function(e){this.mousedover=!0,this.$menu.find(".active").removeClass("active"),$(e.currentTarget).addClass("active")},mouseleave:function(){this.mousedover=!1,!this.focused&&this.shown&&this.hide()}};var old=$.fn.typeahead;$.fn.typeahead=function(option){var arg=arguments;return this.each(function(){var $this=$(this),data=$this.data("typeahead"),options="object"==typeof option&&option;data||$this.data("typeahead",data=new Typeahead(this,options)),"string"==typeof option&&(arg.length>1?data[option].apply(data,Array.prototype.slice.call(arg,1)):data[option]())})},$.fn.typeahead.defaults={source:[],items:8,menu:'',item:'
  • ',minLength:1,scrollHeight:0,autoSelect:!0},$.fn.typeahead.Constructor=Typeahead,$.fn.typeahead.noConflict=function(){return $.fn.typeahead=old,this},$(document).on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(){var $this=$(this);$this.data("typeahead")||$this.typeahead($this.data())})}(window.jQuery); \ No newline at end of file diff --git a/public/js/piggy-banks.js b/public/js/piggy-banks.js new file mode 100644 index 0000000000..0b603306cd --- /dev/null +++ b/public/js/piggy-banks.js @@ -0,0 +1,22 @@ +$(function () { + $('.addMoney').on('click', addMoney); + $('.removeMoney').on('click', removeMoney); + + if (typeof(googleLineChart) === 'function' && typeof(piggyBankID) !== 'undefined') { + googleLineChart('chart/piggy-history/' + piggyBankID, 'piggy-bank-history'); + } +}); + +function addMoney(e) { + var pigID = parseInt($(e.target).data('id')); + $('#moneyManagementModal').empty().load('piggy-banks/add/' + pigID).modal('show'); + + return false; +} + +function removeMoney(e) { + var pigID = parseInt($(e.target).data('id')); + $('#moneyManagementModal').empty().load('piggy-banks/remove/' + pigID).modal('show'); + + return false; +} \ No newline at end of file diff --git a/public/js/transactions.js b/public/js/transactions.js new file mode 100644 index 0000000000..5719db469c --- /dev/null +++ b/public/js/transactions.js @@ -0,0 +1,21 @@ +if ($('input[name="expense_account"]').length > 0) { + $.getJSON('json/expense-accounts').success(function (data) { + $('input[name="expense_account"]').typeahead({source: data}); + }); +} +if ($('input[name="revenue_account"]').length > 0) { + $.getJSON('json/revenue-accounts').success(function (data) { + $('input[name="revenue_account"]').typeahead({source: data}); + }); +} +if ($('input[name="category"]').length > 0) { + $.getJSON('json/categories').success(function (data) { + $('input[name="category"]').typeahead({source: data}); + }); +} + +$(document).ready(function () { + if(typeof googleTablePaged != 'undefined') { + googleTablePaged('table/transactions/' + what,'transaction-table'); + } +}); \ No newline at end of file diff --git a/resources/views/partials/menu.blade.php b/resources/views/partials/menu.blade.php index 07c825d9e3..38c237cd90 100644 --- a/resources/views/partials/menu.blade.php +++ b/resources/views/partials/menu.blade.php @@ -137,8 +137,8 @@ @@ -146,7 +146,7 @@ Money management