$ruleGroup->title]); $ruleGroupList = ExpandedForm::makeSelectList($repository->get(), true); unset($ruleGroupList[$ruleGroup->id]); // put previous url in session Session::put('rules.rule-group.delete.url', URL::previous()); Session::flash('gaEventCategory', 'rules'); Session::flash('gaEventAction', 'delete-rule-group'); return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle', 'ruleGroupList')); } /** * @param RuleGroupRepositoryInterface $repository * * @param RuleGroup $ruleGroup * * @return \Illuminate\Http\RedirectResponse */ public function destroy(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) { $title = $ruleGroup->title; $moveTo = Auth::user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete'))); $repository->destroy($ruleGroup, $moveTo); Session::flash('success', trans('firefly.deleted_rule_group', ['title' => $title])); Preferences::mark(); return redirect(session('rules.rule-group.delete.url')); } /** * @param RuleGroupRepositoryInterface $repository * @param RuleGroup $ruleGroup * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function down(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) { $repository->moveDown($ruleGroup); return redirect(route('rules.index')); } /** * @param RuleGroup $ruleGroup * * @return View */ public function edit(RuleGroup $ruleGroup) { $subTitle = trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]); // put previous url in session if not redirect from store (not "return_to_edit"). if (session('rules.rule-group.edit.fromUpdate') !== true) { Session::put('rules.rule-group.edit.url', URL::previous()); } Session::forget('rules.rule-group.edit.fromUpdate'); Session::flash('gaEventCategory', 'rules'); Session::flash('gaEventAction', 'edit-rule-group'); return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle')); } /** * Execute the given rulegroup on a set of existing transactions * * @param SelectTransactionsRequest $request * @param AccountRepositoryInterface $repository * @param RuleGroup $ruleGroup * * @return \Illuminate\Http\RedirectResponse */ public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup) { // Get parameters specified by the user $accounts = $repository->get($request->get('accounts')); $startDate = new Carbon($request->get('start_date')); $endDate = new Carbon($request->get('end_date')); // Create a job to do the work asynchronously $job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup); // Apply parameters to the job $job->setUser(Auth::user()); $job->setAccounts($accounts); $job->setStartDate($startDate); $job->setEndDate($endDate); // Dispatch a new job to execute it in a queue $this->dispatch($job); // Tell the user that the job is queued Session::flash('success', trans('firefly.executed_group_on_existing_transactions', ['title' => $ruleGroup->title])); return redirect()->route('rules.index'); } /** * Shows a form for the user to select a range of transactions to execute this rulegroup for * * @param AccountRepositoryInterface $repository * @param RuleGroup $ruleGroup * * @return View */ public function selectTransactions(AccountRepositoryInterface $repository, RuleGroup $ruleGroup) { // does the user have shared accounts? $accounts = $repository->getAccounts(['Default account', 'Asset account']); $accountList = ExpandedForm::makeSelectList($accounts); $checkedAccounts = array_keys($accountList); $first = session('first')->format('Y-m-d'); $today = Carbon::create()->format('Y-m-d'); $subTitle = (string)trans('firefly.execute_on_existing_transactions'); return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup', 'subTitle')); } /** * @param RuleGroupFormRequest $request * @param RuleGroupRepositoryInterface $repository * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository) { $data = [ 'title' => $request->input('title'), 'description' => $request->input('description'), 'user_id' => Auth::user()->id, ]; $ruleGroup = $repository->store($data); Session::flash('success', trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title])); Preferences::mark(); if (intval(Input::get('create_another')) === 1) { // set value so create routine will not overwrite URL: Session::put('rules.rule-group.create.fromStore', true); return redirect(route('rules.rule-group.create'))->withInput(); } // redirect to previous URL. return redirect(session('rules.rule-group.create.url')); } /** * @param RuleGroupRepositoryInterface $repository * @param RuleGroup $ruleGroup * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function up(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) { $repository->moveUp($ruleGroup); return redirect(route('rules.index')); } /** * @param RuleGroupFormRequest $request * @param RuleGroupRepositoryInterface $repository * @param RuleGroup $ruleGroup * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) { $data = [ 'title' => $request->input('title'), 'description' => $request->input('description'), 'active' => intval($request->input('active')) == 1, ]; $repository->update($ruleGroup, $data); Session::flash('success', trans('firefly.updated_rule_group', ['title' => $ruleGroup->title])); Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: Session::put('rules.rule-group.edit.fromUpdate', true); return redirect(route('rules.rule-group.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]); } // redirect to previous URL. return redirect(session('rules.rule-group.edit.url')); } }