D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
idoso
/
adm
/
app
/
gre
/
Models
/
Filename :
AntGreCadastrarPrescricaoResidente.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit();} /** * Description of GreCadastrarEstoqueResidente * * @copyright (c) year,Carlos Marques CM */ class GreCadastrarPrescricaoResidente{ private $Resultado; private $Dados; private $ResidId; private $idResidLanc; private $idUser; private $itens; private $diferenca; private $UltimoResidLanc; private $substituicao = array( ' ' => '', '_' => '', '/' => '', '.' => '', ',' => '.', '(' => '', ')' => ''); function getResultado() { return $this->Resultado; } public function cadPrescrResid(array $Dados) { $this->Dados = $Dados; $this->verPrescrDupla(); if ($this->itens[0]['itens'] > 0) { $_SESSION['msg'] = '<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><strong>Erro!</strong> Prescrição JÁ EXISTE para o Residente !!</div>'; $this->Resultado = false; }else{ $this->retiraMasc(); if($this->Dados['data_fim_tratamento']==''){ $this->Dados['data_fim_tratamento'] = '9999-12-31'; $this->Dados['dias_tratamento'] = 0; }else{ $this->diferenca = strtotime($this->Dados['data_fim_tratamento']) - strtotime($this->Dados['data_inicio_tratamento']); $this->Dados['dias_tratamento'] = floor($this->diferenca / (60 * 60 * 24)); } if($this->Dados['intervalo_id']==1){ $this->Dados['uso_dia'] = $this->Dados['qtde_prescrita'] * $this->Dados['qtde_adm']; $this->Dados['intervalo'] = 'Dia'; $this->Dados['intervalo_id'] = 1; } if($this->Dados['intervalo_id']==2){ $this->Dados['uso_dia'] = ( 24/ $this->Dados['qtde_adm']) * $this->Dados['qtde_prescrita']; $this->Dados['intervalo'] = 'Horas'; $this->Dados['intervalo_id'] = 2; } if($this->Dados['intervalo_id']==9){ $this->Dados['uso_dia'] = $this->Dados['qtde_prescrita']; $this->Dados['intervalo'] = 'Mês'; $this->Dados['intervalo_id'] = 9; } if($this->Dados['intervalo_id']==8){ $this->Dados['uso_dia'] = $this->Dados['qtde_prescrita']; $this->Dados['intervalo'] = 'Sem'; $this->Dados['intervalo_id'] = 8; } if($this->Dados['crm']== '') { unset($this->Dados['crm']); unset($this->Dados['gre_uf_id']); }else{ $this->Dados['uf_crm'] = $this->Dados['gre_uf_id']; unset($this->Dados['gre_uf_id']); } unset($this->Dados['qtde_apres']); unset($this->Dados['apres_sigla']); unset ($this->Dados['gre_produto_id_aux']); unset($this->Dados['medico']); unset($this->Dados['preco']); $this->Dados['created'] = date("Y-m-d H:i:s"); $this->Dados['adms_sit_id'] = 1; $this->Dados['gre_empr_princ_id'] = $_SESSION['id_user']; //var_dump( $this->Dados); $cadPrescrResid = new \App\adms\Models\helper\AdmsCreate; $cadPrescrResid->exeCreate("gre_prescricao", $this->Dados); if ($cadPrescrResid->getResultado()) { $_SESSION['msg'] = "<div class='alert alert-success'>Lançamento cadastrado com sucesso!</div>"; $this->Resultado = true; } else { $_SESSION['msg'] = "<div class='alert alert-danger'>Erro: Lançamento não foi cadastrado!</div>"; $this->Resultado = false; } } } private function retiraMasc() { $this->Dados['qtde_prescrita'] = strtr($this->Dados['qtde_prescrita'] , $this->substituicao); //$this->Dados['qtde_apres'] = strtr($this->Dados['qtde_apres'] , $this->substituicao); } public function verPrescrDupla(){ { $verPrescrDupla = new \App\adms\Models\helper\AdmsRead(); $verPrescrDupla->fullRead("SELECT count(*) itens FROM gre_prescricao WHERE gre_residente_id = :resid_id and adms_sit_id = 1 and gre_produto_id = :prod_id and data_fim_tratamento >= :data_inicio", "resid_id=" . $this->Dados['gre_residente_id'] . "&prod_id=" . $this->Dados['gre_produto_id']. "&data_inicio=" . $this->Dados['data_inicio_tratamento']); $this->itens = $verPrescrDupla->getResultado(); } } public function listarCadastrar($Dados = null) { $this->ResidId = $Dados; $listar = new \App\adms\Models\helper\AdmsRead(); $this->idUser = $_SESSION['id_user']; $listar->fullRead("SELECT empr.id id_empr FROM gre_empresa empr where empr.id= ". $this->idUser); $registro['empr'] = $listar->getResultado(); if($_SESSION['filial']==0){ $listar->fullRead("SELECT resid.id id_resid, resid.nome resid_nome, resid.gre_filial_id resid_gre_filial_id FROM gre_residente resid where resid.id=". $this->ResidId); $registro['resid'] = $listar->getResultado(); }else{ $listar->fullRead("SELECT resid.id id_resid, resid.nome resid_nome, resid.gre_filial_id resid_gre_filial_id FROM gre_residente resid where resid.gre_empr_princ_id=". $_SESSION['id_user']. " AND resid.gre_filial_id = ". $_SESSION['filial']); $registro['resid'] = $listar->getResultado(); } $listar->fullRead("SELECT tempo.id tempo_id, tempo.nome tempo_nome, tempo.qtde_dias tempo_dias FROM gre_tempo_prescricao tempo order by tempo.ordem"); $registro['tempo'] = $listar->getResultado(); $listar->fullRead("Select * from gre_produto where gre_empr_princ_id = " . $_SESSION['id_user']); $registro['produtos'] = $listar->getResultado(); $listar->fullRead("Select uf.favorito uf_favorito, uf.sigla uf_sigla from gre_uf uf order by uf.favorito desc"); $registro['uf'] = $listar->getResultado(); $listar->fullRead("SELECT pre.gre_filial_id, pre.gre_produto_id prod, format(coalesce(round(pre.preco_venda / pro.qtde_apres,3),0), 3, 'de_DE') preco_venda from gre_tabela_precos pre join gre_produto pro on pro.id = pre.gre_produto_id WHERE pre.gre_empr_princ_id = " .$_SESSION['id_user']. " and pre.gre_produto_id > 0 and coalesce(round(pre.preco_venda / pro.qtde_apres,3),0) > 0 and pro.adms_sit_id = 1 order by pre.gre_filial_id, pre.gre_produto_id"); $registro['preco'] = $listar->getResultado(); $this->Resultado = ['empr' => $registro['empr'], 'tempo' => $registro['tempo'], 'produtos' => $registro['produtos'], 'resid' => $registro['resid'], 'uf' => $registro['uf'], 'preco' => $registro['preco']]; return $this->Resultado; } }