D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Models
/
Filename :
ModPsaudeClienteCadastrar.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of GreCadastrarContr * * @copyright (c) year,Carlos Marques CM */ class ModPsaudeClienteCadastrar { private $Resultado; private $Dados; private $UltimoForn; private $ResCnpj; private $contCnpj; private $Data; private $substituicao = array( ' ' => '', '_' => '', '-' => '', '/' => '', '.' => '', ',' => '', '(' => '', ')' => '' ); function getResultado() { return $this->Resultado; } public function CadPsaudeCliente(array $Dados) { $this->Dados = $Dados; $valCpf = new \App\gre\Models\helper\GreValCpf(); $valCpf->valCpf($this->Dados['cpf']); if ($valCpf->getResultado() !== false) { $this->retiraMasc(); $this->validaCpfDuplo(); if (($this->ContCpf[0]['itens'] == 0)) { $this->inserirCliente(); } else { $_SESSION['msg'] = "<div class='alert alert-danger'> CPF já Cadastrado Nesse Programa!</div>"; } } } private function inserirCliente() { if($this->Dados['tipo_id']== 2){ $this->Dados['empr_convenio_id'] = null; //unset($this->Dados['empr_convenio_id']); } $this->Dados['usu_created_id'] = $_SESSION['usuario_id']; $this->Dados['loja_id'] = $_SESSION['filial']; $this->Dados['created'] = date("Y-m-d H:i:s"); $data = date("Y-m-d"); $this->Dados['libera_limite'] = date('Y-m-d', strtotime("+29 days",strtotime($data))); $this->Dados['adms_sit_id'] = '1'; $this->Dados['sit_programa'] = '1'; $this->Dados['data_ult_checkup'] = $this->Dados['data_ult_checkup'].'-01'; $this->retiraMasc(); if ($this->Dados['celular2'] == '') { unset($this->Dados['celular2']); } $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']))); //var_dump($this->Dados); if($this->Dados['dife'] == 'N'){ unset ($this->Dados['nome_pagador']); unset ($this->Dados['sexo_id_pagador']); unset ($this->Dados['cpf_pagador']); unset ($this->Dados['cep_pagador']); unset ($this->Dados['endereco_pagador']); unset ($this->Dados['numero_pagador']); unset ($this->Dados['bairro_pagador']); unset ($this->Dados['complemento_pagador']); unset ($this->Dados['municipio_id_pagador']); unset ($this->Dados['celular_pagador']); unset ($this->Dados['email_pagador']); } unset($this->Dados['dife']); $cadCliente = new \App\adms\Models\helper\AdmsCreate; $cadCliente->exeCreate("ps_cliente", $this->Dados); if ($cadCliente->getResultado()) { $_SESSION['msg'] = "<div class='alert alert-success'> Cliente cadastrado com sucesso!</div>"; $this->Resultado = true; } else { $_SESSION['msg'] = "<div class='alert alert-danger'>Erro: CLiente não foi cadastrado!</div>"; $this->Resultado = false; } } private function validaCpfDuplo() { $verCpf = new \App\adms\Models\helper\AdmsRead(); $verCpf->fullRead("SELECT coalesce(count(*),0) itens FROM ps_cliente WHERE cpf =:cpf and prog_id = :prog_id", "cpf=" . $this->Dados['cpf']."&prog_id=" . $this->Dados['prog_id']); $this->ContCpf = $verCpf->getResultado(); if(empty($this->ContCpf)) { $this->ContCpf[0]['itens'] = 0; // var_dump( $this->ContCpf[0]['itens']); } } /** * <b>Listar registros para chave estrangeira:</b> Buscar informações na tabela "adms_sits" para utilizar como chave estrangeira */ 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_uf, sigla sigla_uf FROM gre_uf ORDER BY favorito desc,sigla ASC"); $registro['uf'] = $listar->getResultado(); $listar->fullRead("SELECT muni.id id_muni, concat(muni.nome,' - ', uf.sigla) nome_muni FROM ro_municipios muni inner join ro_uf uf on muni.uf_id = uf.id where uf.favorito = 'S' ORDER BY muni.favorito desc, muni.nome"); $registro['muni'] = $listar->getResultado(); $listar->fullRead("SELECT id id_sexo, nome nome_sexo FROM ps_sexo ORDER BY id_sexo"); $registro['sexo'] = $listar->getResultado(); $listar->fullRead("SELECT cod_empresa id_empr, nome nome_empr FROM ps_empresa_convenio where adms_sit_id = 1 ORDER BY nome"); $registro['empresa'] = $listar->getResultado(); $listar->fullRead("SELECT id id_tipo, nome nome_tipo FROM ps_tipo_cliente ORDER BY id ASC"); $registro['tipo'] = $listar->getResultado(); $listar->fullRead("SELECT id id_prog, nome nome_prog FROM ps_programa where adms_sit_id = 1 ORDER BY id"); $registro['prog'] = $listar->getResultado(); $listar->fullRead("SELECT pr.programa_id id_prog, pr.tipo_cliente_id id_tipo, pr.preco_venda FROM ps_preco pr inner join ps_programa p on p.id = pr.programa_id where p.adms_sit_id = 1 ORDER BY pr.programa_id, pr.tipo_cliente_id"); $registro['preco'] = $listar->getResultado(); $listar->fullRead("SELECT dia id_dia, dia dia_vencimento FROM ps_dia_vencimento ORDER BY dia"); $registro['dia'] = $listar->getResultado(); $this->Resultado = ['sit' => $registro['sit'], 'tipo' => $registro['tipo'],'preco' => $registro['preco'], 'muni' => $registro['muni'], 'sexo' => $registro['sexo'], 'prog' => $registro['prog'], 'empresa' => $registro['empresa'], 'dia' => $registro['dia']]; return $this->Resultado; } private function retiraMasc() { $this->Dados['cpf'] = strtr($this->Dados['cpf'] , $this->substituicao); $this->Dados['cep'] = strtr($this->Dados['cep'] , $this->substituicao); $this->Dados['cpf_pagador'] = strtr($this->Dados['cpf_pagador'] , $this->substituicao); $this->Dados['cep_pagador'] = strtr($this->Dados['cep_pagador'] , $this->substituicao); $this->Dados['celular_pagador'] = strtr($this->Dados['celular_pagador'] , $this->substituicao); $this->Dados['celular1'] = strtr($this->Dados['celular1'] , $this->substituicao); $this->Dados['celular2'] = strtr($this->Dados['celular2'] , $this->substituicao); } }