| Total Complexity | 84 |
| Total Lines | 338 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like SalesFooterHTMLMod often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SalesFooterHTMLMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class SalesFooterHTMLMod implements SalesModInterface |
||
| 33 | { |
||
| 34 | public function apply(SalesDocument &$model, array $formData): void |
||
| 36 | |||
| 37 | } |
||
| 38 | |||
| 39 | public function applyBefore(SalesDocument &$model, array $formData): void |
||
| 40 | { |
||
| 41 | if ($model->modelClassName() === 'FacturaCliente') { |
||
| 42 | $model->numeroncf = isset($formData['numeroncf']) ? (string)$formData['numeroncf'] : $model->numeroncf; |
||
| 43 | $model->tipocomprobante = isset($formData['tipocomprobante']) ? (string)$formData['tipocomprobante'] : $model->tipocomprobante; |
||
| 44 | $model->ncffechavencimiento = isset($formData['ncffechavencimiento']) ? (string)$formData['ncffechavencimiento'] : $model->ncffechavencimiento; |
||
| 45 | $model->ncftipopago = isset($formData['ncftipopago']) ? (string)$formData['ncftipopago'] : $model->ncftipopago; |
||
| 46 | $model->ncftipomovimiento = isset($formData['ncftipomovimiento']) ? (string)$formData['ncftipomovimiento'] : $model->ncftipomovimiento; |
||
| 47 | $model->ncftipoanulacion = isset($formData['ncftipoanulacion']) ? (string)$formData['ncftipoanulacion'] : $model->ncftipoanulacion; |
||
| 48 | $model->ecf_fecha_firma = isset($formData['ecf_fecha_firma']) ? (string)$formData['ecf_fecha_firma'] : $model->ecf_fecha_firma; |
||
| 49 | $model->ecf_codigo_seguridad = isset($formData['ecf_codigo_seguridad']) ? (string)$formData['ecf_codigo_seguridad'] : $model->ecf_codigo_seguridad; |
||
| 50 | } |
||
| 51 | $model->totalexento = isset($formData['totalexento']) ? (float)$formData['totalexento'] : $model->totalexento; |
||
| 52 | $model->totaladdedtaxes = isset($formData['totaladdedtaxes']) ? (float)$formData['totaladdedtaxes'] : $model->totaladdedtaxes; |
||
| 53 | $model->totalplustaxes = isset($formData['totalplustaxes']) ? (float)$formData['totalplustaxes'] : $model->totalplustaxes; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function assets(): void |
||
| 57 | { |
||
| 58 | } |
||
| 59 | |||
| 60 | public function newBtnFields(): array |
||
| 61 | { |
||
| 62 | return []; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function newFields(): array |
||
| 66 | { |
||
| 67 | return ['numeroncf', 'tipocomprobante', 'ncffechavencimiento', 'ncftipopago', 'ncftipomovimiento', |
||
| 68 | 'ncftipoanulacion','cifnif_empresa']; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function newModalFields(): array |
||
| 72 | { |
||
| 73 | return []; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function renderField(SalesDocument $model, string $field): ?string |
||
| 77 | { |
||
| 78 | $i18n = new Translator(); |
||
| 79 | switch ($field) { |
||
| 80 | case "total": |
||
| 81 | return self::renderTotal($model) |
||
| 82 | . '</div><div class="row g-2">' |
||
| 83 | . self::ecfFechaFirma($i18n, $model) |
||
| 84 | . self::ecfCodigoSeguridad($i18n, $model) |
||
| 85 | . self::inputTotalExento($i18n, $model) |
||
| 86 | . self::inputTotalAddedTaxes($i18n, $model) |
||
| 87 | . self::inputTotalPlusTaxes($i18n, $model); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($model->modelClassName() === 'FacturaCliente') { |
||
| 91 | switch ($field) { |
||
| 92 | case "numeroncf": |
||
| 93 | return self::numeroncf($i18n, $model); |
||
| 94 | case "tipocomprobante": |
||
| 95 | return self::tipoComprobante($i18n, $model); |
||
| 96 | case "ncffechavencimiento": |
||
| 97 | return self::ncfFechaVencimiento($i18n, $model) . '</div><div class="row g-2">'; |
||
| 98 | case "ncftipopago": |
||
| 99 | return self::ncfTipoPago($i18n, $model); |
||
| 100 | case "ncftipomovimiento": |
||
| 101 | return self::ncfTipoMovimiento($i18n, $model); |
||
| 102 | case "ncftipoanulacion": |
||
| 103 | return self::ncfTipoAnulacion($i18n, $model) . '</div><div class="row g-2">'; |
||
| 104 | case "btnLoadXmlEcf": |
||
| 105 | return self::btnLoadXmlEcf($i18n, $model); |
||
| 106 | case "cifnif_empresa": |
||
| 107 | return self::cifnifEmpresa($i18n, $model); |
||
| 108 | default: |
||
| 109 | return null; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | return null; |
||
| 113 | } |
||
| 114 | |||
| 115 | private static function cifnifEmpresa(Translator $i18n, SalesDocument $model): string |
||
| 116 | { |
||
| 117 | $empresa = new Empresa(); |
||
| 118 | $cifnifEmpresa = ""; |
||
| 119 | if ($empresa->load($model->idempresa)) { |
||
| 120 | $cifnifEmpresa = $empresa->cifnif; |
||
| 121 | } |
||
| 122 | return '<input type="hidden" class="form-control" id="cifnif_empresa" name="cifnif_empresa" value="' . $cifnifEmpresa . '" readonly>'; |
||
| 123 | } |
||
| 124 | |||
| 125 | private static function btnLoadXmlEcf(Translator $i18n, SalesDocument $model): string |
||
| 126 | { |
||
| 127 | return '<div class="row align-items-start">' |
||
| 128 | . '<div class="col-sm-5 text-start">' |
||
| 129 | . '<label for="xmlFile" class="form-label">' |
||
| 130 | . '<i class="fa-solid fa-file-code me-1 text-primary"></i> Archivo XML de e-Factura' |
||
| 131 | . '</label>' |
||
| 132 | . '<div class="input-group">' |
||
| 133 | . ' <input type="file" class="form-control" id="xmlFile" name="xmlFile" onchange="enableParseIfReady()" ' |
||
| 134 | . ' accept=".xml,text/xml,application/xml">' |
||
| 135 | . ' <div class="invalid-feedback">Seleccione un archivo XML válido.</div>' |
||
| 136 | . '<button type="button" id="btnParseXml" onclick="btnParseClick()" class="btn btn-danger" disabled>' |
||
| 137 | . '<i class="fas fa-fw fa-file-code"></i>' |
||
| 138 | . $i18n->trans('btn-load-xml-ecf') |
||
| 139 | . '</button>' |
||
| 140 | . '</div>' |
||
| 141 | . '</div></div>'; |
||
| 142 | } |
||
| 143 | |||
| 144 | private static function infoCliente($codcliente) |
||
| 145 | { |
||
| 146 | $cliente = new Cliente(); |
||
| 147 | $actualCliente = $cliente::find($codcliente); |
||
| 148 | if ('' !== $actualCliente) { |
||
| 149 | return $actualCliente; |
||
| 150 | } |
||
| 151 | return null; |
||
| 152 | } |
||
| 153 | |||
| 154 | private static function tipoComprobante(Translator $i18n, SalesDocument $model): string |
||
| 155 | { |
||
| 156 | $tipoComprobante = NCFTipo::allVentas(); |
||
| 157 | if (count($tipoComprobante) === 0) { |
||
| 158 | return ''; |
||
| 159 | } |
||
| 160 | |||
| 161 | $cliente = self::infoCliente($model->codcliente); |
||
| 162 | $cliente->tipocomprobante = ($cliente->tipocomprobante === null) ? "02" : $cliente->tipocomprobante; |
||
| 163 | |||
| 164 | $invoiceTipoComprobante = ($model->tipocomprobante !== null) ? $model->tipocomprobante : $cliente->tipocomprobante; |
||
| 165 | if (!$model->editable) { |
||
| 166 | $invoiceTipoComprobante = $model->tipocomprobante; |
||
| 167 | } elseif ($model->editable === true && ($cliente->tipocomprobante !== $model->tipocomprobante) && $model->tipocomprobante !== null) { |
||
| 168 | $invoiceTipoComprobante = $model->tipocomprobante; |
||
| 169 | } elseif ($model->editable === true && ($cliente->tipocomprobante === $model->tipocomprobante) && $model->tipocomprobante !== null) { |
||
| 170 | $invoiceTipoComprobante = $cliente->tipocomprobante; |
||
| 171 | } |
||
| 172 | |||
| 173 | $options = ['<option value="">------</option>']; |
||
| 174 | foreach ($tipoComprobante as $row) { |
||
| 175 | $options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
||
| 176 | '<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
||
| 177 | '<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
||
| 178 | } |
||
| 179 | |||
| 180 | $attributes = ($model->editable || $model->numeroncf === '') ? |
||
| 181 | 'id="tipocomprobante" name="tipocomprobante" required="" onChange="verificarCorrelativoNCF(this.value,\'Ventas\')"' : |
||
| 182 | 'disabled=""'; |
||
| 183 | |||
| 184 | return '<div class="col-sm-3">' |
||
| 185 | . '<div class="mb-3">' |
||
| 186 | . $i18n->trans('tipocomprobante') |
||
| 187 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 188 | . '</div>' |
||
| 189 | . '</div>'; |
||
| 190 | } |
||
| 191 | |||
| 192 | private static function ncfTipoPago(Translator $i18n, SalesDocument $model): string |
||
| 193 | { |
||
| 194 | $NCFTipoPago = new NCFTipoPago(); |
||
| 195 | $tipoPago = $NCFTipoPago->findAllByTipopago('01'); |
||
| 196 | if (count($tipoPago) === 0) { |
||
| 197 | return ''; |
||
| 198 | } |
||
| 199 | |||
| 200 | $cliente = self::infoCliente($model->codcliente); |
||
| 201 | |||
| 202 | if ($model->ncftipopago) { |
||
| 203 | $invoiceTipoPago = $model->ncftipopago; |
||
| 204 | } else { |
||
| 205 | $invoiceTipoPago = ($cliente->ncftipopago !== '') ? $cliente->ncftipopago : "17"; |
||
| 206 | } |
||
| 207 | |||
| 208 | $options = ['<option value="">------</option>']; |
||
| 209 | foreach ($tipoPago as $row) { |
||
| 210 | $options[] = ($row->codigo === $invoiceTipoPago) ? |
||
| 211 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 212 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 213 | } |
||
| 214 | |||
| 215 | $attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
||
| 216 | return '<div class="col-sm-4">' |
||
| 217 | . '<div class="mb-3">' |
||
| 218 | . $i18n->trans('ncf-payment-type') |
||
| 219 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 220 | . '</div>' |
||
| 221 | . '</div>'; |
||
| 222 | } |
||
| 223 | |||
| 224 | private static function ncfTipoMovimiento(Translator $i18n, SalesDocument $model): string |
||
| 248 | } |
||
| 249 | |||
| 250 | private static function ncfTipoAnulacion(Translator $i18n, SalesDocument $model): string |
||
| 251 | { |
||
| 252 | $NCFTipoAnulacion = new NCFTipoAnulacion(); |
||
| 253 | $tipoAnulacion = $NCFTipoAnulacion->all(); |
||
| 254 | if (count($tipoAnulacion) === 0) { |
||
| 255 | return ''; |
||
| 256 | } |
||
| 257 | |||
| 258 | $invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
||
| 259 | |||
| 260 | $options = ['<option value="">------</option>']; |
||
| 261 | foreach ($tipoAnulacion as $row) { |
||
| 262 | $options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
||
| 263 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 264 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 265 | } |
||
| 266 | |||
| 267 | $attributes = $model->editable ? 'name="ncftipoanulacion"' : 'disabled=""'; |
||
| 268 | return '<div class="col-sm-4">' |
||
| 269 | . '<div class="mb-3">' |
||
| 270 | . $i18n->trans('ncf-cancellation-type') |
||
| 271 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 272 | . '</div>' |
||
| 273 | . '</div>'; |
||
| 274 | } |
||
| 275 | |||
| 276 | private static function ncfFechaVencimiento(Translator $i18n, SalesDocument $model): string |
||
| 277 | { |
||
| 278 | $attributes = ($model->editable && $model->numero2 === '') ? 'name="ncffechavencimiento"' : 'name="ncffechavencimiento" disabled=""'; |
||
| 279 | $ncfFechaVencimiento = ($model->ncffechavencimiento) |
||
| 280 | ? date('Y-m-d', strtotime($model->ncffechavencimiento)) |
||
| 281 | : ''; |
||
| 282 | return '<div class="col-sm-2">' |
||
| 283 | . '<div class="mb-3">' . $i18n->trans('due-date') |
||
| 284 | . '<input type="date" ' . $attributes . ' value="' . $ncfFechaVencimiento . '" class="form-control"/>' |
||
| 285 | . '</div>' |
||
| 286 | . '</div>'; |
||
| 287 | } |
||
| 288 | |||
| 289 | private static function numeroncf(Translator $i18n, SalesDocument $model): string |
||
| 290 | { |
||
| 291 | $attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
||
| 292 | return empty($model->codcliente) ? '' : '<div class="col-sm-3">' |
||
| 293 | . '<div class="mb-3">' |
||
| 294 | . $i18n->trans('desc-numeroncf-sales') |
||
| 295 | . '<input type="text" ' . $attributes . ' value="' . $model->numeroncf . '" class="form-control"/>' |
||
| 296 | . '</div>' |
||
| 297 | . '</div>'; |
||
| 298 | } |
||
| 299 | |||
| 300 | private static function ecfFechaFirma(Translator $i18n, SalesDocument $model): string |
||
| 314 | } |
||
| 315 | |||
| 316 | private static function ecfCodigoSeguridad(Translator $i18n, SalesDocument $model): string |
||
| 317 | { |
||
| 318 | $attributes = ($model->editable) ? 'name="ecf_codigo_seguridad" maxlength="64"' : 'disabled=""'; |
||
| 319 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 320 | . '<div class="mb-2">' |
||
| 321 | . $i18n->trans('desc-ecf_codigo_seguridad') |
||
| 322 | . '<div class="input-group">' |
||
| 323 | . '<input type="text" ' . $attributes . ' value="' . $model->ecf_codigo_seguridad . '" class="form-control"/>' |
||
| 324 | . '</div>' |
||
| 325 | . '</div>' |
||
| 326 | . '</div>'; |
||
| 327 | } |
||
| 328 | |||
| 329 | private static function renderTotal(SalesDocument $model): string |
||
| 330 | { |
||
| 331 | $nf0 = Tools::settings('default', 'decimals', 2); |
||
| 332 | return '<div class="col-sm-6 col-md-4 col-lg-2" lang="es_DO">' |
||
| 333 | . '<div class="mb-2">' . Tools::trans('total') |
||
| 334 | . '<input type="text" name="total" value="' . number_format($model->total, $nf0, '.','') . '" class="form-control" disabled/>' |
||
| 335 | . '</div>' |
||
| 336 | . '</div>'; |
||
| 337 | } |
||
| 338 | |||
| 339 | private static function inputTotalExento(Translator $i18n, SalesDocument $model): string |
||
| 340 | { |
||
| 341 | $attributes = 'name="totalexento" disabled=""'; |
||
| 342 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 343 | . '<div class="mb-2">' |
||
| 344 | . $i18n->trans('desc-total-exento') |
||
| 345 | . '<input type="text" '. $attributes. ' value="'.$model->totalexento.'" class="form-control">' |
||
| 346 | . '</div>' |
||
| 347 | . '</div>'; |
||
| 348 | } |
||
| 349 | |||
| 350 | private static function inputTotalAddedTaxes(Translator $i18n, SalesDocument $model): string |
||
| 351 | { |
||
| 352 | $attributes = 'name="totaladdedtaxes" disabled=""'; |
||
| 353 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 354 | . '<div class="mb-2">' |
||
| 355 | . $i18n->trans('desc-total-added-taxes') |
||
| 356 | . '<input type="text" '. $attributes. ' value="'.$model->totaladdedtaxes.'" class="form-control">' |
||
| 357 | . '</div>' |
||
| 358 | . '</div>'; |
||
| 359 | } |
||
| 360 | |||
| 361 | private static function inputTotalPlusTaxes(Translator $i18n, SalesDocument $model): string |
||
| 370 | } |
||
| 371 | } |
||
| 372 |
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