| Total Complexity | 73 |
| Total Lines | 320 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like PurchasesFooterHTMLMod 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 PurchasesFooterHTMLMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class PurchasesFooterHTMLMod implements PurchasesModInterface |
||
| 33 | { |
||
| 34 | public function apply(PurchaseDocument &$model, array $formData): void |
||
| 35 | { |
||
| 36 | } |
||
| 37 | |||
| 38 | public function applyBefore(PurchaseDocument &$model, array $formData): void |
||
| 39 | { |
||
| 40 | if ($model->modelClassName() === 'FacturaProveedor') { |
||
| 41 | $model->numeroncf = isset($formData['numeroncf']) ? (string)$formData['numeroncf'] : $model->numeroncf; |
||
| 42 | $model->tipocomprobante = isset($formData['tipocomprobante']) ? (string)$formData['tipocomprobante'] : $model->tipocomprobante; |
||
| 43 | $model->ncffechavencimiento = isset($formData['ncffechavencimiento']) ? (string)$formData['ncffechavencimiento'] : $model->ncffechavencimiento; |
||
| 44 | $model->ncftipopago = isset($formData['ncftipopago']) ? (string)$formData['ncftipopago'] : $model->ncftipopago; |
||
| 45 | $model->ncftipomovimiento = isset($formData['ncftipomovimiento']) ? (string)$formData['ncftipomovimiento'] : $model->ncftipomovimiento; |
||
| 46 | $model->ncftipoanulacion = isset($formData['ncftipoanulacion']) ? (string)$formData['ncftipoanulacion'] : $model->ncftipoanulacion; |
||
| 47 | $model->ecf_fecha_firma = isset($formData['ecf_fecha_firma']) ? (string)$formData['ecf_fecha_firma'] : $model->ecf_fecha_firma; |
||
| 48 | $model->ecf_codigo_seguridad = isset($formData['ecf_codigo_seguridad']) ? (string)$formData['ecf_codigo_seguridad'] : $model->ecf_codigo_seguridad; |
||
| 49 | } |
||
| 50 | $model->totalexento = isset($formData['totalexento']) ? (float)$formData['totalexento'] : $model->totalexento; |
||
| 51 | $model->totaladdedtaxes = isset($formData['totaladdedtaxes']) ? (float)$formData['totaladdedtaxes'] : $model->totaladdedtaxes; |
||
| 52 | $model->totalplustaxes = isset($formData['totalplustaxes']) ? (float)$formData['totalplustaxes'] : $model->totalplustaxes; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function assets(): void |
||
| 56 | { |
||
| 57 | } |
||
| 58 | |||
| 59 | public function newBtnFields(): array |
||
| 60 | { |
||
| 61 | return ['btnLoadXmlEcf','btnLoadXmlAck','btnLoadPdfEcf']; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function newFields(): array |
||
| 65 | { |
||
| 66 | return ['numeroncf', 'tipocomprobante', 'ncffechavencimiento', 'ncftipopago', 'ncftipomovimiento', |
||
| 67 | 'ncftipoanulacion']; |
||
| 68 | } |
||
| 69 | |||
| 70 | public function newModalFields(): array |
||
| 71 | { |
||
| 72 | return []; |
||
| 73 | } |
||
| 74 | |||
| 75 | public function renderField(PurchaseDocument $model, string $field): ?string |
||
| 76 | { |
||
| 77 | $i18n = new Translator(); |
||
| 78 | switch ($field) { |
||
| 79 | case "total": |
||
| 80 | return self::renderTotal($model) |
||
| 81 | . '</div><div class="row g-2">' |
||
| 82 | . self::ecfFechaFirma($i18n, $model) |
||
| 83 | . self::ecfCodigoSeguridad($i18n, $model) |
||
| 84 | . self::inputTotalExento($i18n, $model) |
||
| 85 | . self::inputTotalAddedTaxes($i18n, $model) |
||
| 86 | . self::inputTotalPlusTaxes($i18n, $model); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($model->modelClassName() === 'FacturaProveedor') { |
||
| 90 | switch ($field) { |
||
| 91 | case "numeroncf": |
||
| 92 | return self::numeroNCF($i18n, $model); |
||
| 93 | case "tipocomprobante": |
||
| 94 | return self::tipoComprobante($i18n, $model); |
||
| 95 | case "ncffechavencimiento": |
||
| 96 | return self::ncfFechaVencimiento($i18n, $model). '</div><div class="row g-2">'; |
||
| 97 | case "ncftipopago": |
||
| 98 | return self::ncfTipoPago($i18n, $model); |
||
| 99 | case "ncftipomovimiento": |
||
| 100 | return self::ncfTipoMovimiento($i18n, $model); |
||
| 101 | case "ncftipoanulacion": |
||
| 102 | return self::ncfTipoAnulacion($i18n, $model) . '</div><div class="row g-2">'; |
||
| 103 | case "btnLoadXmlEcf": |
||
| 104 | return self::btnLoadXmlEcf($i18n, $model); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | return null; |
||
| 108 | } |
||
| 109 | |||
| 110 | private static function btnLoadXmlEcf(Translator $i18n, PurchaseDocument $model): string |
||
| 111 | { |
||
| 112 | return '<div class="row align-items-start">' |
||
| 113 | . '<div class="col-sm-5 text-start">' |
||
| 114 | . '<label for="xmlFile" class="form-label">' |
||
| 115 | . '<i class="fa-solid fa-file-code me-1 text-primary"></i> Archivo XML de e-Factura' |
||
| 116 | . '</label>' |
||
| 117 | . '<div class="input-group">' |
||
| 118 | . ' <input type="file" class="form-control" id="xmlFile" name="xmlFile" onchange="enableParseIfReady()" ' |
||
| 119 | . ' accept=".xml,text/xml,application/xml">' |
||
| 120 | . ' <div class="invalid-feedback">Seleccione un archivo XML válido.</div>' |
||
| 121 | . '<button type="button" id="btnParseXml" onclick="btnParseClick(\'xmlFile\')" class="btn btn-danger" disabled>' |
||
| 122 | . '<i class="fas fa-fw fa-file-code"></i>' |
||
| 123 | . $i18n->trans('btn-load-xml-ecf') |
||
| 124 | . '</button>' |
||
| 125 | . '</div>' |
||
| 126 | . '</div></div>'; |
||
| 127 | } |
||
| 128 | |||
| 129 | private static function infoProveedor($codproveedor) |
||
| 130 | { |
||
| 131 | $proveedor = new Proveedor(); |
||
| 132 | $actualProveedor = $proveedor::find($codproveedor); |
||
| 133 | if ('' !== $actualProveedor) { |
||
| 134 | return $actualProveedor; |
||
| 135 | } |
||
| 136 | return null; |
||
| 137 | } |
||
| 138 | |||
| 139 | private static function tipoComprobante(Translator $i18n, PurchaseDocument $model): string |
||
| 140 | { |
||
| 141 | $tipoComprobante = NCFTipo::allCompras(); |
||
| 142 | if (count($tipoComprobante) === 0) { |
||
| 143 | return ''; |
||
| 144 | } |
||
| 145 | |||
| 146 | $invoiceTipoComprobante = ($model->tipocomprobante) ? $model->tipocomprobante : ""; |
||
| 147 | |||
| 148 | $options = ['<option value="">------</option>']; |
||
| 149 | foreach ($tipoComprobante as $row) { |
||
| 150 | $options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
||
| 151 | '<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
||
| 152 | '<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
||
| 153 | } |
||
| 154 | |||
| 155 | $attributes = ($model->editable || $model->numeroncf === '') ? 'name="tipocomprobante" required=""' : 'disabled=""'; |
||
| 156 | return '<div class="col-sm-4">' |
||
| 157 | . '<div class="mb-3">' |
||
| 158 | . $i18n->trans('tipocomprobante') |
||
| 159 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 160 | . '</div>' |
||
| 161 | . '</div>'; |
||
| 162 | } |
||
| 163 | |||
| 164 | private static function ncfTipoPago(Translator $i18n, PurchaseDocument $model): string |
||
| 165 | { |
||
| 166 | $NCFTipoPago = new NCFTipoPago(); |
||
| 167 | $tipoPago = $NCFTipoPago->findAllByTipopago('02'); |
||
| 168 | if (count($tipoPago) === 0) { |
||
| 169 | return ''; |
||
| 170 | } |
||
| 171 | |||
| 172 | $proveedor = self::infoProveedor($model->codproveedor); |
||
| 173 | |||
| 174 | if ($model->ncftipopago) { |
||
| 175 | $invoiceTipoPago = $model->ncftipopago; |
||
| 176 | } else { |
||
| 177 | $invoiceTipoPago = ($proveedor->ncftipopago !== '') ? $proveedor->ncftipopago : "01"; |
||
| 178 | } |
||
| 179 | |||
| 180 | $options = ['<option value="">------</option>']; |
||
| 181 | foreach ($tipoPago as $row) { |
||
| 182 | $options[] = ($row->codigo === $invoiceTipoPago) ? |
||
| 183 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 184 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 185 | } |
||
| 186 | |||
| 187 | $attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
||
| 188 | return '<div class="col-sm-4">' |
||
| 189 | . '<div class="mb-3">' |
||
| 190 | . $i18n->trans('ncf-payment-type') |
||
| 191 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 192 | . '</div>' |
||
| 193 | . '</div>'; |
||
| 194 | } |
||
| 195 | |||
| 196 | private static function ncfTipoMovimiento(Translator $i18n, PurchaseDocument $model): string |
||
| 220 | } |
||
| 221 | |||
| 222 | private static function ncfTipoAnulacion(Translator $i18n, PurchaseDocument $model): string |
||
| 223 | { |
||
| 224 | $NCFTipoAnulacion = new NCFTipoAnulacion(); |
||
| 225 | $tipoAnulacion = $NCFTipoAnulacion->all(); |
||
| 226 | if (count($tipoAnulacion) === 0) { |
||
| 227 | return ''; |
||
| 228 | } |
||
| 229 | |||
| 230 | $invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
||
| 231 | |||
| 232 | $options = ['<option value="">------</option>']; |
||
| 233 | foreach ($tipoAnulacion as $row) { |
||
| 234 | $options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
||
| 235 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 236 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 237 | } |
||
| 238 | |||
| 239 | $attributes = $model->editable ? 'name="ncftipoanulacion"' : 'name="ncftipoanulacion" readonly=""'; |
||
| 240 | return '<div class="col-sm-4">' |
||
| 241 | . '<div class="mb-3">' |
||
| 242 | . $i18n->trans('ncf-cancellation-type') |
||
| 243 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 244 | . '</div>' |
||
| 245 | . '</div>'; |
||
| 246 | } |
||
| 247 | |||
| 248 | private static function ncfFechaVencimiento(Translator $i18n, PurchaseDocument $model): string |
||
| 249 | { |
||
| 250 | $attributes = ($model->editable) ? 'name="ncffechavencimiento"' : 'disabled=""'; |
||
| 251 | $ncfFechaVencimiento = ($model->ncffechavencimiento) |
||
| 252 | ? date('Y-m-d', strtotime($model->ncffechavencimiento)) |
||
| 253 | : ''; |
||
| 254 | return '<div class="col-sm-2">' |
||
| 255 | . '<div class="mb-3">' . $i18n->trans('due-date') |
||
| 256 | . '<input type="date" ' . $attributes . ' value="' |
||
| 257 | . $ncfFechaVencimiento . '" class="form-control"/>' |
||
| 258 | . '</div>' |
||
| 259 | . '</div>'; |
||
| 260 | } |
||
| 261 | |||
| 262 | private static function numeroNCF(Translator $i18n, PurchaseDocument $model): string |
||
| 263 | { |
||
| 264 | $attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
||
| 265 | $btnColor = (in_array($model->numeroncf, ['', null], true)) ? "btn-secondary" : "btn-success"; |
||
| 266 | return empty($model->codproveedor) ? '' : '<div class="col-sm-3">' |
||
| 267 | . '<div class="mb-3">' |
||
| 268 | . $i18n->trans('desc-numeroncf-purchases') |
||
| 269 | . '<div class="input-group">' |
||
| 270 | . '<input type="text" ' . $attributes . ' value="' . $model->numeroncf . '" class="form-control"/>' |
||
| 271 | . '<button class="btn ' . $btnColor . ' btn-spin-action" id="btnVerifyNCF"' |
||
| 272 | . 'onclick="purchasesNCFVerify()" ' |
||
| 273 | . 'title="' . $i18n->trans('verify-numproveedor') |
||
| 274 | . '" type="button">' |
||
| 275 | . '<i id="iconBtnVerify" class="fa-solid fa-search fa-fw"></i>' |
||
| 276 | . '</button>' |
||
| 277 | . '</div>' |
||
| 278 | . '</div>' |
||
| 279 | . '</div>'; |
||
| 280 | } |
||
| 281 | |||
| 282 | private static function ecfFechaFirma(Translator $i18n, PurchaseDocument $model): string |
||
| 283 | { |
||
| 284 | $attributes = ($model->editable) ? 'name="ecf_fecha_firma" maxlength="32"' : 'disabled=""'; |
||
| 285 | $ecfFechaFirma = ($model->ecf_fecha_firma) |
||
| 286 | ? date('Y-m-d\TH:i', strtotime($model->ecf_fecha_firma)) |
||
| 287 | : ''; |
||
| 288 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 289 | . '<div class="mb-2">' |
||
| 290 | . $i18n->trans('desc-ecf_fecha_firma') |
||
| 291 | . '<div class="input-group">' |
||
| 292 | . '<input type="datetime-local" ' . $attributes . ' value="' . $ecfFechaFirma . '" step="1" class="form-control"/>' |
||
| 293 | . '</div>' |
||
| 294 | . '</div>' |
||
| 295 | . '</div>'; |
||
| 296 | } |
||
| 297 | |||
| 298 | private static function ecfCodigoSeguridad(Translator $i18n, PurchaseDocument $model): string |
||
| 299 | { |
||
| 300 | $attributes = ($model->editable) ? 'name="ecf_codigo_seguridad" maxlength="64"' : 'disabled=""'; |
||
| 301 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 302 | . '<div class="mb-2">' |
||
| 303 | . $i18n->trans('desc-ecf_codigo_seguridad') |
||
| 304 | . '<div class="input-group">' |
||
| 305 | . '<input type="text" ' . $attributes . ' value="' . $model->ecf_codigo_seguridad . '" class="form-control"/>' |
||
| 306 | . '</div>' |
||
| 307 | . '</div>' |
||
| 308 | . '</div>'; |
||
| 309 | } |
||
| 310 | |||
| 311 | private static function renderTotal(PurchaseDocument $model): string |
||
| 312 | { |
||
| 313 | $nf0 = Tools::settings('default', 'decimals', 2); |
||
| 314 | return '<div class="col-sm-6 col-md-4 col-lg-2">' |
||
| 315 | . '<div class="mb-2">' . Tools::trans('total') |
||
| 316 | . '<input type="text" name="total" value="' . Tools::number($model->total, $nf0) . '" class="form-control" disabled/>' |
||
| 317 | . '</div>' |
||
| 318 | . '</div>'; |
||
| 319 | } |
||
| 320 | |||
| 321 | private static function inputTotalExento(Translator $i18n, PurchaseDocument $model): string |
||
| 330 | } |
||
| 331 | |||
| 332 | private static function inputTotalAddedTaxes(Translator $i18n, PurchaseDocument $model): string |
||
| 333 | { |
||
| 334 | $attributes = 'name="totaladdedtaxes" disabled=""'; |
||
| 335 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 336 | . '<div class="mb-2">' |
||
| 337 | . $i18n->trans('desc-total-added-taxes') |
||
| 338 | . '<input type="text" '. $attributes. ' value="'.$model->totaladdedtaxes.'" class="form-control">' |
||
| 339 | . '</div>' |
||
| 341 | } |
||
| 342 | |||
| 343 | private static function inputTotalPlusTaxes(Translator $i18n, PurchaseDocument $model): string |
||
| 344 | { |
||
| 345 | $attributes = 'name="totalplustaxes" disabled=""'; |
||
| 346 | return '<div class="col-sm-6 col-md-4 col-lg">' |
||
| 352 | } |
||
| 353 | } |
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