@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @author Joe Nilson <joenilson at gmail.com> |
23 | 23 | */ |
24 | -class residentes_edificaciones extends \fs_model{ |
|
24 | +class residentes_edificaciones extends \fs_model { |
|
25 | 25 | /** |
26 | 26 | * El Id de la de edificacion |
27 | 27 | * @var integer serial |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | public $cliente_info; |
96 | 96 | public $cliente_vehiculo; |
97 | 97 | public function __construct($t = FALSE) { |
98 | - parent::__construct('residentes_edificaciones','plugins/residentes'); |
|
99 | - if($t){ |
|
98 | + parent::__construct('residentes_edificaciones', 'plugins/residentes'); |
|
99 | + if ($t) { |
|
100 | 100 | $this->id = $t['id']; |
101 | 101 | $this->iddireccion = $t['iddireccion']; |
102 | 102 | $this->id_edificacion = $t['id_edificacion']; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $this->ocupado = $this->str2bool($t['ocupado']); |
110 | 110 | $this->fecha_ocupacion = $t['fecha_ocupacion']; |
111 | 111 | $this->fecha_disponibilidad = $t['fecha_disponibilidad']; |
112 | - }else{ |
|
112 | + }else { |
|
113 | 113 | $this->id = null; |
114 | 114 | $this->iddireccion = 0; |
115 | 115 | $this->id_edificacion = null; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | if (!is_null($this->id)) { |
149 | 149 | return FS_PATH.'index.php?page=ver_residente&id='.$this->id; |
150 | - } else { |
|
150 | + }else { |
|
151 | 151 | return FS_PATH.'index.php?page=residentes'; |
152 | 152 | } |
153 | 153 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $lista[] = $item; |
178 | 178 | } |
179 | 179 | return $lista; |
180 | - } else { |
|
180 | + }else { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | } |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | return $this->listaInfo($data); |
199 | 199 | } |
200 | 200 | |
201 | - public function get($id){ |
|
201 | + public function get($id) { |
|
202 | 202 | $sql = "SELECT * FROM ".$this->table_name." WHERE id = ".$this->intval($id).";"; |
203 | 203 | $data = $this->db->select($sql); |
204 | - if($data){ |
|
204 | + if ($data) { |
|
205 | 205 | $item = new residentes_edificaciones($data[0]); |
206 | 206 | $item->pertenencia = $this->pertenencia($item); |
207 | 207 | $this->info($item); |
208 | 208 | return $item; |
209 | - }else{ |
|
209 | + }else { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | } |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | * @param string $value |
218 | 218 | * @return boolean|\FacturaScripts\model\residentes_edificaciones |
219 | 219 | */ |
220 | - public function get_by_field($field,$value){ |
|
221 | - $query = (is_string($value))?$this->var2str($value):$this->intval($value); |
|
220 | + public function get_by_field($field, $value) { |
|
221 | + $query = (is_string($value)) ? $this->var2str($value) : $this->intval($value); |
|
222 | 222 | $sql = "SELECT * FROM ".$this->table_name." WHERE ".strtoupper(trim($field))." = ".$query. |
223 | 223 | " ORDER BY codigo_interno,numero;"; |
224 | 224 | $data = $this->db->select($sql); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | { |
230 | 230 | if (is_null($this->id)) { |
231 | 231 | return false; |
232 | - } else { |
|
232 | + }else { |
|
233 | 233 | return $this->get($this->id); |
234 | 234 | } |
235 | 235 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | "ocupado = ".$this->var2str($this->ocupado)." ". |
252 | 252 | "WHERE id = ".$this->intval($this->id).";"; |
253 | 253 | return $this->db->exec($sql); |
254 | - } else { |
|
254 | + }else { |
|
255 | 255 | $sql = "INSERT INTO ".$this->table_name." (id_edificacion, iddireccion, codigo, codigo_interno, numero, ubicacion, coordenadas,codcliente, ocupado, fecha_ocupacion, fecha_disponibilidad) VALUES (". |
256 | 256 | $this->intval($this->id_edificacion).", ". |
257 | 257 | $this->intval($this->iddireccion).", ". |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $this->var2str($this->fecha_disponibilidad).");"; |
267 | 267 | if ($this->db->exec($sql)) { |
268 | 268 | return $this->db->lastval(); |
269 | - } else { |
|
269 | + }else { |
|
270 | 270 | return false; |
271 | 271 | } |
272 | 272 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | public function buscar_ubicacion_inmueble($id, $linea) |
310 | 310 | { |
311 | - $inicio_busqueda = ($linea===0)?"{\"":"{%\""; |
|
311 | + $inicio_busqueda = ($linea === 0) ? "{\"" : "{%\""; |
|
312 | 312 | $sql = "SELECT * FROM ".$this->table_name." WHERE codigo_interno LIKE '". |
313 | 313 | $inicio_busqueda.$id."\":%}' ORDER BY codigo;"; |
314 | 314 | $data = $this->db->select($sql); |
@@ -319,14 +319,14 @@ discard block |
||
319 | 319 | $lista[] = $this->pertenencia($l); |
320 | 320 | } |
321 | 321 | return $lista; |
322 | - } else { |
|
322 | + }else { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | - public function buscar_cantidad_inmuebles($id,$linea) |
|
327 | + public function buscar_cantidad_inmuebles($id, $linea) |
|
328 | 328 | { |
329 | - $inicio_busqueda = ($linea===0)?"{\"":"{%\""; |
|
329 | + $inicio_busqueda = ($linea === 0) ? "{\"" : "{%\""; |
|
330 | 330 | $sql = "SELECT DISTINCT codigo FROM ".$this->table_name." WHERE codigo_interno LIKE '". |
331 | 331 | $inicio_busqueda.$id."\":%}' ORDER BY codigo;"; |
332 | 332 | $data = $this->db->select($sql); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $lista[] = $l; |
338 | 338 | } |
339 | 339 | return $lista; |
340 | - } else { |
|
340 | + }else { |
|
341 | 341 | return false; |
342 | 342 | } |
343 | 343 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $data = $this->db->select($sql); |
350 | 350 | if ($data) { |
351 | 351 | return $data[0]['cantidad']; |
352 | - } else { |
|
352 | + }else { |
|
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | $mapa = array(); |
361 | 361 | $linea = 0; |
362 | 362 | foreach ($edificaciones_tipo->all() as $data) { |
363 | - if ($linea===1) { |
|
363 | + if ($linea === 1) { |
|
364 | 364 | break; |
365 | 365 | } |
366 | 366 | $items = $this->buscar_cantidad_inmuebles($data->id, $data->padre); |
@@ -376,19 +376,19 @@ discard block |
||
376 | 376 | { |
377 | 377 | $sql = "SELECT * FROM ".$this->table_name." WHERE "; |
378 | 378 | $OR = ""; |
379 | - if ($type=='inmueble') { |
|
380 | - $sql.=" numero LIKE '%".strtoupper($query)."%' "; |
|
381 | - $sql.=" OR codigo LIKE '%".strtoupper($query)."%' "; |
|
382 | - } else { |
|
379 | + if ($type == 'inmueble') { |
|
380 | + $sql .= " numero LIKE '%".strtoupper($query)."%' "; |
|
381 | + $sql .= " OR codigo LIKE '%".strtoupper($query)."%' "; |
|
382 | + }else { |
|
383 | 383 | if (is_int($query)) { |
384 | - $sql.=" id_edificacion LIKE '%".$query."%' "; |
|
385 | - $sql.=" id LIKE '%".$query."%' "; |
|
384 | + $sql .= " id_edificacion LIKE '%".$query."%' "; |
|
385 | + $sql .= " id LIKE '%".$query."%' "; |
|
386 | 386 | $OR = "OR"; |
387 | 387 | } |
388 | - $sql.=" $OR numero LIKE '%".strtoupper($query)."%' "; |
|
389 | - $sql.=" OR codigo LIKE '%".strtoupper($query)."%' "; |
|
388 | + $sql .= " $OR numero LIKE '%".strtoupper($query)."%' "; |
|
389 | + $sql .= " OR codigo LIKE '%".strtoupper($query)."%' "; |
|
390 | 390 | } |
391 | - $sql.=" ORDER BY codigo,numero"; |
|
391 | + $sql .= " ORDER BY codigo,numero"; |
|
392 | 392 | $data = $this->db->select($sql); |
393 | 393 | $lista = array(); |
394 | 394 | if ($data) { |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | " order by ".$sort." ".$order; |
469 | 469 | if ($todo) { |
470 | 470 | $data = $this->db->select($sql); |
471 | - } else { |
|
471 | + }else { |
|
472 | 472 | $data = $this->db->select_limit($sql, $limit, $offset); |
473 | 473 | } |
474 | 474 | $sql_cantidad = "select count(r.id) as total from residentes_edificaciones as r ". |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | " order by ".$sort." ".$order; |
507 | 507 | if ($todo) { |
508 | 508 | $data = $this->db->select($sql); |
509 | - } else { |
|
509 | + }else { |
|
510 | 510 | $data = $this->db->select_limit($sql, $limit, $offset); |
511 | 511 | } |
512 | 512 | |
513 | 513 | $sql_cantidad = "select count(r.id) as total from residentes_edificaciones as r"; |
514 | 514 | if ($whereSQL) { |
515 | - $sql_cantidad.=" WHERE r.codigo!='' ".$whereSQL; |
|
515 | + $sql_cantidad .= " WHERE r.codigo!='' ".$whereSQL; |
|
516 | 516 | } |
517 | 517 | $data_cantidad = $this->db->select($sql_cantidad); |
518 | 518 | return array($data, $data_cantidad[0]['total']); |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | " order by ".$sort." ".$order; |
551 | 551 | if ($todo) { |
552 | 552 | $data = $this->db->select($sql); |
553 | - } else { |
|
553 | + }else { |
|
554 | 554 | $data = $this->db->select_limit($sql, $limit, $offset); |
555 | 555 | } |
556 | 556 | |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | */ |
567 | 567 | public function totalFacturas() |
568 | 568 | { |
569 | - $sql = "SELECT count(idfactura) as total from facturascli where codcliente = ". $this->codcliente ." and anulada = false;"; |
|
569 | + $sql = "SELECT count(idfactura) as total from facturascli where codcliente = ".$this->codcliente." and anulada = false;"; |
|
570 | 570 | $data = $this->db->select($sql); |
571 | 571 | return $data[0]['total']; |
572 | 572 | } |
@@ -574,33 +574,33 @@ discard block |
||
574 | 574 | public function facturas_from_cliente($orden) |
575 | 575 | { |
576 | 576 | $sql = "SELECT ". |
577 | - "fa.codcliente, fa.idfactura, fa.numero2, fa.codigo, fa.fecha, fa.vencimiento, " . |
|
578 | - "fa.observaciones, fa.idfacturarect, fa.pagada as estadopago, fa.pagada, " . |
|
579 | - "fa.total, fa.referencia, fa.descripcion, fa.cantidad, fa.pvptotal, " . |
|
580 | - "d.numero2, d.idfacturarect, " . |
|
581 | - "COALESCE(d.cantidad,0) as cantidaddev, COALESCE(d.pvptotal,0) as pvptotaldev, " . |
|
582 | - "(COALESCE(fa.cantidad,0)+COALESCE(d.cantidad,0)) as qdadfinal, " . |
|
583 | - "(COALESCE(fa.pvptotal,0)+COALESCE(d.pvptotal,0)) as pvpfinal " . |
|
584 | - "FROM " . |
|
585 | - "(SELECT f.codcliente, f.idfactura, f.numero2, f.codigo, f.fecha, f.vencimiento, f.observaciones, f.idfacturarect, " . |
|
586 | - "(CASE WHEN f.pagada = true THEN 'Pagada' ELSE 'Pendiente' END) AS pagada, f.total, " . |
|
587 | - "lf.referencia, lf.descripcion, lf.cantidad, lf.pvptotal " . |
|
588 | - "FROM facturascli as f " . |
|
589 | - "LEFT JOIN lineasfacturascli as lf ON (lf.idfactura = f.idfactura) " . |
|
590 | - "WHERE f.anulada = false " . |
|
591 | - "order by f.fecha ". $orden .", f.idfactura ". $orden .") AS fa " . |
|
592 | - "LEFT OUTER JOIN " . |
|
593 | - "(SELECT f2.codcliente, f2.idfactura, f2.numero2, f2.codigo, f2.fecha, f2.idfacturarect, " . |
|
594 | - "(CASE WHEN f2.pagada = true THEN 'Pagada' ELSE 'Pendiente' END) AS pagada, f2.total, " . |
|
595 | - "lf2.referencia, lf2.descripcion, lf2.cantidad, lf2.pvptotal " . |
|
596 | - "FROM facturascli as f2 " . |
|
597 | - "LEFT JOIN lineasfacturascli as lf2 ON (lf2.idfactura = f2.idfactura) " . |
|
598 | - "WHERE f2.anulada = false and f2.codcliente = '". $this->codcliente ."' and f2.idfacturarect is not null " . |
|
599 | - ") AS d " . |
|
600 | - "ON (fa.idfactura = d.idfacturarect AND fa.referencia = d.referencia) " . |
|
601 | - "WHERE " . |
|
602 | - "fa.codcliente = '". $this->codcliente ."' " . |
|
603 | - "order by fa.fecha ". $orden .", fa.idfactura ". $orden .";"; |
|
577 | + "fa.codcliente, fa.idfactura, fa.numero2, fa.codigo, fa.fecha, fa.vencimiento, ". |
|
578 | + "fa.observaciones, fa.idfacturarect, fa.pagada as estadopago, fa.pagada, ". |
|
579 | + "fa.total, fa.referencia, fa.descripcion, fa.cantidad, fa.pvptotal, ". |
|
580 | + "d.numero2, d.idfacturarect, ". |
|
581 | + "COALESCE(d.cantidad,0) as cantidaddev, COALESCE(d.pvptotal,0) as pvptotaldev, ". |
|
582 | + "(COALESCE(fa.cantidad,0)+COALESCE(d.cantidad,0)) as qdadfinal, ". |
|
583 | + "(COALESCE(fa.pvptotal,0)+COALESCE(d.pvptotal,0)) as pvpfinal ". |
|
584 | + "FROM ". |
|
585 | + "(SELECT f.codcliente, f.idfactura, f.numero2, f.codigo, f.fecha, f.vencimiento, f.observaciones, f.idfacturarect, ". |
|
586 | + "(CASE WHEN f.pagada = true THEN 'Pagada' ELSE 'Pendiente' END) AS pagada, f.total, ". |
|
587 | + "lf.referencia, lf.descripcion, lf.cantidad, lf.pvptotal ". |
|
588 | + "FROM facturascli as f ". |
|
589 | + "LEFT JOIN lineasfacturascli as lf ON (lf.idfactura = f.idfactura) ". |
|
590 | + "WHERE f.anulada = false ". |
|
591 | + "order by f.fecha ".$orden.", f.idfactura ".$orden.") AS fa ". |
|
592 | + "LEFT OUTER JOIN ". |
|
593 | + "(SELECT f2.codcliente, f2.idfactura, f2.numero2, f2.codigo, f2.fecha, f2.idfacturarect, ". |
|
594 | + "(CASE WHEN f2.pagada = true THEN 'Pagada' ELSE 'Pendiente' END) AS pagada, f2.total, ". |
|
595 | + "lf2.referencia, lf2.descripcion, lf2.cantidad, lf2.pvptotal ". |
|
596 | + "FROM facturascli as f2 ". |
|
597 | + "LEFT JOIN lineasfacturascli as lf2 ON (lf2.idfactura = f2.idfactura) ". |
|
598 | + "WHERE f2.anulada = false and f2.codcliente = '".$this->codcliente."' and f2.idfacturarect is not null ". |
|
599 | + ") AS d ". |
|
600 | + "ON (fa.idfactura = d.idfacturarect AND fa.referencia = d.referencia) ". |
|
601 | + "WHERE ". |
|
602 | + "fa.codcliente = '".$this->codcliente."' ". |
|
603 | + "order by fa.fecha ".$orden.", fa.idfactura ".$orden.";"; |
|
604 | 604 | $data = $this->db->select($sql); |
605 | 605 | $list = []; |
606 | 606 | if ($data) { |