| Total Complexity | 67 |
| Total Lines | 399 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 3 | Features | 0 |
Complex classes like admin_rd 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 admin_rd, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class admin_rd extends rd_controller |
||
| 26 | { |
||
| 27 | public $conf_divisa; |
||
| 28 | public $conf_impuestos; |
||
| 29 | public $conf_pais; |
||
| 30 | public $conf_regional; |
||
| 31 | public $impuestos_rd; |
||
| 32 | public $variables; |
||
| 33 | public function __construct() |
||
| 36 | } |
||
| 37 | |||
| 38 | protected function private_core() |
||
| 39 | { |
||
| 40 | parent::private_core(); |
||
| 41 | $this->share_extensions(); |
||
| 42 | $impuesto_empresa = new impuesto(); |
||
|
|
|||
| 43 | $this->init_variables(); |
||
| 44 | $this->init_impuestos(); |
||
| 45 | |||
| 46 | $this->init_router(); |
||
| 47 | |||
| 48 | $this->get_config(); |
||
| 49 | |||
| 50 | $this->conf_divisa = ($this->empresa->coddivisa == 'DOP') ? true : false; |
||
| 51 | $this->conf_pais = ($this->empresa->codpais == 'DOM') ? true : false; |
||
| 52 | $this->conf_regional = ($GLOBALS['config2']['iva'] == 'ITBIS') ? true : false; |
||
| 53 | $this->conf_impuestos = ($impuesto_empresa->get_by_iva(18)) ? true : false; |
||
| 54 | //Cargamos el menu |
||
| 55 | $this->check_menu(); |
||
| 56 | } |
||
| 57 | |||
| 58 | public function init_models() |
||
| 59 | { |
||
| 60 | parent::init_models(); |
||
| 61 | new ncf_tipo(); |
||
| 62 | new ncf_entidad_tipo(); |
||
| 63 | new ncf_rango(); |
||
| 64 | new ncf_tipo_anulacion(); |
||
| 65 | new ncf_ventas(); |
||
| 66 | } |
||
| 67 | |||
| 68 | public function init_variables() |
||
| 69 | { |
||
| 70 | $this->variables = array('zona_horaria'=>'America/Santo_Domingo', |
||
| 71 | 'nf0' => "2", 'nf0_art' => "4", 'nf1' => ".", 'nf2' => ",", |
||
| 72 | 'pos_divisa' => "left", |
||
| 73 | 'factura' => "factura", 'facturas' => "facturas", |
||
| 74 | 'factura_simplificada' => "Ticket", 'factura_rectificativa' => "nota de credito", |
||
| 75 | 'albaran' => "conduce", 'albaranes' => "conduces", |
||
| 76 | 'pedido' => "pedido", 'pedidos' => "pedidos", |
||
| 77 | 'presupuesto' => "presupuesto", 'presupuestos' => "presupuestos", |
||
| 78 | 'provincia' => "provincia", 'apartado' => "apartado", 'cifnif' => "Cedula/RNC", |
||
| 79 | 'iva' => "ITBIS", 'numero2' => "NCF", 'serie' => "serie", 'series' => "series"); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function init_impuestos() |
||
| 83 | { |
||
| 84 | $this->impuestos_rd = array( |
||
| 85 | array('codigo' => 'ITBIS18', 'descripcion' => 'ITBIS 18%', 'porcentaje' => 18, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>true), |
||
| 86 | array('codigo' => 'ITBIS10', 'descripcion' => 'ITBIS 10%', 'porcentaje' => 10, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false), |
||
| 87 | array('codigo' => 'ITBIS8', 'descripcion' => 'ITBIS 8%', 'porcentaje' => 8, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false), |
||
| 88 | array('codigo' => 'EXENTO', 'descripcion' => 'EXENTO', 'porcentaje' => 0, 'recargo' => 0, 'subcuenta_compras' => '', 'subcuenta_ventas' => '', 'default'=>false) |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function init_router() |
||
| 93 | { |
||
| 94 | $opcion = \filter_input(INPUT_GET, 'opcion'); |
||
| 95 | switch ($opcion) { |
||
| 96 | case 'moneda': |
||
| 97 | $this->moneda(); |
||
| 98 | break; |
||
| 99 | case 'impuestos': |
||
| 100 | $this->impuestos(); |
||
| 101 | break; |
||
| 102 | case 'pais': |
||
| 103 | $this->pais(); |
||
| 104 | break; |
||
| 105 | case 'configuracion_regional': |
||
| 106 | $this->configuracion_regional(); |
||
| 107 | break; |
||
| 108 | case 'impresion': |
||
| 109 | $this->impresion(); |
||
| 110 | break; |
||
| 111 | default: |
||
| 112 | break; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Cargamos el menú en la base de datos, pero en varias pasadas. |
||
| 118 | */ |
||
| 119 | private function check_menu() |
||
| 120 | { |
||
| 121 | if (file_exists(__DIR__)) { |
||
| 122 | $max = 25; |
||
| 123 | |||
| 124 | /// leemos todos los controladores del plugin |
||
| 125 | foreach (scandir(__DIR__) as $f) { |
||
| 126 | if ($f != '.' and $f != '..' and is_string($f) and strlen($f) > 4 and ! is_dir($f) and $f != __CLASS__ . '.php') { |
||
| 127 | /// obtenemos el nombre |
||
| 128 | $page_name = substr($f, 0, -4); |
||
| 129 | |||
| 130 | /// lo buscamos en el menú |
||
| 131 | $encontrado = false; |
||
| 132 | foreach ($this->menu as $m) { |
||
| 133 | if ($m->name == $page_name) { |
||
| 134 | $encontrado = true; |
||
| 135 | break; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | if (!$encontrado) { |
||
| 140 | require_once __DIR__ . '/' . $f; |
||
| 141 | $new_fsc = new $page_name(); |
||
| 142 | |||
| 143 | if (!$new_fsc->page->save()) { |
||
| 144 | $this->new_error_msg("Imposible guardar la página " . $page_name); |
||
| 145 | } |
||
| 146 | |||
| 147 | unset($new_fsc); |
||
| 148 | |||
| 149 | if ($max > 0) { |
||
| 150 | $max--; |
||
| 151 | } else { |
||
| 152 | $this->recargar = true; |
||
| 153 | $this->new_message('Instalando las entradas al menú para el plugin... <i class="fa fa-refresh fa-spin"></i>'); |
||
| 154 | break; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } else { |
||
| 160 | $this->new_error_msg('No se encuentra el directorio ' . __DIR__); |
||
| 161 | } |
||
| 162 | |||
| 163 | $this->load_menu(true); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function impresion() |
||
| 167 | { |
||
| 168 | $fsvar = new fs_var(); |
||
| 169 | $op_imprimir_cabecera_fcolor = \filter_input(INPUT_POST, 'rd_imprimir_cabecera_fcolor'); |
||
| 170 | $op_imprimir_cabecera_tcolor = \filter_input(INPUT_POST, 'rd_imprimir_cabecera_tcolor'); |
||
| 171 | $op_imprimir_detalle_color = \filter_input(INPUT_POST, 'rd_imprimir_detalle_color'); |
||
| 172 | |||
| 173 | $rd_config = array( |
||
| 174 | 'rd_imprimir_logo' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_logo'), 'TRUE', 'FALSE'), |
||
| 175 | 'rd_imprimir_marca_agua' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_marca_agua'), 'TRUE', 'FALSE'), |
||
| 176 | 'rd_imprimir_sello_pagado' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_sello_pagado'), 'TRUE', 'FALSE'), |
||
| 177 | 'rd_imprimir_bn' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_bn'), 'TRUE', 'FALSE'), |
||
| 178 | 'rd_imprimir_cliente_box' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_cliente_box'), 'TRUE', 'FALSE'), |
||
| 179 | 'rd_imprimir_detalle_box' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_box'), 'TRUE', 'FALSE'), |
||
| 180 | 'rd_imprimir_detalle_lineas' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_lineas'), 'TRUE', 'FALSE'), |
||
| 181 | 'rd_imprimir_detalle_colores' => $this->setValor(\filter_input(INPUT_POST, 'rd_imprimir_detalle_lineas'), 'TRUE', 'FALSE'), |
||
| 182 | 'rd_imprimir_cabecera_fcolor' => $this->confirmarValor($op_imprimir_cabecera_fcolor, '#000000'), |
||
| 183 | 'rd_imprimir_cabecera_tcolor' => $this->confirmarValor($op_imprimir_cabecera_tcolor, '#dadada'), |
||
| 184 | 'rd_imprimir_detalle_color' => $this->confirmarValor($op_imprimir_detalle_color, '#000000') |
||
| 185 | ); |
||
| 186 | |||
| 187 | if ($fsvar->array_save($rd_config)) { |
||
| 188 | $this->new_message('Opciones de impresión actualizadas correctamente.'); |
||
| 189 | } else { |
||
| 190 | $this->new_error_msg('Ocurrió un error al intentar actualizar la información de impresión, por favor revise sus datos.'); |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | public function moneda() |
||
| 195 | { |
||
| 196 | $div0 = new divisa(); |
||
| 197 | $tratamiento = false; |
||
| 198 | //Validamos si existe la moneda DOP |
||
| 199 | $this->moneda_dop($div0, $tratamiento); |
||
| 200 | |||
| 201 | //Validamos si existe la moneda USD |
||
| 202 | //por temas de operaciones en dolares |
||
| 203 | $this->moneda_usd($div0, $tratamiento); |
||
| 204 | |||
| 205 | if ($tratamiento) { |
||
| 206 | $this->new_message('Datos de moneda DOP y USD actualizados correctamente.'); |
||
| 207 | } |
||
| 208 | |||
| 209 | if ($this->empresa->coddivisa != 'DOP') { |
||
| 210 | //Elegimos la divisa para la empresa como DOP si no esta generada |
||
| 211 | $this->empresa->coddivisa = 'DOP'; |
||
| 212 | if ($this->empresa->save()) { |
||
| 213 | $this->new_message('Datos de moneda para la empresa guardados correctamente.'); |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | private function moneda_dop($div0, &$tratamiento) |
||
| 219 | { |
||
| 220 | |||
| 221 | $divisa1 = $div0->get('DOP'); |
||
| 222 | if (!$divisa1) { |
||
| 223 | $div0->coddivisa = 'DOP'; |
||
| 224 | $div0->codiso = '214'; |
||
| 225 | $div0->descripcion = 'PESOS DOMINICANOS'; |
||
| 226 | $div0->simbolo = 'RD$'; |
||
| 227 | $div0->tasaconv = 57.1438; |
||
| 228 | $div0->tasaconv_compra = 57.1438; |
||
| 229 | $div0->save(); |
||
| 230 | } |
||
| 231 | $tratamiento = true; |
||
| 232 | } |
||
| 233 | |||
| 234 | private function moneda_usd($div0, &$tratamiento) |
||
| 235 | { |
||
| 236 | $divisa2 = $div0->get('USD'); |
||
| 237 | if (!$divisa2) { |
||
| 238 | $div0->coddivisa = 'USD'; |
||
| 239 | $div0->codiso = '840'; |
||
| 240 | $div0->descripcion = 'DÓLARES EE.UU.'; |
||
| 241 | $div0->simbolo = '$'; |
||
| 242 | $div0->tasaconv = 1; |
||
| 243 | $div0->tasaconv_compra = 1; |
||
| 244 | $div0->save(); |
||
| 245 | } |
||
| 246 | $tratamiento = true; |
||
| 247 | } |
||
| 248 | |||
| 249 | public function impuestos() |
||
| 250 | { |
||
| 251 | $impuestos = new impuesto(); |
||
| 252 | //Eliminamos los Impuestos que no son de RD |
||
| 253 | $lista_impuestos = array(); |
||
| 254 | foreach ($this->impuestos_rd as $imp) { |
||
| 255 | $lista_impuestos[] = $imp['porcentaje']; |
||
| 256 | } |
||
| 257 | |||
| 258 | foreach ($impuestos->all() as $imp) { |
||
| 259 | $imp->delete(); |
||
| 260 | } |
||
| 261 | $tratamiento=false; |
||
| 262 | //Agregamos los Impuestos de RD |
||
| 263 | $this->agregar_impuestos($tratamiento); |
||
| 264 | |||
| 265 | |||
| 266 | //Corregimos la información de las Cuentas especiales con los nombres correctos |
||
| 267 | $this->cuentas_especiales(); |
||
| 268 | |||
| 269 | //Cargamos el ejercicio configurando la longitud de cuentas a 8 |
||
| 270 | $this->corregir_ejercicio($tratamiento); |
||
| 271 | |||
| 272 | } |
||
| 273 | |||
| 274 | public function agregar_impuestos(&$tratamiento) |
||
| 275 | { |
||
| 276 | $impuestos = new impuesto(); |
||
| 277 | foreach ($this->impuestos_rd as $imp) { |
||
| 278 | if (!$impuestos->get_by_iva($imp['porcentaje'])) { |
||
| 279 | $imp0 = new impuesto(); |
||
| 280 | $imp0->codimpuesto = $imp['codigo']; |
||
| 281 | $imp0->descripcion = $imp['descripcion']; |
||
| 282 | $imp0->iva = $imp['porcentaje']; |
||
| 283 | $imp0->recargo = $imp['recargo']; |
||
| 284 | $imp0->codsubcuentasop = $imp['subcuenta_compras']; |
||
| 285 | $imp0->codsubcuentarep = $imp['subcuenta_ventas']; |
||
| 286 | $imp0->is_default(); |
||
| 287 | if ($imp0->save()) { |
||
| 288 | $tratamiento = true; |
||
| 289 | } |
||
| 290 | if($tratamiento===true AND $imp['default']){ |
||
| 291 | $this->save_codimpuesto($imp['codigo']); |
||
| 292 | } |
||
| 293 | } |
||
| 294 | } |
||
| 295 | } |
||
| 296 | |||
| 297 | public function corregir_ejercicio($tratamiento) |
||
| 298 | { |
||
| 299 | $cod = $this->empresa->codejercicio; |
||
| 300 | $ejer0 = new ejercicio(); |
||
| 301 | $ejer = $ejer0->get($cod); |
||
| 302 | $ejer->longsubcuenta = 8; |
||
| 303 | $ejer->save(); |
||
| 304 | |||
| 305 | if ($tratamiento) { |
||
| 306 | $this->new_message('Información de impuestos actualizada correctamente'); |
||
| 307 | } else { |
||
| 308 | $this->new_message('No se modificaron datos de impuestos previamente tratados.'); |
||
| 309 | } |
||
| 310 | } |
||
| 311 | |||
| 312 | private function cuentas_especiales() |
||
| 313 | { |
||
| 314 | $cuentas_especiales_rd = array(); |
||
| 315 | $cuentas_especiales_rd['IVAACR'] = 'Cuentas acreedoras de ITBIS en la regularización'; |
||
| 316 | $cuentas_especiales_rd['IVASOP'] = 'Cuentas de ITBIS Compras'; |
||
| 317 | $cuentas_especiales_rd['IVARXP'] = 'Cuentas de ITBIS exportaciones'; |
||
| 318 | $cuentas_especiales_rd['IVASIM'] = 'Cuentas de ITBIS importaciones'; |
||
| 319 | $cuentas_especiales_rd['IVAREX'] = 'Cuentas de ITBIS para clientes exentos'; |
||
| 320 | $cuentas_especiales_rd['IVAREP'] = 'Cuentas de ITBIS Ventas'; |
||
| 321 | $cuentas_especiales = new cuenta_especial(); |
||
| 322 | foreach ($cuentas_especiales_rd as $id => $desc) { |
||
| 323 | $linea = $cuentas_especiales->get($id); |
||
| 324 | if ($linea->descripcion !== $desc) { |
||
| 325 | $linea->descripcion = $desc; |
||
| 326 | $linea->save(); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | } |
||
| 330 | |||
| 331 | public function pais() |
||
| 353 | } |
||
| 354 | } |
||
| 355 | |||
| 356 | public function configuracion_regional() |
||
| 357 | { |
||
| 358 | //Configuramos la información básica para config2.ini |
||
| 359 | $guardar = false; |
||
| 360 | foreach ($GLOBALS['config2'] as $i => $value) { |
||
| 361 | if (isset($this->variables[$i])) { |
||
| 362 | $GLOBALS['config2'][$i] = $this->variables[$i]; |
||
| 363 | $guardar = true; |
||
| 364 | } |
||
| 365 | } |
||
| 366 | |||
| 367 | if ($guardar) { |
||
| 368 | $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w'); |
||
| 369 | if ($file) { |
||
| 370 | foreach ($GLOBALS['config2'] as $i => $value) { |
||
| 371 | if (is_numeric($value)) { |
||
| 372 | fwrite($file, $i . " = " . $value . ";\n"); |
||
| 373 | } else { |
||
| 374 | fwrite($file, $i . " = '" . $value . "';\n"); |
||
| 375 | } |
||
| 376 | } |
||
| 377 | fclose($file); |
||
| 378 | } |
||
| 379 | $this->new_message('Datos de configuracion regional guardados correctamente.'); |
||
| 380 | } |
||
| 381 | } |
||
| 382 | |||
| 383 | private function share_extensions() |
||
| 424 | } |
||
| 425 | } |
||
| 426 | } |
||
| 427 | } |
||
| 428 |
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