Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some basic fixes for the transaction controller [skip ci]
James Coled75632443202
diff --git a/app/assets/javascripts/firefly/piggybanks.js b/app/assets/javascripts/firefly/piggybanks.jsindex 598b6480bd..56f02c9fbf 100644--- a/app/assets/javascripts/firefly/piggybanks.js+++ b/app/assets/javascripts/firefly/piggybanks.js@@ -15,24 +15,21 @@ function inputRange(e) {var target = $(e.target);var piggyBankId = target.attr('name').substring(6);var accountId = target.data('account');- var value = parseFloat(target.val());+ var amount = parseFloat(target.val());+- var leftInAccount = leftInAccounts(accountId);- if(leftInAccount <= 0) {- value = parseFloat($('#piggy_'+piggyBankId+'_amount').val());- target.val(parseFloat(value));- }- var valueId = 'piggy_' + piggyBankId + '_amount';- $('#' + valueId).val(value.toFixed(2));//-// // new percentage for amount in piggy bank, formatted.+ // new percentage for amount in piggy bank, formatted.var pctId = 'piggy_' + piggyBankId + '_pct';- percentage = Math.round((value / parseFloat(target.attr('max'))) * 100) + '%'; //Math.round((value / parseFloat(target.attr('total'))) * 100) + '%';+ percentage = Math.round((amount / parseFloat(target.attr('max'))) * 100) + '%'; //Math.round((value / parseFloat(target.attr('total'))) * 100) + '%';$('#' + pctId).text(percentage);- // update the bar accordingly.+ // new value for number input:+ var valueId = 'piggy_' + piggyBankId + '_amount';+ $('#' + valueId).val(amount.toFixed(2));+ leftInAccounts(accountId);return true;}@@ -42,27 +39,27 @@ function inputNumber(e) {var amount = parseFloat(target.val());var piggyBankId = target.data('piggy');var accountId = target.data('account');- var leftInAccount = leftInAccounts(accountId);- if(leftInAccount <= 0) {- amount = parseFloat($('#piggy_'+piggyBankId+'_amount').val());- } else {- // do something!- }++ // update amount in range input:target.val(amount);- console.log('SERVER');$('input[name="piggy_'+piggyBankId+'"]').val(amount);+ console.log('SERVER: ' + amount);$.post('piggybanks/updateAmount/' + piggyBankId, {amount: amount});++ leftInAccounts(accountId);}function updateAmount(e) {++ // update amount on server:var target = $(e.target);var piggyBankId = target.attr('name').substring(6);var accountId = target.data('account');- var value = target.val();- console.log('SERVER');- $.post('piggybanks/updateAmount/' + piggyBankId, {amount: value});+ var amount = target.val();+ console.log('SERVER: ' + amount);+ $.post('piggybanks/updateAmount/' + piggyBankId, {amount: amount});}@@ -80,7 +77,11 @@ function leftInAccounts(accountId) {}});var left = total - inPiggies;- console.log('LEFT: ' + left);++ // set amount left:+ leftFormatted = '€ ' + left.toFixed(2);+ $('#account_'+accountId+'_left').text(leftFormatted);+// return amount left:return left;diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.phpindex b098fbefca..14c0465076 100644--- a/app/controllers/CategoryController.php+++ b/app/controllers/CategoryController.php@@ -1,7 +1,7 @@<?php-use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;use Firefly\Helper\Controllers\CategoryInterface as CI;+use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;/*** Class CategoryController@@ -35,6 +35,7 @@ class CategoryController extends BaseController} else {Session::flash('error', 'Could not delete the category. Check the logs to be sure.');}+return Redirect::route('categories.index');}@@ -46,6 +47,7 @@ class CategoryController extends BaseControllerpublic function index(){$categories = $this->_repository->get();+return View::make('categories.index')->with('categories', $categories);}@@ -57,7 +59,7 @@ class CategoryController extends BaseController$journals = $this->_category->journalsInRange($category, $start, $end);- return View::make('categories.show')->with('category', $category)->with('journals',$journals);+ return View::make('categories.show')->with('category', $category)->with('journals', $journals);}public function store()@@ -69,9 +71,11 @@ class CategoryController extends BaseControllerif (Input::get('create') == '1') {return Redirect::route('categories.create');}+return Redirect::route('categories.index');} else {Session::flash('error', 'Could not save the new category!');+return Redirect::route('categories.create')->withInput();}}diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.phpindex 0c776e55ab..150992a659 100644--- a/app/controllers/ChartController.php+++ b/app/controllers/ChartController.php@@ -35,8 +35,8 @@ class ChartController extends BaseController$end = Session::get('end');\Log::debug('Draw home account chart.');- \Log::debug('From: '.$start.' ('.$start->timezone.')');- \Log::debug('Until: '.$end);+ \Log::debug('From: ' . $start . ' (' . $start->timezone . ')');+ \Log::debug('Until: ' . $end);if (is_null($account)) {// get, depending on preferences:@@ -116,7 +116,9 @@ class ChartController extends BaseController}- public function categoryShowChart(Category $category) {++ public function categoryShowChart(Category $category)+ {$start = Session::get('start');$end = Session::get('end');$range = Session::get('range');@@ -124,11 +126,11 @@ class ChartController extends BaseController$serie = $this->_chart->categoryShowChart($category, $range, $start, $end);$data = ['chart_title' => $category->name,- 'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',- 'series' => $serie+ 'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',+ 'series' => $serie];- return Response::json($data);+ return Response::json($data);}diff --git a/app/controllers/LimitController.php b/app/controllers/LimitController.phpindex 8898c74ece..2d85bd8b3c 100644--- a/app/controllers/LimitController.php+++ b/app/controllers/LimitController.php@@ -33,9 +33,9 @@ class LimitController extends BaseController{$periods = \Config::get('firefly.periods_to_text');$prefilled = [- 'startdate' => Input::get('startdate') ? : date('Y-m-d'),+ 'startdate' => Input::get('startdate') ? : date('Y-m-d'),'repeat_freq' => Input::get('repeat_freq') ? : 'monthly',- 'budget_id' => $budget ? $budget->id : null+ 'budget_id' => $budget ? $budget->id : null];$budgets = $this->_budgets->getAsSelectList();diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.phpindex 860f46f41e..71c9f7e045 100644--- a/app/controllers/PiggybankController.php+++ b/app/controllers/PiggybankController.php@@ -27,19 +27,24 @@ class PiggybankController extends BaseControllerreturn View::make('piggybanks.create')->with('accounts', $accounts);}- public function delete()+ public function delete(Piggybank $piggyBank){+ return View::make('piggybanks.delete')->with('piggybank', $piggyBank);}- public function destroy()+ public function destroy(Piggybank $piggyBank){+ $piggyBank->delete();+ Session::flash('success', 'Piggy bank deleted.');++ return Redirect::route('piggybanks.index');}- public function edit()+ public function edit(Piggybank $piggyBank){- }- public function updateAmount(Piggybank $piggybank) {- $this->_repository->updateAmount($piggybank,Input::get('amount'));+ $accounts = $this->_accounts->getActiveDefaultAsSelectList();++ return View::make('piggybanks.edit')->with('piggybank', $piggyBank)->with('accounts', $accounts);}public function index()@@ -55,8 +60,10 @@ class PiggybankController extends BaseControllerif (!isset($accounts[$id])) {$account->balance = $account->balance();$account->left = $account->balance - $piggyBank->amount;+ $account->total = $piggyBank->target;} else {$account->left -= $piggyBank->amount;+ $account->total += $piggyBank->target;}$accounts[$id] = $account;@@ -80,7 +87,12 @@ class PiggybankController extends BaseControllerreturn Redirect::route('piggybanks.create')->withInput();} else {- Session::flash('success', 'New piggy bank created!');+ Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');+++ if (Input::get('create') == '1') {+ return Redirect::route('piggybanks.create')->withInput();+ }return Redirect::route('piggybanks.index');}@@ -89,5 +101,15 @@ class PiggybankController extends BaseControllerpublic function update(){++ $piggyBank = $this->_repository->update(Input::all());+ Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');++ return Redirect::route('piggybanks.index');+ }++ public function updateAmount(Piggybank $piggybank)+ {+ $this->_repository->updateAmount($piggybank, Input::get('amount'));}}\ No newline at end of filediff --git a/app/controllers/RecurringControlle.php b/app/controllers/RecurringController.phpsimilarity index 86%rename from app/controllers/RecurringControlle.phprename to app/controllers/RecurringController.phpindex 10b48a027e..a45bfb0b00 100644--- a/app/controllers/RecurringControlle.php+++ b/app/controllers/RecurringController.php@@ -1,6 +1,7 @@<?php-class RecurringController extends BaseController {+class RecurringController extends BaseController+{public function create(){}diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.phpindex 0c1ddd23e2..efc703856d 100644--- a/app/controllers/ReportController.php+++ b/app/controllers/ReportController.php@@ -1,5 +1,7 @@<?php-class ReportController extends BaseController {++class ReportController extends BaseController+{public function index()diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.phpindex a6c72059b8..0dad583244 100644--- a/app/controllers/TransactionController.php+++ b/app/controllers/TransactionController.php@@ -1,9 +1,6 @@<?php-use Firefly\Storage\Account\AccountRepositoryInterface as ARI;-use Firefly\Storage\Budget\BudgetRepositoryInterface as Bud;-use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;/**@@ -12,38 +9,33 @@ use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface asclass TransactionController extends BaseController{- protected $_accounts;- protected $_budgets;- protected $_categories;- protected $_journal;+ protected $_repository;/**- * @param ARI $accounts- * @param Bud $budgets- * @param Cat $categories- * @param TJRI $journal+ * @param TJRI $repository*/- public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $journal)+ public function __construct(TJRI $repository){- $this->_accounts = $accounts;- $this->_budgets = $budgets;- $this->_categories = $categories;- $this->_journal = $journal;--+ $this->_repository = $repository;View::share('menu', 'home');}/**- * @param $what+ * @param string $what*- * @return $this|\Illuminate\View\View+ * @return \Illuminate\View\View*/- public function create($what)+ public function create($what = 'deposit'){// get accounts with names and id's.- $accounts = $this->_accounts->getActiveDefaultAsSelectList();- $budgets = $this->_budgets->getAsSelectList();+ /** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */+ $accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');+ $accounts = $accountRepository->getActiveDefaultAsSelectList();++ // get budgets as a select list.+ /** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */+ $budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');+ $budgets = $budgetRepository->getAsSelectList();$budgets[0] = '(no budget)';@@ -52,63 +44,78 @@ class TransactionController extends BaseController);}+ public function delete(TransactionJournal $transactionJournal)+ {+ return View::make('transactions.delete')->with('journal', $transactionJournal);+++ }++ public function destroy(TransactionJournal $transactionJournal)+ {+ $transactionJournal->delete();++ return Redirect::route('transactions.index');++ }+/*** @param $journalId** @return $this|\Illuminate\View\View*/- public function edit($journalId)+ public function edit(TransactionJournal $journal){- // get journal:- $journal = $this->_journal->find($journalId);-- if ($journal) {- // type is useful for display:- $what = strtolower($journal->transactiontype->type);-- // some lists prefilled:- $budgets = $this->_budgets->getAsSelectList();- $budgets[0] = '(no budget)';- $accounts = $this->_accounts->getActiveDefaultAsSelectList();-- // data to properly display form:- $data = [- 'date' => $journal->date->format('Y-m-d'),- 'category' => '',- 'budget_id' => 0- ];- $category = $journal->categories()->first();- if (!is_null($category)) {- $data['category'] = $category->name;- }- switch ($journal->transactiontype->type) {- case 'Withdrawal':- $data['account_id'] = $journal->transactions[0]->account->id;- $data['beneficiary'] = $journal->transactions[1]->account->name;- $data['amount'] = floatval($journal->transactions[1]->amount);- $budget = $journal->budgets()->first();- if (!is_null($budget)) {- $data['budget_id'] = $budget->id;- }- break;- case 'Deposit':- $data['account_id'] = $journal->transactions[1]->account->id;- $data['beneficiary'] = $journal->transactions[0]->account->name;- $data['amount'] = floatval($journal->transactions[1]->amount);- break;- case 'Transfer':- $data['account_from_id'] = $journal->transactions[1]->account->id;- $data['account_to_id'] = $journal->transactions[0]->account->id;- $data['amount'] = floatval($journal->transactions[1]->amount);- break;- }+ // type is useful for display:+ $what = strtolower($journal->transactiontype->type);- return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(- 'what', $what- )->with('budgets', $budgets)->with('data', $data);+ // some lists prefilled:+ // get accounts with names and id's.+ /** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */+ $accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');+ $accounts = $accountRepository->getActiveDefaultAsSelectList();++ // get budgets as a select list.+ /** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */+ $budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');+ $budgets = $budgetRepository->getAsSelectList();+ $budgets[0] = '(no budget)';++ // data to properly display form:+ $data = [+ 'date' => $journal->date->format('Y-m-d'),+ 'category' => '',+ 'budget_id' => 0+ ];+ $category = $journal->categories()->first();+ if (!is_null($category)) {+ $data['category'] = $category->name;+ }+ switch ($journal->transactiontype->type) {+ case 'Withdrawal':+ $data['account_id'] = $journal->transactions[0]->account->id;+ $data['beneficiary'] = $journal->transactions[1]->account->name;+ $data['amount'] = floatval($journal->transactions[1]->amount);+ $budget = $journal->budgets()->first();+ if (!is_null($budget)) {+ $data['budget_id'] = $budget->id;+ }+ break;+ case 'Deposit':+ $data['account_id'] = $journal->transactions[1]->account->id;+ $data['beneficiary'] = $journal->transactions[0]->account->name;+ $data['amount'] = floatval($journal->transactions[1]->amount);+ break;+ case 'Transfer':+ $data['account_from_id'] = $journal->transactions[1]->account->id;+ $data['account_to_id'] = $journal->transactions[0]->account->id;+ $data['amount'] = floatval($journal->transactions[1]->amount);+ break;}- return View::make('error')->with('message', 'Invalid journal');+ return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(+ 'what', $what+ )->with('budgets', $budgets)->with('data', $data);}/**@@ -116,9 +123,9 @@ class TransactionController extends BaseController*/public function index(){- $transactions = $this->_journal->paginate(25);+ $journals = $this->_repository->paginate(25);- return View::make('transactions.index')->with('transactions', $transactions);+ return View::make('transactions.index')->with('journals', $journals);}/**@@ -128,12 +135,12 @@ class TransactionController extends BaseController*/public function show($journalId){- $journal = $this->_journal->find($journalId);- if ($journal) {- return View::make('transactions.show')->with('journal', $journal);- }-- return View::make('error')->with('message', 'Invalid journal');+// $journal = $this->_journal->find($journalId);+// if ($journal) {+// return View::make('transactions.show')->with('journal', $journal);+// }+//+// return View::make('error')->with('message', 'Invalid journal');}/**@@ -143,137 +150,37 @@ class TransactionController extends BaseController*/public function store($what){- // $fromAccount and $toAccount are found- // depending on the $what-- $fromAccount = null;- $toAccount = null;-- switch ($what) {- case 'withdrawal':- $fromAccount = $this->_accounts->find(intval(Input::get('account_id')));- $toAccount = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));- break;- case 'deposit':- $fromAccount = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));- $toAccount = $this->_accounts->find(intval(Input::get('account_id')));- break;- case 'transfer':- $fromAccount = $this->_accounts->find(intval(Input::get('account_from_id')));- $toAccount = $this->_accounts->find(intval(Input::get('account_to_id')));- break;- }- // fall back to cash if necessary:- $fromAccount = is_null($fromAccount) ? $fromAccount = $this->_accounts->getCashAccount() : $fromAccount;- $toAccount = is_null($toAccount) ? $toAccount = $this->_accounts->getCashAccount() : $toAccount;-- // create or find category:- $category = $this->_categories->createOrFind(Input::get('category'));-- // find budget:- $budget = $this->_budgets->find(intval(Input::get('budget_id')));-- // find amount & description:- $description = trim(Input::get('description'));- $amount = floatval(Input::get('amount'));- $date = new \Carbon\Carbon(Input::get('date'));-- // create journal- /** @var \TransactionJournal $journal */- try {- $journal = $this->_journal->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);- } catch (\Firefly\Exception\FireflyException $e) {- return Redirect::route('transactions.create', $what)->withInput();- }-- // attach bud/cat (?)- if (!is_null($budget)) {- $journal->budgets()->save($budget);- }- if (!is_null($category)) {- $journal->categories()->save($category);- }-- Session::flash('success', 'Transaction "' . $description . '" saved');-- if (Input::get('create') == '1') {- return Redirect::route('transactions.create', $what)->withInput();+ $transactionJournal = $this->_repository->store($what, Input::all());+ if ($transactionJournal->id) {+ Session::flash('success', 'Transaction "' . $transactionJournal->description . '" saved!');+ if (Input::get('create') == '1') {+ return Redirect::route('transactions.create', [$what])->withInput();+ } else {+ return Redirect::route('transactions.index');+ }} else {- return Redirect::route('index');+ Session::flash('error', 'Could not save transaction: ' . $transactionJournal->errors()->first());++ return Redirect::route('transactions.create', [$what])->withInput()->withErrors(+ $transactionJournal->errors()+ );}}- public function update($journalId)+ public function update(TransactionJournal $journal){+ $journal = $this->_repository->update($journal, Input::all());+ if ($journal->validate()) {+ // has been saved, return to index:+ Session::flash('success', 'Transaction updated!');- // get journal:- $journal = $this->_journal->find($journalId);-- if ($journal) {- // update basics first:- $journal->description = Input::get('description');- $journal->date = Input::get('date');- $amount = floatval(Input::get('amount'));-- // remove previous category, if any:- if (!is_null($journal->categories()->first())) {- $journal->categories()->detach($journal->categories()->first()->id);- }- // remove previous budget, if any:- if (!is_null($journal->budgets()->first())) {- $journal->budgets()->detach($journal->budgets()->first()->id);- }-- // get the category:- $category = $this->_categories->findByName(Input::get('category'));- if (!is_null($category)) {- $journal->categories()->attach($category);- }- // update the amounts:- $journal->transactions[0]->amount = $amount * -1;- $journal->transactions[1]->amount = $amount;-- // switch on type to properly change things:- switch ($journal->transactiontype->type) {- case 'Withdrawal':- // means transaction[0] is the users account.- $account = $this->_accounts->find(Input::get('account_id'));- $beneficiary = $this->_accounts->findByName(Input::get('beneficiary'));- $journal->transactions[0]->account()->associate($account);- $journal->transactions[1]->account()->associate($beneficiary);--- // do budget:- $budget = $this->_budgets->find(Input::get('budget_id'));- $journal->budgets()->attach($budget);-- break;- case 'Deposit':- // means transaction[0] is the beneficiary.- $account = $this->_accounts->find(Input::get('account_id'));- $beneficiary = $this->_accounts->findByName(Input::get('beneficiary'));- $journal->transactions[0]->account()->associate($beneficiary);- $journal->transactions[1]->account()->associate($account);- break;- case 'Transfer':- // means transaction[0] is account that sent the money (from).- $fromAccount = $this->_accounts->find(Input::get('account_from_id'));- $toAccount = $this->_accounts->find(Input::get('account_to_id'));- $journal->transactions[0]->account()->associate($fromAccount);- $journal->transactions[1]->account()->associate($toAccount);- break;- default:- throw new \Firefly\Exception\FireflyException('Cannot edit this!');- break;- }-- $journal->transactions[0]->save();- $journal->transactions[1]->save();- $journal->save();+ return Redirect::route('transactions.index');+ } else {+ Session::flash('error', 'Could not update transaction: ' . $journal->errors()->first());- return Redirect::route('transactions.edit', $journal->id);+ return Redirect::route('transactions.edit', $journal->id)->withInput()->withErrors($journal->errors());}diff --git a/app/lib/Firefly/Helper/Controllers/Category.php b/app/lib/Firefly/Helper/Controllers/Category.phpindex 1f31dd9c04..0b3444ce87 100644--- a/app/lib/Firefly/Helper/Controllers/Category.php+++ b/app/lib/Firefly/Helper/Controllers/Category.php@@ -15,10 +15,9 @@ class Category implements CategoryInterface{public function journalsInRange(\Category $category, Carbon $start, Carbon $end){- return $category->transactionjournals()->- with(['transactions','transactions.account','transactiontype','components'])->-- orderBy('date','DESC')->orderBy('id','DESC')->before($end)->after($start)->get();+ return $category->transactionjournals()->with(+ ['transactions', 'transactions.account', 'transactiontype', 'components']+ )->orderBy('date', 'DESC')->orderBy('id', 'DESC')->before($end)->after($start)->get();}}\ No newline at end of filediff --git a/app/lib/Firefly/Helper/Controllers/CategoryInterface.php b/app/lib/Firefly/Helper/Controllers/CategoryInterface.phpindex 621c6a6600..f858f301b9 100644--- a/app/lib/Firefly/Helper/Controllers/CategoryInterface.php+++ b/app/lib/Firefly/Helper/Controllers/CategoryInterface.php@@ -11,7 +11,8 @@ namespace Firefly\Helper\Controllers;use Carbon\Carbon;-interface CategoryInterface {+interface CategoryInterface+{public function journalsInRange(\Category $category, Carbon $start, Carbon $end);diff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.phpindex dc9015c029..62290d58cd 100644--- a/app/lib/Firefly/Helper/Controllers/Chart.php+++ b/app/lib/Firefly/Helper/Controllers/Chart.php@@ -21,7 +21,9 @@ class Chart implements ChartInterface$return = ['name' => $account->name, 'id' => $account->id, 'data' => []];while ($current <= $end) {- \Log::debug('Now at day: ' . $current . '('.$current->timestamp.'), ('.($current->timestamp * 1000).') ');+ \Log::debug(+ 'Now at day: ' . $current . '(' . $current->timestamp . '), (' . ($current->timestamp * 1000) . ') '+ );if ($current > $today) {$return['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];} else {@@ -38,7 +40,7 @@ class Chart implements ChartInterface{$result = ['rows' => [],- 'sum' => 0+ 'sum' => 0];if ($account) {// get journals in range:@@ -219,7 +221,6 @@ class Chart implements ChartInterface}-// now format the current range:$title = '';switch ($range) {@@ -240,7 +241,7 @@ class Chart implements ChartInterface$title = $beginning->format('M Y') . ' - ' . $currentEnd->format('M Y');break;case 'custom':- $title = $beginning->format('d-m-Y').' - '.$currentEnd->format('d-m-Y');+ $title = $beginning->format('d-m-Y') . ' - ' . $currentEnd->format('d-m-Y');break;case 'yearly':// return $this->startdate->format('Y');@@ -257,7 +258,10 @@ class Chart implements ChartInterface)->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->where('transaction_types.type', 'Withdrawal')- ->leftJoin('component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')+ ->leftJoin(+ 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',+ 'transaction_journals.id'+ )->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->where('components.id', '=', $category->id)//->leftJoin()@@ -306,6 +310,7 @@ class Chart implements ChartInterface}}+return $data;diff --git a/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php b/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.phpindex f6ab03d581..ca422ca541 100644--- a/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php+++ b/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php@@ -14,6 +14,7 @@ interface CategoryRepositoryInterface* @return mixed*/public function get();+public function find($categoryId);/**diff --git a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.phpindex c703200dbd..0ab79e6a43 100644--- a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php+++ b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php@@ -66,6 +66,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface$category->user()->associate(\Auth::user());$category->save();+return $category;}diff --git a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.phpindex 946c6f35f1..efcca6ae9b 100644--- a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php+++ b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php@@ -23,7 +23,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface{return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where('accounts.user_id', \Auth::user()->id- )->where('piggybanks.id', $piggyBankId)->first('piggybanks.*');+ )->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);}public function get()@@ -32,13 +32,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface'accounts.user_id', \Auth::user()->id)->get(['piggybanks.*']);}- public function updateAmount(\Piggybank $piggyBank, $amount) {- $piggyBank->amount = floatval($amount);- if($piggyBank->validate()) {- $piggyBank->save();- }-- }public function store($data){@@ -62,4 +55,31 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterfacereturn $piggyBank;}++ public function update($data)+ {+ $piggyBank = $this->find($data['id']);+ if ($piggyBank) {+ $accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');+ $account = $accounts->find($data['account_id']);+ // update piggybank accordingly:+ $piggyBank->name = $data['name'];+ $piggyBank->target = floatval($data['target']);+ $piggyBank->account()->associate($account);+ if ($piggyBank->validate()) {+ $piggyBank->save();+ }+ }++ return $piggyBank;+ }++ public function updateAmount(\Piggybank $piggyBank, $amount)+ {+ $piggyBank->amount = floatval($amount);+ if ($piggyBank->validate()) {+ $piggyBank->save();+ }++ }}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php b/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.phpindex 57535460dc..995dacaf43 100644--- a/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php+++ b/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php@@ -12,9 +12,15 @@ interface PiggybankRepositoryInterface{public function find($piggyBankId);+public function count();+public function store($data);+public function get();public function updateAmount(\Piggybank $piggyBank, $amount);++ public function update($data);+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/StorageServiceProvider.php b/app/lib/Firefly/Storage/StorageServiceProvider.phpindex 3d3145aa46..420e57ce8c 100644--- a/app/lib/Firefly/Storage/StorageServiceProvider.php+++ b/app/lib/Firefly/Storage/StorageServiceProvider.php@@ -32,8 +32,6 @@ class StorageServiceProvider extends ServiceProvider);--$this->app->bind('Firefly\Storage\Account\AccountRepositoryInterface','Firefly\Storage\Account\EloquentAccountRepository'diff --git a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.phpindex 5e37cf683e..fc04b223fb 100644--- a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php+++ b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php@@ -14,26 +14,6 @@ use Firefly\Exception\FireflyException;class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface{- /**- * @param $journalId- *- * @return mixed- */- public function find($journalId)- {- return \Auth::user()->transactionjournals()->with(- ['transactions' => function ($q) {- return $q->orderBy('amount', 'ASC');- }, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',- 'transactions.account.accounttype']- )- ->where('id', $journalId)->first();- }- /*-- *- */-/**** We're building this thinking the money goes from A to B.@@ -66,20 +46,24 @@ class EloquentTransactionJournalRepository implements TransactionJournalRepositopublic function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date){\Log::debug('Creating tranaction "' . $description . '".');+ $journal = new \TransactionJournal;$amountFrom = $amount * -1;$amountTo = $amount;if (round(floatval($amount), 2) == 0.00) {\Log::error('Transaction will never save: amount = 0');- \Session::flash('error', 'The amount should not be empty or zero.');- throw new FireflyException('Could not figure out transaction type.');+ $journal->errors()->add('amount', 'Amount must not be zero.');++ return $journal;}// same account:if ($from->id == $toAccount->id) {\Log::error('Accounts cannot be equal');- \Session::flash('error', 'Select two different accounts.');- throw new FireflyException('Select two different accounts.');+ $journal->errors()->add('account_id', 'Must be different accounts.');+ $journal->errors()->add('account_from_id', 'Must be different accounts.');++ return $journal;}// account types for both:@@ -129,18 +113,15 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito}// new journal:- $journal = new \TransactionJournal();+$journal->transactionType()->associate($journalType);$journal->transactionCurrency()->associate($currency);$journal->user()->associate(\Auth::user());$journal->completed = false;$journal->description = $description;$journal->date = $date;- if (!$journal->save()) {- \Log::error('Cannot create valid journal.');- \Log::error('Errors: ' . print_r($journal->errors()->all(), true));- \Session::flash('error', 'Could not create journal: ' . $journal->errors()->first());- throw new FireflyException('Cannot create valid journal.');+ if (!$journal->validate()) {+ return $journal;}$journal->save();@@ -150,7 +131,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito$fromTransaction->transactionJournal()->associate($journal);$fromTransaction->description = null;$fromTransaction->amount = $amountFrom;- if (!$fromTransaction->save()) {+ if (!$fromTransaction->validate()) {\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));throw new FireflyException('Cannot create valid transaction (from).');@@ -162,7 +143,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito$toTransaction->transactionJournal()->associate($journal);$toTransaction->description = null;$toTransaction->amount = $amountTo;- if (!$toTransaction->save()) {+ if (!$toTransaction->validate()) {\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));throw new FireflyException('Cannot create valid transaction (to).');@@ -174,6 +155,26 @@ class EloquentTransactionJournalRepository implements TransactionJournalRepositoreturn $journal;}+ /*++ *+ */++ /**+ * @param $journalId+ *+ * @return mixed+ */+ public function find($journalId)+ {+ return \Auth::user()->transactionjournals()->with(+ ['transactions' => function ($q) {+ return $q->orderBy('amount', 'ASC');+ }, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',+ 'transactions.account.accounttype']+ )+ ->where('id', $journalId)->first();+ }/***@@ -185,57 +186,60 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito/*** @param \Account $account- * @param int $count- * @param Carbon $start- * @param Carbon $end+ * @param Carbon $date** @return mixed*/- public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end)+ public function getByAccountAndDate(\Account $account, Carbon $date){$accountID = $account->id;$query = \Auth::user()->transactionjournals()->with(['transactions',+ 'transactions.account','transactioncurrency','transactiontype'])+ ->distinct()->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')- ->where('accounts.id', $accountID)- ->where('date', '>=', $start->format('Y-m-d'))- ->where('date', '<=', $end->format('Y-m-d'))+ ->where('transactions.account_id', $accountID)+ ->where('transaction_journals.date', $date->format('Y-m-d'))->orderBy('transaction_journals.date', 'DESC')->orderBy('transaction_journals.id', 'DESC')- ->take($count)->get(['transaction_journals.*']);return $query;}/**- * @param int $count+ * @param \Account $account+ * @param int $count+ * @param Carbon $start+ * @param Carbon $end** @return mixed*/- public function paginate($count = 25)+ public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end){+ $accountID = $account->id;$query = \Auth::user()->transactionjournals()->with([- 'transactions' => function ($q) {- return $q->orderBy('amount', 'ASC');- },- 'transactions.account',- 'transactions.account.accounttype',+ 'transactions','transactioncurrency','transactiontype'])+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')+ ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')+ ->where('accounts.id', $accountID)+ ->where('date', '>=', $start->format('Y-m-d'))+ ->where('date', '<=', $end->format('Y-m-d'))->orderBy('transaction_journals.date', 'DESC')->orderBy('transaction_journals.id', 'DESC')->take($count)- ->paginate($count);+ ->get(['transaction_journals.*']);return $query;}@@ -252,33 +256,174 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito}/**- * @param \Account $account- * @param Carbon $date+ * @param int $count** @return mixed*/- public function getByAccountAndDate(\Account $account, Carbon $date)+ public function paginate($count = 25){- $accountID = $account->id;$query = \Auth::user()->transactionjournals()->with([- 'transactions',+ 'transactions' => function ($q) {+ return $q->orderBy('amount', 'ASC');+ },'transactions.account',+ 'transactions.account.accounttype','transactioncurrency','transactiontype'])- ->distinct()- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')- ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')- ->where('transactions.account_id', $accountID)- ->where('transaction_journals.date', $date->format('Y-m-d'))->orderBy('transaction_journals.date', 'DESC')->orderBy('transaction_journals.id', 'DESC')- ->get(['transaction_journals.*']);+ ->paginate($count);return $query;}+ public function store($what, $data)+ {+ // $fromAccount and $toAccount are found+ // depending on the $what++ $fromAccount = null;+ $toAccount = null;++ /** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */+ $accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');++ /** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */+ $catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');++ /** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budRepository */+ $budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');+++ switch ($what) {+ case 'withdrawal':+ $fromAccount = $accountRepository->find(intval($data['account_id']));+ $toAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);+ break;+ case 'deposit':+ $fromAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);+ $toAccount = $accountRepository->find(intval($data['account_id']));+ break;+ case 'transfer':+ $fromAccount = $accountRepository->find(intval($data['account_from_id']));+ $toAccount = $accountRepository->find(intval($data['account_to_id']));+ break;+ }+ // fall back to cash if necessary:+ $fromAccount = is_null($fromAccount) ? $fromAccount = $accountRepository->getCashAccount() : $fromAccount;+ $toAccount = is_null($toAccount) ? $toAccount = $accountRepository->getCashAccount() : $toAccount;++ // create or find category:+ $category = isset($data['category']) ? $catRepository->createOrFind($data['category']) : null;++ // find budget:+ $budget = isset($data['budget_id']) ? $budRepository->find(intval($data['budget_id'])) : null;+//+// // find amount & description:+ $description = trim($data['description']);+ $amount = floatval($data['amount']);+ $date = new \Carbon\Carbon($data['date']);++ // try to create a journal:+ $transactionJournal = $this->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);+ if (!$transactionJournal->id || $transactionJournal->completed == 0) {+ return $transactionJournal;+ }++ // attach:+ if (!is_null($budget)) {+ $transactionJournal->budgets()->save($budget);+ }+ if (!is_null($category)) {+ $transactionJournal->categories()->save($category);+ }++ return $transactionJournal;+ }++ public function update(\TransactionJournal $journal, $data)+ {+ /** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */+ $catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');++ /** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */+ $budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');++ /** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */+ $accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');+++ // update basics first:+ $journal->description = $data['description'];+ $journal->date = $data['date'];+ $amount = floatval($data['amount']);++ // remove previous category, if any:+ if (!is_null($journal->categories()->first())) {+ $journal->categories()->detach($journal->categories()->first()->id);+ }+ // remove previous budget, if any:+ if (!is_null($journal->budgets()->first())) {+ $journal->budgets()->detach($journal->budgets()->first()->id);+ }+++ $category = isset($data['category']) ? $catRepository->findByName($data['category']) : null;+ if (!is_null($category)) {+ $journal->categories()->attach($category);+ }+ // update the amounts:+ /** @var \Transaction $transaction */+ $transactions = $journal->transactions()->orderBy('amount', 'ASC')->get();+ $transactions[0]->amount = $amount;+ $transactions[1]->amount = $amount;++ // switch on type to properly change things:+ switch ($journal->transactiontype->type) {+ case 'Withdrawal':+ // means transaction[0] is the users account.+ $account = $accountRepository->find($data['account_id']);+ $beneficiary = $accountRepository->findByName($data['beneficiary']);+ $transactions[0]->account()->associate($account);+ $transactions[1]->account()->associate($beneficiary);++ // do budget:+ $budget = $budRepository->find($data['budget_id']);+ $journal->budgets()->attach($budget);++ break;+ case 'Deposit':+ // means transaction[0] is the beneficiary.+ $account = $accountRepository->find($data['account_id']);+ $beneficiary = $accountRepository->findByName($data['beneficiary']);+ $journal->transactions[0]->account()->associate($beneficiary);+ $journal->transactions[1]->account()->associate($account);+ break;+ case 'Transfer':+ // means transaction[0] is account that sent the money (from).+ $fromAccount = $accountRepository->find($data['account_from_id']);+ $toAccount = $accountRepository->find($data['account_to_id']);+ $journal->transactions[0]->account()->associate($fromAccount);+ $journal->transactions[1]->account()->associate($toAccount);+ break;+ default:+ throw new \Firefly\Exception\FireflyException('Cannot edit this!');+ break;+ }++ $transactions[0]->save();+ $transactions[1]->save();+ if ($journal->validate()) {+ $journal->save();+ }++ return $journal;+++ }+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php b/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.phpindex 6bf727d259..71ccee399d 100644--- a/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php+++ b/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php@@ -27,6 +27,10 @@ interface TransactionJournalRepositoryInterface*/public function get();+ public function store($what, $data);++ public function update(\TransactionJournal $journal, $data);+/*** @param $journalId*diff --git a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.phpindex b7b05a154d..4af5f62e5f 100644--- a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php+++ b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php@@ -46,14 +46,14 @@ class EloquentLimitTriggerif ($limit->repeats == 0) {$limit->createRepetition($limit->startdate);}- if($limit->repeats == 1) {+ if ($limit->repeats == 1) {$start = $limit->startdate;$end = new Carbon;// repeat for period:$current = clone $start;- \Log::debug('Create repeating limit for #'.$limit->id.' starting on ' . $current);- while($current <= $end) {+ \Log::debug('Create repeating limit for #' . $limit->id . ' starting on ' . $current);+ while ($current <= $end) {\Log::debug('Current is now: ' . $current);$limit->createRepetition(clone $current);// switch period, add time:@@ -128,10 +128,10 @@ class EloquentLimitTrigger// }//// }- }-}+}+ }////diff --git a/app/models/Piggybank.php b/app/models/Piggybank.phpindex f1b4291d7c..2afb4908a3 100644--- a/app/models/Piggybank.php+++ b/app/models/Piggybank.php@@ -1,6 +1,29 @@<?phpuse LaravelBook\Ardent\Ardent as Ardent;+/**+ * Piggybank+ *+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property integer $account_id+ * @property \Carbon\Carbon $targetdate+ * @property string $name+ * @property float $amount+ * @property float $target+ * @property integer $order+ * @property-read \Account $account+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereId($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereCreatedAt($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereUpdatedAt($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereAccountId($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereName($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereAmount($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereTarget($value)+ * @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value)+ */class Piggybank extends Ardent{public static $rules@@ -18,4 +41,9 @@ class Piggybank extends Ardentreturn $this->belongsTo('Account');}+ public function getDates()+ {+ return array('created_at', 'updated_at', 'targetdate');+ }+}\ No newline at end of filediff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.phpindex fb5d474bdd..4afdac6c13 100644--- a/app/models/TransactionJournal.php+++ b/app/models/TransactionJournal.php@@ -47,6 +47,14 @@ use LaravelBook\Ardent\Ardent;* 'Budget[] $budgets* @property-read \Illuminate\Database\Eloquent\Collection|\* 'Category[] $categories+ * @property-read \Illuminate\Database\Eloquent\Collection|\+ * 'Budget[] $budgets+ * @property-read \Illuminate\Database\Eloquent\Collection|\+ * 'Category[] $categories+ * @property-read \Illuminate\Database\Eloquent\Collection|\+ * 'Budget[] $budgets+ * @property-read \Illuminate\Database\Eloquent\Collection|\+ * 'Category[] $categories*/class TransactionJournal extends Ardent{diff --git a/app/models/User.php b/app/models/User.phpindex 72ea913144..1250c2710f 100644--- a/app/models/User.php+++ b/app/models/User.php@@ -32,6 +32,7 @@ use LaravelBook\Ardent\Ardent;* @method static \Illuminate\Database\Query\Builder|\User whereRememberToken($value)* @method static \Illuminate\Database\Query\Builder|\User whereMigrated($value)* @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals+ * @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks*/class User extends Ardent implements UserInterface, RemindableInterface{@@ -72,7 +73,8 @@ class User extends Ardent implements UserInterface, RemindableInterfacereturn $this->hasMany('Account');}- public function piggybanks() {+ public function piggybanks()+ {return $this->hasMany('Piggybank');}diff --git a/app/routes.php b/app/routes.phpindex f4f8fe4ccb..ea47f032c5 100644--- a/app/routes.php+++ b/app/routes.php@@ -30,6 +30,16 @@ Route::bind('category', function($value, $route)return null;});+Route::bind('tj', function($value, $route)+ {+ if(Auth::check()) {+ return TransactionJournal::+ where('id', $value)->+ where('user_id',Auth::user()->id)->first();+ }+ return null;+ });+Route::bind('limit', function($value, $route){if(Auth::check()) {@@ -78,6 +88,8 @@ Route::group(['before' => 'auth'], function () {// piggy bank controllerRoute::get('/piggybanks',['uses' => 'PiggybankController@index','as' => 'piggybanks.index']);Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create','as' => 'piggybanks.create']);+ Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);+ Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']);Route::post('/piggybanks/updateAmount/{piggybank}',['uses' => 'PiggybankController@updateAmount','as' => 'piggybanks.updateAmount']);@@ -119,10 +131,11 @@ Route::group(['before' => 'auth'], function () {// transaction controller:Route::get('/transactions/create/{what}', ['uses' => 'TransactionController@create', 'as' => 'transactions.create'])->where(['what' => 'withdrawal|deposit|transfer']);- Route::get('/transaction/show/{id}',['uses' => 'TransactionController@show','as' => 'transactions.show']);- Route::get('/transaction/edit/{id}',['uses' => 'TransactionController@edit','as' => 'transactions.edit']);- Route::get('/transaction/delete/{id}',['uses' => 'TransactionController@delete','as' => 'transactions.delete']);+ Route::get('/transaction/show/{tj}',['uses' => 'TransactionController@show','as' => 'transactions.show']);+ Route::get('/transaction/edit/{tj}',['uses' => 'TransactionController@edit','as' => 'transactions.edit']);+ Route::get('/transaction/delete/{tj}',['uses' => 'TransactionController@delete','as' => 'transactions.delete']);Route::get('/transactions/index',['uses' => 'TransactionController@index','as' => 'transactions.index']);+// migration controllerRoute::get('/migrate', ['uses' => 'MigrationController@index', 'as' => 'migrate']);@@ -149,7 +162,8 @@ Route::group(['before' => 'csrf|auth'], function () {// piggy bank controllerRoute::post('/piggybanks/store',['uses' => 'PiggybankController@store','as' => 'piggybanks.store']);-+ Route::post('/piggybanks/update', ['uses' => 'PiggybankController@update','as' => 'piggybanks.update']);+ Route::post('/piggybanks/destroy/{piggybank}', ['uses' => 'PiggybankController@destroy','as' => 'piggybanks.destroy']);@@ -169,7 +183,8 @@ Route::group(['before' => 'csrf|auth'], function () {// transaction controller:Route::post('/transactions/store/{what}', ['uses' => 'TransactionController@store', 'as' => 'transactions.store'])->where(['what' => 'withdrawal|deposit|transfer']);- Route::post('/transaction/update/{id}',['uses' => 'TransactionController@update','as' => 'transactions.update']);+ Route::post('/transaction/update/{tj}',['uses' => 'TransactionController@update','as' => 'transactions.update']);+ Route::post('/transaction/destroy/{tj}',['uses' => 'TransactionController@destroy','as' => 'transactions.destroy']);});diff --git a/app/views/lists/transactions.blade.php b/app/views/lists/transactions.blade.phpindex 49bdca4665..b41db9db0d 100644--- a/app/views/lists/transactions.blade.php+++ b/app/views/lists/transactions.blade.php@@ -28,10 +28,10 @@<td>@foreach($journal->components as $component)@if($component->class == 'Budget')- <a href="#budget-overview"><span class="glyphicon glyphicon-tasks" title="Budget: {{{$component->name}}}"></span></a>+ <a href="#budget-overview-in-month"><span class="glyphicon glyphicon-tasks" title="Budget: {{{$component->name}}}"></span></a>@endif@if($component->class == 'Category')- <a href="#category-overview"><span class="glyphicon glyphicon-tag" title="Category: {{{$component->name}}}"></span></a>+ <a href="#category-overview-in-month"><span class="glyphicon glyphicon-tag" title="Category: {{{$component->name}}}"></span></a>@endif@endforeach</td>diff --git a/app/views/piggybanks/delete.blade.php b/app/views/piggybanks/delete.blade.phpnew file mode 100644index 0000000000..275e65d6b1--- /dev/null+++ b/app/views/piggybanks/delete.blade.php@@ -0,0 +1,45 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly+ <small>Delete piggy bank</small>+ </h1>+ <p class="lead">Remember that deleting something is permanent.</p>++ </div>++</div>++{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.destroy',$piggybank->id)])}}++<div class="row">+ <div class="col-lg-6">+ <h4> </h4>+ <p class="text-info">+ This form allows you to delete the piggy bank "{{{$piggybank->name}}}".+ </p>+ <p class="text-info">+ Destroying an envelope does not remove any transactions or accounts.+ </p>+ <p class="text-danger">+ Are you sure?+ </p>++ <div class="form-group">+ <div class="col-sm-8">+ <input type="submit" name="submit" value="Remove piggy bank" class="btn btn-danger" />+ @if(Input::get('from') == 'date')+ <a href="{{route('budgets.index')}}" class="btn-default btn">Cancel</a>+ @else+ <a href="{{route('budgets.index.budget')}}" class="btn-default btn">Cancel</a>+ @endif+ </div>+ </div>+ </div>+</div>+++{{Form::close()}}++@stopdiff --git a/app/views/piggybanks/edit.blade.php b/app/views/piggybanks/edit.blade.phpnew file mode 100644index 0000000000..b771baa80e--- /dev/null+++ b/app/views/piggybanks/edit.blade.php@@ -0,0 +1,105 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly+ <small>Edit piggy bank "{{{$piggybank->name}}}"</small>+ </h1>+ <p class="lead">Use piggy banks to make saving money easier</p>+ <p class="text-info">+ Saving money is <em>hard</em>. Piggy banks allow you to group money+ from an account together. If you also set a target (and a target date) you+ can save towards your goals.+ </p>+ </div>+</div>++{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update')])}}+{{Form::hidden('id',$piggybank->id)}}+<div class="row">+ <div class="col-lg-6 col-md-12 col-sm-6">+ <h4>Mandatory fields</h4>++ <div class="form-group">+ <label for="name" class="col-sm-4 control-label">Name</label>+ <div class="col-sm-8">+ <input type="text" name="name" class="form-control" id="name" value="{{{Input::old('name') ?: $piggybank->name}}}" placeholder="Name">+ @if($errors->has('name'))+ <p class="text-danger">{{$errors->first('name')}}</p>+ @else+ <span class="help-block">For example: new bike, new camera</span>+ @endif+ </div>+ </div>++ <div class="form-group">+ {{ Form::label('target', 'Target amount', ['class' => 'col-sm-4 control-label'])}}+ <div class="col-sm-8">+ <div class="input-group">+ <span class="input-group-addon">€</span>+ {{Form::input('number','target', Input::old('target') ?: $piggybank->target, ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}+ </div>++ @if($errors->has('target'))+ <p class="text-danger">{{$errors->first('target')}}</p>+ @else+ <span class="help-block">How much money do you need to save?</span>+ @endif+ </div>+ </div>++ <div class="form-group">+ <label for="account_id" class="col-sm-4 control-label">+ Saving account+ </label>+ <div class="col-sm-8">+ {{Form::select('account_id',$accounts,Input::old('account_id') ?: $piggybank->account_id,['class' => 'form-control'])}}+ @if($errors->has('account_id'))+ <p class="text-danger">{{$errors->first('account_id')}}</p>+ @else+ <span class="help-block">Indicate on which account you've got your savings.</span>+ @endif+ </div>+ </div>++ </div>+ <div class="col-lg-6 col-md-12 col-sm-6">+ <h4>Optional fields</h4>++ <div class="form-group">+ {{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}+ <div class="col-sm-8">+ {{ Form::input('date','targetdate', Input::old('targetdate') ?: $piggybank->targetdate, ['class'+ => 'form-control']) }}+ @if($errors->has('targetdate'))+ <p class="text-danger">{{$errors->first('targetdate')}}</p>+ @else+ <span class="help-block">+ If you want to, set a target date. This will inform you how much money you should save to+ get to the target amount.+ </span>+ @endif+ </div>+ </div>+++ </div>+</div>++<div class="row">+ <div class="col-lg-6 col-md-12 col-sm-6">++++ <div class="form-group">+ <div class="col-sm-offset-4 col-sm-8">+ <button type="submit" class="btn btn-default btn-success">Create the piggy bank</button>+ </div>+ </div>+ </div>+</div>++{{Form::close()}}+++@stopdiff --git a/app/views/piggybanks/index.blade.php b/app/views/piggybanks/index.blade.phpindex bf59731ce2..c6e3986845 100644--- a/app/views/piggybanks/index.blade.php+++ b/app/views/piggybanks/index.blade.php@@ -28,12 +28,14 @@<th>Account</th><th>Current balance</th><th>Left for (other) piggy banks</th>+ <th>Total target</th></tr>@foreach($accounts as $account)<tr><td>{{{$account->name}}}</td><td id="account_{{$account->id}}_total" data-raw="{{$account->balance}}">{{mf($account->balance)}}</td><td id="account_{{$account->id}}_left" data-raw="{{$account->left}}">{{mf($account->left)}}</td>+ <td>{{mf($account->total)}}</td></tr>@endforeach</table>@@ -46,6 +48,11 @@@foreach($piggybanks as $piggybank)<h4>{{{$piggybank->name}}} <small>{{mf($piggybank->target)}}</small></h4>+ @if(!is_null($piggybank->targetdate))+ <p>+ Target date: {{$piggybank->targetdate->format('jS F Y')}}+ </p>+ @endif<table class="table table-bordered"><tr><td style="width:15%;">@@ -56,6 +63,12 @@</td><td><input type="range" data-account="{{$piggybank->account_id}}" name="piggy_{{$piggybank->id}}" min="0" max="{{$piggybank->target}}" step="any" value="{{$piggybank->amount}}" /></td><td style="width: 10%;"><span id="piggy_{{$piggybank->id}}_pct">{{$piggybank->pct}}</span></td>+ <td style="width:8%;">+ <div class="btn-group btn-group-xs">+ <a href="{{route('piggybanks.edit',$piggybank->id)}}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>+ <a href="{{route('piggybanks.delete',$piggybank->id)}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a>+ </div>+ </td></tr></table>@endforeachdiff --git a/app/views/transactions/create.blade.php b/app/views/transactions/create.blade.phpindex 211e7027f4..28f4d0a9e8 100644--- a/app/views/transactions/create.blade.php+++ b/app/views/transactions/create.blade.php@@ -82,6 +82,9 @@<label for="account_from_id" class="col-sm-4 control-label">Account from</label><div class="col-sm-8">{{Form::select('account_from_id',$accounts,Input::old('account_from_id'),['class' => 'form-control'])}}+ @if($errors->has('account_from_id'))+ <p class="text-danger">{{$errors->first('account_from_id')}}</p>+ @endif</div></div>@@ -89,6 +92,9 @@<label for="account_to_id" class="col-sm-4 control-label">Account to</label><div class="col-sm-8">{{Form::select('account_to_id',$accounts,Input::old('account_to_id'),['class' => 'form-control'])}}+ @if($errors->has('account_to_id'))+ <p class="text-danger">{{$errors->first('account_to_id')}}</p>+ @endif</div></div>@endif@@ -108,6 +114,9 @@</label><div class="col-sm-8"><input type="number" name="amount" min="0.01" value="{{Input::old('amount')}}" step="any" class="form-control" />+ @if($errors->has('amount'))+ <p class="text-danger">{{$errors->first('amount')}}</p>+ @endif</div></div>diff --git a/app/views/transactions/delete.blade.php b/app/views/transactions/delete.blade.phpnew file mode 100644index 0000000000..6c57de415a--- /dev/null+++ b/app/views/transactions/delete.blade.php@@ -0,0 +1,38 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly+ <small>Delete transaction</small>+ </h1>+ <p class="lead">Remember that deleting something is permanent.</p>++ </div>++</div>++{{Form::open(['class' => 'form-horizontal','url' => route('transactions.destroy',$journal->id)])}}++<div class="row">+ <div class="col-lg-6">+ <p class="text-info">+ This form allows you to delete the transaction labelled "{{{$journal->description}}}".+ </p>+ <p class="text-danger">+ Are you sure?+ </p>++ <div class="form-group">+ <div class="col-sm-8">+ <input type="submit" name="submit" value="Delete transaction" class="btn btn-danger" />+ <a href="{{route('transactions.index')}}" class="btn-default btn">Cancel</a>+ </div>+ </div>+ </div>++</div>+++{{Form::close()}}++@stopdiff --git a/app/views/transactions/index.blade.php b/app/views/transactions/index.blade.phpindex 6c350c37da..d6cf35f6c4 100644--- a/app/views/transactions/index.blade.php+++ b/app/views/transactions/index.blade.php@@ -1,6 +1,8 @@@extends('layouts.default')@section('content')-Bla bla TODO++@include('paginated.transactions')+@stopdiff --git a/ide-helper.sh b/ide-helper.shindex 3ff97756bc..78fa9ea3a9 100755--- a/ide-helper.sh+++ b/ide-helper.sh@@ -1,7 +1,8 @@#!/bin/bash+composer self-updatecomposer updatephp artisan clear-compiled --env=localphp artisan ide-helper:generate --env=localphp artisan ide-helper:models --env=local --writephp artisan optimize --env=local-php artisan dump-autoload --env=local\ No newline at end of file+php artisan dump-autoload --env=m n\ No newline at end of file