diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 2c81e339a0..518618ba49 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -1,8 +1,9 @@
_budgets->find($budgetId);
-
- $list = $budget->transactionjournals()->get();
- $return = [];
- /** @var \TransactionJournal $entry */
- foreach ($list as $entry) {
- $month = $entry->date->format('F Y');
- $return[$month] = isset($return[$month]) ? $return[$month] : [];
- $return[$month][] = $entry;
-
- }
- $str = '';
-
- foreach ($return as $month => $set) {
- $str .= '
' . $month . '
';
- /** @var \TransactionJournal $tj */
- $sum = 0;
- foreach ($set as $tj) {
- $str .= '#' . $tj->id . ' ' . $tj->description . ': ';
-
- foreach ($tj->transactions as $index => $t) {
- $str .= $t->amount . ', ';
- if ($index == 0) {
- $sum += $t->amount;
-
- }
- }
- $str .= '
';
-
- }
- $str .= 'sum: ' . $sum . '
';
- }
-
- return $str;
-
+ return $budget->id;
+// /** @var \Budget $budget */
+// $budget = $this->_budgets->find($budgetId);
+//
+// $list = $budget->transactionjournals()->get();
+// $return = [];
+// /** @var \TransactionJournal $entry */
+// foreach ($list as $entry) {
+// $month = $entry->date->format('F Y');
+// $return[$month] = isset($return[$month]) ? $return[$month] : [];
+// $return[$month][] = $entry;
+//
+// }
+// $str = '';
+//
+// foreach ($return as $month => $set) {
+// $str .= '' . $month . '
';
+// /** @var \TransactionJournal $tj */
+// $sum = 0;
+// foreach ($set as $tj) {
+// $str .= '#' . $tj->id . ' ' . $tj->description . ': ';
+//
+// foreach ($tj->transactions as $index => $t) {
+// $str .= $t->amount . ', ';
+// if ($index == 0) {
+// $sum += $t->amount;
+//
+// }
+// }
+// $str .= '
';
+//
+// }
+// $str .= 'sum: ' . $sum . '
';
+// }
+//
+// return $str;
}
@@ -113,17 +114,25 @@ class BudgetController extends BaseController
public function store()
{
- $data = [
- 'name' => Input::get('name'),
- 'amount' => floatval(Input::get('amount')),
- 'repeat_freq' => Input::get('period'),
- 'repeats' => intval(Input::get('repeats'))
- ];
+ $budget = $this->_repository->store(Input::all());
+ if ($budget->id) {
+ Session::flash('success', 'Budget created!');
- $this->_budgets->store($data);
- Session::flash('success', 'Budget created!');
+ if (Input::get('create') == '1') {
+ return Redirect::route('budgets.create', ['from' => Input::get('from')]);
+ }
+
+ if (Input::get('from') == 'date') {
+ return Redirect::route('budgets.index');
+ } else {
+ return Redirect::route('budgets.index.budget');
+ }
+ } else {
+ Session::flash('error', 'Could not save the new budget');
+
+ return Redirect::route('budgets.create')->withInput();
+ }
- return Redirect::route('budgets.index');
}
diff --git a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
index 113e2adc5b..26ea2236d3 100644
--- a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
+++ b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
@@ -121,7 +121,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
$budget->save();
// if limit, create limit (repetition itself will be picked up elsewhere).
- if ($data['amount'] > 0) {
+ if (floatval($data['amount']) > 0) {
$limit = new \Limit;
$limit->budget()->associate($budget);
$startDate = new Carbon;
@@ -152,10 +152,13 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
$limit->amount = $data['amount'];
$limit->repeats = $data['repeats'];
$limit->repeat_freq = $data['repeat_freq'];
- $limit->save();
+ if ($limit->validate()) {
+ $limit->save();
+ }
+ }
+ if($budget->validate()) {
+ $budget->save();
}
-
-
return $budget;
}
diff --git a/app/views/accounts/create.blade.php b/app/views/accounts/create.blade.php
index 25b83aff34..7a2f3a6ebc 100644
--- a/app/views/accounts/create.blade.php
+++ b/app/views/accounts/create.blade.php
@@ -5,6 +5,7 @@
Firefly
Add a new personal account
+
Accounts are the record holders for transactions and transfers. Money moves
from one account to another.
@@ -35,8 +36,7 @@
@if($errors->has('name'))
{{$errors->first('name')}}
@else
- Use something descriptive such as "checking account" or "My Bank Main Account".
+ Use something descriptive such as "checking account" or "My Bank Main Account".
@endif
@@ -51,8 +51,7 @@
€
- {{Form::input('number','openingbalance', Input::old('openingbalance'), ['step' => 'any', 'class' =>
- 'form-control'])}}
+ {{Form::input('number','openingbalance', Input::old('openingbalance'), ['step' => 'any', 'class' => 'form-control'])}}
@if($errors->has('openingbalance'))
diff --git a/app/views/budgets/create.blade.php b/app/views/budgets/create.blade.php
index e25252c560..c40103f946 100644
--- a/app/views/budgets/create.blade.php
+++ b/app/views/budgets/create.blade.php
@@ -5,6 +5,7 @@
Firefly
Create a budget
+
Use budgets to organize and limit your expenses.
Firefly uses the envelope system. Every budget
is an envelope in which you put money every [period]. Expenses allocated to each budget are paid from this
@@ -19,15 +20,21 @@
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.store')])}}
+{{Form::hidden('from',e(Input::get('from')))}}
+