|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2023 Joe Nilson <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Lesser General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Mod; |
|
19
|
|
|
|
|
20
|
|
|
use FacturaScripts\Core\Contract\SalesLineModInterface; |
|
|
|
|
|
|
21
|
|
|
use FacturaScripts\Core\Translator; |
|
|
|
|
|
|
22
|
|
|
use FacturaScripts\Core\Tools; |
|
23
|
|
|
use FacturaScripts\Core\Model\Base\SalesDocument; |
|
|
|
|
|
|
24
|
|
|
use FacturaScripts\Core\Model\Base\SalesDocumentLine; |
|
|
|
|
|
|
25
|
|
|
use FacturaScripts\Core\Base\DataBase\DataBaseWhere; |
|
26
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoAdicional; |
|
27
|
|
|
|
|
28
|
|
|
class SalesLineHTMLMod implements SalesLineModInterface |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
public function apply(SalesDocument &$model, array &$lines, array $formData): void |
|
32
|
|
|
{ |
|
33
|
|
|
// TODO: Implement apply() method. |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $formData |
|
38
|
|
|
* @param SalesDocumentLine $line |
|
39
|
|
|
* @param string $id |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function applyToLine(array $formData, SalesDocumentLine &$line, string $id): void |
|
43
|
|
|
{ |
|
44
|
|
|
$line->rdtaxcodisc = $formData['rdtaxcodisc_' . $id] ?? $line->rdtaxcodisc; |
|
45
|
|
|
$line->rdtaxcodcdt = $formData['rdtaxcodcdt_' . $id] ?? $line->rdtaxcodcdt; |
|
46
|
|
|
$line->rdtaxcodlegaltip = $formData['rdtaxcodlegaltip_' . $id] ?? $line->rdtaxcodlegaltip; |
|
47
|
|
|
$line->rdtaxcodfirstplate = $formData['rdtaxcodfirstplate_' . $id] ?? $line->rdtaxcodfirstplate; |
|
48
|
|
|
$line->totalplustaxes = $formData['totalplustaxes_' . $id] ?? $line->totalplustaxes; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function assets(): void |
|
52
|
|
|
{ |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param Translator $i18n |
|
57
|
|
|
* @param string $attributes |
|
58
|
|
|
* @param string $label |
|
59
|
|
|
* @param int $idlinea |
|
60
|
|
|
* @param array $options |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
private function getStr(Translator $i18n, string $attributes, string $label, $idlinea, array $options): string |
|
64
|
|
|
{ |
|
65
|
|
|
$idlinea = (!$idlinea) ? 0 : $idlinea; |
|
66
|
|
|
return '<div class="col-6">' |
|
67
|
|
|
. '<div class="mb-2">' |
|
68
|
|
|
. $i18n->trans($label) |
|
69
|
|
|
. '<select onchange="return salesFormAction(\'recalculate-line\', \'' . $idlinea . '\');"' |
|
70
|
|
|
. $attributes . ' class="form-select" >' . implode('', $options) . '</select>' |
|
71
|
|
|
. '</div>' |
|
72
|
|
|
. '</div>'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function getLineAddedTaxes(SalesDocumentLine $line): float |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
$rdtaxisc = isset($line->rdtaxisc) ? (float)$line->rdtaxisc : 0.0; |
|
78
|
|
|
$rdtaxcdt = isset($line->rdtaxcdt) ? (float)$line->rdtaxcdt : 0.0; |
|
79
|
|
|
$rdtaxlegaltip = isset($line->rdtaxlegaltip) ? (float)$line->rdtaxlegaltip : 0.0; |
|
80
|
|
|
$rdtaxfirstplate = isset($line->rdtaxfirstplate) ? (float)$line->rdtaxfirstplate : 0.0; |
|
81
|
|
|
$pvpsindto = isset($line->pvpsindto) ? (float)$line->pvpsindto : 0.0; |
|
82
|
|
|
|
|
83
|
|
|
return $pvpsindto * ($rdtaxisc + $rdtaxcdt + $rdtaxlegaltip + $rdtaxfirstplate) / 100.0; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function map(array $lines, SalesDocument $model): array |
|
87
|
|
|
{ |
|
88
|
|
|
$map = []; |
|
89
|
|
|
$num = 0; |
|
90
|
|
|
foreach ($lines as $line) { |
|
91
|
|
|
$num++; |
|
92
|
|
|
$idlinea = $line->idlinea ?? 'n' . $num; |
|
93
|
|
|
$map['rdtaxcodisc_' . $idlinea] = $line->rdtaxcodisc; |
|
94
|
|
|
$map['rdtaxcodcdt_' . $idlinea] = $line->rdtaxcodcdt; |
|
95
|
|
|
$map['rdtaxcodlegaltip_' . $idlinea] = $line->rdtaxcodlegaltip; |
|
96
|
|
|
$map['rdtaxcodfirstplate_' . $idlinea] = $line->rdtaxcodfirstplate; |
|
97
|
|
|
// El total de la línea es el totalplustaxes (pvptotal + IVA) |
|
98
|
|
|
$map['totalplustaxes_' . $idlinea] = $line->totalplustaxes; |
|
99
|
|
|
} |
|
100
|
|
|
return $map; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function newModalFields(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return ['rdtaxcodisc','rdtaxcodcdt','rdtaxcodlegaltip','rdtaxcodfirstplate']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function newFields(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return ['totalplustaxes']; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function newTitles(): array |
|
114
|
|
|
{ |
|
115
|
|
|
return ['totalplustaxes']; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function renderField(string $idlinea, SalesDocumentLine $line, SalesDocument $model, string $field): ?string |
|
119
|
|
|
{ |
|
120
|
|
|
switch ($field) { |
|
121
|
|
|
case "rdtaxcodisc": |
|
122
|
|
|
return $this->loadCodeISC($idlinea, $line, $model->editable); |
|
123
|
|
|
case "rdtaxcodcdt": |
|
124
|
|
|
return $this->loadCodeCDT($idlinea, $line, $model->editable); |
|
125
|
|
|
case "rdtaxcodlegaltip": |
|
126
|
|
|
return $this->loadCodeLegalTip($idlinea, $line, $model->editable); |
|
127
|
|
|
case "rdtaxcodfirstplate": |
|
128
|
|
|
return $this->loadCodeFirstPlate($idlinea, $line, $model->editable); |
|
129
|
|
|
case "totalplustaxes": |
|
130
|
|
|
return $this->renderTotalField($idlinea, $line, $model, $model->editable); |
|
|
|
|
|
|
131
|
|
|
default: |
|
132
|
|
|
return null; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
private function renderTotalField(string $idlinea, SalesDocumentLine $line, SalesDocument $model): string |
|
137
|
|
|
{ |
|
138
|
|
|
$nf0 = Tools::settings('default', 'decimals', 2); |
|
139
|
|
|
|
|
140
|
|
|
return '<div class="col col-lg-1 order-8 columnTotalPlusTaxes" lang="es-DO">' |
|
141
|
|
|
. '<div class="d-lg-none mt-2 small">' . Tools::trans('desc-total-plustaxes') . '</div>' |
|
142
|
|
|
. '<input type="number" name="totalplustaxes_' . $idlinea . '" value="' . number_format($line->totalplustaxes, $nf0,'.', '') |
|
143
|
|
|
. '" class="form-control form-control-sm text-lg-end border-0" readonly/>' |
|
144
|
|
|
. '</div>'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function renderTitle(SalesDocument $model, string $field): ?string |
|
148
|
|
|
{ |
|
149
|
|
|
switch ($field) { |
|
150
|
|
|
case "totalplustaxes": |
|
151
|
|
|
return '<div class="col-lg-1 text-end order-8 columTotalPlusTaxes">' .Tools::trans('desc-total-plustaxes') . '</div>'; |
|
152
|
|
|
default: |
|
153
|
|
|
return null; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function getFastLine(SalesDocument $model, array $formData): ?SalesDocumentLine |
|
158
|
|
|
{ |
|
159
|
|
|
return null; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function loadCodeISC(string $idlinea, SalesDocumentLine $line, $editable): string |
|
163
|
|
|
{ |
|
164
|
|
|
$i18n = new Translator(); |
|
165
|
|
|
$impuestosAdicionales = new ImpuestoAdicional(); |
|
166
|
|
|
$where = [new DataBaseWhere('tipo_impuesto_short', 'ISC')]; |
|
167
|
|
|
$iscList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
|
168
|
|
|
if (!$iscList) { |
|
169
|
|
|
return ''; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$invoiceLineISC = ($line->rdtaxcodisc) ? $line->rdtaxcodisc : ""; |
|
173
|
|
|
$options = ['<option value="">----------'.$invoiceLineISC.'</option>']; |
|
174
|
|
|
foreach ($iscList as $row) { |
|
175
|
|
|
$options[] = ($row->codigo === $invoiceLineISC) ? |
|
176
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
|
177
|
|
|
'<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$attributes = ($editable) ? 'name="rdtaxcodisc_' . $idlinea . '"' : 'name="rdtaxcodisc_' . $idlinea . '" disabled=""'; |
|
181
|
|
|
return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodisc", $idlinea, $options); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
public function loadCodeCDT(string $idlinea, SalesDocumentLine $line, $editable): string |
|
184
|
|
|
{ |
|
185
|
|
|
$i18n = new Translator(); |
|
186
|
|
|
$impuestosAdicionales = new ImpuestoAdicional(); |
|
187
|
|
|
$where = [new DataBaseWhere('tipo_impuesto_short', 'CDT')]; |
|
188
|
|
|
$cdtList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
|
189
|
|
|
if (!$cdtList) { |
|
190
|
|
|
return ''; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$invoiceLineCDT = ($line->rdtaxcodcdt) ? $line->rdtaxcodcdt : ""; |
|
194
|
|
|
|
|
195
|
|
|
$options = ['<option value="">----------</option>']; |
|
196
|
|
|
foreach ($cdtList as $row) { |
|
197
|
|
|
$options[] = ($row->codigo === $invoiceLineCDT) ? |
|
198
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
|
199
|
|
|
'<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
$attributes = ($editable) ? 'name="rdtaxcodcdt_' . $idlinea . '"' : 'disabled=""'; |
|
203
|
|
|
return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodcdt", $idlinea, $options); |
|
|
|
|
|
|
204
|
|
|
} |
|
205
|
|
|
public function loadCodeLegalTip(string $idlinea, SalesDocumentLine $line, $editable): string |
|
206
|
|
|
{ |
|
207
|
|
|
$i18n = new Translator(); |
|
208
|
|
|
$impuestosAdicionales = new ImpuestoAdicional(); |
|
209
|
|
|
$where = [new DataBaseWhere('tipo_impuesto_short', 'Propina Legal')]; |
|
210
|
|
|
$legalTipList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
|
211
|
|
|
if (!$legalTipList) { |
|
212
|
|
|
return ''; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$invoiceLineLegalTip = ($line->rdtaxcodlegaltip) ? $line->rdtaxcodlegaltip : ""; |
|
216
|
|
|
|
|
217
|
|
|
$options = ['<option value="">----------</option>']; |
|
218
|
|
|
foreach ($legalTipList as $row) { |
|
219
|
|
|
$options[] = ($row->codigo === $invoiceLineLegalTip) ? |
|
220
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
|
221
|
|
|
'<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
$attributes = ($editable) ? 'name="rdtaxcodlegaltip_' . $idlinea . '"' : 'disabled=""'; |
|
225
|
|
|
return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodlegaltip", $idlinea, $options); |
|
|
|
|
|
|
226
|
|
|
} |
|
227
|
|
|
public function loadCodeFirstPlate(string $idlinea, SalesDocumentLine $line, $editable): string |
|
228
|
|
|
{ |
|
229
|
|
|
$i18n = new Translator(); |
|
230
|
|
|
$impuestosAdicionales = new ImpuestoAdicional(); |
|
231
|
|
|
$where = [new DataBaseWhere('tipo_impuesto_short', 'Primera Placa')]; |
|
232
|
|
|
$firstPlateList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
|
233
|
|
|
if (!$firstPlateList) { |
|
234
|
|
|
return ''; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
$invoiceLineFirstPlate = ($line->rdtaxcodfirstplate) ? $line->rdtaxcodfirstplate : ""; |
|
238
|
|
|
|
|
239
|
|
|
$options = ['<option value="">----------</option>']; |
|
240
|
|
|
foreach ($firstPlateList as $row) { |
|
241
|
|
|
$options[] = ($row->codigo === $invoiceLineFirstPlate) ? |
|
242
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
|
243
|
|
|
'<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
$attributes = ($editable) ? 'name="rdtaxcodfirstplate_' . $idlinea . '"' : 'disabled=""'; |
|
247
|
|
|
return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodfirstplate", $idlinea, $options); |
|
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths