joenilson /
residentes
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Copyright (C) 2018 Joe Nilson <joenilson at gmail.com> |
||
| 4 | * |
||
| 5 | * This program is free software: you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU Lesser General Public License as published by |
||
| 7 | * the Free Software Foundation, either version 3 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU Lesser General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU Lesser General Public License |
||
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 17 | */ |
||
| 18 | /** |
||
| 19 | * Description of residentes_controller |
||
| 20 | * |
||
| 21 | * @author Joe Nilson <joenilson at gmail.com> |
||
| 22 | */ |
||
| 23 | class residentes_controller extends fs_controller |
||
| 24 | { |
||
| 25 | public $cliente_residente; |
||
| 26 | public $clientes; |
||
| 27 | public $edificaciones; |
||
| 28 | public $desde; |
||
| 29 | public $hasta; |
||
| 30 | public $tesoreria; |
||
| 31 | public $CRM_plugin; |
||
| 32 | public $RD_plugin; |
||
| 33 | |||
| 34 | protected function private_core() |
||
| 35 | { |
||
| 36 | parent::private_core(); |
||
| 37 | $this->init(); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function generar_tipo_doc($tipo_documento) |
||
| 41 | { |
||
| 42 | return ucfirst(str_replace('_', ' ', $tipo_documento)); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @throws Exception |
||
| 47 | */ |
||
| 48 | public function diasAtraso($f1, $f2) |
||
| 49 | { |
||
| 50 | $date1 = new \DateTime($f1); |
||
| 51 | $date2 = new \DateTime($f2); |
||
| 52 | return $date2->diff($date1)->format("%a"); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function existe_tesoreria() |
||
| 56 | { |
||
| 57 | $this->tesoreria = false; |
||
| 58 | $this->CRM_plugin = false; |
||
| 59 | $this->RD_plugin = false; |
||
| 60 | //revisamos si esta el plugin de tesoreria |
||
| 61 | $disabled = array(); |
||
| 62 | if (defined('FS_DISABLED_PLUGINS')) { |
||
| 63 | foreach (explode(',', FS_DISABLED_PLUGINS) as $aux) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 64 | $disabled[] = $aux; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (in_array('tesoreria', $GLOBALS['plugins'], true) && !in_array('tesoreria', $disabled, true)) { |
||
| 69 | $this->tesoreria = true; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (in_array('CRM', $GLOBALS['plugins'], true) && !in_array('CRM', $disabled, true)) { |
||
| 73 | $this->CRM_plugin = true; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (in_array('republica_dominicana', $GLOBALS['plugins'], true) |
||
| 77 | && !in_array('republica_dominicana', $disabled, true)) { |
||
| 78 | $this->RD_plugin = true; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Función para devolver el valor de una variable pasada ya sea por POST o GET |
||
| 84 | * @param string $nombre |
||
| 85 | * @return string|boolean |
||
| 86 | */ |
||
| 87 | public function filter_request($nombre) |
||
| 88 | { |
||
| 89 | $nombre_post = \filter_input(INPUT_POST, $nombre); |
||
| 90 | $nombre_get = \filter_input(INPUT_GET, $nombre); |
||
| 91 | return ($nombre_post) ?: $nombre_get; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $nombre |
||
| 96 | * @return string|boolean |
||
| 97 | */ |
||
| 98 | public function filter_request_array($nombre) |
||
| 99 | { |
||
| 100 | $nombre_post = \filter_input(INPUT_POST, $nombre, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
||
| 101 | $nombre_get = \filter_input(INPUT_GET, $nombre, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
||
| 102 | return ($nombre_post) ?: $nombre_get; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function init() |
||
| 106 | { |
||
| 107 | $this->clientes = new cliente(); |
||
| 108 | $this->edificaciones = new residentes_edificaciones(); |
||
| 109 | $this->init_templates(); |
||
| 110 | $this->existe_tesoreria(); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $codcliente |
||
| 115 | * @throws JsonException |
||
| 116 | */ |
||
| 117 | public function mostrar_direcciones_residente($codcliente) |
||
| 118 | { |
||
| 119 | $cli = new cliente(); |
||
| 120 | $cliente = $cli->get($codcliente); |
||
| 121 | $data = $cliente->get_direcciones(); |
||
| 122 | $this->template = false; |
||
| 123 | header('Content-Type: application/json'); |
||
| 124 | echo json_encode($data, JSON_THROW_ON_ERROR); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function init_templates() |
||
| 128 | { |
||
| 129 | $fsvar = new fs_var(); |
||
|
0 ignored issues
–
show
The type
fs_var was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 130 | $residentes_email_plantillas = array(); |
||
| 131 | $residentes_email_plantillas['mail_informe_residentes'] = "Buenos dÃas, le adjunto su #DOCUMENTO#.". |
||
| 132 | "\n\n#FIRMA# 4"; |
||
| 133 | $email_plantillas = $fsvar->array_get($residentes_email_plantillas, false); |
||
| 134 | $fsvar->array_save($email_plantillas); |
||
| 135 | } |
||
| 136 | |||
| 137 | public function mostrar_informacion_residente() |
||
| 138 | { |
||
| 139 | $this->template = 'mostrar_informacion_residente'; |
||
| 140 | $cod = $this->filter_request('codcliente'); |
||
| 141 | $this->cliente_residente = $this->clientes->get($cod); |
||
| 142 | $this->cliente_residente->residente = $this->edificaciones->get_by_field('codcliente', $cod); |
||
| 143 | $this->pagos_pendientes = $this->pagosFactura(false); |
||
|
0 ignored issues
–
show
|
|||
| 144 | $this->pagos_realizados = $this->pagosFactura(true); |
||
|
0 ignored issues
–
show
|
|||
| 145 | } |
||
| 146 | |||
| 147 | public function pagosFactura($pagada = false) |
||
| 148 | { |
||
| 149 | $fecha = ''; |
||
|
0 ignored issues
–
show
|
|||
| 150 | if (isset($this->desde, $this->hasta)) { |
||
| 151 | $fecha = " AND f.fecha between ".$this->empresa->var2str(\date('Y-m-d', strtotime($this->desde))). |
||
| 152 | " AND ". |
||
| 153 | $this->empresa->var2str(\date('Y-m-d', strtotime($this->hasta))); |
||
| 154 | } |
||
| 155 | $tipo_pagada = ($pagada)?'TRUE':'FALSE'; |
||
| 156 | $sql = "SELECT f.idfactura, f.numero2, f.vencimiento, lf.referencia, lf.descripcion, f.fecha, lf.pvpsindto, ". |
||
| 157 | "lf.dtopor, lf.pvptotal". |
||
| 158 | " FROM facturascli as f left join lineasfacturascli as lf ON (f.idfactura = lf.idfactura)". |
||
| 159 | " WHERE f.anulada = FALSE AND f.pagada = ".$tipo_pagada. |
||
| 160 | " AND f.codcliente = ".$this->empresa->var2str($this->cliente_residente->codcliente). |
||
| 161 | " ORDER BY f.fecha,f.idfactura;"; |
||
| 162 | $data = $this->db->select($sql); |
||
| 163 | $lista = array(); |
||
| 164 | $fact = new factura_cliente(); |
||
| 165 | foreach ($data as $l) { |
||
| 166 | $linea = (object) $l; |
||
| 167 | $linea->f_pago = $linea->fecha; |
||
| 168 | $linea->dias_atraso = ($pagada)?0:$this->diasAtraso($linea->vencimiento, \date('d-m-Y')); |
||
| 169 | $linea->abono = 0; |
||
| 170 | if (in_array('tesoreria', $GLOBALS['plugins'], true)) { |
||
| 171 | //TO-DO Restar recibos de pagos realizados |
||
| 172 | $recibos = new recibo_cliente(); |
||
|
0 ignored issues
–
show
The type
recibo_cliente was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 173 | $recibo = $recibos->all_from_factura($linea->idfactura); |
||
|
0 ignored issues
–
show
|
|||
| 174 | //$recibos->get |
||
| 175 | } |
||
| 176 | if ($pagada) { |
||
| 177 | $f = $fact->get($linea->idfactura); |
||
| 178 | $fp = $f->get_asiento_pago(); |
||
| 179 | $linea->f_pago = $fp->fecha ?? $linea->f_pago; |
||
| 180 | } |
||
| 181 | $lista[] = $linea; |
||
| 182 | } |
||
| 183 | return $lista; |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Función para actualizar la dirección de un cliente al asignarlo a un inmueble |
||
| 188 | * @param string $codcliente |
||
| 189 | * @param integer $iddireccion |
||
| 190 | * @param string $nueva_direccion |
||
| 191 | * @return integer |
||
| 192 | */ |
||
| 193 | public function actualizar_direccion_residente($codcliente, $iddireccion, $nueva_direccion) |
||
| 194 | { |
||
| 195 | $cli = new cliente(); |
||
| 196 | $cliente = $cli->get($codcliente); |
||
| 197 | if ($iddireccion !== '') { |
||
|
0 ignored issues
–
show
|
|||
| 198 | foreach ($cliente->get_direcciones() as $dir) { |
||
| 199 | if ($dir->id === (int)$iddireccion) { |
||
| 200 | $dir->direccion = $nueva_direccion; |
||
| 201 | $dir->save(); |
||
| 202 | break; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | return $iddireccion; |
||
| 206 | } else { |
||
| 207 | $dir = new direccion_cliente(); |
||
|
0 ignored issues
–
show
The type
direccion_cliente was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 208 | $dir->direccion = $nueva_direccion; |
||
| 209 | $dir->codcliente = $codcliente; |
||
| 210 | $dir->ciudad = $this->empresa->ciudad; |
||
| 211 | $dir->apartado = $this->empresa->apartado; |
||
| 212 | $dir->provincia = $this->empresa->provincia; |
||
| 213 | $dir->codpais = $this->empresa->codpais; |
||
| 214 | $dir->codpostal = $this->empresa->codpostal; |
||
| 215 | $dir->domenvio = true; |
||
| 216 | $dir->domfacturacion = true; |
||
| 217 | $dir->descripcion = 'Inmueble '.$nueva_direccion; |
||
| 218 | $dir->fecha = \date('d-m-Y'); |
||
| 219 | $dir->save(); |
||
| 220 | return $dir->id; |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 |