joenilson /
residentes
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Copyright (C) 2017 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 | namespace FacturaScripts\model; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Tabla para guardar la información adicional de los residentes |
||
| 22 | * para guardar la información de los vehiculos de los mismos |
||
| 23 | * se debe usar el model residentes_vehiculos |
||
| 24 | * @author Joe Nilson <joenilson at gmail.com> |
||
| 25 | * @version 1 |
||
| 26 | */ |
||
| 27 | class residentes_informacion extends \fs_model{ |
||
| 28 | /** |
||
| 29 | * Codigo del cliente |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | public $codcliente; |
||
| 33 | /** |
||
| 34 | * Codigo auxiliar del cliente |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | public $codigo; |
||
| 38 | /** |
||
| 39 | * Cantidad de ocupantes del inmueble |
||
| 40 | * @var integer |
||
| 41 | */ |
||
| 42 | public $ocupantes; |
||
| 43 | /** |
||
| 44 | * Cantidad de ocupantes menores de 5 años |
||
| 45 | * @var integer |
||
| 46 | */ |
||
| 47 | public $ocupantes5anos; |
||
| 48 | /** |
||
| 49 | * Cantidad de ocupantes menores de 12 años |
||
| 50 | * @var integer |
||
| 51 | */ |
||
| 52 | public $ocupantes12anos; |
||
| 53 | /** |
||
| 54 | * Cantidad de ocupantes menores de 18 años |
||
| 55 | * @var integer |
||
| 56 | */ |
||
| 57 | public $ocupantes18anos; |
||
| 58 | /** |
||
| 59 | * Cantidad de ocupantes menores de 30 años |
||
| 60 | * @var integer |
||
| 61 | */ |
||
| 62 | public $ocupantes30anos; |
||
| 63 | /** |
||
| 64 | * Cantidad de ocupantes menores de 50 años |
||
| 65 | * @var integer |
||
| 66 | */ |
||
| 67 | public $ocupantes50anos; |
||
| 68 | /** |
||
| 69 | * Cantidad de ocupantes menores de 70 años |
||
| 70 | * @var integer |
||
| 71 | */ |
||
| 72 | public $ocupantes70anos; |
||
| 73 | /** |
||
| 74 | * Cantidad de ocupantes mayores de 70 años |
||
| 75 | * @var integer |
||
| 76 | */ |
||
| 77 | public $ocupantes71anos; |
||
| 78 | /** |
||
| 79 | * Información sobre alguna discapacidad |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | public $informacion_discapacidad; |
||
| 83 | /** |
||
| 84 | * Si es propietario valor TRUE si es solo inquilino FALSE |
||
| 85 | * @var boolean |
||
| 86 | */ |
||
| 87 | public $propietario; |
||
| 88 | /** |
||
| 89 | * Información de la profesión del residente |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | public $profesion; |
||
| 93 | /** |
||
| 94 | * Información de la ocupación del residente |
||
| 95 | * sale del model residentes_ayudas tipo = 'ocupacion' |
||
| 96 | * @var string |
||
| 97 | */ |
||
| 98 | public $ocupacion; |
||
| 99 | /** |
||
| 100 | * Nombres del Contacto Adicional |
||
| 101 | * @var string |
||
| 102 | */ |
||
| 103 | public $ca_nombres; |
||
| 104 | /** |
||
| 105 | * Apellidos del contacto Adicional |
||
| 106 | * @var string |
||
| 107 | */ |
||
| 108 | public $ca_apellidos; |
||
| 109 | /** |
||
| 110 | * Información del teléfono del contacto Adicional |
||
| 111 | * @var string |
||
| 112 | */ |
||
| 113 | public $ca_telefono; |
||
| 114 | /** |
||
| 115 | * Correo electrónico del contacto Adicional |
||
| 116 | * @var string |
||
| 117 | */ |
||
| 118 | public $ca_email; |
||
| 119 | /** |
||
| 120 | * si el contacto adicional es el propietario se pone TRUE, si no se pone FALSE |
||
| 121 | * @var boolean |
||
| 122 | */ |
||
| 123 | public $ca_propietario; |
||
| 124 | /** |
||
| 125 | * Información de el parentezco del contacto Adicional |
||
| 126 | * sale del model residentes_ayudas tipo = 'parentezco' |
||
| 127 | * @var string |
||
| 128 | */ |
||
| 129 | public $ca_parentesco; |
||
| 130 | /** |
||
| 131 | * Si el tipo de parentezco es OTROS entonces se llena la información adicional |
||
| 132 | * @var string |
||
| 133 | */ |
||
| 134 | public $ca_parentesco_obs; |
||
| 135 | /** |
||
| 136 | * Cantidad de Vehiculos a agregar |
||
| 137 | * @var integer |
||
| 138 | */ |
||
| 139 | public $vehiculos; |
||
| 140 | public $cliente; |
||
| 141 | public function __construct($t = false) |
||
| 142 | { |
||
| 143 | parent::__construct('residentes_informacion', 'plugins/residentes'); |
||
| 144 | if ($t) { |
||
| 145 | $this->codcliente=$t['codcliente']; |
||
| 146 | $this->codigo=$t['codigo']; |
||
| 147 | $this->ocupantes=$t['ocupantes']; |
||
| 148 | $this->ocupantes5anos=$t['ocupantes5anos']; |
||
| 149 | $this->ocupantes12anos=$t['ocupantes12anos']; |
||
| 150 | $this->ocupantes18anos=$t['ocupantes18anos']; |
||
| 151 | $this->ocupantes30anos=$t['ocupantes30anos']; |
||
| 152 | $this->ocupantes50anos=$t['ocupantes50anos']; |
||
| 153 | $this->ocupantes70anos=$t['ocupantes70anos']; |
||
| 154 | $this->ocupantes71anos=$t['ocupantes71anos']; |
||
| 155 | $this->informacion_discapacidad=$t['informacion_discapacidad']; |
||
| 156 | $this->propietario=$this->str2bool($t['propietario']); |
||
| 157 | $this->profesion=$t['profesion']; |
||
| 158 | $this->ocupacion=$t['ocupacion']; |
||
| 159 | $this->ca_nombres=$t['ca_nombres']; |
||
| 160 | $this->ca_apellidos=$t['ca_apellidos']; |
||
| 161 | $this->ca_telefono=$t['ca_telefono']; |
||
| 162 | $this->ca_email=$t['ca_email']; |
||
| 163 | $this->ca_propietario=$this->str2bool($t['ca_propietario']); |
||
| 164 | $this->ca_parentesco=$t['ca_parentesco']; |
||
| 165 | $this->ca_parentesco_obs=$t['ca_parentesco_obs']; |
||
| 166 | $this->vehiculos=$t['vehiculos']; |
||
| 167 | } else { |
||
| 168 | $this->codcliente=NULL; |
||
| 169 | $this->codigo=NULL; |
||
| 170 | $this->ocupantes=NULL; |
||
| 171 | $this->ocupantes5anos=NULL; |
||
| 172 | $this->ocupantes12anos=NULL; |
||
| 173 | $this->ocupantes18anos=NULL; |
||
| 174 | $this->ocupantes30anos=NULL; |
||
| 175 | $this->ocupantes50anos=NULL; |
||
| 176 | $this->ocupantes70anos=NULL; |
||
| 177 | $this->ocupantes71anos=NULL; |
||
| 178 | $this->informacion_discapacidad=NULL; |
||
| 179 | $this->propietario='FALSE'; |
||
|
0 ignored issues
–
show
|
|||
| 180 | $this->profesion=NULL; |
||
| 181 | $this->ocupacion=NULL; |
||
| 182 | $this->ca_nombres=NULL; |
||
| 183 | $this->ca_apellidos=NULL; |
||
| 184 | $this->ca_telefono=NULL; |
||
| 185 | $this->ca_email=NULL; |
||
| 186 | $this->ca_propietario='FALSE'; |
||
|
0 ignored issues
–
show
The property
$ca_propietario was declared of type boolean, but 'FALSE' is of type string. Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
| 187 | $this->ca_parentesco=NULL; |
||
| 188 | $this->ca_parentesco_obs=''; |
||
| 189 | $this->vehiculos=0; |
||
| 190 | } |
||
| 191 | $this->cliente = new cliente(); |
||
| 192 | } |
||
| 193 | |||
| 194 | public function install(){ |
||
| 195 | return ""; |
||
| 196 | } |
||
| 197 | |||
| 198 | public function info_adicional($i){ |
||
| 199 | $data = $this->cliente->get($i->codcliente); |
||
| 200 | $i->nombre = $data->nombre; |
||
| 201 | $i->telefono1 = $data->telefono1; |
||
| 202 | $i->telefono2 = $data->telefono2; |
||
| 203 | $i->email = $data->email; |
||
| 204 | $i->observaciones = $data->observaciones; |
||
| 205 | return $i; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function all(){ |
||
| 209 | $sql = "SELECT * FROM ".$this->table_name." ORDER BY codcliente"; |
||
| 210 | $data = $this->db->select($sql); |
||
| 211 | if($data){ |
||
| 212 | $lista = array(); |
||
| 213 | foreach($data as $d){ |
||
| 214 | $item = new residentes_informacion($d); |
||
| 215 | $lista[] = $item->info_adicional($item); |
||
| 216 | } |
||
| 217 | return $lista; |
||
| 218 | }else{ |
||
| 219 | return false; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * //Retornamos un punto del mapa en particular |
||
| 225 | * @param string $codcliente |
||
| 226 | * @param string $codigo_edificacion |
||
| 227 | * @param integer $padre_tipo |
||
| 228 | * @return \FacturaScripts\model\residentes_informacion|boolean |
||
| 229 | */ |
||
| 230 | public function get($codcliente){ |
||
| 231 | $sql = "SELECT * FROM ".$this->table_name. |
||
| 232 | " WHERE codcliente = ".$this->var2str($codcliente).";"; |
||
| 233 | $data = $this->db->select($sql); |
||
| 234 | if($data){ |
||
| 235 | $item = new residentes_informacion($data[0]); |
||
| 236 | return $item->info_adicional($item); |
||
| 237 | }else{ |
||
| 238 | return false; |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * //Si queremos buscar por codcliente o codigo_interno o numero |
||
| 244 | * @param string $field |
||
| 245 | * @param string $value |
||
| 246 | * @return boolean|\FacturaScripts\model\residentes_informacion |
||
| 247 | */ |
||
| 248 | public function get_by_field($field,$value){ |
||
| 249 | $query = (is_string($value))?$this->var2str($value):$this->intval($value); |
||
|
0 ignored issues
–
show
|
|||
| 250 | $sql = "SELECT * FROM ".$this->table_name." WHERE ".strtoupper(trim($field))." = ".$query.";"; |
||
| 251 | $data = $this->db->select($sql); |
||
| 252 | if($data){ |
||
| 253 | $lista = array(); |
||
| 254 | foreach($data as $d){ |
||
| 255 | $item = new residentes_informacion($d); |
||
| 256 | $lista[] = $item->info_adicional($item); |
||
| 257 | } |
||
| 258 | return $lista; |
||
|
0 ignored issues
–
show
|
|||
| 259 | }else{ |
||
| 260 | return false; |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | public function exists() { |
||
| 265 | if(!$this->get($this->codcliente)){ |
||
| 266 | return false; |
||
| 267 | }else{ |
||
| 268 | return $this->get($this->codcliente); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | public function save() { |
||
| 273 | if($this->exists()){ |
||
| 274 | $sql = "UPDATE ".$this->table_name." SET ". |
||
| 275 | "codigo = ".$this->var2str($this->codigo).", ". |
||
| 276 | "ocupantes = ".$this->intval($this->ocupantes).", ". |
||
| 277 | "ocupantes5anos = ".$this->intval($this->ocupantes5anos).", ". |
||
| 278 | "ocupantes12anos = ".$this->intval($this->ocupantes12anos).", ". |
||
| 279 | "ocupantes18anos = ".$this->intval($this->ocupantes18anos).", ". |
||
| 280 | "ocupantes30anos = ".$this->intval($this->ocupantes30anos).", ". |
||
| 281 | "ocupantes50anos = ".$this->intval($this->ocupantes50anos).", ". |
||
| 282 | "ocupantes70anos = ".$this->intval($this->ocupantes70anos).", ". |
||
| 283 | "ocupantes71anos = ".$this->intval($this->ocupantes71anos).", ". |
||
| 284 | "informacion_discapacidad = ".$this->var2str($this->informacion_discapacidad).", ". |
||
| 285 | "propietario = ".$this->var2str($this->propietario).", ". |
||
| 286 | "profesion = ".$this->var2str($this->profesion).", ". |
||
| 287 | "ocupacion = ".$this->var2str($this->ocupacion).", ". |
||
| 288 | "ca_nombres = ".$this->var2str($this->ca_nombres).", ". |
||
| 289 | "ca_apellidos = ".$this->var2str($this->ca_apellidos).", ". |
||
| 290 | "ca_telefono = ".$this->var2str($this->ca_telefono).", ". |
||
| 291 | "ca_email = ".$this->var2str($this->ca_email).", ". |
||
| 292 | "ca_propietario = ".$this->var2str($this->ca_propietario).", ". |
||
| 293 | "ca_parentesco = ".$this->var2str($this->ca_parentesco).", ". |
||
| 294 | "ca_parentesco_obs = ".$this->var2str($this->ca_parentesco_obs).", ". |
||
| 295 | "vehiculos = ".$this->intval($this->vehiculos)." ". |
||
| 296 | "WHERE codcliente = ".$this->var2str($this->codcliente).";"; |
||
| 297 | return $this->db->exec($sql); |
||
| 298 | }else{ |
||
| 299 | $sql = "INSERT INTO ".$this->table_name." (codcliente, codigo, ocupantes, ocupantes5anos, ocupantes12anos, ocupantes18anos, ocupantes30anos, ocupantes50anos, ocupantes70anos, ocupantes71anos, informacion_discapacidad, propietario, profesion, ocupacion, ca_nombres, ca_apellidos, ca_telefono, ca_email, ca_propietario, ca_parentesco, ca_parentesco_obs, vehiculos) VALUES (". |
||
| 300 | $this->var2str($this->codcliente).", ". |
||
| 301 | $this->var2str($this->codigo).", ". |
||
| 302 | $this->intval($this->ocupantes).", ". |
||
| 303 | $this->intval($this->ocupantes5anos).", ". |
||
| 304 | $this->intval($this->ocupantes12anos).", ". |
||
| 305 | $this->intval($this->ocupantes18anos).", ". |
||
| 306 | $this->intval($this->ocupantes30anos).", ". |
||
| 307 | $this->intval($this->ocupantes50anos).", ". |
||
| 308 | $this->intval($this->ocupantes70anos).", ". |
||
| 309 | $this->intval($this->ocupantes71anos).", ". |
||
| 310 | $this->var2str($this->informacion_discapacidad).", ". |
||
| 311 | $this->var2str($this->propietario).", ". |
||
| 312 | $this->var2str($this->profesion).", ". |
||
| 313 | $this->var2str($this->ocupacion).", ". |
||
| 314 | $this->var2str($this->ca_nombres).", ". |
||
| 315 | $this->var2str($this->ca_apellidos).", ". |
||
| 316 | $this->var2str($this->ca_telefono).", ". |
||
| 317 | $this->var2str($this->ca_email).", ". |
||
| 318 | $this->var2str($this->ca_propietario).", ". |
||
| 319 | $this->var2str($this->ca_parentesco).", ". |
||
| 320 | $this->var2str($this->ca_parentesco_obs).", ". |
||
| 321 | $this->intval($this->vehiculos).");"; |
||
| 322 | if($this->db->exec($sql)){ |
||
| 323 | return true; |
||
| 324 | }else{ |
||
| 325 | return false; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Función para realizar buquedas en la mayor cantidad de información del residente |
||
| 332 | * @param string|integer $query |
||
| 333 | */ |
||
| 334 | public function search($busqueda, $offset = 0) { |
||
| 335 | $clilist = array(); |
||
| 336 | $query = mb_strtolower($this->no_html($busqueda), 'UTF8'); |
||
| 337 | |||
| 338 | $consulta = "SELECT * FROM " . $this->table_name . " WHERE "; |
||
| 339 | if (is_numeric($query)) { |
||
| 340 | $consulta .= "(ca_telefono LIKE '%" . $query . "%' OR codigo LIKE '%" . $query . "%')"; |
||
| 341 | } else { |
||
| 342 | $buscar = str_replace(' ', '%', $query); |
||
| 343 | $consulta .= "(lower(ca_nombres) LIKE '%" . $buscar . "%' OR lower(ca_apellidos) LIKE '%" . $buscar . "%'" |
||
| 344 | . " OR lower(ocupacion) LIKE '%" . $buscar . "%' OR lower(profesion) LIKE '%" . $buscar . "%'" |
||
| 345 | . " OR lower(ca_email) LIKE '%" . $buscar . "%')"; |
||
| 346 | } |
||
| 347 | $consulta .= " ORDER BY codcliente ASC"; |
||
| 348 | |||
| 349 | $data = $this->db->select_limit($consulta, FS_ITEM_LIMIT, $offset); |
||
|
0 ignored issues
–
show
|
|||
| 350 | if ($data) { |
||
| 351 | foreach ($data as $d) { |
||
| 352 | $item = new residentes_informacion($d); |
||
| 353 | $clilist[] = $item->info_adicional($item); |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | return $clilist; |
||
| 358 | } |
||
| 359 | |||
| 360 | public function delete() { |
||
| 361 | $sql = "DELETE FROM ".$this->table_name. |
||
| 362 | " WHERE codcliente = ".$this->var2str($this->codcliente).";"; |
||
| 363 | return $this->db->exec($sql); |
||
| 364 | } |
||
| 365 | |||
| 366 | } |
||
| 367 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.