1 | <?php |
||||
2 | /** |
||||
3 | * This file is part of FacturaScripts |
||||
4 | * Copyright (C) 2021-2023 Carlos Garcia Gomez <[email protected]> |
||||
5 | * |
||||
6 | * This program is free software: you can redistribute it and/or modify |
||||
7 | * it under the terms of the GNU Lesser General Public License as |
||||
8 | * published by the Free Software Foundation, either version 3 of the |
||||
9 | * License, or (at your option) any later version. |
||||
10 | * |
||||
11 | * This program is distributed in the hope that it will be useful, |
||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
14 | * GNU Lesser General Public License for more details. |
||||
15 | * |
||||
16 | * You should have received a copy of the GNU Lesser General Public License |
||||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
18 | */ |
||||
19 | |||||
20 | namespace FacturaScripts\Core\Base\AjaxForms; |
||||
21 | |||||
22 | use FacturaScripts\Core\Base\Contract\SalesModInterface; |
||||
23 | use FacturaScripts\Core\Base\Translator; |
||||
24 | use FacturaScripts\Core\Model\Base\SalesDocument; |
||||
25 | use FacturaScripts\Core\Model\User; |
||||
26 | use FacturaScripts\Core\Tools; |
||||
27 | |||||
28 | /** |
||||
29 | * Description of SalesFooterHTML |
||||
30 | * |
||||
31 | * @author Carlos Garcia Gomez <[email protected]> |
||||
32 | * @author Daniel Fernández Giménez <[email protected]> |
||||
33 | */ |
||||
34 | class SalesFooterHTML |
||||
35 | { |
||||
36 | use CommonSalesPurchases; |
||||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
37 | |||||
38 | /** @var SalesModInterface[] */ |
||||
39 | private static $mods = []; |
||||
40 | |||||
41 | public static function addMod(SalesModInterface $mod) |
||||
42 | { |
||||
43 | self::$mods[] = $mod; |
||||
44 | } |
||||
45 | |||||
46 | public static function apply(SalesDocument &$model, array $formData, User $user) |
||||
47 | { |
||||
48 | // mods |
||||
49 | foreach (self::$mods as $mod) { |
||||
50 | $mod->applyBefore($model, $formData, $user); |
||||
51 | } |
||||
52 | |||||
53 | self::$columnView = $formData['columnView'] ?? Tools::settings('default', 'columnetosubtotal', 'subtotal'); |
||||
54 | |||||
55 | $model->dtopor1 = isset($formData['dtopor1']) ? (float)$formData['dtopor1'] : $model->dtopor1; |
||||
56 | $model->dtopor2 = isset($formData['dtopor2']) ? (float)$formData['dtopor2'] : $model->dtopor2; |
||||
57 | $model->observaciones = $formData['observaciones'] ?? $model->observaciones; |
||||
58 | |||||
59 | // mods |
||||
60 | foreach (self::$mods as $mod) { |
||||
61 | $mod->apply($model, $formData, $user); |
||||
62 | } |
||||
63 | } |
||||
64 | |||||
65 | public static function assets() |
||||
66 | { |
||||
67 | // mods |
||||
68 | foreach (self::$mods as $mod) { |
||||
69 | $mod->assets(); |
||||
70 | } |
||||
71 | } |
||||
72 | |||||
73 | public static function render(SalesDocument $model): string |
||||
74 | { |
||||
75 | if (empty(self::$columnView)) { |
||||
76 | self::$columnView = Tools::settings('default', 'columnetosubtotal', 'subtotal'); |
||||
77 | } |
||||
78 | |||||
79 | if (empty($model->codcliente)) { |
||||
80 | return ''; |
||||
81 | } |
||||
82 | |||||
83 | $i18n = new Translator(); |
||||
0 ignored issues
–
show
The class
FacturaScripts\Core\Base\Translator has been deprecated: since FacturaScripts 2023.06
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
84 | return '<div class="container-fluid mt-3">' |
||||
85 | . '<div class="form-row">' |
||||
86 | . self::renderField($i18n, $model, '_productBtn') |
||||
87 | . self::renderField($i18n, $model, '_newLineBtn') |
||||
88 | . self::renderField($i18n, $model, '_sortableBtn') |
||||
89 | . self::renderField($i18n, $model, '_fastLineInput') |
||||
90 | . self::renderField($i18n, $model, '_subtotalNetoBtn') |
||||
91 | . '</div>' |
||||
92 | . '<div class="form-row">' |
||||
93 | . self::renderField($i18n, $model, 'observaciones') |
||||
94 | . self::renderNewFields($i18n, $model) |
||||
95 | . self::renderField($i18n, $model, 'netosindto') |
||||
96 | . self::renderField($i18n, $model, 'dtopor1') |
||||
97 | . self::renderField($i18n, $model, 'dtopor2') |
||||
98 | . self::renderField($i18n, $model, 'neto') |
||||
99 | . self::renderField($i18n, $model, 'totaliva') |
||||
100 | . self::renderField($i18n, $model, 'totalrecargo') |
||||
101 | . self::renderField($i18n, $model, 'totalirpf') |
||||
102 | . self::renderField($i18n, $model, 'totalsuplidos') |
||||
103 | . self::renderField($i18n, $model, 'totalcoste') |
||||
104 | . self::renderField($i18n, $model, 'totalbeneficio') |
||||
105 | . self::renderField($i18n, $model, 'total') |
||||
106 | . '</div>' |
||||
107 | . '<div class="form-row">' |
||||
108 | . '<div class="col-auto">' |
||||
109 | . self::renderField($i18n, $model, '_deleteBtn') |
||||
110 | . '</div>' |
||||
111 | . '<div class="col text-right">' |
||||
112 | . self::renderNewBtnFields($i18n, $model) |
||||
113 | . self::renderField($i18n, $model, '_modalFooter') |
||||
114 | . self::renderField($i18n, $model, '_undoBtn') |
||||
115 | . self::renderField($i18n, $model, '_saveBtn') |
||||
116 | . '</div>' |
||||
117 | . '</div>' |
||||
118 | . '</div>'; |
||||
119 | } |
||||
120 | |||||
121 | private static function modalFooter(Translator $i18n, SalesDocument $model): string |
||||
122 | { |
||||
123 | $htmlModal = self::renderNewModalFields($i18n, $model); |
||||
124 | |||||
125 | if (empty($htmlModal)) { |
||||
126 | return ''; |
||||
127 | } |
||||
128 | |||||
129 | return '<button class="btn btn-outline-secondary mr-2" type="button" data-toggle="modal" data-target="#footerModal">' |
||||
130 | . '<i class="fas fa-plus fa-fw" aria-hidden="true"></i></button>' |
||||
131 | . self::modalFooterHtml($i18n, $htmlModal); |
||||
132 | } |
||||
133 | |||||
134 | private static function modalFooterHtml(Translator $i18n, string $htmlModal): string |
||||
135 | { |
||||
136 | return '<div class="modal fade" id="footerModal" tabindex="-1" aria-labelledby="footerModalLabel" aria-hidden="true">' |
||||
137 | . '<div class="modal-dialog modal-dialog-centered modal-lg">' |
||||
138 | . '<div class="modal-content">' |
||||
139 | . '<div class="modal-header">' |
||||
140 | . '<h5 class="modal-title">' . $i18n->trans('detail') . ' ' . $i18n->trans('footer') . '</h5>' |
||||
141 | . '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' |
||||
142 | . '<span aria-hidden="true">×</span>' |
||||
143 | . '</button>' |
||||
144 | . '</div>' |
||||
145 | . '<div class="modal-body">' |
||||
146 | . '<div class="form-row">' |
||||
147 | . $htmlModal |
||||
148 | . '</div>' |
||||
149 | . '</div>' |
||||
150 | . '<div class="modal-footer">' |
||||
151 | . '<button type="button" class="btn btn-secondary" data-dismiss="modal">' . $i18n->trans('close') . '</button>' |
||||
152 | . '<button type="button" class="btn btn-primary" data-dismiss="modal">' . $i18n->trans('accept') . '</button>' |
||||
153 | . '</div>' |
||||
154 | . '</div>' |
||||
155 | . '</div>' |
||||
156 | . '</div>'; |
||||
157 | } |
||||
158 | |||||
159 | private static function renderField(Translator $i18n, SalesDocument $model, string $field): ?string |
||||
160 | { |
||||
161 | foreach (self::$mods as $mod) { |
||||
162 | $html = $mod->renderField($i18n, $model, $field); |
||||
163 | if ($html !== null) { |
||||
164 | return $html; |
||||
165 | } |
||||
166 | } |
||||
167 | |||||
168 | switch ($field) { |
||||
169 | case '_deleteBtn': |
||||
170 | return self::deleteBtn($i18n, $model, 'salesFormSave'); |
||||
171 | |||||
172 | case '_fastLineInput': |
||||
173 | return self::fastLineInput($i18n, $model, 'salesFastLine'); |
||||
174 | |||||
175 | case '_modalFooter': |
||||
176 | return self::modalFooter($i18n, $model); |
||||
177 | |||||
178 | case '_newLineBtn': |
||||
179 | return self::newLineBtn($i18n, $model, 'salesFormAction'); |
||||
180 | |||||
181 | case '_productBtn': |
||||
182 | return self::productBtn($i18n, $model); |
||||
183 | |||||
184 | case '_saveBtn': |
||||
185 | return self::saveBtn($i18n, $model, 'salesFormSave'); |
||||
186 | |||||
187 | case '_sortableBtn': |
||||
188 | return self::sortableBtn($i18n, $model); |
||||
189 | |||||
190 | case '_subtotalNetoBtn': |
||||
191 | return self::subtotalNetoBtn($i18n); |
||||
192 | |||||
193 | case '_undoBtn': |
||||
194 | return self::undoBtn($i18n, $model); |
||||
195 | |||||
196 | case 'dtopor1': |
||||
197 | return self::dtopor1($i18n, $model, 'salesFormActionWait'); |
||||
198 | |||||
199 | case 'dtopor2': |
||||
200 | return self::dtopor2($i18n, $model, 'salesFormActionWait'); |
||||
201 | |||||
202 | case 'neto': |
||||
203 | return self::column($i18n, $model, 'neto', 'net', true); |
||||
204 | |||||
205 | case 'netosindto': |
||||
206 | return self::netosindto($i18n, $model); |
||||
207 | |||||
208 | case 'observaciones': |
||||
209 | return self::observaciones($i18n, $model); |
||||
210 | |||||
211 | case 'total': |
||||
212 | return self::column($i18n, $model, 'total', 'total', true); |
||||
213 | |||||
214 | case 'totalbeneficio': |
||||
215 | return self::column($i18n, $model, 'totalbeneficio', 'profits', true, Tools::settings('default', 'levelbenefitsales', 0)); |
||||
216 | |||||
217 | case 'totalcoste': |
||||
218 | return self::column($i18n, $model, 'totalcoste', 'total-cost', true, Tools::settings('default', 'levelcostsales', 0)); |
||||
219 | |||||
220 | case 'totalirpf': |
||||
221 | return self::column($i18n, $model, 'totalirpf', 'irpf', true); |
||||
222 | |||||
223 | case 'totaliva': |
||||
224 | return self::column($i18n, $model, 'totaliva', 'taxes', true); |
||||
225 | |||||
226 | case 'totalrecargo': |
||||
227 | return self::column($i18n, $model, 'totalrecargo', 're', true); |
||||
228 | |||||
229 | case 'totalsuplidos': |
||||
230 | return self::column($i18n, $model, 'totalsuplidos', 'supplied-amount', true); |
||||
231 | } |
||||
232 | |||||
233 | return null; |
||||
234 | } |
||||
235 | |||||
236 | private static function renderNewBtnFields(Translator $i18n, SalesDocument $model): string |
||||
237 | { |
||||
238 | // cargamos los nuevos campos |
||||
239 | $newFields = []; |
||||
240 | foreach (self::$mods as $mod) { |
||||
241 | foreach ($mod->newBtnFields() as $field) { |
||||
242 | if (false === in_array($field, $newFields)) { |
||||
243 | $newFields[] = $field; |
||||
244 | } |
||||
245 | } |
||||
246 | } |
||||
247 | |||||
248 | // renderizamos los campos |
||||
249 | $html = ''; |
||||
250 | foreach ($newFields as $field) { |
||||
251 | foreach (self::$mods as $mod) { |
||||
252 | $fieldHtml = $mod->renderField($i18n, $model, $field); |
||||
253 | if ($fieldHtml !== null) { |
||||
254 | $html .= $fieldHtml; |
||||
255 | break; |
||||
256 | } |
||||
257 | } |
||||
258 | } |
||||
259 | return $html; |
||||
260 | } |
||||
261 | |||||
262 | private static function renderNewFields(Translator $i18n, SalesDocument $model): string |
||||
263 | { |
||||
264 | // cargamos los nuevos campos |
||||
265 | $newFields = []; |
||||
266 | foreach (self::$mods as $mod) { |
||||
267 | foreach ($mod->newFields() as $field) { |
||||
268 | if (false === in_array($field, $newFields)) { |
||||
269 | $newFields[] = $field; |
||||
270 | } |
||||
271 | } |
||||
272 | } |
||||
273 | |||||
274 | // renderizamos los campos |
||||
275 | $html = ''; |
||||
276 | foreach ($newFields as $field) { |
||||
277 | foreach (self::$mods as $mod) { |
||||
278 | $fieldHtml = $mod->renderField($i18n, $model, $field); |
||||
279 | if ($fieldHtml !== null) { |
||||
280 | $html .= $fieldHtml; |
||||
281 | break; |
||||
282 | } |
||||
283 | } |
||||
284 | } |
||||
285 | return $html; |
||||
286 | } |
||||
287 | |||||
288 | private static function renderNewModalFields(Translator $i18n, SalesDocument $model): string |
||||
289 | { |
||||
290 | // cargamos los nuevos campos |
||||
291 | $newFields = []; |
||||
292 | foreach (self::$mods as $mod) { |
||||
293 | foreach ($mod->newModalFields() as $field) { |
||||
294 | if (false === in_array($field, $newFields)) { |
||||
295 | $newFields[] = $field; |
||||
296 | } |
||||
297 | } |
||||
298 | } |
||||
299 | |||||
300 | // renderizamos los campos |
||||
301 | $html = ''; |
||||
302 | foreach ($newFields as $field) { |
||||
303 | foreach (self::$mods as $mod) { |
||||
304 | $fieldHtml = $mod->renderField($i18n, $model, $field); |
||||
305 | if ($fieldHtml !== null) { |
||||
306 | $html .= $fieldHtml; |
||||
307 | break; |
||||
308 | } |
||||
309 | } |
||||
310 | } |
||||
311 | |||||
312 | return $html; |
||||
313 | } |
||||
314 | } |
||||
315 |