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\PurchasesModInterface; |
|
|
|
|
21
|
|
|
use FacturaScripts\Core\Base\Translator; |
|
|
|
|
22
|
|
|
use FacturaScripts\Core\Model\Base\PurchaseDocument; |
|
|
|
|
23
|
|
|
use FacturaScripts\Core\Model\User; |
|
|
|
|
24
|
|
|
use FacturaScripts\Dinamic\Model\Proveedor; |
|
|
|
|
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 PurchasesFooterMod implements PurchasesModInterface |
31
|
|
|
{ |
32
|
|
|
public function apply(PurchaseDocument &$model, array $formData, User $user) |
33
|
|
|
{ |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function applyBefore(PurchaseDocument &$model, array $formData, User $user) |
37
|
|
|
{ |
38
|
|
|
if ($model->modelClassName() === 'FacturaProveedor') { |
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, PurchaseDocument $model, string $field): ?string |
68
|
|
|
{ |
69
|
|
|
if ($model->modelClassName() === 'FacturaProveedor') { |
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 infoProveedor($codproveedor) |
91
|
|
|
{ |
92
|
|
|
$proveedor = new Proveedor(); |
93
|
|
|
$actualProveedor = $proveedor->get($codproveedor); |
94
|
|
|
if ('' !== $actualProveedor) { |
95
|
|
|
return $actualProveedor; |
96
|
|
|
} |
97
|
|
|
return null; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
private static function tipoComprobante(Translator $i18n, PurchaseDocument $model): string |
101
|
|
|
{ |
102
|
|
|
$tipoComprobante = NCFTipo::allCompras(); |
103
|
|
|
if (count($tipoComprobante) === 0) { |
104
|
|
|
return ''; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$invoiceTipoComprobante = ($model->tipocomprobante) ? $model->tipocomprobante : ""; |
108
|
|
|
|
109
|
|
|
$options = ['<option value="">------</option>']; |
110
|
|
|
foreach ($tipoComprobante as $row) { |
111
|
|
|
$options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
112
|
|
|
'<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
113
|
|
|
'<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$attributes = ($model->editable || $model->numeroncf === '') ? 'name="tipocomprobante" required=""' : 'disabled=""'; |
117
|
|
|
return '<div class="col-sm-3">' |
118
|
|
|
. '<div class="form-group">' |
119
|
|
|
. $i18n->trans('tipocomprobante') |
120
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
121
|
|
|
. '</div>' |
122
|
|
|
. '</div>'; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
private static function ncfTipoPago(Translator $i18n, PurchaseDocument $model): string |
126
|
|
|
{ |
127
|
|
|
$NCFTipoPago = new NCFTipoPago(); |
128
|
|
|
$tipoPago = $NCFTipoPago->findAllByTipopago('02'); |
129
|
|
|
if (count($tipoPago) === 0) { |
130
|
|
|
return ''; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$proveedor = self::infoProveedor($model->codproveedor); |
134
|
|
|
|
135
|
|
|
if ($model->ncftipopago) { |
136
|
|
|
$invoiceTipoPago = $model->ncftipopago; |
137
|
|
|
} else { |
138
|
|
|
$invoiceTipoPago = ($proveedor->ncftipopago !== '') ? $proveedor->ncftipopago : "01"; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$options = ['<option value="">------</option>']; |
142
|
|
|
foreach ($tipoPago as $row) { |
143
|
|
|
$options[] = ($row->codigo === $invoiceTipoPago) ? |
144
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
145
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
149
|
|
|
return '<div class="col-sm-2">' |
150
|
|
|
. '<div class="form-group">' |
151
|
|
|
. $i18n->trans('ncf-payment-type') |
152
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
153
|
|
|
. '</div>' |
154
|
|
|
. '</div>'; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
private static function ncfTipoMovimiento(Translator $i18n, PurchaseDocument $model): string |
158
|
|
|
{ |
159
|
|
|
$NCFTipoMovimiento = new NCFTipoMovimiento(); |
160
|
|
|
$tipoMovimiento = $NCFTipoMovimiento->findAllByTipomovimiento('COM'); |
161
|
|
|
if (count($tipoMovimiento) === 0) { |
162
|
|
|
return ''; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
$invoiceTipoMovimiento = ($model->ncftipomovimiento) ?: "09"; |
166
|
|
|
|
167
|
|
|
$options = ['<option value="">------</option>']; |
168
|
|
|
foreach ($tipoMovimiento as $row) { |
169
|
|
|
$options[] = ($row->codigo === $invoiceTipoMovimiento) ? |
170
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
171
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$attributes = $model->editable ? 'name="ncftipomovimiento" required=""' : 'disabled=""'; |
175
|
|
|
return '<div class="col-sm-3">' |
176
|
|
|
. '<div class="form-group">' |
177
|
|
|
. $i18n->trans('ncf-movement-type') |
178
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
179
|
|
|
. '</div>' |
180
|
|
|
. '</div>'; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
private static function ncfTipoAnulacion(Translator $i18n, PurchaseDocument $model): string |
184
|
|
|
{ |
185
|
|
|
$NCFTipoAnulacion = new NCFTipoAnulacion(); |
186
|
|
|
$tipoAnulacion = $NCFTipoAnulacion->all(); |
187
|
|
|
if (count($tipoAnulacion) === 0) { |
188
|
|
|
return ''; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
192
|
|
|
|
193
|
|
|
$options = ['<option value="">------</option>']; |
194
|
|
|
foreach ($tipoAnulacion as $row) { |
195
|
|
|
$options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
196
|
|
|
'<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
197
|
|
|
'<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$attributes = $model->editable ? 'name="ncftipoanulacion"' : 'name="ncftipoanulacion" readonly=""'; |
201
|
|
|
return '<div class="col-sm-2">' |
202
|
|
|
. '<div class="form-group">' |
203
|
|
|
. $i18n->trans('ncf-cancellation-type') |
204
|
|
|
. '<select ' . $attributes . ' class="form-control">' . implode('', $options) . '</select>' |
205
|
|
|
. '</div>' |
206
|
|
|
. '</div>'; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
private static function ncfFechaVencimiento(Translator $i18n, PurchaseDocument $model): string |
210
|
|
|
{ |
211
|
|
|
$attributes = ($model->editable) ? 'name="ncffechavencimiento"' : 'disabled=""'; |
212
|
|
|
$ncfFechaVencimiento = ($model->ncffechavencimiento) |
213
|
|
|
? date('Y-m-d', strtotime($model->ncffechavencimiento)) |
214
|
|
|
: ''; |
215
|
|
|
return '<div class="col-sm-2">' |
216
|
|
|
. '<div class="form-group">' . $i18n->trans('due-date') |
217
|
|
|
. '<input type="date" ' . $attributes . ' value="' |
218
|
|
|
. $ncfFechaVencimiento . '" class="form-control"/>' |
219
|
|
|
. '</div>' |
220
|
|
|
. '</div>'; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
private static function numeroNCF(Translator $i18n, PurchaseDocument $model): string |
224
|
|
|
{ |
225
|
|
|
$attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
226
|
|
|
$btnColor = (in_array($model->numeroncf, ['', null], true)) ? "btn-secondary" : "btn-success"; |
227
|
|
|
return empty($model->codproveedor) ? '' : '<div class="col-sm">' |
228
|
|
|
. '<div class="form-group">' |
229
|
|
|
. $i18n->trans('desc-numeroncf-purchases') |
230
|
|
|
. '<div class="input-group">' |
231
|
|
|
. '<input type="text" ' . $attributes . ' value="' . $model->numeroncf . '" class="form-control"/>' |
232
|
|
|
. '<div class="input-group-append">' |
233
|
|
|
. '<button class="btn ' . $btnColor . ' btn-spin-action" id="btnVerifyNCF"' |
234
|
|
|
. 'onclick="purchasesNCFVerify()" ' |
235
|
|
|
. 'title="' . $i18n->trans('verify-numproveedor') |
236
|
|
|
. '" type="button">' |
237
|
|
|
. '<i id="iconBtnVerify" class="fas fa-search fa-fw"></i>' |
238
|
|
|
. '</button>' |
239
|
|
|
. '</div>' |
240
|
|
|
. '</div>' |
241
|
|
|
. '</div>' |
242
|
|
|
. '</div>'; |
243
|
|
|
} |
244
|
|
|
} |
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