Total Complexity | 56 |
Total Lines | 326 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ver_residente 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 ver_residente, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class ver_residente extends residentes_controller |
||
32 | { |
||
33 | public $cliente; |
||
34 | public $cliente_data; |
||
35 | public $articulos; |
||
36 | public $articulos_cobrables; |
||
37 | public $familia; |
||
38 | public $familias; |
||
39 | public $facturas; |
||
40 | public $impuesto; |
||
41 | public $residente; |
||
42 | public $forma_pago; |
||
43 | public $lista_notas; |
||
44 | |||
45 | public function __construct() |
||
48 | } |
||
49 | |||
50 | public function initVars() |
||
60 | } |
||
61 | |||
62 | protected function private_core() |
||
63 | { |
||
64 | $this->initVars(); |
||
65 | |||
66 | if (\filter_input(INPUT_GET, 'id')) { |
||
67 | $res0 = new residentes_edificaciones(); |
||
68 | $this->residente = $res0->get(\filter_input(INPUT_GET, 'id')); |
||
69 | $this->cliente_data = $this->cliente->get($this->residente->codcliente); |
||
70 | $this->cliente_data->codcontacto = ''; |
||
71 | |||
72 | if (class_exists('contacto_cliente')) { |
||
73 | $concli = new contacto_cliente(); |
||
74 | $infoCRM = $concli->all_from_cliente($this->residente->codcliente); |
||
75 | $this->cliente_data->codcontacto = $infoCRM[0]->codcontacto; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | if ($this->residente) { |
||
80 | $accion = \filter_input(INPUT_POST, 'accion'); |
||
81 | if ($accion == 'generar_factura') { |
||
82 | $this->nueva_factura(); |
||
83 | } |
||
84 | $this->informacionResidente(); |
||
85 | } else { |
||
86 | $this->new_error_msg('Residente no encontrado.'); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | public function url() |
||
91 | { |
||
92 | if (\filter_input(INPUT_GET, 'id')) { |
||
93 | return $this->residente->url(); |
||
94 | } |
||
95 | return parent::url(); |
||
96 | } |
||
97 | |||
98 | public function informacionResidente() |
||
99 | { |
||
100 | $this->page->title = 'Residente ' . $this->residente->nombre; |
||
101 | $factura = new factura_cliente(); |
||
102 | $facts = $factura->all_from_cliente($this->residente->codcliente); |
||
103 | $this->facturas = array(); |
||
104 | $articulos_cobrados = array(); |
||
105 | |||
106 | foreach ($facts as $fac) { |
||
107 | $fac->referencias = ""; |
||
108 | foreach ($fac->get_lineas() as $linea) { |
||
109 | if ($linea->referencia) { |
||
110 | $fac->referencias .= $linea->referencia . " "; |
||
111 | $this->validarArticulos($articulos_cobrados, $fac, $linea); |
||
112 | } else { |
||
113 | $fac->referencias .= $linea->descripcion . " "; |
||
114 | } |
||
115 | } |
||
116 | $this->facturas[] = $fac; |
||
117 | } |
||
118 | $this->generarArticulosCobrables($articulos_cobrados); |
||
119 | } |
||
120 | |||
121 | public function validarArticulos(&$articulos_cobrados, &$fac, &$linea) |
||
122 | { |
||
123 | if (!$fac->idfacturarect) { |
||
124 | $rectificativas = $fac->get_rectificativas(); |
||
125 | $articulosDevueltos = array(); |
||
126 | $this->validarDevoluciones($articulosDevueltos, $rectificativas); |
||
127 | |||
128 | if (!isset($articulosDevueltos[$linea->referencia])) { |
||
129 | $articulos_cobrados[$linea->referencia] = 1; |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | public function validarDevoluciones(&$articulosDevueltos, $rectificativas) |
||
135 | { |
||
136 | foreach ($rectificativas as $rectificativa) { |
||
137 | $lineas_r = $rectificativa->get_lineas(); |
||
138 | foreach ($lineas_r as $linea_r) { |
||
139 | $articulosDevueltos[$linea_r->referencia] = 1; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | |||
144 | public function generarArticulosCobrables($articulos_cobrados) |
||
145 | { |
||
146 | foreach ($this->familia->get_articulos(0, 1000) as $art) { |
||
147 | if (!isset($articulos_cobrados[$art->referencia]) && $art->bloqueado == 0) { |
||
148 | $this->articulos_cobrables[] = $art; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | private function nueva_factura() |
||
154 | { |
||
155 | $cliente = $this->cliente->get($this->residente->codcliente); |
||
156 | if ($cliente) { |
||
157 | $factura = new factura_cliente(); |
||
158 | |||
159 | $this->cabeceraFactura($factura, $cliente); |
||
160 | |||
161 | $this->datosClienteFactura($factura, $cliente); |
||
162 | |||
163 | /// función auxiliar para implementar en los plugins que lo necesiten |
||
164 | if (!fs_generar_numero2($factura)) { |
||
165 | $factura->numero2 = ''; |
||
166 | } |
||
167 | if ($factura->save()) { |
||
168 | $this->lineasFactura($factura); |
||
169 | |||
170 | $this->lineasLibresFactura($factura, 'otro'); |
||
171 | $this->lineasLibresFactura($factura, 'otro2'); |
||
172 | |||
173 | $this->totalFactura($factura); |
||
174 | } else { |
||
175 | $this->new_error_msg('Imposible guardar la factura.'); |
||
176 | } |
||
177 | } else { |
||
178 | $this->new_error_msg('Cliente no encontrado.'); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | private function cabeceraFactura(&$factura, $cliente) |
||
183 | { |
||
184 | $factura->codserie = ($cliente->codserie) ?: $this->empresa->codserie; |
||
185 | $factura->codagente = $this->user->codagente; |
||
186 | $factura->codpago = \filter_input(INPUT_POST, 'forma_pago'); |
||
187 | $factura->codalmacen = $this->empresa->codalmacen; |
||
188 | $factura->set_fecha_hora($this->today(), $this->hour()); |
||
189 | $factura->observaciones = htmlentities(trim(\filter_input(INPUT_POST, 'observaciones'))); |
||
190 | $this->datosContabilidadFactura($factura, $cliente); |
||
191 | |||
192 | $div0 = new divisa(); |
||
1 ignored issue
–
show
|
|||
193 | $divisa = $div0->get($cliente->coddivisa); |
||
194 | if ($divisa) { |
||
195 | $factura->coddivisa = $divisa->coddivisa; |
||
196 | $factura->tasaconv = $divisa->tasaconv; |
||
197 | } |
||
198 | } |
||
199 | |||
200 | private function datosContabilidadFactura(&$factura, $cliente) |
||
201 | { |
||
202 | $eje0 = new ejercicio(); |
||
1 ignored issue
–
show
|
|||
203 | $ejercicio = $eje0->get_by_fecha(date('d-m-Y')); |
||
204 | if ($ejercicio) { |
||
205 | $factura->codejercicio = $ejercicio->codejercicio; |
||
206 | } |
||
207 | if ($this->empresa->contintegrada) { |
||
208 | $cliente->get_subcuenta($this->empresa->codejercicio); |
||
209 | } |
||
210 | |||
211 | $forma_pago = $this->forma_pago->get($factura->codpago); |
||
212 | if ($forma_pago->genrecibos === 'Pagados') { |
||
213 | $factura->pagada = true; |
||
214 | } |
||
215 | } |
||
216 | |||
217 | private function datosClienteFactura(&$factura, $cliente) |
||
218 | { |
||
219 | $factura->codcliente = $cliente->codcliente; |
||
220 | foreach ($cliente->get_direcciones() as $d) { |
||
221 | if ($d->domfacturacion) { |
||
222 | $factura->codcliente = $cliente->codcliente; |
||
223 | $factura->cifnif = $cliente->cifnif; |
||
224 | $factura->nombrecliente = $cliente->nombre; |
||
225 | $factura->apartado = $d->apartado; |
||
226 | $factura->ciudad = $d->ciudad; |
||
227 | $factura->coddir = $d->id; |
||
228 | $factura->codpais = $d->codpais; |
||
229 | $factura->codpostal = $d->codpostal; |
||
230 | $factura->direccion = $d->direccion; |
||
231 | $factura->provincia = $d->provincia; |
||
232 | break; |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | |||
237 | private function lineasFactura(&$factura) |
||
262 | } |
||
263 | } |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 | |||
268 | private function lineasLibresFactura(&$factura, $linea_nombre) |
||
293 | } |
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | |||
298 | private function totalFactura(&$factura) |
||
299 | { |
||
300 | /// redondeamos |
||
301 | $factura->neto = round($factura->neto, FS_NF0); |
||
1 ignored issue
–
show
|
|||
302 | $factura->totaliva = round($factura->totaliva, FS_NF0); |
||
303 | $factura->totalirpf = round($factura->totalirpf, FS_NF0); |
||
304 | $factura->totalrecargo = round($factura->totalrecargo, FS_NF0); |
||
305 | $factura->total = $factura->neto + $factura->totaliva - $factura->totalirpf + $factura->totalrecargo; |
||
306 | |||
307 | if (abs((float)(\filter_input(INPUT_POST, 'total_importe')) - $factura->total) > .01) { |
||
308 | $this->new_error_msg("El total difiere entre la vista y el controlador (" . |
||
309 | \filter_input(INPUT_POST, 'total_importe') . |
||
310 | " frente a " . $factura->total . "). Debes informar del error."); |
||
311 | $factura->delete(); |
||
312 | } elseif ($factura->save()) { |
||
313 | $this->generar_asiento($factura); |
||
314 | /// Función de ejecución de tareas post guardado correcto de la factura |
||
315 | fs_documento_post_save($factura); |
||
316 | $this->new_message("<a href='" . $factura->url() . "'>Factura</a> guardada correctamente."); |
||
317 | $this->new_change('Factura Cliente ' . $factura->codigo, $factura->url(), true); |
||
318 | } else { |
||
319 | $this->new_error_msg("¡Imposible actualizar la <a href='" . $factura->url() . "'>Factura</a>!"); |
||
320 | } |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Genera el asiento para la factura, si procede |
||
325 | * @param factura_cliente $factura |
||
326 | */ |
||
327 | private function generar_asiento(&$factura) |
||
335 | } |
||
336 | } |
||
337 | |||
338 | private function buscar_referencia() |
||
339 | { |
||
340 | /// desactivamos la plantilla HTML |
||
341 | $this->template = false; |
||
1 ignored issue
–
show
|
|||
342 | |||
343 | $articulo = new articulo(); |
||
344 | $json = array(); |
||
345 | foreach ($articulo->search($_REQUEST['buscar_referencia']) as $art) { |
||
359 |
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