D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
idoso
/
adm
/
app
/
gre
/
Models
/
Filename :
GreEditarResid.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of GreEditarResid * * @copyright (c) year, Carlos Marques - CM */ class GreEditarResid { private $Resultado; private $Dados; private $DadosId; private $DadosFav; private $ContCpf; private $ContSitu; private $substituicao = array( ' ' => '', '_' => '', '-' => '', '/' => '', '.' => '', ',' => '.', '(' => '', ')' => '' ); function getResultado() { return $this->Resultado; } public function verResid($DadosId) { $this->DadosId = filter_input_array(INPUT_GET, FILTER_DEFAULT); unset($this->DadosId['url']); $verResid = new \App\adms\Models\helper\AdmsRead(); $verResid->fullRead("SELECT resid.*, filial.nome_fantasia filial_nome, muni.nome muni_nome, docto.nome docto_nome, prof.nome prof_nome, est_civil.nome est_civil_nome, naci.nome naci_nome, esco.nome esco_nome, prev.nome prev_nome, cor.nome cor_nome, sexo.nome sexo_nome, alas.nome ala_nome, tipoacomo.nome tipoacomo_nome, acomo.nome acomo_nome, :filial_sel filial_sel, :nome_sel nome_sel FROM gre_residente resid INNER JOIN gre_tipos_documento docto ON docto.id= resid.gre_tipos_documento_id INNER JOIN gre_cbo prof ON prof.id= resid.gre_cbo_id INNER JOIN gre_municipio_ibge muni ON muni.id= resid.gre_municipio_id INNER JOIN gre_estado_civil est_civil ON est_civil.id= resid.gre_estado_civil_id INNER JOIN gre_nacionalidade naci ON naci.id= resid.gre_nacionalidade_id INNER JOIN gre_escolaridade esco ON esco.id= resid.gre_escolaridade_id INNER JOIN gre_direito_previdenciario prev ON prev.id= resid.gre_direito_previdenciario_id INNER JOIN gre_convenio conv ON conv.id= resid.gre_convenio_id INNER JOIN gre_cor cor ON cor.id= resid.gre_cor_id INNER JOIN gre_sexo sexo ON sexo.id= resid.gre_sexo_id INNER JOIN adms_sits sit ON sit.id=resid.adms_sit_id inner join gre_contratante contr on contr.id = resid.gre_contratante_id inner join gre_filial filial on filial.id = contr.gre_filial_id left join gre_alas alas on alas.id = resid.gre_alas_id left join gre_tipo_acomodacao tipoacomo on resid.gre_tipo_acomodacao_id = tipoacomo.id left join gre_acomodacao acomo on resid.gre_acomodacao_id = acomo.id INNER JOIN adms_cors cr ON cr.id= sit.adms_cor_id where resid.id = :id LIMIT :limit", "id={$this->DadosId['id']}&filial_sel={$this->DadosId['filial_sel']}&nome_sel={$this->DadosId['nome_sel']}&limit=1"); $this->Resultado = $verResid->getResultado(); $this->Resultado[0]['cpf'] = str_pad($this->Resultado[0]['cpf'] , 11 , '0' , STR_PAD_LEFT); $this->Resultado[0]['cep'] = str_pad($this->Resultado[0]['cep'] , 8 , '0' , STR_PAD_LEFT); return $this->Resultado; } public function altResid(array $Dados) { $this->Dados = $Dados; //var_dump($this->Dados); $this->retiraMasc(); // var_dump($this->Dados); $this->trata_cpf(); } private function trata_cpf() { $valCpf = new \App\gre\Models\helper\GreValCpf(); $valCpf->valCpf($this->Dados['cpf']); if ($valCpf->getResultado() !== false) { $this->Dados['cpf'] = strtr($this->Dados['cpf'] , $this->substituicao); // $this->Dados['cpf'] = preg_filter("/[^0-9]/", "", $this->Dados['cpf']); $this->Resultado = true; $this->validaCpfDuplo(); if (($this->ContCpf[0]['itens'] <> 0)) { $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Erro: CPF Já cadastrado! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = false; } $this->verSituacao(); if (($this->ContSitu[0]['itens'] <> 0)) { // var_dump($this->ContSitu); $this->Resultado = false; // var_dump($this->Dados); $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Erro: Situação do residente em ANÁLISE faça o acolhimento! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; } } if($this->Resultado) { $this->alterarResid(); } } /** * <b>Listar registros para chave estrangeira:</b> Buscar informações na tabela "adms_sits" para utilizar como chave estrangeira */ public function alterarResid() { unset( $this->Dados['gre_municipio_id_aux'], $this->Dados['EditResid'],$this->Dados['filial_nome'],$this->Dados['docto_nome_docto'], $this->Dados['est_civil_nome'], $this->Dados['cor_nome'], $this->Dados['naci_nome'], $this->Dados['esco_nome'], $this->Dados['muni_nome'], $this->Dados['conv_nome'], $this->Dados['prof_nome'], $this->Dados['uf_sigla']); date_default_timezone_set ("America/Sao_Paulo"); $this->Dados['modified'] = date("Y-m-d H:i:s"); $this->Dados['data_nasc'] = implode(preg_match("~\/~", $this->Dados['data_nasc']) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $this->Dados['data_nasc']) == 0 ? "-" : "/", $this->Dados['data_nasc']))); $this->Dados['data_acolhimento'] = implode(preg_match("~\/~", $this->Dados['data_acolhimento']) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $this->Dados['data_acolhimento']) == 0 ? "-" : "/", $this->Dados['data_acolhimento']))); if(!empty($this->Dados['data_acolhimento'])) { $this->Dados['ultimo_reajuste'] = date("Y").'-'.substr($this->Dados['data_acolhimento'],5,5); if (substr($this->Dados['data_acolhimento'],5,2) > (date("m") - 2)) { $this->Dados['ultimo_reajuste'] = (date("Y")-1).'-'.substr($this->Dados['data_acolhimento'],5,5); }else{ $this->Dados['ultimo_reajuste'] = (date("Y")).'-'.substr($this->Dados['data_acolhimento'],5,5); } } $this->Dados['id_modified'] = $_SESSION['usuario_id']; if(isset($this->Dados['valor_acomodacao']) and $this->Dados['valor_acomodacao'] == '') { unset ($this->Dados['valor_acomodacao']); } // var_dump($this->Dados); // die; $upAltResid = new \App\adms\Models\helper\AdmsUpdate(); $upAltResid->exeUpdate("gre_residente", $this->Dados, "WHERE id =:id", "id=" . $this->Dados['id']); if ($upAltResid->getResultado()) { $_SESSION['msg'] = "<div class='alert alert-success' role='alert'> Residente atualizado com sucesso! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = true; } else { $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Erro: Residente não foi atualizado!! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = false; } } public function listarCadastrar() { $listar = new \App\adms\Models\helper\AdmsRead(); $listar->fullRead("SELECT id id_sit, nome nome_sit FROM adms_sits ORDER BY nome ASC"); $registro['sit'] = $listar->getResultado(); $listar->fullRead("SELECT id id_contr, nome nome_contr FROM gre_contratante where adms_sit_id = 3 and gre_empr_princ_id = ". $_SESSION['id_user'] . " ORDER BY nome asc"); $registro['contr'] = $listar->getResultado(); $listar->fullRead("SELECT muni.id id_muni, concat(muni.nome,' - ', muni.uf) nome_muni FROM gre_municipio_ibge muni ORDER BY nome_muni ASC"); $registro['muni'] = $listar->getResultado(); $listar->fullRead("SELECT id id_tipdoc, nome nome_tipdoc FROM gre_tipos_documento ORDER BY ordem ASC"); $registro['tipodoc'] = $listar->getResultado(); $listar->fullRead("SELECT id id_est_civil, nome nome_est_civil FROM gre_estado_civil ORDER BY ordem ASC"); $registro['est_civil'] = $listar->getResultado(); $listar->fullRead("SELECT id id_cor, nome nome_cor FROM gre_cor ORDER BY ordem ASC"); $registro['cor'] = $listar->getResultado(); $listar->fullRead("SELECT id id_sexo, nome nome_sexo FROM gre_sexo ORDER BY nome asc"); $registro['sexo'] = $listar->getResultado(); $listar->fullRead("SELECT id id_prof, nome nome_prof FROM gre_cbo ORDER BY favoritos desc"); $registro['prof'] = $listar->getResultado(); $listar->fullRead("SELECT id id_esco, nome nome_esco FROM gre_escolaridade ORDER BY ordem asc"); $registro['esco'] = $listar->getResultado(); $listar->fullRead("SELECT id id_naci, nome nome_naci FROM gre_nacionalidade ORDER BY ordem asc"); $registro['naci'] = $listar->getResultado(); $listar->fullRead("SELECT id id_prev, nome nome_prev FROM gre_direito_previdenciario ORDER BY ordem asc"); $registro['prev'] = $listar->getResultado(); $listar->fullRead("SELECT id id_conv, nome nome_conv FROM gre_convenio ORDER BY ordem asc"); $registro['conv'] = $listar->getResultado(); $listar->fullRead("SELECT id id_alas, nome nome_alas FROM gre_alas ORDER BY nome asc"); $registro['alas'] = $listar->getResultado(); $listar->fullRead("SELECT id id_tipoacomo, nome nome_tipoacomo FROM gre_tipo_acomodacao ORDER BY nome asc"); $registro['tipoacomo'] = $listar->getResultado(); $listar->fullRead("SELECT id id_acomo, nome nome_acomo FROM gre_acomodacao ORDER BY nome asc"); $registro['acomo'] = $listar->getResultado(); $this->Resultado = ['sit' => $registro['sit'], 'contr' => $registro['contr'], 'muni' => $registro['muni'],'tipodoc' => $registro['tipodoc'],'est_civil' => $registro['est_civil'],'cor' => $registro['cor'],'sexo' => $registro['sexo'],'prof' => $registro['prof'],'esco' => $registro['esco'],'naci' => $registro['naci'],'prev' => $registro['prev'],'conv' => $registro['conv'],'alas' => $registro['alas'],'acomo' => $registro['acomo'],'tipoacomo' => $registro['tipoacomo']]; // var_dump($this->Resultado['tipoacomo']); return $this->Resultado; } private function validaCpfDuplo() { $verCpf = new \App\adms\Models\helper\AdmsRead(); $verCpf->fullRead("SELECT count(*) itens FROM gre_residente WHERE cpf =:cpf and id <>:id LIMIT :limit", "cpf=" . $this->Dados['cpf'] . "&id=" . $this->Dados['id'] . "&limit=1"); $this->ContCpf = $verCpf->getResultado(); } private function VerSituacao() { // var_dump($this->Dados['id']); $verSitu = new \App\adms\Models\helper\AdmsRead(); $verSitu->fullRead("SELECT count(*) itens FROM gre_residente WHERE id =:id and adms_sit_id = 3", "id=".$this->Dados['id']); $this->ContSitu = $verSitu->getResultado(); if( $this->ContSitu[0]['itens'] > 0 and $this->Dados['adms_sit_id'] <> 1){ $this->ContSitu[0]['itens'] = 0; } } private function retiraMasc() { $this->Dados['cep'] = strtr($this->Dados['cep'] , $this->substituicao); $this->Dados['telefone_residencial'] = strtr($this->Dados['telefone_residencial'] , $this->substituicao); $this->Dados['telefone_comercial'] = strtr($this->Dados['telefone_comercial'] , $this->substituicao); $this->Dados['celular'] = strtr($this->Dados['celular'] , $this->substituicao); $this->Dados['telefone_remocao'] = strtr($this->Dados['telefone_remocao'] , $this->substituicao); $this->Dados['telefone_convenio'] = strtr($this->Dados['telefone_convenio'] , $this->substituicao); if(isset($this->Dados['valor_acomodacao'])) { $this->Dados['valor_acomodacao'] = strtr($this->Dados['valor_acomodacao'] , $this->substituicao); } } }