| Total Complexity | 55 |
| Total Lines | 377 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like facturacion_residentes 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 facturacion_residentes, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class facturacion_residentes extends residentes_controller |
||
| 34 | { |
||
| 35 | public $printExtensions; |
||
| 36 | public $configuracionEmail; |
||
| 37 | public $edificaciones_tipo; |
||
| 38 | public $edificaciones_mapa; |
||
| 39 | public $familia; |
||
| 40 | public $familias; |
||
| 41 | public $impuesto; |
||
| 42 | public $mapa; |
||
| 43 | public $padre; |
||
| 44 | public $padre_interior; |
||
| 45 | public $referencia; |
||
| 46 | public $forma_pago; |
||
| 47 | public $loop_horas; |
||
| 48 | public $proxima_hora; |
||
| 49 | public $idProg; |
||
| 50 | public $programaciones; |
||
| 51 | public $programaciones_conceptos; |
||
| 52 | public $programaciones_edificaciones; |
||
| 53 | |||
| 54 | public function __construct() |
||
| 55 | { |
||
| 56 | parent::__construct(__CLASS__, 'Facturación Residentes', 'residentes', false, true); |
||
| 57 | } |
||
| 58 | |||
| 59 | protected function private_core() |
||
| 60 | { |
||
| 61 | parent::private_core(); |
||
| 62 | $this->shared_functions(); |
||
| 63 | $this->tratarAccion(); |
||
| 64 | |||
| 65 | $eCfg = new residentes_email_config(); |
||
| 66 | $this->configuracionEmail = $eCfg->currentConfig(); |
||
| 67 | $this->programaciones = new residentes_facturacion_programada(); |
||
| 68 | $this->programaciones_conceptos = new residentes_facturacion_programada_conceptos(); |
||
| 69 | $this->programaciones_edificaciones = new residentes_facturacion_programada_edificaciones(); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function init() |
||
| 73 | { |
||
| 74 | parent::init(); |
||
| 75 | $extensions = new fs_extension(); |
||
| 76 | $this->printExtensions = $extensions->all_to('ventas_factura'); |
||
| 77 | $this->forma_pago = new forma_pago(); |
||
|
|
|||
| 78 | $this->familia = new familia(); |
||
| 79 | $this->familias = $this->familia->get("RESIDENT"); |
||
| 80 | $this->impuesto = new impuesto(); |
||
| 81 | $this->loop_horas = []; |
||
| 82 | //Creamos un array para el selector de horas para cron |
||
| 83 | for ($x = 0; $x < 24; $x++) { |
||
| 84 | $this->loop_horas[] = str_pad($x, 2, "0", STR_PAD_LEFT); |
||
| 85 | } |
||
| 86 | $this->edificaciones_tipo = new residentes_edificaciones_tipo(); |
||
| 87 | $this->edificaciones_mapa = new residentes_edificaciones_mapa(); |
||
| 88 | $tipos = $this->edificaciones_tipo->all(); |
||
| 89 | $this->padre = $tipos[0]; |
||
| 90 | $this->mapa = $this->edificaciones_mapa->get_by_field('id_tipo', $this->padre->id); |
||
| 91 | $this->proxima_hora = date('H', strtotime('+1 hour')); |
||
| 92 | } |
||
| 93 | |||
| 94 | private function shared_functions() |
||
| 95 | { |
||
| 96 | $extensiones = array( |
||
| 97 | array( |
||
| 98 | 'name' => '001_facturacion_residentes', |
||
| 99 | 'page_from' => __CLASS__, |
||
| 100 | 'page_to' => __CLASS__, |
||
| 101 | 'type' => 'head', |
||
| 102 | 'text' => '<link rel="stylesheet" type="text/css" media="screen" href="' . FS_PATH . |
||
| 103 | 'plugins/residentes/view/css/bootstrap-select.min.css"/>', |
||
| 104 | 'params' => '' |
||
| 105 | ), |
||
| 106 | array( |
||
| 107 | 'name' => '002_facturacion_residentes', |
||
| 108 | 'page_from' => __CLASS__, |
||
| 109 | 'page_to' => __CLASS__, |
||
| 110 | 'type' => 'head', |
||
| 111 | 'text' => '<script src="'.FS_PATH. |
||
| 112 | 'plugins/residentes/view/js/bootstrap-select.min.js" type="text/javascript"></script>', |
||
| 113 | 'params' => '' |
||
| 114 | ), |
||
| 115 | array( |
||
| 116 | 'name' => '003_facturacion_residentes', |
||
| 117 | 'page_from' => __CLASS__, |
||
| 118 | 'page_to' => __CLASS__, |
||
| 119 | 'type' => 'head', |
||
| 120 | 'text' => '<script src="'.FS_PATH. |
||
| 121 | 'plugins/residentes/view/js/i18n/defaults-es_ES.min.js" type="text/javascript"></script>', |
||
| 122 | 'params' => '' |
||
| 123 | ), |
||
| 124 | array( |
||
| 125 | 'name' => '004_facturacion_residentes', |
||
| 126 | 'page_from' => __CLASS__, |
||
| 127 | 'page_to' => __CLASS__, |
||
| 128 | 'type' => 'head', |
||
| 129 | 'text' => '<script src="'.FS_PATH. |
||
| 130 | 'plugins/residentes/view/js/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.js" type="text/javascript"></script>', |
||
| 131 | 'params' => '' |
||
| 132 | ), |
||
| 133 | array( |
||
| 134 | 'name' => '005_facturacion_residentes', |
||
| 135 | 'page_from' => __CLASS__, |
||
| 136 | 'page_to' => __CLASS__, |
||
| 137 | 'type' => 'head', |
||
| 138 | 'text' => '<script src="'.FS_PATH. |
||
| 139 | 'plugins/residentes/view/js/bootstrap-wysihtml5/locales/bootstrap-wysihtml5.es-ES.js" type="text/javascript"></script>', |
||
| 140 | 'params' => '' |
||
| 141 | ), |
||
| 142 | array( |
||
| 143 | 'name' => '006_facturacion_residentes', |
||
| 144 | 'page_from' => __CLASS__, |
||
| 145 | 'page_to' => __CLASS__, |
||
| 146 | 'type' => 'head', |
||
| 147 | 'text' => '<link rel="stylesheet" type="text/css" media="screen" href="' . FS_PATH . |
||
| 148 | 'plugins/residentes/view/js/bootstrap-wysihtml5/bootstrap3-wysihtml5.css"/>', |
||
| 149 | 'params' => '' |
||
| 150 | ), |
||
| 151 | |||
| 152 | ); |
||
| 153 | |||
| 154 | foreach ($extensiones as $ext) { |
||
| 155 | $fsext0 = new fs_extension($ext); |
||
| 156 | if (!$fsext0->save()) { |
||
| 157 | $this->new_error_msg('Imposible guardar los datos de la extensión ' . $ext['name'] . '.'); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | public function tratarAccion() |
||
| 163 | { |
||
| 164 | $accion = $this->filter_request('accion'); |
||
| 165 | switch ($accion) { |
||
| 166 | case "nueva_programacion": |
||
| 167 | $this->template = 'block/nueva_programacion_facturacion'; |
||
| 168 | break; |
||
| 169 | case "configurar_metodo_envio": |
||
| 170 | $this->template = 'block/configurar_metodo_envio'; |
||
| 171 | break; |
||
| 172 | case "guardar_configuracion_envio": |
||
| 173 | $this->guardarConfiguracionMetodoEnvio(); |
||
| 174 | break; |
||
| 175 | case "guardar_programacion": |
||
| 176 | $this->guardarProgramacion(); |
||
| 177 | break; |
||
| 178 | case "eliminar_programacion": |
||
| 179 | $this->eliminarProgramacion(); |
||
| 180 | break; |
||
| 181 | case "reiniciar_programacion": |
||
| 182 | $this->reiniciarProgramacion(); |
||
| 183 | break; |
||
| 184 | case "lista_programacion": |
||
| 185 | $this->listaProgramacion(); |
||
| 186 | break; |
||
| 187 | case "test_email": |
||
| 188 | $this->testEmail(); |
||
| 189 | break; |
||
| 190 | default: |
||
| 191 | break; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | public function listaProgramacion() |
||
| 196 | { |
||
| 197 | $idProgramacion = $this->filter_request('idprogramacion'); |
||
| 198 | $this->template = 'block/lista_programacion_facturacion'; |
||
| 199 | $rfpe = new residentes_facturacion_programada_edificaciones(); |
||
| 200 | $this->lista_programaciones = $rfpe->get_lista_edificaciones($idProgramacion); |
||
| 201 | $this->idProg = $idProgramacion; |
||
| 202 | } |
||
| 203 | |||
| 204 | public function eliminarProgramacion() |
||
| 205 | { |
||
| 206 | $estado = false; |
||
| 207 | $idProgramacion = $this->filter_request('idprogramacion'); |
||
| 208 | if ($this->user->allow_delete_on(__CLASS__) && isset($idProgramacion) && $idProgramacion !== '') { |
||
| 209 | $programaciones = new residentes_facturacion_programada(); |
||
| 210 | $programa = $programaciones->get($idProgramacion); |
||
| 211 | if ($programa) { |
||
| 212 | $estado = $programa->delete(); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | if ($estado === true) { |
||
| 216 | $this->new_message('Programación eliminada correctamente.'); |
||
| 217 | } else { |
||
| 218 | $this->new_error_msg('La Programación no pudo ser eliminada, verifique los datos o sus permisos.'); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | public function reiniciarProgramacion() |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | public function guardarConfiguracionMetodoEnvio() |
||
| 244 | { |
||
| 245 | $this->template = 'block/configurar_metodo_envio'; |
||
| 246 | $id = $this->filter_request('id'); |
||
| 247 | $tiposervicio = $this->filter_request('tiposervicio'); |
||
| 248 | $apikey = $this->filter_request('apikey'); |
||
| 249 | $apisecret = $this->filter_request('apisecret'); |
||
| 250 | $apisenderemail = $this->filter_request('apisenderemail'); |
||
| 251 | $apisendername = $this->filter_request('apisendername'); |
||
| 252 | $emailsubject = stripslashes(htmlentities($this->filter_request('emailsubject'))); |
||
| 253 | $remcfg = new residentes_email_config(); |
||
| 254 | $remcfg->id = $id; |
||
| 255 | $remcfg->tiposervicio = $tiposervicio; |
||
| 256 | $remcfg->apikey = $apikey; |
||
| 257 | $remcfg->apisecret = $apisecret; |
||
| 258 | $remcfg->apisenderemail = $apisenderemail; |
||
| 259 | $remcfg->apisendername = $apisendername; |
||
| 260 | $remcfg->emailsubject = $emailsubject; |
||
| 261 | $remcfg->fecha_creacion = \date('Y-m-d h:i:s'); |
||
| 262 | $remcfg->usuario_creacion = $this->user->nick; |
||
| 263 | $remcfg->fecha_modificacion = \date('Y-m-d h:i:s'); |
||
| 264 | $remcfg->usuario_modificacion = $this->user->nick; |
||
| 265 | return $remcfg->save(); |
||
| 266 | $this->new_message('Configuración de envio guardada.'); |
||
| 267 | } |
||
| 268 | |||
| 269 | public function testEmail() |
||
| 270 | { |
||
| 271 | $this->template = false; |
||
| 272 | header('Content-Type: application/json'); |
||
| 273 | $cfg = new residentes_email_config(); |
||
| 274 | $actualConfig = $cfg->currentConfig(); |
||
| 275 | $envioMails = new ResidentesEnviarMail(); |
||
| 276 | switch($actualConfig->tiposervicio) { |
||
| 277 | case "mailjet": |
||
| 278 | echo $envioMails->mailjetEmailTest(); |
||
| 279 | break; |
||
| 280 | case "sendgrid": |
||
| 281 | echo $envioMails->sendgridEmailTest(); |
||
| 282 | break; |
||
| 283 | case "interno": default: |
||
| 284 | echo $envioMails->internalEmailTest(); |
||
| 285 | break; |
||
| 286 | } |
||
| 287 | |||
| 288 | } |
||
| 289 | |||
| 290 | public function guardarProgramacion() |
||
| 291 | { |
||
| 292 | $residentesProcesar = $this->cantidadResidentesProcesar(); |
||
| 293 | $cantidadResidentesProcesar = count($residentesProcesar); |
||
| 294 | $idProgramacion = $this->cabeceraProgramacion($cantidadResidentesProcesar); |
||
| 295 | |||
| 296 | if ($idProgramacion) { |
||
| 297 | $this->detalleProgramacion($idProgramacion); |
||
| 298 | $this->edificacionesProgramacion($idProgramacion, $residentesProcesar); |
||
| 299 | } |
||
| 300 | $this->new_message('¡Programación generada!'); |
||
| 301 | } |
||
| 302 | |||
| 303 | private function cabeceraProgramacion($cantidadResidentesProcesar) |
||
| 304 | { |
||
| 305 | //Cabecera de Programacion |
||
| 306 | $id = $this->filter_request('id'); |
||
| 307 | $descripcion = $this->filter_request('descripcion'); |
||
| 308 | $tipo_programacion = $this->filter_request('tipo_programacion'); |
||
| 309 | $forma_pago = $this->filter_request('forma_pago'); |
||
| 310 | $fecha_vencimiento = $this->filter_request('fecha_vencimiento'); |
||
| 311 | $fecha_envio = $this->filter_request('fecha_envio'); |
||
| 312 | $hora_envio = $this->filter_request('hora_envio'); |
||
| 313 | |||
| 314 | $rfp = new residentes_facturacion_programada(); |
||
| 315 | $rfp->id = (isset($id) && $id !== '') ? $id : null; |
||
| 316 | $rfp->descripcion = htmlentities(trim($descripcion)); |
||
| 317 | $rfp->tipo_programacion = $tipo_programacion; |
||
| 318 | $rfp->forma_pago = $forma_pago; |
||
| 319 | $rfp->fecha_vencimiento = $fecha_vencimiento; |
||
| 320 | $rfp->fecha_envio = $fecha_envio; |
||
| 321 | $rfp->hora_envio = $hora_envio; |
||
| 322 | $rfp->residentes_facturar = $cantidadResidentesProcesar; |
||
| 323 | $rfp->estado = 'ENCOLA'; |
||
| 324 | $rfp->fecha_creacion = \date('Y-m-d h:i:s'); |
||
| 325 | $rfp->usuario_creacion = $this->user->nick; |
||
| 326 | $rfp->fecha_modificacion = \date('Y-m-d h:i:s'); |
||
| 327 | $rfp->usuario_modificacion = $this->user->nick; |
||
| 328 | |||
| 329 | return $rfp->save(); |
||
| 330 | } |
||
| 331 | |||
| 332 | public function detalleProgramacion($idProgramacion) |
||
| 333 | { |
||
| 334 | $referencias = $this->filter_request_array('referencia'); |
||
| 335 | $cantidades = $this->filter_request_array('cantidad'); |
||
| 336 | $pvps = $this->filter_request_array('pvp'); |
||
| 337 | $impuestos = $this->filter_request_array('impuesto'); |
||
| 338 | $importes = $this->filter_request_array('importe'); |
||
| 339 | foreach ($referencias as $id => $referencia) { |
||
| 340 | $rfpc = new residentes_facturacion_programada_conceptos(); |
||
| 341 | $rfpc->idprogramacion = $idProgramacion; |
||
| 342 | $rfpc->referencia = $referencia; |
||
| 343 | $rfpc->cantidad = $cantidades[$id]; |
||
| 344 | $rfpc->pvp = $pvps[$id]; |
||
| 345 | $rfpc->codimpuesto = $impuestos[$id]; |
||
| 346 | $rfpc->importe = $importes[$id]; |
||
| 347 | if (!$rfpc->save()) { |
||
| 348 | $this->new_error_msg('¡Ocurrió un error al grabar el concepto con codigo: '.$referencia); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | return true; |
||
| 352 | } |
||
| 353 | |||
| 354 | public function edificacionesProgramacion($idProgramacion, $residentesProcesar) |
||
| 355 | { |
||
| 356 | $edificaciones_residentes = new residentes_edificaciones(); |
||
| 357 | foreach ($residentesProcesar as $codcliente => $datos) { |
||
| 358 | $data_edificacion = $edificaciones_residentes->get_by_field('codcliente', $codcliente); |
||
| 359 | $rfpe = new residentes_facturacion_programada_edificaciones(); |
||
| 360 | $rfpe->idprogramacion = $idProgramacion; |
||
| 361 | $rfpe->codcliente = $codcliente; |
||
| 362 | $rfpe->id_edificacion = $data_edificacion[0]->id; |
||
| 363 | $rfpe->save(); |
||
| 364 | } |
||
| 365 | } |
||
| 366 | |||
| 367 | private function cantidadResidentesProcesar() |
||
| 379 | } |
||
| 380 | |||
| 381 | private function cargarResidentesEdificacion($edificacion, &$listaResidentes) |
||
| 382 | { |
||
| 383 | $residentesDisponibles = []; |
||
| 384 | $edificaciones_residentes = new residentes_edificaciones(); |
||
| 385 | $edificacionesDisponibles = $edificaciones_residentes->get_by_field('id_edificacion', $edificacion); |
||
| 392 | } |
||
| 393 | |||
| 394 | private function cargarResidentesFacturables($residentesDisponibles, &$listaResidentes) |
||
| 395 | { |
||
| 396 | foreach ($residentesDisponibles as $datosResidente) { |
||
| 397 | $this->generarPrefacturacion($datosResidente['codcliente'], $listaResidentes); |
||
| 398 | } |
||
| 399 | } |
||
| 400 | |||
| 401 | private function generarPrefacturacion($codcliente, &$listaResidentes) |
||
| 410 | } |
||
| 411 | } |
||
| 412 | } |
||
| 413 | } |
||
| 414 |
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