From bcf066ead7a6c4002f25e269091fd25eb83edff8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 11:51:26 +0200 Subject: [PATCH 01/63] Cleaned up some double code. --- app/Helpers/Report/ReportQuery.php | 81 +++++++++---------- app/Http/Controllers/BillController.php | 45 ++--------- .../Controllers/TransactionController.php | 68 ++++------------ app/Http/Requests/BillFormRequest.php | 21 +++++ app/Http/Requests/JournalFormRequest.php | 26 +++++- 5 files changed, 111 insertions(+), 130 deletions(-) diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 55d0b5ec73..c210efd29a 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -87,9 +87,9 @@ class ReportQuery implements ReportQueryInterface ->whereNull('budget_transaction_journal.budget_id')->whereNull('transaction_journals.deleted_at') ->whereNull('otherJournals.deleted_at') ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') ->whereNotNull('transaction_group_transaction_journal.transaction_group_id') ->get( [ @@ -174,26 +174,9 @@ class ReportQuery implements ReportQueryInterface */ public function getBudgetSummary(Account $account, Carbon $start, Carbon $end) { - $set = TransactionJournal:: - leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->leftJoin( - 'transactions', function (JoinClause $join) { - $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); - } - ) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->before($end) - ->after($start) - ->where('accounts.id', $account->id) - ->where('transaction_journals.user_id', Auth::user()->id) - ->where('transaction_types.type', 'Withdrawal') - ->groupBy('budgets.id') - ->orderBy('budgets.name', 'ASC') - ->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) as `amount`')]); + $query = $this->queryJournalsNoBudget($account, $start, $end); - return $set; + return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) as `amount`')]); } @@ -209,26 +192,9 @@ class ReportQuery implements ReportQueryInterface */ public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end) { - $set = TransactionJournal:: - leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->leftJoin( - 'transactions', function (JoinClause $join) { - $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); - } - ) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->before($end) - ->after($start) - ->where('accounts.id', $account->id) - ->where('transaction_journals.user_id', Auth::user()->id) - ->where('transaction_types.type', 'Withdrawal') - ->whereNull('budgets.id') - ->orderBy('transaction_journals.date', 'ASC') - ->get(['budgets.name', 'transactions.amount', 'transaction_journals.*']); + $query = $this->queryJournalsNoBudget($account, $start, $end); - return $set; + return $query->get(['budgets.name', 'transactions.amount', 'transaction_journals.*']); } /** @@ -604,4 +570,37 @@ class ReportQuery implements ReportQueryInterface ); } + /** + * + * This query will get all transaction journals and budget information for a specified account + * in a certain date range, where the transaction journal does not have a budget. + * There is no get() specified, this is up to the method itself. + * + * @param Account $account + * @param Carbon $start + * @param Carbon $end + * + * @return Builder + */ + public function queryJournalsNoBudget(Account $account, Carbon $start, Carbon $end) + { + return TransactionJournal:: + leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->leftJoin( + 'transactions', function (JoinClause $join) { + $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); + } + ) + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->before($end) + ->after($start) + ->where('accounts.id', $account->id) + ->where('transaction_journals.user_id', Auth::user()->id) + ->where('transaction_types.type', 'Withdrawal') + ->groupBy('budgets.id') + ->orderBy('budgets.name', 'ASC'); + } + } diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 457b20bdb1..a2dcc48624 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -1,7 +1,6 @@ transactionjournals()->withRelevantData() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') - - ->get(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get(); $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $hideBill = true; @@ -156,22 +154,8 @@ class BillController extends Controller */ public function store(BillFormRequest $request, BillRepositoryInterface $repository) { - - $billData = [ - 'name' => $request->get('name'), - 'match' => $request->get('match'), - 'amount_min' => floatval($request->get('amount_min')), - 'amount_currency_id' => floatval($request->get('amount_currency_id')), - 'amount_max' => floatval($request->get('amount_max')), - 'date' => new Carbon($request->get('date')), - 'user' => Auth::user()->id, - 'repeat_freq' => $request->get('repeat_freq'), - 'skip' => intval($request->get('skip')), - 'automatch' => intval($request->get('automatch')) === 1, - 'active' => intval($request->get('active')) === 1, - ]; - - $bill = $repository->store($billData); + $billData = $request->getBillData(); + $bill = $repository->store($billData); Session::flash('success', 'Bill "' . e($bill->name) . '" stored.'); if (intval(Input::get('create_another')) === 1) { @@ -189,21 +173,8 @@ class BillController extends Controller */ public function update(Bill $bill, BillFormRequest $request, BillRepositoryInterface $repository) { - $billData = [ - 'name' => $request->get('name'), - 'match' => $request->get('match'), - 'amount_min' => floatval($request->get('amount_min')), - 'amount_currency_id' => floatval($request->get('amount_currency_id')), - 'amount_max' => floatval($request->get('amount_max')), - 'date' => new Carbon($request->get('date')), - 'user' => Auth::user()->id, - 'repeat_freq' => $request->get('repeat_freq'), - 'skip' => intval($request->get('skip')), - 'automatch' => intval($request->get('automatch')) === 1, - 'active' => intval($request->get('active')) === 1, - ]; - - $bill = $repository->update($bill, $billData); + $billData = $request->getBillData(); + $bill = $repository->update($bill, $billData); if (intval(Input::get('return_to_edit')) === 1) { return Redirect::route('bills.edit', $bill->id); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 56054d859e..04650dc5e6 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -1,7 +1,6 @@ 0 ? ($page - 1) * 50 : 0; - $set = Auth::user()-> - transactionJournals()-> - transactionTypes($types)-> - withRelevantData()->take(50)->offset($offset) - ->orderBy('date', 'DESC') - ->orderBy('order','ASC') - ->orderBy('id','DESC') - ->get( - ['transaction_journals.*'] - ); + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) + ->orderBy('date', 'DESC') + ->orderBy('order', 'ASC') + ->orderBy('id', 'DESC') + ->get( + ['transaction_journals.*'] + ); $count = Auth::user()->transactionJournals()->transactionTypes($types)->count(); $journals = new LengthAwarePaginator($set, $count, 50, $page); $journals->setPath('transactions/' . $what); @@ -227,13 +223,14 @@ class TransactionController extends Controller $order = 0; foreach ($ids as $id) { $journal = Auth::user()->transactionjournals()->where('id', $id)->where('date', Input::get('date'))->first(); - if($journal) { + if ($journal) { $journal->order = $order; $order++; $journal->save(); } } } + return Response::json(true); } @@ -251,10 +248,10 @@ class TransactionController extends Controller $t->account->transactions()->leftJoin( 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' ) - ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) - ->where('transaction_journals.order','>=',$journal->order) - ->where('transaction_journals.id', '!=', $journal->id) - ->sum('transactions.amount') + ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) + ->where('transaction_journals.order', '>=', $journal->order) + ->where('transaction_journals.id', '!=', $journal->id) + ->sum('transactions.amount') ); $t->after = $t->before + $t->amount; } @@ -274,23 +271,8 @@ class TransactionController extends Controller */ public function store(JournalFormRequest $request, JournalRepositoryInterface $repository) { - $journalData = [ - 'what' => $request->get('what'), - 'description' => $request->get('description'), - 'account_id' => intval($request->get('account_id')), - 'account_from_id' => intval($request->get('account_from_id')), - 'account_to_id' => intval($request->get('account_to_id')), - 'expense_account' => $request->get('expense_account'), - 'revenue_account' => $request->get('revenue_account'), - 'amount' => floatval($request->get('amount')), - 'user' => Auth::user()->id, - 'amount_currency_id' => intval($request->get('amount_currency_id')), - 'date' => new Carbon($request->get('date')), - 'budget_id' => intval($request->get('budget_id')), - 'category' => $request->get('category'), - ]; - - $journal = $repository->store($journalData); + $journalData = $request->getJournalData(); + $journal = $repository->store($journalData); event(new JournalSaved($journal)); event(new JournalCreated($journal, intval($request->get('piggy_bank_id')))); @@ -321,23 +303,7 @@ class TransactionController extends Controller public function update(TransactionJournal $journal, JournalFormRequest $request, JournalRepositoryInterface $repository) { - - $journalData = [ - 'what' => $request->get('what'), - 'description' => $request->get('description'), - 'account_id' => intval($request->get('account_id')), - 'account_from_id' => intval($request->get('account_from_id')), - 'account_to_id' => intval($request->get('account_to_id')), - 'expense_account' => $request->get('expense_account'), - 'revenue_account' => $request->get('revenue_account'), - 'amount' => floatval($request->get('amount')), - 'user' => Auth::user()->id, - 'amount_currency_id' => intval($request->get('amount_currency_id')), - 'date' => new Carbon($request->get('date')), - 'budget_id' => intval($request->get('budget_id')), - 'category' => $request->get('category'), - ]; - + $journalData = $request->getJournalData(); $repository->update($journal, $journalData); event(new JournalSaved($journal)); diff --git a/app/Http/Requests/BillFormRequest.php b/app/Http/Requests/BillFormRequest.php index b3057bc885..b225ab91bc 100644 --- a/app/Http/Requests/BillFormRequest.php +++ b/app/Http/Requests/BillFormRequest.php @@ -3,6 +3,7 @@ namespace FireflyIII\Http\Requests; use Auth; +use Carbon\Carbon; use Input; /** @@ -21,6 +22,26 @@ class BillFormRequest extends Request return Auth::check(); } + /** + * @return array + */ + public function getBillData() + { + return [ + 'name' => $this->get('name'), + 'match' => $this->get('match'), + 'amount_min' => floatval($this->get('amount_min')), + 'amount_currency_id' => floatval($this->get('amount_currency_id')), + 'amount_max' => floatval($this->get('amount_max')), + 'date' => new Carbon($this->get('date')), + 'user' => Auth::user()->id, + 'repeat_freq' => $this->get('repeat_freq'), + 'skip' => intval($this->get('skip')), + 'automatch' => intval($this->get('automatch')) === 1, + 'active' => intval($this->get('active')) === 1, + ]; + } + /** * @return array */ diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php index 82b8f8549e..b0da081e4a 100644 --- a/app/Http/Requests/JournalFormRequest.php +++ b/app/Http/Requests/JournalFormRequest.php @@ -3,8 +3,10 @@ namespace FireflyIII\Http\Requests; use Auth; -use Input; +use Carbon\Carbon; use Exception; +use Input; + /** * Class JournalFormRequest * @@ -21,6 +23,28 @@ class JournalFormRequest extends Request return Auth::check(); } + /** + * @return array + */ + public function getJournalData() + { + return [ + 'what' => $this->get('what'), + 'description' => $this->get('description'), + 'account_id' => intval($this->get('account_id')), + 'account_from_id' => intval($this->get('account_from_id')), + 'account_to_id' => intval($this->get('account_to_id')), + 'expense_account' => $this->get('expense_account'), + 'revenue_account' => $this->get('revenue_account'), + 'amount' => floatval($this->get('amount')), + 'user' => Auth::user()->id, + 'amount_currency_id' => intval($this->get('amount_currency_id')), + 'date' => new Carbon($this->get('date')), + 'budget_id' => intval($this->get('budget_id')), + 'category' => $this->get('category'), + ]; + } + /** * @return array * @throws Exception From 70a01c082b89c7e819565e8879e57f494ba6a206 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 12:12:06 +0200 Subject: [PATCH 02/63] Removed some double code. --- app/Helpers/Report/ReportQuery.php | 102 +++++++++++++---------------- 1 file changed, 45 insertions(+), 57 deletions(-) diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index c210efd29a..6820771f2f 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -210,30 +210,7 @@ class ReportQuery implements ReportQueryInterface */ public function incomeByPeriod(Carbon $start, Carbon $end, $showSharedReports = false) { - $query = TransactionJournal:: - leftJoin( - 'transactions as t_from', function (JoinClause $join) { - $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); - } - ) - ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function (JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function (JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function (JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + $query = $this->queryJournalsWithTransactions($start, $end); if ($showSharedReports === false) { // only get deposits not to a shared account // and transfers to a shared account. @@ -257,9 +234,7 @@ class ReportQuery implements ReportQueryInterface // any deposit is fine. $query->where('transaction_types.type', 'Deposit'); } - $query->before($end)->after($start) - ->where('transaction_journals.user_id', Auth::user()->id) - ->groupBy('t_from.account_id')->orderBy('transaction_journals.date'); + $query->groupBy('t_from.account_id')->orderBy('transaction_journals.date'); return $query->get( ['transaction_journals.id', @@ -366,6 +341,7 @@ class ReportQuery implements ReportQueryInterface */ public function journalsByExpenseAccount(Carbon $start, Carbon $end, $showSharedReports = false) { + $query = $this->queryJournalsWithTransactions($start, $end); $query = TransactionJournal::leftJoin( 'transactions as t_from', function (JoinClause $join) { $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); @@ -412,8 +388,7 @@ class ReportQuery implements ReportQueryInterface // any withdrawal goes: $query->where('transaction_types.type', 'Withdrawal'); } - $query->before($end) - ->after($start) + $query->before($end)->after($start) ->where('transaction_journals.user_id', Auth::user()->id) ->groupBy('t_to.account_id') ->orderBy('amount', 'DESC'); @@ -432,30 +407,7 @@ class ReportQuery implements ReportQueryInterface */ public function journalsByRevenueAccount(Carbon $start, Carbon $end, $showSharedReports = false) { - $query = TransactionJournal:: - leftJoin( - 'transactions as t_from', function (JoinClause $join) { - $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); - } - ) - ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function (JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function (JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function (JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + $query = $this->queryJournalsWithTransactions($start, $end); if ($showSharedReports === false) { // show queries where transfer type is deposit, and its not to a shared account @@ -480,9 +432,8 @@ class ReportQuery implements ReportQueryInterface // any deposit goes: $query->where('transaction_types.type', 'Deposit'); } - $query->before($end)->after($start) - ->where('transaction_journals.user_id', Auth::user()->id) - ->groupBy('t_from.account_id')->orderBy('amount'); + + $query->groupBy('t_from.account_id')->orderBy('amount'); return $query->get(['t_from.account_id as account_id', 'ac_from.name as name', DB::Raw('SUM(t_from.amount) as `amount`')]); } @@ -582,7 +533,7 @@ class ReportQuery implements ReportQueryInterface * * @return Builder */ - public function queryJournalsNoBudget(Account $account, Carbon $start, Carbon $end) + protected function queryJournalsNoBudget(Account $account, Carbon $start, Carbon $end) { return TransactionJournal:: leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') @@ -603,4 +554,41 @@ class ReportQuery implements ReportQueryInterface ->orderBy('budgets.name', 'ASC'); } + /** + * @param Carbon $start + * @param Carbon $end + * + * @return Builder + */ + protected function queryJournalsWithTransactions(Carbon $start, Carbon $end) + { + $query = TransactionJournal:: + leftJoin( + 'transactions as t_from', function (JoinClause $join) { + $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); + } + ) + ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') + ->leftJoin( + 'account_meta as acm_from', function (JoinClause $join) { + $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); + } + ) + ->leftJoin( + 'transactions as t_to', function (JoinClause $join) { + $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); + } + ) + ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') + ->leftJoin( + 'account_meta as acm_to', function (JoinClause $join) { + $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); + $query->before($end)->after($start)->where('transaction_journals.user_id', Auth::user()->id); + + return $query; + } + } From f601af3da091be22a1c72a009fedcd8010065f8a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 12:25:46 +0200 Subject: [PATCH 03/63] Cleaned up report controller. --- app/Helpers/Report/ReportHelper.php | 38 ++++--- app/Helpers/Report/ReportQuery.php | 23 ----- app/Http/Controllers/ReportController.php | 119 ++++++++-------------- 3 files changed, 62 insertions(+), 118 deletions(-) diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index cec2b058e3..98dfaa9807 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -2,6 +2,7 @@ namespace FireflyIII\Helpers\Report; +use App; use Auth; use Carbon\Carbon; use FireflyIII\Models\Account; @@ -40,17 +41,20 @@ class ReportHelper implements ReportHelperInterface * This method gets some kind of list for a monthly overview. * * @param Carbon $date + * @param bool $showSharedReports * * @return Collection */ - public function getBudgetsForMonth(Carbon $date) + public function getBudgetsForMonth(Carbon $date, $showSharedReports = false) { + /** @var \FireflyIII\Helpers\Report\ReportQueryInterface $query */ + $query = App::make('FireflyIII\Helpers\Report\ReportQueryInterface'); + $start = clone $date; $start->startOfMonth(); $end = clone $date; $end->endOfMonth(); - // all budgets - $set = Auth::user()->budgets() + $set = Auth::user()->budgets()->orderBy('budgets.name', 'ASC') ->leftJoin( 'budget_limits', function (JoinClause $join) use ($date) { $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); @@ -58,22 +62,24 @@ class ReportHelper implements ReportHelperInterface ) ->get(['budgets.*', 'budget_limits.amount as amount']); + $budgets = Steam::makeArray($set); + $amountSet = $query->journalsByBudget($start, $end, $showSharedReports); + $amounts = Steam::makeArray($amountSet); + $budgets = Steam::mergeArrays($budgets, $amounts); + $budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0; + $budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0; + $budgets[0]['name'] = 'No budget'; - $budgets = $this->_helper->makeArray($set); - $amountSet = $this->_queries->journalsByBudget($start, $end); - $amounts = $this->_helper->makeArray($amountSet); - $combined = $this->_helper->mergeArrays($budgets, $amounts); - $combined[0]['spent'] = isset($combined[0]['spent']) ? $combined[0]['spent'] : 0.0; - $combined[0]['amount'] = isset($combined[0]['amount']) ? $combined[0]['amount'] : 0.0; - $combined[0]['name'] = 'No budget'; - - // find transactions to shared expense accounts, which are without a budget by default: - $transfers = $this->_queries->sharedExpenses($start, $end); - foreach ($transfers as $transfer) { - $combined[0]['spent'] += floatval($transfer->amount) * -1; + // find transactions to shared asset accounts, which are without a budget by default: + // which is only relevant when shared asset accounts are hidden. + if ($showSharedReports === false) { + $transfers = $query->sharedExpenses($start, $end); + foreach ($transfers as $transfer) { + $budgets[0]['spent'] += floatval($transfer->amount) * -1; + } } - return $combined; + return $budgets; } /** diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 6820771f2f..6774143650 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -342,29 +342,6 @@ class ReportQuery implements ReportQueryInterface public function journalsByExpenseAccount(Carbon $start, Carbon $end, $showSharedReports = false) { $query = $this->queryJournalsWithTransactions($start, $end); - $query = TransactionJournal::leftJoin( - 'transactions as t_from', function (JoinClause $join) { - $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0); - } - )->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id') - ->leftJoin( - 'account_meta as acm_from', function (JoinClause $join) { - $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole'); - } - ) - ->leftJoin( - 'transactions as t_to', function (JoinClause $join) { - $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0); - } - ) - ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id') - ->leftJoin( - 'account_meta as acm_to', function (JoinClause $join) { - $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); - if ($showSharedReports === false) { // get all withdrawals not from a shared accounts // and all transfers to a shared account diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 1a6eef25ee..da0f357c6d 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -1,18 +1,16 @@ query = $query; + $this->helper = $helper; + View::share('title', 'Reports'); View::share('mainTitleIcon', 'fa-line-chart'); @@ -38,7 +45,7 @@ class ReportController extends Controller * * @return \Illuminate\View\View */ - public function budget($year = '2014', $month = '1', ReportQueryInterface $query) + public function budget($year = '2014', $month = '1') { try { new Carbon($year . '-' . $month . '-01'); @@ -52,7 +59,7 @@ class ReportController extends Controller $end->endOfMonth(); $start->subDay(); - // shared accounts preference: + /** @var Preference $pref */ $pref = Preferences::get('showSharedReports', false); $showSharedReports = $pref->data; @@ -61,13 +68,13 @@ class ReportController extends Controller $subTitle = 'Budget report for ' . $date->format('F Y'); $subTitleIcon = 'fa-calendar'; $dayEarly = $dayEarly->subDay(); - $accounts = $query->getAllAccounts($start, $end, $showSharedReports); + $accounts = $this->query->getAllAccounts($start, $end, $showSharedReports); $start->addDay(); $accounts->each( - function (Account $account) use ($start, $end, $query) { - $budgets = $query->getBudgetSummary($account, $start, $end); - $balancedAmount = $query->balancedTransactionsSum($account, $start, $end); + function (Account $account) use ($start, $end) { + $budgets = $this->query->getBudgetSummary($account, $start, $end); + $balancedAmount = $this->query->balancedTransactionsSum($account, $start, $end); $array = []; $hide = true; foreach ($budgets as $budget) { @@ -85,35 +92,10 @@ class ReportController extends Controller } ); - $start = clone $date; - $start->startOfMonth(); - /** * Start getBudgetsForMonth DONE */ - $set = Auth::user()->budgets()->orderBy('budgets.name', 'ASC') - ->leftJoin( - 'budget_limits', function (JoinClause $join) use ($date) { - $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); - } - ) - ->get(['budgets.*', 'budget_limits.amount as amount']); - $budgets = Steam::makeArray($set); - $amountSet = $query->journalsByBudget($start, $end, $showSharedReports); - $amounts = Steam::makeArray($amountSet); - $budgets = Steam::mergeArrays($budgets, $amounts); - $budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0; - $budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0; - $budgets[0]['name'] = 'No budget'; - - // find transactions to shared asset accounts, which are without a budget by default: - // which is only relevant when shared asset accounts are hidden. - if ($showSharedReports === false) { - $transfers = $query->sharedExpenses($start, $end); - foreach ($transfers as $transfer) { - $budgets[0]['spent'] += floatval($transfer->amount) * -1; - } - } + $budgets = $this->helper->getBudgetsForMonth($date, $showSharedReports); /** * End getBudgetsForMonth DONE @@ -128,11 +110,11 @@ class ReportController extends Controller * * @return View */ - public function index(ReportHelperInterface $helper) + public function index() { $start = Session::get('first'); - $months = $helper->listOfMonths($start); - $years = $helper->listOfYears($start); + $months = $this->helper->listOfMonths($start); + $years = $this->helper->listOfYears($start); $title = 'Reports'; $mainTitleIcon = 'fa-line-chart'; @@ -146,7 +128,7 @@ class ReportController extends Controller * * @return \Illuminate\View\View */ - public function modalBalancedTransfers(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query) + public function modalBalancedTransfers(Account $account, $year = '2014', $month = '1') { try { @@ -158,7 +140,7 @@ class ReportController extends Controller $end = clone $start; $end->endOfMonth(); - $journals = $query->balancedTransactionsList($account, $start, $end); + $journals = $this->query->balancedTransactionsList($account, $start, $end); return view('reports.modal-journal-list', compact('journals')); @@ -173,7 +155,7 @@ class ReportController extends Controller * * @return View */ - public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query) + public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1') { try { new Carbon($year . '-' . $month . '-01'); @@ -183,7 +165,7 @@ class ReportController extends Controller $start = new Carbon($year . '-' . $month . '-01'); $end = clone $start; $end->endOfMonth(); - $set = $query->getTransactionsWithoutBudget($account, $start, $end); + $set = $this->query->getTransactionsWithoutBudget($account, $start, $end); $journals = $set->filter( function (TransactionJournal $journal) { @@ -204,7 +186,7 @@ class ReportController extends Controller * * @return \Illuminate\View\View */ - public function modalNoBudget(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query) + public function modalNoBudget(Account $account, $year = '2014', $month = '1') { try { new Carbon($year . '-' . $month . '-01'); @@ -214,7 +196,7 @@ class ReportController extends Controller $start = new Carbon($year . '-' . $month . '-01'); $end = clone $start; $end->endOfMonth(); - $journals = $query->getTransactionsWithoutBudget($account, $start, $end); + $journals = $this->query->getTransactionsWithoutBudget($account, $start, $end); return view('reports.modal-journal-list', compact('journals')); @@ -226,7 +208,7 @@ class ReportController extends Controller * * @return \Illuminate\View\View */ - public function month($year = '2014', $month = '1', ReportQueryInterface $query) + public function month($year = '2014', $month = '1') { try { new Carbon($year . '-' . $month . '-01'); @@ -237,7 +219,7 @@ class ReportController extends Controller $subTitle = 'Report for ' . $date->format('F Y'); $subTitleIcon = 'fa-calendar'; $displaySum = true; // to show sums in report. - + /** @var Preference $pref */ $pref = Preferences::get('showSharedReports', false); $showSharedReports = $pref->data; @@ -256,14 +238,14 @@ class ReportController extends Controller /** * Start getIncomeForMonth DONE */ - $income = $query->incomeByPeriod($start, $end, $showSharedReports); + $income = $this->query->incomeByPeriod($start, $end, $showSharedReports); /** * End getIncomeForMonth DONE */ /** * Start getExpenseGroupedForMonth DONE */ - $set = $query->journalsByExpenseAccount($start, $end, $showSharedReports); + $set = $this->query->journalsByExpenseAccount($start, $end, $showSharedReports); $expenses = Steam::makeArray($set); $expenses = Steam::sortArray($expenses); $expenses = Steam::limitArray($expenses, 10); @@ -273,28 +255,7 @@ class ReportController extends Controller /** * Start getBudgetsForMonth DONE */ - $set = Auth::user()->budgets() - ->leftJoin( - 'budget_limits', function (JoinClause $join) use ($date) { - $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); - } - ) - ->get(['budgets.*', 'budget_limits.amount as amount']); - $budgets = Steam::makeArray($set); - $amountSet = $query->journalsByBudget($start, $end, $showSharedReports); - $amounts = Steam::makeArray($amountSet); - $budgets = Steam::mergeArrays($budgets, $amounts); - $budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0; - $budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0; - $budgets[0]['name'] = 'No budget'; - - // find transactions to shared expense accounts, which are without a budget by default: - if ($showSharedReports === false) { - $transfers = $query->sharedExpenses($start, $end); - foreach ($transfers as $transfer) { - $budgets[0]['spent'] += floatval($transfer->amount) * -1; - } - } + $budgets = $this->helper->getBudgetsForMonth($date, $showSharedReports); /** * End getBudgetsForMonth DONE @@ -303,12 +264,12 @@ class ReportController extends Controller * Start getCategoriesForMonth DONE */ // all categories. - $result = $query->journalsByCategory($start, $end); + $result = $this->query->journalsByCategory($start, $end); $categories = Steam::makeArray($result); // all transfers if ($showSharedReports === false) { - $result = $query->sharedExpensesByCategory($start, $end); + $result = $this->query->sharedExpensesByCategory($start, $end); $transfers = Steam::makeArray($result); $merged = Steam::mergeArrays($categories, $transfers); } else { @@ -326,7 +287,7 @@ class ReportController extends Controller /** * Start getAccountsForMonth */ - $list = $query->accountList($showSharedReports); + $list = $this->query->accountList($showSharedReports); $accounts = []; /** @var Account $account */ foreach ($list as $account) { @@ -360,7 +321,7 @@ class ReportController extends Controller * * @return $this */ - public function year($year, ReportHelperInterface $helper, ReportQueryInterface $query) + public function year($year) { try { new Carbon('01-01-' . $year); @@ -377,9 +338,9 @@ class ReportController extends Controller $subTitle = $year; $subTitleIcon = 'fa-bar-chart'; $mainTitleIcon = 'fa-line-chart'; - $balances = $helper->yearBalanceReport($date, $showSharedReports); - $groupedIncomes = $query->journalsByRevenueAccount($date, $end, $showSharedReports); - $groupedExpenses = $query->journalsByExpenseAccount($date, $end, $showSharedReports); + $balances = $this->helper->yearBalanceReport($date, $showSharedReports); + $groupedIncomes = $this->query->journalsByRevenueAccount($date, $end, $showSharedReports); + $groupedExpenses = $this->query->journalsByExpenseAccount($date, $end, $showSharedReports); return view( 'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') From bd96b2819f5202ce0888a6d32a3ff36fee9589bb Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 12:32:00 +0200 Subject: [PATCH 04/63] Removed double code. --- .../Journal/JournalRepository.php | 92 +++++++------------ 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index a3bde0c535..e89e631406 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -139,41 +139,7 @@ class JournalRepository implements JournalRepositoryInterface } // store accounts (depends on type) - switch ($transactionType->type) { - case 'Withdrawal': - - $from = Account::find($data['account_id']); - - if (strlen($data['expense_account']) > 0) { - $toType = AccountType::where('type', 'Expense account')->first(); - $to = Account::firstOrCreate( - ['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => $data['expense_account'], 'active' => 1] - ); - } else { - $toType = AccountType::where('type', 'Cash account')->first(); - $to = Account::firstOrCreate(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]); - } - break; - - case 'Deposit': - $to = Account::find($data['account_id']); - - if (strlen($data['revenue_account']) > 0) { - $fromType = AccountType::where('type', 'Revenue account')->first(); - $from = Account::firstOrCreate( - ['user_id' => $data['user'], 'account_type_id' => $fromType->id, 'name' => $data['revenue_account'], 'active' => 1] - ); - } else { - $toType = AccountType::where('type', 'Cash account')->first(); - $from = Account::firstOrCreate(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]); - } - - break; - case 'Transfer': - $from = Account::find($data['account_from_id']); - $to = Account::find($data['account_to_id']); - break; - } + list($from, $to) = $this->storeAccounts($transactionType, $data); // store accompanying transactions. Transaction::create( // first transaction. @@ -198,7 +164,6 @@ class JournalRepository implements JournalRepositoryInterface } - /** * @param TransactionJournal $journal * @param array $data @@ -228,7 +193,39 @@ class JournalRepository implements JournalRepositoryInterface } // store accounts (depends on type) - switch ($journal->transactionType->type) { + list($from, $to) = $this->storeAccounts($journal->transactionType, $data); + + // update the from and to transaction. + /** @var Transaction $transaction */ + foreach ($journal->transactions()->get() as $transaction) { + if (floatval($transaction->amount) < 0) { + // this is the from transaction, negative amount: + $transaction->amount = $data['amount'] * -1; + $transaction->account_id = $from->id; + $transaction->save(); + } + if (floatval($transaction->amount) > 0) { + $transaction->amount = $data['amount']; + $transaction->account_id = $to->id; + $transaction->save(); + } + } + + + $journal->save(); + + return $journal; + } + + /** + * @param TransactionType $type + * @param array $data + * + * @return array + */ + protected function storeAccounts(TransactionType $type, array $data) + { + switch ($type->type) { case 'Withdrawal': $from = Account::find($data['account_id']); @@ -264,26 +261,7 @@ class JournalRepository implements JournalRepositoryInterface break; } - // update the from and to transaction. - /** @var Transaction $transaction */ - foreach ($journal->transactions()->get() as $transaction) { - if (floatval($transaction->amount) < 0) { - // this is the from transaction, negative amount: - $transaction->amount = $data['amount'] * -1; - $transaction->account_id = $from->id; - $transaction->save(); - } - if (floatval($transaction->amount) > 0) { - $transaction->amount = $data['amount']; - $transaction->account_id = $to->id; - $transaction->save(); - } - } - - - $journal->save(); - - return $journal; + return [$from, $to]; } } From 9be05e7e17af778ee365fc7056ed3d9795a8c04f Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 18:28:49 +0200 Subject: [PATCH 05/63] Small optimisations. --- app/Http/Controllers/HomeController.php | 11 +++++++++++ app/Support/Preferences.php | 4 ++-- app/User.php | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index b44db645be..a0c828a2c5 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,5 +1,6 @@ getFrontpageAccounts($frontPage); $savings = $repository->getSavingsAccounts(); + // check if all books are correct. + $sum = floatval(Auth::user()->transactions()->sum('amount')); + if ($sum == 0) { + Session::flash( + 'error', 'Your transactions are unbalanced. This means a' + . ' withdrawal, deposit or transfer was not stored properly. ' + . 'Please check your accounts and transactions for errors.' + ); + } + foreach ($accounts as $account) { $set = $repository->getFrontpageTransactions($account, $start, $end); if (count($set) > 0) { diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index b12a8fef6a..0604a0b1be 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -16,7 +16,7 @@ class Preferences * @param $name * @param null $default * - * @return null|\Preference + * @return null|Preference */ public function get($name, $default = null) { @@ -37,7 +37,7 @@ class Preferences * @param $name * @param $value * - * @return \Preference + * @return Preference */ public function set($name, $value) { diff --git a/app/User.php b/app/User.php index 659d236c1d..1631995fd7 100644 --- a/app/User.php +++ b/app/User.php @@ -75,6 +75,14 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->hasManyThrough('FireflyIII\Models\PiggyBank', 'FireflyIII\Models\Account'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough + */ + public function transactions() + { + return $this->hasManyThrough('FireflyIII\Models\Transaction', 'FireflyIII\Models\TransactionJournal'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ From be10e836dc2d79affab5dd3df15182e04160ccad Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 19:40:22 +0200 Subject: [PATCH 06/63] Updated composer.lock --- composer.lock | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 1a108b872b..4cf0ddf120 100644 --- a/composer.lock +++ b/composer.lock @@ -1135,16 +1135,16 @@ }, { "name": "league/flysystem", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "51cd7cd7ee0defbaafc6ec0d3620110a5d71e11a" + "reference": "3c2400a99ccc3be6884d40361890010449c6b447" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/51cd7cd7ee0defbaafc6ec0d3620110a5d71e11a", - "reference": "51cd7cd7ee0defbaafc6ec0d3620110a5d71e11a", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/3c2400a99ccc3be6884d40361890010449c6b447", + "reference": "3c2400a99ccc3be6884d40361890010449c6b447", "shasum": "" }, "require": { @@ -1154,7 +1154,7 @@ "ext-fileinfo": "*", "league/phpunit-coverage-listener": "~1.1", "mockery/mockery": "~0.9", - "phpspec/phpspec": "~2.0.0", + "phpspec/phpspec": "~2.0", "phpspec/prophecy-phpunit": "~1.0", "phpunit/phpunit": "~4.1", "predis/predis": "~1.0", @@ -1214,7 +1214,7 @@ "sftp", "storage" ], - "time": "2015-03-10 11:04:14" + "time": "2015-03-29 14:01:43" }, { "name": "monolog/monolog", @@ -2889,21 +2889,22 @@ }, { "name": "phpspec/prophecy", - "version": "v1.3.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "9ca52329bcdd1500de24427542577ebf3fc2f1c9" + "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/9ca52329bcdd1500de24427542577ebf3fc2f1c9", - "reference": "9ca52329bcdd1500de24427542577ebf3fc2f1c9", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", + "reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5", "shasum": "" }, "require": { - "doctrine/instantiator": "~1.0,>=1.0.2", - "phpdocumentor/reflection-docblock": "~2.0" + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" }, "require-dev": { "phpspec/phpspec": "~2.0" @@ -2911,7 +2912,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.4.x-dev" } }, "autoload": { @@ -2935,7 +2936,7 @@ } ], "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "http://phpspec.org", + "homepage": "https://github.com/phpspec/prophecy", "keywords": [ "Double", "Dummy", @@ -2944,7 +2945,7 @@ "spy", "stub" ], - "time": "2014-11-17 16:23:49" + "time": "2015-03-27 19:31:25" }, { "name": "phpunit/php-code-coverage", @@ -3192,16 +3193,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.5.0", + "version": "4.5.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "5b578d3865a9128b9c209b011fda6539ec06e7a5" + "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5b578d3865a9128b9c209b011fda6539ec06e7a5", - "reference": "5b578d3865a9128b9c209b011fda6539ec06e7a5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d6429b0995b24a2d9dfe5587ee3a7071c1161af4", + "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4", "shasum": "" }, "require": { @@ -3211,8 +3212,8 @@ "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpspec/prophecy": "~1.3.1", - "phpunit/php-code-coverage": "~2.0", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.0,>=2.0.11", "phpunit/php-file-iterator": "~1.3.2", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "~1.0.2", @@ -3260,7 +3261,7 @@ "testing", "xunit" ], - "time": "2015-02-05 15:51:19" + "time": "2015-03-29 09:24:05" }, { "name": "phpunit/phpunit-mock-objects", From 8d982c1a902f7d2be62148717589131fa1bcbbc8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 19:44:59 +0200 Subject: [PATCH 07/63] Some extensions. --- app/Http/Controllers/HomeController.php | 2 +- .../2015_03_29_174140_changes_for_336.php | 33 +++++++++++++++++++ database/seeds/DatabaseSeeder.php | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2015_03_29_174140_changes_for_336.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a0c828a2c5..9eb08a7f94 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -49,7 +49,7 @@ class HomeController extends Controller // check if all books are correct. $sum = floatval(Auth::user()->transactions()->sum('amount')); - if ($sum == 0) { + if ($sum != 0) { Session::flash( 'error', 'Your transactions are unbalanced. This means a' . ' withdrawal, deposit or transfer was not stored properly. ' diff --git a/database/migrations/2015_03_29_174140_changes_for_336.php b/database/migrations/2015_03_29_174140_changes_for_336.php new file mode 100644 index 0000000000..a1681111be --- /dev/null +++ b/database/migrations/2015_03_29_174140_changes_for_336.php @@ -0,0 +1,33 @@ +smallInteger('active',false,true)->default(1); + + } + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } + +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 4c2e245530..4fc3a0b3d2 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -21,7 +21,7 @@ class DatabaseSeeder extends Seeder $this->call('TransactionCurrencySeeder'); $this->call('TransactionTypeSeeder'); - if (App::environment() == 'testing' || App::environment() == 'homestead') { + if (App::environment() == 'testing' || App::environment() == 'homestead' || gethostname() == 'vagrant-firefly-iii') { $this->call('TestDataSeeder'); } } From e6b1b58379331222d96943b4b79a65e0679cef8c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 19:50:29 +0200 Subject: [PATCH 08/63] Enable inactive budgets. --- README.md | 3 --- app/Http/Controllers/BudgetController.php | 5 +++-- resources/views/budgets/index.blade.php | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 033f8f3f0c..2d54514d55 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,4 @@ Some stuff has been removed: ## Current state I have the basics up and running. Test coverage is currently coming, slowly. -Although I have not checked extensively, some forms and views have CSRF vulnerabilities. This is because not all -views escape all characters by default. Will be fixed. - Questions, ideas or other things to contribute? [Let me know](https://github.com/JC5/firefly-iii/issues/new)! diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 1cd2d46706..5d947c27e3 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -98,7 +98,8 @@ class BudgetController extends Controller */ public function index(BudgetRepositoryInterface $repository) { - $budgets = Auth::user()->budgets()->get(); + $budgets = Auth::user()->budgets()->where('active',1)->get(); + $inactive = Auth::user()->budgets()->where('active',0)->get(); // loop the budgets: $budgets->each( @@ -117,7 +118,7 @@ class BudgetController extends Controller $budgetMax = Preferences::get('budgetMaximum', 1000); $budgetMaximum = $budgetMax->data; - return view('budgets.index', compact('budgetMaximum', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); + return view('budgets.index', compact('budgetMaximum','inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); } /** diff --git a/resources/views/budgets/index.blade.php b/resources/views/budgets/index.blade.php index 6d1642f930..2d7877f4f8 100644 --- a/resources/views/budgets/index.blade.php +++ b/resources/views/budgets/index.blade.php @@ -64,6 +64,7 @@ +
@@ -142,6 +143,25 @@ +
+ + +
+
+
+ + Inactive budgets +
+
+ @foreach($inactive as $index => $budget) + @if($index != count($inactive)-1) + {{$budget->name}}, + @else + {{$budget->name}} + @endif + @endforeach +
+
From d4c642741f481e8d76526b24e778aeca26521e6a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 21:09:33 +0200 Subject: [PATCH 09/63] Fixed division by zero. --- resources/views/budgets/show.blade.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/views/budgets/show.blade.php b/resources/views/budgets/show.blade.php index bb218f1246..c698f2b9b4 100644 --- a/resources/views/budgets/show.blade.php +++ b/resources/views/budgets/show.blade.php @@ -46,7 +46,8 @@ ?> @if($overspent) amount / $rep->spentInRepetition()*100; + $spent = floatval($rep->spentInRepetition()); + $pct = $spent != 0 ? ($rep->amount / $spent)*100 : 0; ?>
@@ -54,7 +55,8 @@
@else spentInRepetition() / $rep->amount*100; + $amount = floatval($rep->amount); + $pct = $amount != 0 ? ($rep->spentInRepetition() / $amount)*100 : 0; ?>
From 210f84b6ea57bef155a8c483456045f88092ca1f Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 21:27:13 +0200 Subject: [PATCH 10/63] Allow edit from budget overview, and allow changing of active setting. --- app/Http/Controllers/BudgetController.php | 1 + app/Http/Requests/BudgetFormRequest.php | 3 ++- app/Repositories/Budget/BudgetRepository.php | 1 + resources/views/budgets/edit.blade.php | 1 + resources/views/budgets/show.blade.php | 15 +++++++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 5d947c27e3..13287972ce 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -211,6 +211,7 @@ class BudgetController extends Controller { $budgetData = [ 'name' => $request->input('name'), + 'active' => intval($request->input('active')) == 1 ]; $repository->update($budget, $budgetData); diff --git a/app/Http/Requests/BudgetFormRequest.php b/app/Http/Requests/BudgetFormRequest.php index 19c3924417..e03c0c708b 100644 --- a/app/Http/Requests/BudgetFormRequest.php +++ b/app/Http/Requests/BudgetFormRequest.php @@ -34,7 +34,8 @@ class BudgetFormRequest extends Request } return [ - 'name' => $nameRule, + 'name' => $nameRule, + 'active' => 'numeric|between:0,1' ]; } } diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 2c547d1618..6d5694e348 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -104,6 +104,7 @@ class BudgetRepository implements BudgetRepositoryInterface { // update the account: $budget->name = $data['name']; + $budget->active = $data['active']; $budget->save(); return $budget; diff --git a/resources/views/budgets/edit.blade.php b/resources/views/budgets/edit.blade.php index a2860bc391..51883f5319 100644 --- a/resources/views/budgets/edit.blade.php +++ b/resources/views/budgets/edit.blade.php @@ -16,6 +16,7 @@ Mandatory fields
+ {!! ExpandedForm::checkbox('active') !!} {!! ExpandedForm::text('name') !!}
diff --git a/resources/views/budgets/show.blade.php b/resources/views/budgets/show.blade.php index c698f2b9b4..b3554aa66f 100644 --- a/resources/views/budgets/show.blade.php +++ b/resources/views/budgets/show.blade.php @@ -6,6 +6,21 @@
Overview + + + +
+
+ + +
+
From bea321939e7dd03e36acd24369c01bc1e9342577 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 21:27:51 +0200 Subject: [PATCH 11/63] Code rearrange and optimise. --- app/Events/JournalCreated.php | 27 +++--- app/Events/JournalSaved.php | 25 +++--- .../Events/ConnectJournalToPiggyBank.php | 5 +- app/Handlers/Events/RescanJournal.php | 2 +- .../Events/UpdateJournalConnection.php | 4 +- .../Reminders/ReminderHelperInterface.php | 7 +- app/Http/Controllers/AccountController.php | 3 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BudgetController.php | 14 ++-- app/Http/Controllers/CategoryController.php | 30 ++++--- .../Controllers/GoogleChartController.php | 18 ++-- app/Http/Controllers/JsonController.php | 4 +- app/Http/Middleware/PiggyBanks.php | 4 +- app/Http/Middleware/ReplaceTestVars.php | 2 +- app/Http/Requests/AccountFormRequest.php | 2 +- app/Http/Requests/ProfileFormRequest.php | 2 +- app/Http/breadcrumbs.php | 6 +- app/Http/routes.php | 4 +- app/Models/Account.php | 3 +- app/Models/AccountMeta.php | 4 +- app/Models/Bill.php | 2 +- app/Models/Component.php | 2 +- app/Models/PiggyBank.php | 5 +- app/Providers/EventServiceProvider.php | 3 +- .../Account/AccountRepository.php | 7 +- .../Account/AccountRepositoryInterface.php | 9 +- .../Bill/BillRepositoryInterface.php | 5 +- app/Repositories/Budget/BudgetRepository.php | 9 +- .../PiggyBank/PiggyBankRepository.php | 2 +- app/Repositories/PiggyBank/PiggybankPart.php | 5 +- app/Support/Navigation.php | 84 +++++++++---------- app/Support/Search/Search.php | 4 +- app/Support/Search/SearchInterface.php | 3 +- app/Validation/FireflyValidator.php | 2 +- 34 files changed, 155 insertions(+), 155 deletions(-) diff --git a/app/Events/JournalCreated.php b/app/Events/JournalCreated.php index debbefd1b8..0fc11fb491 100644 --- a/app/Events/JournalCreated.php +++ b/app/Events/JournalCreated.php @@ -1,7 +1,5 @@ journal = $journal; + /** + * Create a new event instance. + * + * @return void + */ + public function __construct(TransactionJournal $journal, $piggyBankId) + { + // + $this->journal = $journal; $this->piggyBankId = $piggyBankId; - } + } } diff --git a/app/Events/JournalSaved.php b/app/Events/JournalSaved.php index e618861169..25471ca809 100644 --- a/app/Events/JournalSaved.php +++ b/app/Events/JournalSaved.php @@ -1,25 +1,24 @@ journal = $journal; - } + } } diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index 73329f983b..7280ccc3c6 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -38,7 +38,7 @@ class ConnectJournalToPiggyBank /** @var TransactionJournal $journal */ $journal = $event->journal; $piggyBankId = $event->piggyBankId; - if(intval($piggyBankId) < 1) { + if (intval($piggyBankId) < 1) { return; } @@ -66,7 +66,8 @@ class ConnectJournalToPiggyBank // update piggy bank rep for date of transaction journal. $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); if (is_null($repetition)) { - Log::debug('Found no repetition for piggy bank for date '.$journal->date->format('Y M d')); + Log::debug('Found no repetition for piggy bank for date ' . $journal->date->format('Y M d')); + return; } diff --git a/app/Handlers/Events/RescanJournal.php b/app/Handlers/Events/RescanJournal.php index 9b74e3bb44..226ae01a3c 100644 --- a/app/Handlers/Events/RescanJournal.php +++ b/app/Handlers/Events/RescanJournal.php @@ -1,8 +1,8 @@ id)->first(); - if(is_null($event)) { + $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); + if (is_null($event)) { return; } $piggyBank = $event->piggyBank()->first(); diff --git a/app/Helpers/Reminders/ReminderHelperInterface.php b/app/Helpers/Reminders/ReminderHelperInterface.php index 833afe1a24..c3db2dd1d1 100644 --- a/app/Helpers/Reminders/ReminderHelperInterface.php +++ b/app/Helpers/Reminders/ReminderHelperInterface.php @@ -2,16 +2,17 @@ namespace FireflyIII\Helpers\Reminders; -use FireflyIII\Models\Reminder; -use FireflyIII\Models\PiggyBank; use Carbon\Carbon; +use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\Reminder; /** * Interface ReminderHelperInterface * * @package FireflyIII\Helpers\Reminders */ -interface ReminderHelperInterface { +interface ReminderHelperInterface +{ /** * Takes a reminder, finds the piggy bank and tells you what to do now. * Aka how much money to put in. diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 9cf2d0918e..fef73a1085 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -169,7 +169,8 @@ class AccountController extends Controller $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); $journals = $repository->getJournals($account, $page); $subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; - $journals->setPath('accounts/show/'.$account->id); + $journals->setPath('accounts/show/' . $account->id); + return view('accounts.show', compact('account', 'what', 'subTitleIcon', 'journals', 'subTitle')); } diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index a4fd311bfd..89668589df 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -64,7 +64,7 @@ class AuthController extends Controller ); } - $data =$request->all(); + $data = $request->all(); $data['password'] = bcrypt($data['password']); $this->auth->login($this->registrar->create($data)); diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 13287972ce..79247f0397 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -98,8 +98,8 @@ class BudgetController extends Controller */ public function index(BudgetRepositoryInterface $repository) { - $budgets = Auth::user()->budgets()->where('active',1)->get(); - $inactive = Auth::user()->budgets()->where('active',0)->get(); + $budgets = Auth::user()->budgets()->where('active', 1)->get(); + $inactive = Auth::user()->budgets()->where('active', 0)->get(); // loop the budgets: $budgets->each( @@ -118,7 +118,7 @@ class BudgetController extends Controller $budgetMax = Preferences::get('budgetMaximum', 1000); $budgetMaximum = $budgetMax->data; - return view('budgets.index', compact('budgetMaximum','inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); + return view('budgets.index', compact('budgetMaximum', 'inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); } /** @@ -134,9 +134,9 @@ class BudgetController extends Controller ->whereNull('budget_transaction_journal.id') ->before($end) ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') ->get(['transaction_journals.*']); $subTitle = 'Transactions without a budget in ' . $start->format('F Y'); @@ -210,7 +210,7 @@ class BudgetController extends Controller public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository) { $budgetData = [ - 'name' => $request->input('name'), + 'name' => $request->input('name'), 'active' => intval($request->input('active')) == 1 ]; diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index b128d6e37d..0e45a06d8b 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -89,10 +89,10 @@ class CategoryController extends Controller $categories->each( function (Category $category) { $latest = $category->transactionjournals() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') - ->first(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->first(); if ($latest) { $category->lastActivity = $latest->date; } @@ -115,9 +115,9 @@ class CategoryController extends Controller ->whereNull('category_transaction_journal.id') ->before($end) ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') ->get(['transaction_journals.*']); $subTitle = 'Transactions without a category between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y'); @@ -136,14 +136,12 @@ class CategoryController extends Controller $page = intval(Input::get('page')); $offset = $page > 0 ? $page * 50 : 0; $set = $category->transactionJournals()->withRelevantData()->take(50)->offset($offset) - - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') - - ->get( - ['transaction_journals.*'] - ); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get( + ['transaction_journals.*'] + ); $count = $category->transactionJournals()->count(); $journals = new LengthAwarePaginator($set, $count, 50, $page); @@ -166,7 +164,7 @@ class CategoryController extends Controller $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); - + if (intval(Input::get('create_another')) === 1) { return Redirect::route('categories.create')->withInput(); } diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php index c7095c0c84..fd624319da 100644 --- a/app/Http/Controllers/GoogleChartController.php +++ b/app/Http/Controllers/GoogleChartController.php @@ -51,7 +51,7 @@ class GoogleChartController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $current = clone $start; - $today = new Carbon; + $today = new Carbon; while ($end >= $current) { $certain = $current < $today; @@ -237,20 +237,20 @@ class GoogleChartController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $set = TransactionJournal:: - where('transaction_journals.user_id',Auth::user()->id) - ->leftJoin( - 'transactions', - function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); - } - ) + where('transaction_journals.user_id', Auth::user()->id) + ->leftJoin( + 'transactions', + function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); + } + ) ->leftJoin( 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' ) ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->before($end) - ->where('categories.user_id',Auth::user()->id) + ->where('categories.user_id', Auth::user()->id) ->after($start) ->where('transaction_types.type', 'Withdrawal') ->groupBy('categories.id') diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 48981f8143..c4d411ba0b 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -89,8 +89,8 @@ class JsonController extends Controller // paid a bill in this range? $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); if ($count != 0) { - $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); - $currentAmount = 0; + $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); + $currentAmount = 0; foreach ($journal->transactions as $t) { if (floatval($t->amount) > 0) { $currentAmount = floatval($t->amount); diff --git a/app/Http/Middleware/PiggyBanks.php b/app/Http/Middleware/PiggyBanks.php index 92ac858ba4..fc2c40aa39 100644 --- a/app/Http/Middleware/PiggyBanks.php +++ b/app/Http/Middleware/PiggyBanks.php @@ -98,10 +98,10 @@ class PiggyBanks // first loop fixes this date. or should fix it. $max = new Carbon; - echo '[#'.$piggyBank->id.', from: '.$start->format('Y-m-d.').' to '.$end->format('Y-m-d.').']'; + echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']'; // create stuff. Or at least, try: $repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first(); - if(!$repetition) { + if (!$repetition) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = $start; diff --git a/app/Http/Middleware/ReplaceTestVars.php b/app/Http/Middleware/ReplaceTestVars.php index ad35519a3e..bc75e07f7c 100644 --- a/app/Http/Middleware/ReplaceTestVars.php +++ b/app/Http/Middleware/ReplaceTestVars.php @@ -46,7 +46,7 @@ class ReplaceTestVars $input = $request->all(); $input['_token'] = $request->session()->token(); // we need to update _token value to make sure we get the POST / PUT tests passed. - Log::debug('Input token replaced ('.$input['_token'].').'); + Log::debug('Input token replaced (' . $input['_token'] . ').'); $request->replace($input); } diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index 3ab4a26faf..a9b704f4b3 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -33,7 +33,7 @@ class AccountFormRequest extends Request $nameRule = 'required|between:1,100|uniqueAccountForUser'; if (Account::find(Input::get('id'))) { - $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:'.Input::get('id'); + $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:' . Input::get('id'); } return [ diff --git a/app/Http/Requests/ProfileFormRequest.php b/app/Http/Requests/ProfileFormRequest.php index 0fc12e3377..8bac377a5b 100644 --- a/app/Http/Requests/ProfileFormRequest.php +++ b/app/Http/Requests/ProfileFormRequest.php @@ -26,7 +26,7 @@ class ProfileFormRequest extends Request public function rules() { return [ - 'current_password' => 'required', + 'current_password' => 'required', 'new_password' => 'required|confirmed', 'new_password_confirmation' => 'required', ]; diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 4ec8165e8c..cdb6a5226e 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -3,13 +3,13 @@ use Carbon\Carbon; use DaveJamesMiller\Breadcrumbs\Generator; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; -use FireflyIII\Models\Budget; -use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\Bill; +use FireflyIII\Models\Budget; use FireflyIII\Models\Category; -use FireflyIII\Models\Reminder; use FireflyIII\Models\LimitRepetition; use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\Reminder; +use FireflyIII\Models\TransactionJournal; /* * Back home. diff --git a/app/Http/routes.php b/app/Http/routes.php index 89e5e5bd1b..685009ac92 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -132,7 +132,7 @@ Route::get('/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'r Route::controllers( [ - 'auth' => 'Auth\AuthController', + 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ] ); @@ -142,7 +142,7 @@ Route::controllers( * Home Controller */ Route::group( - ['middleware' => ['auth', 'range', 'reminders','piggybanks']], function () { + ['middleware' => ['auth', 'range', 'reminders', 'piggybanks']], function () { Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); diff --git a/app/Models/Account.php b/app/Models/Account.php index c6c8816423..0b77b81bbb 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1,10 +1,11 @@ 'required|exists:accounts,id', 'name' => 'required|between:1,100', 'data' => 'required' ]; - protected $table = 'account_meta'; + protected $table = 'account_meta'; /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 7cdcc2e67c..62beebef2d 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model; class Bill extends Model { - protected $fillable = ['name', 'match', 'amount_min','user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; + protected $fillable = ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; /** * @return array diff --git a/app/Models/Component.php b/app/Models/Component.php index 7a9bba141b..a17450943d 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -12,7 +12,7 @@ class Component extends Model { use SoftDeletes; - protected $fillable = ['user_id', 'name','class']; + protected $fillable = ['user_id', 'name', 'class']; /** * @return array diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index ad1b4fd672..b46c34cd3d 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -1,11 +1,10 @@ id.')'); + Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is ' . $this->id . ')'); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index c92888c235..f32718ca75 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -28,7 +28,7 @@ class EventServiceProvider extends ServiceProvider */ protected $listen = [ - 'FireflyIII\Events\JournalSaved' => [ + 'FireflyIII\Events\JournalSaved' => [ 'FireflyIII\Handlers\Events\RescanJournal', 'FireflyIII\Handlers\Events\UpdateJournalConnection', @@ -60,7 +60,6 @@ class EventServiceProvider extends ServiceProvider ); - Account::deleted( function (Account $account) { diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 6ea2ec97a8..92215550dd 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -106,9 +106,9 @@ class AccountRepository implements AccountRepositoryInterface ->withRelevantData() ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $query->before(Session::get('end', Carbon::now()->endOfMonth())); $query->after(Session::get('start', Carbon::now()->startOfMonth())); @@ -119,7 +119,6 @@ class AccountRepository implements AccountRepositoryInterface return $paginator; - } /** diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index e948ba01c8..20d96fbeb0 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -2,11 +2,12 @@ namespace FireflyIII\Repositories\Account; -use FireflyIII\Models\Account; -use FireflyIII\Models\TransactionJournal; -use FireflyIII\Models\Preference; -use Illuminate\Support\Collection; use Carbon\Carbon; +use FireflyIII\Models\Account; +use FireflyIII\Models\Preference; +use FireflyIII\Models\TransactionJournal; +use Illuminate\Support\Collection; + /** * Interface AccountRepositoryInterface * diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php index 44402cea23..34142fcc37 100644 --- a/app/Repositories/Bill/BillRepositoryInterface.php +++ b/app/Repositories/Bill/BillRepositoryInterface.php @@ -11,7 +11,8 @@ use FireflyIII\Models\TransactionJournal; * * @package FireflyIII\Repositories\Bill */ -interface BillRepositoryInterface { +interface BillRepositoryInterface +{ /** * @param Bill $bill @@ -25,7 +26,7 @@ interface BillRepositoryInterface { * and returns date ranges that fall within the given range; those ranges are the bills expected. When a bill is due on the 14th of the month and * you give 1st and the 31st of that month as argument, you'll get one response, matching the range of your bill. * - * @param Bill $bill + * @param Bill $bill * @param Carbon $start * @param Carbon $end * diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 6d5694e348..10a26f898e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -43,9 +43,9 @@ class BudgetRepository implements BudgetRepositoryInterface $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $countQuery = $budget->transactionJournals(); @@ -57,6 +57,7 @@ class BudgetRepository implements BudgetRepositoryInterface $set = $setQuery->get(['transaction_journals.*']); $count = $countQuery->count(); + return new LengthAwarePaginator($set, $count, $take, $offset); } @@ -103,7 +104,7 @@ class BudgetRepository implements BudgetRepositoryInterface public function update(Budget $budget, array $data) { // update the account: - $budget->name = $data['name']; + $budget->name = $data['name']; $budget->active = $data['active']; $budget->save(); diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 3fedcf5871..9eaa117622 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -111,7 +111,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function setOrder($id, $order) { $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) - ->where('piggy_banks.id',$id)->first(['piggy_banks.*']); + ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); if ($piggyBank) { $piggyBank->order = $order; $piggyBank->save(); diff --git a/app/Repositories/PiggyBank/PiggybankPart.php b/app/Repositories/PiggyBank/PiggybankPart.php index 9bbbad807c..bbde8435f3 100644 --- a/app/Repositories/PiggyBank/PiggybankPart.php +++ b/app/Repositories/PiggyBank/PiggybankPart.php @@ -2,10 +2,9 @@ namespace FireflyIII\Repositories\PiggyBank; -use FireflyIII\Models\Reminder; -use FireflyIII\Models\PiggyBankRepetition; - use Carbon\Carbon; +use FireflyIII\Models\PiggyBankRepetition; +use FireflyIII\Models\Reminder; /** * Class PiggyBankPart diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 2ef5c9a4bd..65f3de722b 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -344,6 +344,48 @@ class Navigation throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq); } + /** + * @param Carbon $theDate + * @param $repeatFreq + * @param int $subtract + * + * @return Carbon + * @throws FireflyException + */ + public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1) + { + $date = clone $theDate; + + $functionMap = [ + 'daily' => 'subDays', + 'week' => 'subWeeks', + 'weekly' => 'subWeeks', + 'month' => 'subMonths', + 'monthly' => 'subMonths', + 'year' => 'subYears', + 'yearly' => 'subYears', + ]; + $modifierMap = [ + 'quarter' => 3, + 'quarterly' => 3, + 'half-year' => 6, + ]; + if (isset($functionMap[$repeatFreq])) { + $function = $functionMap[$repeatFreq]; + $date->$function($subtract); + + return $date; + } + if (isset($modifierMap[$repeatFreq])) { + $subtract = $subtract * $modifierMap[$repeatFreq]; + $date->subMonths($subtract); + + return $date; + } + + throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq); + } + /** * @param $range * @param Carbon $start @@ -414,47 +456,5 @@ class Navigation throw new FireflyException('updateStartDate cannot handle $range ' . $range); } - /** - * @param Carbon $theDate - * @param $repeatFreq - * @param int $subtract - * - * @return Carbon - * @throws FireflyException - */ - public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1) - { - $date = clone $theDate; - - $functionMap = [ - 'daily' => 'subDays', - 'week' => 'subWeeks', - 'weekly' => 'subWeeks', - 'month' => 'subMonths', - 'monthly' => 'subMonths', - 'year' => 'subYears', - 'yearly' => 'subYears', - ]; - $modifierMap = [ - 'quarter' => 3, - 'quarterly' => 3, - 'half-year' => 6, - ]; - if (isset($functionMap[$repeatFreq])) { - $function = $functionMap[$repeatFreq]; - $date->$function($subtract); - - return $date; - } - if (isset($modifierMap[$repeatFreq])) { - $subtract = $subtract * $modifierMap[$repeatFreq]; - $date->subMonths($subtract); - - return $date; - } - - throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq); - } - } diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 5270cdf610..f1e0c658ae 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -112,8 +112,8 @@ class Search implements SearchInterface )->get(); // encrypted - $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); - $set = $all->filter( + $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); + $set = $all->filter( function (TransactionJournal $journal) use ($words) { foreach ($words as $word) { $haystack = strtolower($journal->description); diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php index 4b58393065..431275e8fe 100644 --- a/app/Support/Search/SearchInterface.php +++ b/app/Support/Search/SearchInterface.php @@ -9,7 +9,8 @@ use Illuminate\Support\Collection; * * @package FireflyIII\Support\Search */ -interface SearchInterface { +interface SearchInterface +{ /** * @param array $words * diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index d4b4771e90..8ee5399b65 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -152,7 +152,7 @@ class FireflyValidator extends Validator */ public function validateUniquePiggyBankForUser($attribute, $value, $parameters) { - $query = DB::table($parameters[0])->where('piggy_banks.'.$parameters[1], $value); + $query = DB::table($parameters[0])->where('piggy_banks.' . $parameters[1], $value); $query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id'); $query->where('accounts.user_id', Auth::user()->id); if (isset($paramers[2])) { From ac12a4707164bdd3b33f0bc7f9768d8b1d3b3f26 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 21:29:37 +0200 Subject: [PATCH 12/63] Hide inactive budgets when there are none. --- resources/views/budgets/index.blade.php | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/resources/views/budgets/index.blade.php b/resources/views/budgets/index.blade.php index 2d7877f4f8..e9dc51d410 100644 --- a/resources/views/budgets/index.blade.php +++ b/resources/views/budgets/index.blade.php @@ -145,24 +145,25 @@
- -
-
-
- - Inactive budgets -
-
- @foreach($inactive as $index => $budget) - @if($index != count($inactive)-1) - {{$budget->name}}, - @else - {{$budget->name}} - @endif - @endforeach + @if($inactive->count() > 0) +
+
+
+ + Inactive budgets +
+
+ @foreach($inactive as $index => $budget) + @if($index != count($inactive)-1) + {{$budget->name}}, + @else + {{$budget->name}} + @endif + @endforeach +
-
+ @endif
From 38ba64541545af3d275d1d04634b63ac205b07ae Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 30 Mar 2015 09:23:18 +0200 Subject: [PATCH 13/63] Add hidden-xs class. --- resources/views/partials/boxes.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/partials/boxes.blade.php b/resources/views/partials/boxes.blade.php index 4c6b947770..c89134f4e5 100644 --- a/resources/views/partials/boxes.blade.php +++ b/resources/views/partials/boxes.blade.php @@ -1,6 +1,6 @@
-
+