| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | <?php namespace FireflyIII\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  | use Amount; | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | use Auth; | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | use FireflyIII\Http\Requests\BudgetFormRequest; | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | use FireflyIII\Models\Budget; | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | use FireflyIII\Models\LimitRepetition; | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | 
					
						
							|  |  |  | use Input; | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  | use Navigation; | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | use Preferences; | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | use Response; | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | use Session; | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  | use URL; | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  | use View; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class BudgetController | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package FireflyIII\Http\Controllers | 
					
						
							| 
									
										
										
										
											2015-05-26 08:17:58 +02:00
										 |  |  |  * @SuppressWarnings(PHPMD.TooManyMethods) | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | class BudgetController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-03 19:11:55 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-23 20:49:57 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2015-04-03 19:11:55 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:30 +02:00
										 |  |  |         parent::__construct(); | 
					
						
							| 
									
										
										
										
											2015-05-14 13:17:53 +02:00
										 |  |  |         View::share('title', trans('firefly.budgets')); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |         View::share('mainTitleIcon', 'fa-tasks'); | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:30 +02:00
										 |  |  |         View::share('hideBudgets', true); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param Budget                    $budget | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @return \Symfony\Component\HttpFoundation\Response | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |     public function amount(BudgetRepositoryInterface $repository, Budget $budget) | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $amount          = intval(Input::get('amount')); | 
					
						
							|  |  |  |         $date            = Session::get('start', Carbon::now()->startOfMonth()); | 
					
						
							|  |  |  |         $limitRepetition = $repository->updateLimitAmount($budget, $date, $amount); | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         if ($amount == 0) { | 
					
						
							|  |  |  |             $limitRepetition = null; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function create() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |         // put previous url in session if not redirect from store (not "create another").
 | 
					
						
							|  |  |  |         if (Session::get('budgets.create.fromStore') !== true) { | 
					
						
							|  |  |  |             Session::put('budgets.create.url', URL::previous()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Session::forget('budgets.create.fromStore'); | 
					
						
							| 
									
										
										
										
											2015-05-25 08:12:31 +02:00
										 |  |  |         Session::flash('gaEventCategory', 'budgets'); | 
					
						
							|  |  |  |         Session::flash('gaEventAction', 'create'); | 
					
						
							| 
									
										
										
										
											2015-05-21 23:05:31 +02:00
										 |  |  |         $subTitle = trans('firefly.create_new_budget'); | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 10:23:01 +02:00
										 |  |  |         return view('budgets.create', compact('subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Budget $budget | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return \Illuminate\View\View | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function delete(Budget $budget) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-25 22:16:00 +02:00
										 |  |  |         $subTitle = trans('firefly.delete_budget', ['name' => $budget->name]); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |         // put previous url in session
 | 
					
						
							|  |  |  |         Session::put('budgets.delete.url', URL::previous()); | 
					
						
							| 
									
										
										
										
											2015-05-25 08:12:31 +02:00
										 |  |  |         Session::flash('gaEventCategory', 'budgets'); | 
					
						
							|  |  |  |         Session::flash('gaEventAction', 'delete'); | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 16:19:32 +01:00
										 |  |  |         return view('budgets.delete', compact('budget', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param Budget                    $budget | 
					
						
							|  |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return \Illuminate\Http\RedirectResponse | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function destroy(Budget $budget, BudgetRepositoryInterface $repository) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $name = $budget->name; | 
					
						
							|  |  |  |         $repository->destroy($budget); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |         Session::flash('success', 'The  budget "' . e($name) . '" was deleted.'); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 08:12:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |         return redirect(Session::get('budgets.delete.url')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Budget $budget | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function edit(Budget $budget) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-06-13 10:02:36 +02:00
										 |  |  |         $subTitle = trans('firefly.edit_budget', ['name' => $budget->name]); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |         // put previous url in session if not redirect from store (not "return_to_edit").
 | 
					
						
							|  |  |  |         if (Session::get('budgets.edit.fromUpdate') !== true) { | 
					
						
							|  |  |  |             Session::put('budgets.edit.url', URL::previous()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Session::forget('budgets.edit.fromUpdate'); | 
					
						
							| 
									
										
										
										
											2015-05-25 08:12:31 +02:00
										 |  |  |         Session::flash('gaEventCategory', 'budgets'); | 
					
						
							|  |  |  |         Session::flash('gaEventAction', 'edit'); | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 16:19:32 +01:00
										 |  |  |         return view('budgets.edit', compact('budget', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  |     public function index(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository) | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |         $budgets           = $repository->getActiveBudgets(); | 
					
						
							|  |  |  |         $inactive          = $repository->getInactiveBudgets(); | 
					
						
							|  |  |  |         $spent             = '0'; | 
					
						
							|  |  |  |         $budgeted          = '0'; | 
					
						
							|  |  |  |         $range             = Preferences::get('viewRange', '1M')->data; | 
					
						
							|  |  |  |         $start             = Navigation::startOfPeriod(Session::get('start', new Carbon), $range); | 
					
						
							|  |  |  |         $end               = Navigation::endOfPeriod($start, $range); | 
					
						
							|  |  |  |         $key               = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd'); | 
					
						
							|  |  |  |         $budgetIncomeTotal = Preferences::get($key, 1000)->data; | 
					
						
							|  |  |  |         $period            = Navigation::periodShow($start, $range); | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  |         $accounts          = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         bcscale(2); | 
					
						
							| 
									
										
										
										
											2015-04-03 19:39:36 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * Do some cleanup: | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         $repository->cleanupBudgets(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |         // loop the budgets:
 | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         /** @var Budget $budget */ | 
					
						
							|  |  |  |         foreach ($budgets as $budget) { | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  |             $budget->spent      = $repository->balanceInPeriodForList($budget, $start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |             $budget->currentRep = $repository->getCurrentRepetition($budget, $start, $end); | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |             if ($budget->currentRep) { | 
					
						
							|  |  |  |                 $budgeted = bcadd($budgeted, $budget->currentRep->amount); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |             $spent = bcadd($spent, $budget->spent); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $budgetMaximum   = Preferences::get('budgetMaximum', 1000)->data; | 
					
						
							|  |  |  |         $defaultCurrency = Amount::getDefaultCurrency(); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         return view( | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  |             'budgets.index', compact('budgetMaximum', 'period', 'range', 'budgetIncomeTotal', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted') | 
					
						
							| 
									
										
										
										
											2015-05-24 22:54:59 +02:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |     public function noBudget(BudgetRepositoryInterface $repository) | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |         $range    = Preferences::get('viewRange', '1M')->data; | 
					
						
							|  |  |  |         $start    = Navigation::startOfPeriod(Session::get('start', new Carbon), $range); | 
					
						
							|  |  |  |         $end      = Navigation::endOfPeriod($start, $range); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |         $list     = $repository->getWithoutBudget($start, $end); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:17:36 +02:00
										 |  |  |         $subTitle = trans( | 
					
						
							|  |  |  |             'firefly.without_budget_between', | 
					
						
							|  |  |  |             ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 16:19:32 +01:00
										 |  |  |         return view('budgets.noBudget', compact('list', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function postUpdateIncome() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |         $range = Preferences::get('viewRange', '1M')->data; | 
					
						
							|  |  |  |         $start = Navigation::startOfPeriod(Session::get('start', new Carbon), $range); | 
					
						
							|  |  |  |         $end   = Navigation::endOfPeriod($start, $range); | 
					
						
							|  |  |  |         $key   = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd'); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |         Preferences::set($key, intval(Input::get('amount'))); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |         return redirect(route('budgets.index')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param Budget                    $budget | 
					
						
							|  |  |  |      * @param LimitRepetition           $repetition | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |     public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null) | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) { | 
					
						
							| 
									
										
										
										
											2015-05-05 10:23:01 +02:00
										 |  |  |             $message = 'Invalid selection.'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return view('error', compact('message')); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:30 +02:00
										 |  |  |         $journals = $repository->getJournals($budget, $repetition); | 
					
						
							| 
									
										
										
										
											2015-06-04 17:43:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (is_null($repetition->id)) { | 
					
						
							|  |  |  |             $limits   = $repository->getBudgetLimits($budget); | 
					
						
							|  |  |  |             $subTitle = e($budget->name); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $limits   = [$repetition->budgetLimit]; | 
					
						
							|  |  |  |             $subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-02 23:28:04 +02:00
										 |  |  |         $journals->setPath('/budgets/show/' . $budget->id); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:30 +02:00
										 |  |  |         return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 17:45:03 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param BudgetFormRequest         $request | 
					
						
							|  |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return \Illuminate\Http\RedirectResponse | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     public function store(BudgetFormRequest $request, BudgetRepositoryInterface $repository) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $budgetData = [ | 
					
						
							|  |  |  |             'name' => $request->input('name'), | 
					
						
							|  |  |  |             'user' => Auth::user()->id, | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2015-06-06 23:09:12 +02:00
										 |  |  |         $budget     = $repository->store($budgetData); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Session::flash('success', 'New budget "' . $budget->name . '" stored!'); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 18:22:36 +01:00
										 |  |  |         if (intval(Input::get('create_another')) === 1) { | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |             // set value so create routine will not overwrite URL:
 | 
					
						
							|  |  |  |             Session::put('budgets.create.fromStore', true); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |             return redirect(route('budgets.create'))->withInput(); | 
					
						
							| 
									
										
										
										
											2015-03-28 18:22:36 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |         // redirect to previous URL.
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |         return redirect(Session::get('budgets.create.url')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param BudgetFormRequest         $request | 
					
						
							|  |  |  |      * @param BudgetRepositoryInterface $repository | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |      * @param Budget                    $budget | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-03 12:54:39 +02:00
										 |  |  |     public function update(BudgetFormRequest $request, BudgetRepositoryInterface $repository, Budget $budget) | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $budgetData = [ | 
					
						
							| 
									
										
										
										
											2015-03-29 21:27:51 +02:00
										 |  |  |             'name'   => $request->input('name'), | 
					
						
							| 
									
										
										
										
											2015-12-15 12:46:40 +01:00
										 |  |  |             'active' => intval($request->input('active')) == 1, | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $repository->update($budget, $budgetData); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Session::flash('success', 'Budget "' . $budget->name . '" updated.'); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 17:45:03 +01:00
										 |  |  |         if (intval(Input::get('return_to_edit')) === 1) { | 
					
						
							| 
									
										
										
										
											2015-04-01 09:40:19 +02:00
										 |  |  |             // set value so edit routine will not overwrite URL:
 | 
					
						
							|  |  |  |             Session::put('budgets.edit.fromUpdate', true); | 
					
						
							| 
									
										
										
										
											2015-04-05 10:36:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |             return redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]); | 
					
						
							| 
									
										
										
										
											2015-03-26 17:45:03 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 09:43:19 +02:00
										 |  |  |         // redirect to previous URL.
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:27:21 +02:00
										 |  |  |         return redirect(Session::get('budgets.edit.url')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-26 17:50:09 +00:00
										 |  |  |      * @return \Illuminate\View\View | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function updateIncome() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-27 17:44:49 +02:00
										 |  |  |         $range  = Preferences::get('viewRange', '1M')->data; | 
					
						
							|  |  |  |         $start  = Navigation::startOfPeriod(Session::get('start', new Carbon), $range); | 
					
						
							|  |  |  |         $end    = Navigation::endOfPeriod($start, $range); | 
					
						
							|  |  |  |         $key    = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd'); | 
					
						
							|  |  |  |         $amount = Preferences::get($key, 1000); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-03 12:58:55 +02:00
										 |  |  |         return view('budgets.income', compact('amount')); | 
					
						
							| 
									
										
										
										
											2015-02-22 15:40:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 09:46:21 +01:00
										 |  |  | } |