1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EditController.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 FireflyIII\Http\Controllers\Controller; |
28
|
|
|
use FireflyIII\Http\Requests\RecurrenceFormRequest; |
29
|
|
|
use FireflyIII\Models\Recurrence; |
30
|
|
|
use FireflyIII\Models\RecurrenceRepetition; |
31
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; |
32
|
|
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; |
33
|
|
|
use FireflyIII\Transformers\RecurrenceTransformer; |
34
|
|
|
use Illuminate\Http\Request; |
35
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
* Class EditController |
40
|
|
|
*/ |
41
|
|
|
class EditController extends Controller |
42
|
|
|
{ |
43
|
|
|
/** @var BudgetRepositoryInterface The budget repository */ |
44
|
|
|
private $budgets; |
45
|
|
|
/** @var RecurringRepositoryInterface Recurring repository */ |
46
|
|
|
private $recurring; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* EditController constructor. |
50
|
|
|
* @codeCoverageIgnore |
51
|
|
|
*/ |
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
parent::__construct(); |
55
|
|
|
|
56
|
|
|
// translations: |
57
|
|
|
$this->middleware( |
58
|
|
|
function ($request, $next) { |
59
|
|
|
app('view')->share('mainTitleIcon', 'fa-paint-brush'); |
60
|
|
|
app('view')->share('title', (string)trans('firefly.recurrences')); |
61
|
|
|
app('view')->share('subTitle', (string)trans('firefly.recurrences')); |
62
|
|
|
|
63
|
|
|
$this->recurring = app(RecurringRepositoryInterface::class); |
64
|
|
|
$this->budgets = app(BudgetRepositoryInterface::class); |
65
|
|
|
|
66
|
|
|
return $next($request); |
67
|
|
|
} |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Edit a recurring transaction. |
73
|
|
|
* |
74
|
|
|
* @param Request $request |
75
|
|
|
* @param Recurrence $recurrence |
76
|
|
|
* |
77
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
78
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException |
79
|
|
|
* |
80
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
81
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
82
|
|
|
*/ |
83
|
|
|
public function edit(Request $request, Recurrence $recurrence) |
84
|
|
|
{ |
85
|
|
|
/** @var RecurrenceTransformer $transformer */ |
86
|
|
|
$transformer = app(RecurrenceTransformer::class); |
87
|
|
|
$transformer->setParameters(new ParameterBag); |
88
|
|
|
|
89
|
|
|
$array = $transformer->transform($recurrence); |
90
|
|
|
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets()); |
|
|
|
|
91
|
|
|
|
92
|
|
|
/** @var RecurrenceRepetition $repetition */ |
93
|
|
|
$repetition = $recurrence->recurrenceRepetitions()->first(); |
94
|
|
|
$currentRepType = $repetition->repetition_type; |
95
|
|
|
if ('' !== $repetition->repetition_moment) { |
96
|
|
|
$currentRepType .= ',' . $repetition->repetition_moment; // @codeCoverageIgnore |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// put previous url in session if not redirect from store (not "return_to_edit"). |
100
|
|
|
if (true !== session('recurrences.edit.fromUpdate')) { |
101
|
|
|
$this->rememberPreviousUri('recurrences.edit.uri'); |
102
|
|
|
} |
103
|
|
|
$request->session()->forget('recurrences.edit.fromUpdate'); |
104
|
|
|
|
105
|
|
|
$repetitionEnd = 'forever'; |
106
|
|
|
$repetitionEnds = [ |
107
|
|
|
'forever' => (string)trans('firefly.repeat_forever'), |
108
|
|
|
'until_date' => (string)trans('firefly.repeat_until_date'), |
109
|
|
|
'times' => (string)trans('firefly.repeat_times'), |
110
|
|
|
]; |
111
|
|
|
if (null !== $recurrence->repeat_until) { |
112
|
|
|
$repetitionEnd = 'until_date'; // @codeCoverageIgnore |
113
|
|
|
} |
114
|
|
|
if ($recurrence->repetitions > 0) { |
115
|
|
|
$repetitionEnd = 'times'; // @codeCoverageIgnore |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$weekendResponses = [ |
119
|
|
|
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), |
120
|
|
|
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), |
121
|
|
|
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), |
122
|
|
|
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), |
123
|
|
|
]; |
124
|
|
|
|
125
|
|
|
$hasOldInput = null !== $request->old('_token'); |
126
|
|
|
$preFilled = [ |
127
|
|
|
'transaction_type' => strtolower($recurrence->transactionType->type), |
128
|
|
|
'active' => $hasOldInput ? (bool)$request->old('active') : $recurrence->active, |
129
|
|
|
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules, |
130
|
|
|
'deposit_source_id' => $array['transactions'][0]['source_id'], |
131
|
|
|
'withdrawal_destination_id' => $array['transactions'][0]['destination_id'], |
132
|
|
|
|
133
|
|
|
]; |
134
|
|
|
|
135
|
|
|
return view( |
136
|
|
|
'recurring.edit', |
137
|
|
|
compact('recurrence', 'array', 'weekendResponses', 'budgets', 'preFilled', 'currentRepType', 'repetitionEnd', 'repetitionEnds') |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Update the recurring transaction. |
143
|
|
|
* |
144
|
|
|
* @param RecurrenceFormRequest $request |
145
|
|
|
* @param Recurrence $recurrence |
146
|
|
|
* |
147
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
148
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException |
149
|
|
|
*/ |
150
|
|
|
public function update(RecurrenceFormRequest $request, Recurrence $recurrence) |
151
|
|
|
{ |
152
|
|
|
$data = $request->getAll(); |
153
|
|
|
$this->recurring->update($recurrence, $data); |
154
|
|
|
|
155
|
|
|
$request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title])); |
156
|
|
|
app('preferences')->mark(); |
157
|
|
|
$redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); |
158
|
|
|
if (1 === (int)$request->get('return_to_edit')) { |
159
|
|
|
// set value so edit routine will not overwrite URL: |
160
|
|
|
$request->session()->put('recurrences.edit.fromUpdate', true); |
161
|
|
|
|
162
|
|
|
$redirect = redirect(route('recurring.edit', [$recurrence->id]))->withInput(['return_to_edit' => 1]); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
// redirect to previous URL. |
166
|
|
|
return $redirect; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
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.