1 | <?php |
||
2 | /** |
||
3 | * CreateController.php |
||
4 | * Copyright (c) 2018 [email protected] |
||
5 | * |
||
6 | * This file is part of Firefly III. |
||
7 | * |
||
8 | * Firefly III is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation, either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * Firefly III is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | declare(strict_types=1); |
||
23 | |||
24 | namespace FireflyIII\Http\Controllers\Recurring; |
||
25 | |||
26 | |||
27 | use Carbon\Carbon; |
||
28 | use FireflyIII\Exceptions\FireflyException; |
||
29 | use FireflyIII\Http\Controllers\Controller; |
||
30 | use FireflyIII\Http\Requests\RecurrenceFormRequest; |
||
31 | use FireflyIII\Models\RecurrenceRepetition; |
||
32 | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; |
||
33 | use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; |
||
34 | use Illuminate\Http\Request; |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * Class CreateController |
||
39 | */ |
||
40 | class CreateController extends Controller |
||
41 | { |
||
42 | /** @var BudgetRepositoryInterface The budget repository */ |
||
43 | private $budgets; |
||
44 | /** @var RecurringRepositoryInterface Recurring repository */ |
||
45 | private $recurring; |
||
46 | |||
47 | /** |
||
48 | * CreateController constructor. |
||
49 | * @codeCoverageIgnore |
||
50 | */ |
||
51 | public function __construct() |
||
52 | { |
||
53 | parent::__construct(); |
||
54 | |||
55 | // translations: |
||
56 | $this->middleware( |
||
57 | function ($request, $next) { |
||
58 | app('view')->share('mainTitleIcon', 'fa-paint-brush'); |
||
59 | app('view')->share('title', (string)trans('firefly.recurrences')); |
||
60 | app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence')); |
||
61 | |||
62 | $this->recurring = app(RecurringRepositoryInterface::class); |
||
63 | $this->budgets = app(BudgetRepositoryInterface::class); |
||
64 | |||
65 | return $next($request); |
||
66 | } |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Create a new recurring transaction. |
||
72 | * |
||
73 | * @param Request $request |
||
74 | * |
||
75 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
76 | */ |
||
77 | public function create(Request $request) |
||
78 | { |
||
79 | $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets()); |
||
0 ignored issues
–
show
|
|||
80 | $defaultCurrency = app('amount')->getDefaultCurrency(); |
||
81 | $tomorrow = new Carbon; |
||
82 | $oldRepetitionType = $request->old('repetition_type'); |
||
83 | $tomorrow->addDay(); |
||
84 | |||
85 | // put previous url in session if not redirect from store (not "create another"). |
||
86 | if (true !== session('recurring.create.fromStore')) { |
||
87 | $this->rememberPreviousUri('recurring.create.uri'); |
||
88 | } |
||
89 | $request->session()->forget('recurring.create.fromStore'); |
||
90 | $repetitionEnds = [ |
||
91 | 'forever' => (string)trans('firefly.repeat_forever'), |
||
92 | 'until_date' => (string)trans('firefly.repeat_until_date'), |
||
93 | 'times' => (string)trans('firefly.repeat_times'), |
||
94 | ]; |
||
95 | $weekendResponses = [ |
||
96 | RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), |
||
97 | RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), |
||
98 | RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), |
||
99 | RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), |
||
100 | ]; |
||
101 | |||
102 | |||
103 | $hasOldInput = null !== $request->old('_token'); // flash some data |
||
104 | $preFilled = [ |
||
105 | 'first_date' => $tomorrow->format('Y-m-d'), |
||
106 | 'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal', |
||
107 | 'active' => $hasOldInput ? (bool)$request->old('active') : true, |
||
108 | 'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : true, |
||
109 | ]; |
||
110 | $request->session()->flash('preFilled', $preFilled); |
||
111 | |||
112 | return view( |
||
113 | 'recurring.create', compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets') |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | |||
118 | /** |
||
119 | * Store a recurring transaction. |
||
120 | * |
||
121 | * @param RecurrenceFormRequest $request |
||
122 | * |
||
123 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||
124 | */ |
||
125 | public function store(RecurrenceFormRequest $request) |
||
126 | { |
||
127 | $data = $request->getAll(); |
||
128 | try { |
||
129 | $recurrence = $this->recurring->store($data); |
||
130 | } catch (FireflyException $e) { |
||
131 | session()->flash('error', $e->getMessage()); |
||
132 | return redirect(route('recurring.create'))->withInput(); |
||
133 | } |
||
134 | |||
135 | $request->session()->flash('success', (string)trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); |
||
136 | app('preferences')->mark(); |
||
137 | $redirect = redirect($this->getPreviousUri('recurring.create.uri')); |
||
138 | if (1 === (int)$request->get('create_another')) { |
||
139 | // set value so create routine will not overwrite URL: |
||
140 | $request->session()->put('recurring.create.fromStore', true); |
||
141 | |||
142 | $redirect = redirect(route('recurring.create'))->withInput(); |
||
143 | } |
||
144 | |||
145 | // redirect to previous URL. |
||
146 | return $redirect; |
||
147 | |||
148 | } |
||
149 | |||
150 | } |
||
151 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.