Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Simplified some code.
James Cole14b94a5bd277
diff --git a/app/Helpers/Csv/Specifix/AbnAmroDescription.php b/app/Helpers/Csv/Specifix/AbnAmroDescription.phpindex 866f7edf72..7978ab1465 100644--- a/app/Helpers/Csv/Specifix/AbnAmroDescription.php+++ b/app/Helpers/Csv/Specifix/AbnAmroDescription.php@@ -95,11 +95,10 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface// description and opposing account will be the same.$this->data['opposing-account-name'] = $matches[4];+ $this->data['description'] = $matches[4];if ($matches[1] == 'GEA') {$this->data['description'] = 'GEA ' . $matches[4];- } else {- $this->data['description'] = $matches[4];}return true;@@ -154,9 +153,8 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface// Set a new description for the current transaction. If none was given// set the description to type, name and reference- if ($newDescription) {- $this->data['description'] = $newDescription;- } else {+ $this->data['description'] = $newDescription;+ if (strlen($newDescription) === 0) {$this->data['description'] = sprintf('%s - %s (%s)', $type, $name, $reference);}@@ -212,9 +210,8 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface// Set a new description for the current transaction. If none was given// set the description to type, name and reference- if ($newDescription) {- $this->data['description'] = $newDescription;- } else {+ $this->data['description'] = $newDescription;+ if (strlen($newDescription) === 0) {$this->data['description'] = sprintf('%s - %s (%s)', $type, $name, $reference);}}diff --git a/app/Http/Controllers/Auth/ConfirmationController.php b/app/Http/Controllers/Auth/ConfirmationController.phpindex d51100630b..1c6761926c 100644--- a/app/Http/Controllers/Auth/ConfirmationController.php+++ b/app/Http/Controllers/Auth/ConfirmationController.php@@ -55,9 +55,8 @@ class ConfirmationController extends ControllerSession::flash('success', strval(trans('firefly.account_is_confirmed')));return redirect(route('home'));- } else {- throw new FireflyException(trans('firefly.invalid_activation_code'));}+ throw new FireflyException(trans('firefly.invalid_activation_code'));}/**diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.phpindex 0a4570a05b..7b8164c693 100644--- a/app/Http/Controllers/BudgetController.php+++ b/app/Http/Controllers/BudgetController.php@@ -251,34 +251,53 @@ class BudgetController extends Controller/*** @param BudgetRepositoryInterface $repository* @param Budget $budget- * @param LimitRepetition|null $repetition** @return View* @throws FireflyException*/- public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null)+ public function show(BudgetRepositoryInterface $repository, Budget $budget){- if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) {- throw new FireflyException('This budget limit is not part of this budget.');+ $pageSize = Preferences::get('transactionPageSize', 50)->data;+ $journals = $repository->getJournals($budget, new LimitRepetition, $pageSize);+ $start = $repository->firstActivity($budget);+ $end = new Carbon;+ $set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();+ $subTitle = e($budget->name);+ $journals->setPath('/budgets/show/' . $budget->id);+ $spentArray = $repository->spentPerDay($budget, $start, $end);+ $limits = new Collection();++ /** @var LimitRepetition $entry */+ foreach ($set as $entry) {+ $entry->spent = $this->getSumOfRange($entry->startdate, $entry->enddate, $spentArray);+ $limits->push($entry);}- $pageSize = Preferences::get('transactionPageSize', 50)->data;- $journals = $repository->getJournals($budget, $repetition, $pageSize);- if (is_null($repetition->id)) {- $start = $repository->firstActivity($budget);- $end = new Carbon;- $set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();- $subTitle = e($budget->name);- $journals->setPath('/budgets/show/' . $budget->id);- } else {- $start = $repetition->startdate;- $end = $repetition->enddate;- $set = new Collection([$repetition]);- $subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);- $journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);+ return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));+ }++ /**+ * @param BudgetRepositoryInterface $repository+ * @param Budget $budget+ * @param LimitRepetition $repetition+ *+ * @return View+ * @throws FireflyException+ */+ public function showWithRepetition(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)+ {+ if ($repetition->budgetLimit->budget->id != $budget->id) {+ throw new FireflyException('This budget limit is not part of this budget.');}+ $pageSize = Preferences::get('transactionPageSize', 50)->data;+ $journals = $repository->getJournals($budget, $repetition, $pageSize);+ $start = $repetition->startdate;+ $end = $repetition->enddate;+ $set = new Collection([$repetition]);+ $subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);+ $journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);$spentArray = $repository->spentPerDay($budget, $start, $end);$limits = new Collection();@@ -290,6 +309,7 @@ class BudgetController extends Controllerreturn view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));+}/**diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.phpindex 2189b5a22f..e949b6d53c 100644--- a/app/Http/Controllers/CategoryController.php+++ b/app/Http/Controllers/CategoryController.php@@ -186,24 +186,25 @@ class CategoryController extends Controllerif ($cache->has()) {$entries = $cache->get();- } else {- while ($end >= $start) {- $end = Navigation::startOfPeriod($end, $range);- $currentEnd = Navigation::endOfPeriod($end, $range);+ return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));+ }- // get data from spentArray:- $spent = $this->getSumOfRange($end, $currentEnd, $spentArray);- $earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);- $dateStr = $end->format('Y-m-d');- $dateName = Navigation::periodShow($end, $range);- $entries->push([$dateStr, $dateName, $spent, $earned]);+ while ($end >= $start) {+ $end = Navigation::startOfPeriod($end, $range);+ $currentEnd = Navigation::endOfPeriod($end, $range);- $end = Navigation::subtractPeriod($end, $range, 1);+ // get data from spentArray:+ $spent = $this->getSumOfRange($end, $currentEnd, $spentArray);+ $earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);+ $dateStr = $end->format('Y-m-d');+ $dateName = Navigation::periodShow($end, $range);+ $entries->push([$dateStr, $dateName, $spent, $earned]);++ $end = Navigation::subtractPeriod($end, $range, 1);- }- $cache->store($entries);}+ $cache->store($entries);return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));}diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.phpindex f38af543d2..4e92a28f24 100644--- a/app/Http/Controllers/Chart/BillController.php+++ b/app/Http/Controllers/Chart/BillController.php@@ -51,9 +51,11 @@ class BillController extends Controller// expenses are negative (bill not yet paid),$creditCardDue = bcmul($creditCardDue, '-1');$unpaid = bcadd($unpaid, $creditCardDue);- } else {- // if more than zero, the bill has been paid: (transfer = positive).- // amount must be negative to be added to $paid:+ }++ // if $creditCardDue more than zero, the bill has been paid: (transfer = positive).+ // amount must be negative to be added to $paid:+ if ($creditCardDue >= 0) {$paid = bcadd($paid, $creditCardDue);}diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.phpindex 80280c94ca..40a98c2d0d 100644--- a/app/Http/Controllers/CurrencyController.php+++ b/app/Http/Controllers/CurrencyController.php@@ -168,14 +168,16 @@ class CurrencyController extends Controller*/public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository){- $data = $request->getCurrencyData();- if (Auth::user()->hasRole('owner')) {- $currency = $repository->store($data);- Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));- } else {+ if (!Auth::user()->hasRole('owner')) {Log::error('User ' . Auth::user()->id . ' is not admin, but tried to store a currency.');++ return redirect(session('currency.create.url'));}+ $data = $request->getCurrencyData();+ $currency = $repository->store($data);+ Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));+if (intval(Input::get('create_another')) === 1) {Session::put('currency.create.fromStore', true);diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex 32e54220b3..ded94b2943 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -32,16 +32,15 @@ class HomeController extends Controllerpublic function dateRange(){- $start = new Carbon(Input::get('start'));- $end = new Carbon(Input::get('end'));- $label = Input::get('label');+ $start = new Carbon(Input::get('start'));+ $end = new Carbon(Input::get('end'));+ $label = Input::get('label');+ $isCustomRange = false;// check if the label is "everything" or "Custom range" which will betray// a possible problem with the budgets.if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {- Session::put('is_custom_range', true);- } else {- Session::put('is_custom_range', false);+ $isCustomRange = true;}$diff = $start->diffInDays($end);@@ -50,6 +49,7 @@ class HomeController extends ControllerSession::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));}+ Session::put('is_custom_range', $isCustomRange);Session::put('start', $start);Session::put('end', $end);}diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.phpindex b4015ca8d6..4977d37265 100644--- a/app/Http/Controllers/NewUserController.php+++ b/app/Http/Controllers/NewUserController.php@@ -111,12 +111,12 @@ class NewUserController extends Controller$repository->storeMeta($creditCard, 'ccMonthlyPaymentDate', Carbon::now()->year . '-01-01');$count++;}+ $message = strval(trans('firefly.stored_new_accounts_new_user'));if ($count == 1) {- Session::flash('success', strval(trans('firefly.stored_new_account_new_user')));- } else {- Session::flash('success', strval(trans('firefly.stored_new_accounts_new_user')));+ $message = strval(trans('firefly.stored_new_account_new_user'));}+ Session::flash('success', $message);Preferences::mark();return redirect(route('index'));diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.phpindex 19b96bc78e..8619352932 100644--- a/app/Http/Controllers/PiggyBankController.php+++ b/app/Http/Controllers/PiggyBankController.php@@ -127,16 +127,15 @@ class PiggyBankController extends Controller$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));$subTitle = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);$subTitleIcon = 'fa-pencil';-+ $targetDate = null;/** Flash some data to fill the form.*/- if (is_null($piggyBank->targetdate) || $piggyBank->targetdate == '') {- $targetDate = null;- } else {+ if (!is_null($piggyBank->targetdate) || !$piggyBank->targetdate == '') {$targetDate = new Carbon($piggyBank->targetdate);$targetDate = $targetDate->format('Y-m-d');}+$preFilled = ['name' => $piggyBank->name,'account_id' => $piggyBank->account_id,'targetamount' => $piggyBank->targetamount,@@ -246,13 +245,13 @@ class PiggyBankController extends Controller'success', strval(trans('firefly.added_amount_to_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));Preferences::mark();- } else {- Log::error('Cannot add ' . $amount . ' because max amount is ' . $maxAmount . ' (left on account is ' . $leftOnAccount . ')');- Session::flash(- 'error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))- );++ return redirect(route('piggy-banks.index'));}+ Log::error('Cannot add ' . $amount . ' because max amount is ' . $maxAmount . ' (left on account is ' . $leftOnAccount . ')');+ Session::flash('error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));+return redirect(route('piggy-banks.index'));}@@ -280,12 +279,12 @@ class PiggyBankController extends Controller'success', strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));Preferences::mark();- } else {- Session::flash(- 'error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))- );++ return redirect(route('piggy-banks.index'));}+ Session::flash('error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));+return redirect(route('piggy-banks.index'));}diff --git a/app/Http/routes.php b/app/Http/routes.phpindex 2c36250347..0c4ce4b360 100644--- a/app/Http/routes.php+++ b/app/Http/routes.php@@ -124,7 +124,8 @@ Route::group(Route::get('/budgets/create', ['uses' => 'BudgetController@create', 'as' => 'budgets.create']);Route::get('/budgets/edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);Route::get('/budgets/delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);- Route::get('/budgets/show/{budget}/{limitrepetition?}', ['uses' => 'BudgetController@show', 'as' => 'budgets.show']);+ Route::get('/budgets/show/{budget}', ['uses' => 'BudgetController@show', 'as' => 'budgets.show']);+ Route::get('/budgets/show/{budget}/{limitrepetition}', ['uses' => 'BudgetController@showWithRepetition', 'as' => 'budgets.showWithRepetition']);Route::get('/budgets/list/noBudget', ['uses' => 'BudgetController@noBudget', 'as' => 'budgets.noBudget']);Route::post('/budgets/income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'budgets.postIncome']);Route::post('/budgets/store', ['uses' => 'BudgetController@store', 'as' => 'budgets.store']);diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twigindex 37eae3558b..f72ac99270 100644--- a/resources/views/budgets/index.twig+++ b/resources/views/budgets/index.twig@@ -107,7 +107,7 @@<h3 class="box-title"><!-- link in header -->{% if budget.currentRep.id %}- <a href="{{ route('budgets.show', [budget.id, budget.currentRep.id]) }}" class="budget-link"+ <a href="{{ route('budgets.showWithRepetition', [budget.id, budget.currentRep.id]) }}" class="budget-link"data-id="{{ budget.id }}">{{ budget.name }}</a>{% else %}<a href="{{ route('budgets.show',budget.id) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>@@ -173,7 +173,7 @@{% for other in budget.otherRepetitions %}{% if other.id != budget.currentRep.id %}<li>Budgeted- <a href="{{ route('budgets.show', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>+ <a href="{{ route('budgets.showWithRepetition', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>between{{ other.startdate.formatLocalized(monthAndDayFormat) }}and {{ other.enddate.formatLocalized(monthAndDayFormat) }}.diff --git a/resources/views/budgets/show.twig b/resources/views/budgets/show.twigindex 1b04415a0d..5c0ba0c54a 100644--- a/resources/views/budgets/show.twig+++ b/resources/views/budgets/show.twig@@ -48,7 +48,7 @@{% for limit in limits %}<div class="box"><div class="box-header with-border">- <h3 class="box-title"><a href="{{ route('budgets.show',[budget.id,limit.id]) }}">{{ limit.startdate.formatLocalized(monthFormat) }}</a>+ <h3 class="box-title"><a href="{{ route('budgets.showWithRepetition',[budget.id,limit.id]) }}">{{ limit.startdate.formatLocalized(monthFormat) }}</a></h3></div><div class="box-body">diff --git a/resources/views/reports/partials/budgets.twig b/resources/views/reports/partials/budgets.twigindex 4326d9ca7f..c48dfc87ce 100644--- a/resources/views/reports/partials/budgets.twig+++ b/resources/views/reports/partials/budgets.twig@@ -27,7 +27,7 @@</td><td>{% if budgetLine.getRepetition.id %}- <a href="{{ route('budgets.show', [budgetLine.getBudget.id, budgetLine.getRepetition.id]) }}">+ <a href="{{ route('budgets.showWithRepetition', [budgetLine.getBudget.id, budgetLine.getRepetition.id]) }}">{{ budgetLine.getRepetition.startdate.formatLocalized(monthAndDayFormat) }}—{{ budgetLine.getRepetition.enddate.formatLocalized(monthAndDayFormat) }}