|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2022 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\Base\Contract\SalesModInterface; |
|
|
|
|
|
|
21
|
|
|
use FacturaScripts\Core\Base\Translator; |
|
|
|
|
|
|
22
|
|
|
use FacturaScripts\Core\Model\Base\SalesDocument; |
|
|
|
|
|
|
23
|
|
|
use FacturaScripts\Core\Model\User; |
|
|
|
|
|
|
24
|
|
|
use FacturaScripts\Dinamic\Model\Cliente; |
|
|
|
|
|
|
25
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipo; |
|
26
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoAnulacion; |
|
27
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento; |
|
28
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoPago; |
|
29
|
|
|
|
|
30
|
|
|
class SalesFooterMod implements SalesModInterface |
|
31
|
|
|
{ |
|
32
|
|
|
public function apply(SalesDocument &$model, array $formData, User $user) |
|
33
|
|
|
{ |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function applyBefore(SalesDocument &$model, array $formData, User $user) |
|
37
|
|
|
{ |
|
38
|
|
|
if ($model->modelClassName() === 'FacturaCliente') { |
|
39
|
|
|
$model->numeroncf = isset($formData['numeroncf']) ? (string)$formData['numeroncf'] : $model->numeroncf; |
|
40
|
|
|
$model->tipocomprobante = isset($formData['tipocomprobante']) ? (string)$formData['tipocomprobante'] : $model->tipocomprobante; |
|
41
|
|
|
$model->ncffechavencimiento = isset($formData['ncffechavencimiento']) ? (string)$formData['ncffechavencimiento'] : $model->ncffechavencimiento; |
|
42
|
|
|
$model->ncftipopago = isset($formData['ncftipopago']) ? (string)$formData['ncftipopago'] : $model->ncftipopago; |
|
43
|
|
|
$model->ncftipomovimiento = isset($formData['ncftipomovimiento']) ? (string)$formData['ncftipomovimiento'] : $model->ncftipomovimiento; |
|
44
|
|
|
$model->ncftipoanulacion = isset($formData['ncftipoanulacion']) ? (string)$formData['ncftipoanulacion'] : $model->ncftipoanulacion; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function assets(): void |
|
49
|
|
|
{ |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function newBtnFields(): array |
|
53
|
|
|
{ |
|
54
|
|
|
return []; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function newFields(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return []; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function newModalFields(): array |
|
63
|
|
|
{ |
|
64
|
|
|
return ['numeroncf', 'tipocomprobante', 'ncffechavencimiento', 'ncftipopago', 'ncftipomovimiento', 'ncftipoanulacion']; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function renderField(Translator $i18n, SalesDocument $model, string $field): ?string |
|
68
|
|
|
{ |
|
69
|
|
|
if ($model->modelClassName() === 'FacturaCliente') { |
|
70
|
|
|
switch ($field) { |
|
71
|
|
|
case "numeroncf": |
|
72
|
|
|
return $this->numeroNCF($i18n, $model); |
|
73
|
|
|
case "tipocomprobante": |
|
74
|
|
|
return $this->tipoComprobante($i18n, $model); |
|
75
|
|
|
case "ncffechavencimiento": |
|
76
|
|
|
return $this->ncfFechaVencimiento($i18n, $model); |
|
77
|
|
|
case "ncftipopago": |
|
78
|
|
|
return $this->ncfTipoPago($i18n, $model); |
|
79
|
|
|
case "ncftipomovimiento": |
|
80
|
|
|
return $this->ncfTipoMovimiento($i18n, $model); |
|
81
|
|
|
case "ncftipoanulacion": |
|
82
|
|
|
return $this->ncfTipoAnulacion($i18n, $model); |
|
83
|
|
|
default: |
|
84
|
|
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private static function infoCliente($codcliente) |
|
91
|
|
|
{ |
|
92
|
|
|
$cliente = new Cliente(); |
|
93
|
|
|
$actualCliente = $cliente->get($codcliente); |
|
94
|
|
|
if ('' !== $actualCliente) { |
|
95
|
|
|
return $actualCliente; |
|
96
|
|
|
} |
|
97
|
|
|
return null; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private static function tipoComprobante(Translator $i18n, SalesDocument $model): string |
|
101
|
|
|
{ |
|
102
|
|
|
$tipoComprobante = NCFTipo::allVentas(); |
|
103
|
|
|
if (count($tipoComprobante) === 0) { |
|
104
|
|
|
return ''; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$cliente = self::infoCliente($model->codcliente); |
|
108
|
|
|
$cliente->tipocomprobante = ($cliente->tipocomprobante === null) ? "02" : $cliente->tipocomprobante; |
|
109
|
|
|
|
|
110
|
|
|
$invoiceTipoComprobante = ($model->tipocomprobante !== null) ? $model->tipocomprobante : $cliente->tipocomprobante; |
|
111
|
|
|
if (!$model->editable) { |
|
112
|
|
|
$invoiceTipoComprobante = $model->tipocomprobante; |
|
113
|
|
|
} elseif ($model->editable === true && ($cliente->tipocomprobante !== $model->tipocomprobante) && $model->tipocomprobante !== null) { |
|
114
|
|
|
$invoiceTipoComprobante = $model->tipocomprobante; |
|
115
|
|
|
} elseif ($model->editable === true && ($cliente->tipocomprobante === $model->tipocomprobante) && $model->tipocomprobante !== null) { |
|
116
|
|
|
$invoiceTipoComprobante = $cliente->tipocomprobante; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$options = ['<option value="">------</option>']; |
|
120
|
|
|
foreach ($tipoComprobante as $row) { |
|
121
|
|
|
$options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
|
122
|
|
|
'<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
|
123
|
|
|
'<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$attributes = ($model->editable || $model->numeroncf === '') ? |
|
127
|
|
|
'id="tipocomprobante" name="tipocomprobante" required="" onChange="verificarCorrelativoNCF(this.value,\'Ventas\')"' : |
|
128
|
|
|
'disabled=""'; |
|
129
|
|
|
|
|
130
|
|
|
return '<div class="col-sm-3">' |
|
131
|
|
|
. '<div class="form-group">' |
|
132
|
|
|
. $i18n->trans('tipocomprobante') |
|
133
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
|
134
|
|
|
. '</div>' |
|
135
|
|
|
. '</div>'; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
private static function ncfTipoPago(Translator $i18n, SalesDocument $model): string |
|
139
|
|
|
{ |
|
140
|
|
|
$NCFTipoPago = new NCFTipoPago(); |
|
141
|
|
|
$tipoPago = $NCFTipoPago->findAllByTipopago('01'); |
|
142
|
|
|
if (count($tipoPago) === 0) { |
|
143
|
|
|
return ''; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$cliente = self::infoCliente($model->codcliente); |
|
147
|
|
|
|
|
148
|
|
|
if ($model->ncftipopago) { |
|
149
|
|
|
$invoiceTipoPago = $model->ncftipopago; |
|
150
|
|
|
} else { |
|
151
|
|
|
$invoiceTipoPago = ($cliente->ncftipopago !== '') ? $cliente->ncftipopago : "17"; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$options = ['<option value="">------</option>']; |
|
155
|
|
|
foreach ($tipoPago as $row) { |
|
156
|
|
|
$options[] = ($row->codigo === $invoiceTipoPago) ? |
|
157
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
|
158
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
$attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
|
162
|
|
|
return '<div class="col-sm-2">' |
|
163
|
|
|
. '<div class="form-group">' |
|
164
|
|
|
. $i18n->trans('ncf-payment-type') |
|
165
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
|
166
|
|
|
. '</div>' |
|
167
|
|
|
. '</div>'; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
private static function ncfTipoMovimiento(Translator $i18n, SalesDocument $model): string |
|
171
|
|
|
{ |
|
172
|
|
|
$NCFTipoMovimiento = new NCFTipoMovimiento(); |
|
173
|
|
|
$tipoMovimiento = $NCFTipoMovimiento->findAllByTipomovimiento('VEN'); |
|
174
|
|
|
if (count($tipoMovimiento) === 0) { |
|
175
|
|
|
return ''; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$invoiceTipoMovimiento = ($model->ncftipomovimiento) ?: "1"; |
|
179
|
|
|
|
|
180
|
|
|
$options = ['<option value="">------</option>']; |
|
181
|
|
|
foreach ($tipoMovimiento as $row) { |
|
182
|
|
|
$options[] = ($row->codigo === $invoiceTipoMovimiento) ? |
|
183
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
|
184
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
$attributes = $model->editable ? 'name="ncftipomovimiento" required=""' : 'disabled=""'; |
|
188
|
|
|
return '<div class="col-sm-3">' |
|
189
|
|
|
. '<div class="form-group">' |
|
190
|
|
|
. $i18n->trans('ncf-movement-type') |
|
191
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
|
192
|
|
|
. '</div>' |
|
193
|
|
|
. '</div>'; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
private static function ncfTipoAnulacion(Translator $i18n, SalesDocument $model): string |
|
197
|
|
|
{ |
|
198
|
|
|
$NCFTipoAnulacion = new NCFTipoAnulacion(); |
|
199
|
|
|
$tipoAnulacion = $NCFTipoAnulacion->all(); |
|
200
|
|
|
if (count($tipoAnulacion) === 0) { |
|
201
|
|
|
return ''; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
|
205
|
|
|
|
|
206
|
|
|
$options = ['<option value="">------</option>']; |
|
207
|
|
|
foreach ($tipoAnulacion as $row) { |
|
208
|
|
|
$options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
|
209
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
|
210
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
$attributes = $model->editable ? 'name="ncftipoanulacion"' : 'disabled=""'; |
|
214
|
|
|
return '<div class="col-sm-2">' |
|
215
|
|
|
. '<div class="form-group">' |
|
216
|
|
|
. $i18n->trans('ncf-cancellation-type') |
|
217
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
|
218
|
|
|
. '</div>' |
|
219
|
|
|
. '</div>'; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
private static function ncfFechaVencimiento(Translator $i18n, SalesDocument $model): string |
|
223
|
|
|
{ |
|
224
|
|
|
$attributes = ($model->editable && $model->numero2 === '') ? 'name="ncffechavencimiento"' : 'name="ncffechavencimiento" disabled=""'; |
|
225
|
|
|
$ncfFechaVencimiento = ($model->ncffechavencimiento) |
|
226
|
|
|
? date('Y-m-d', strtotime($model->ncffechavencimiento)) |
|
227
|
|
|
: ''; |
|
228
|
|
|
return '<div class="col-sm-2">' |
|
229
|
|
|
. '<div class="form-group">' . $i18n->trans('due-date') |
|
230
|
|
|
. '<input type="date" ' . $attributes . ' value="' . $ncfFechaVencimiento . '" class="form-control"/>' |
|
231
|
|
|
. '</div>' |
|
232
|
|
|
. '</div>'; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
private static function numeroncf(Translator $i18n, SalesDocument $model): string |
|
236
|
|
|
{ |
|
237
|
|
|
$attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
|
238
|
|
|
return empty($model->codcliente) ? '' : '<div class="col-sm">' |
|
239
|
|
|
. '<div class="form-group">' |
|
240
|
|
|
. $i18n->trans('desc-numeroncf-sales') |
|
241
|
|
|
. '<input type="text" ' . $attributes . ' value="' . $model->numeroncf . '" class="form-control"/>' |
|
242
|
|
|
. '</div>' |
|
243
|
|
|
. '</div>'; |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|
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