D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
idoso
/
adm
/
app
/
gre
/
Models
/
Filename :
GreCadastrarItemPedido.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit();} /** * Description of GreCadastrarItemPedido * * @copyright (c) year,Carlos Marques CM */ class GreCadastrarItemPedido{ private $Resultado; private $Dados; private $DadosGet; private $idUser; private $substituicao = array( ' ' => '', '_' => '', '-' => '', '/' => '', '.' => '', ',' => '.', '(' => '', ')' => ''); function getResultado() { return $this->Resultado; } public function cadItemPed(array $Dados) { $this->DadosGet = filter_input_array(INPUT_GET, FILTER_DEFAULT); $this->Dados = $Dados; // var_dump($this->Dados); // var_dump($this->DadosGet); // die; $this->Dados['data'] =$this->DadosGet['data']; $this->Dados['gre_filial_id'] =$this->DadosGet['filial_id']; $this->validaPedDuplo(); if (($this->ContPed[0]['itens'] > 0)) { $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Item do Pedido já Cadastrado ! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span> </button> </div>"; $this->Resultado = false; }else{ $this->retiraMasc(); unset( $this->Dados['gre_produto_id_aux']); unset( $this->Dados['apres_sigla']); $this->Dados['gre_status_fat_id'] = 1; $this->Dados['total_prod'] = $this->Dados['qtde_pedido'] * $this->Dados['pedido_custo']; // var_dump($this->Dados); // die; $cadItemPed = new \App\adms\Models\helper\AdmsCreate; $cadItemPed->exeCreate("gre_pedido", $this->Dados); if ($cadItemPed->getResultado()) { $_SESSION['msg'] = "<div class='alert alert-success' role='alert'> Item do Pedido cadastrado 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'> Item do Pedido não foi Cadastrado ! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span> </button> </div>"; $this->Resultado = false; } } } private function validaPedDuplo() { $verPed = new \App\adms\Models\helper\AdmsRead(); $verPed->fullRead("SELECT count(*) itens FROM gre_pedido WHERE data = :data and gre_produto_id =:prod_id and gre_fornecedor_id = :forn_id and gre_filial_id = :filial_id and gre_empr_princ_id = :id_user LIMIT :limit", "data= {$this->Dados['data']}&prod_id= {$this->Dados['gre_produto_id']}&forn_id= {$this->Dados['gre_fornecedor_id']}&filial_id= {$this->Dados['gre_filial_id']}&id_user= {$_SESSION['id_user']}&limit=1"); $this->ContPed = $verPed->getResultado(); } private function retiraMasc() { $this->Dados['qtde_pedido'] = strtr($this->Dados['qtde_pedido'] , $this->substituicao); $this->Dados['pedido_custo'] = strtr($this->Dados['pedido_custo'] , $this->substituicao); $this->Dados['ultimo_custo_medio'] = strtr($this->Dados['ultimo_custo_medio'] , $this->substituicao); } public function listarCadastrar() { $this->DadosGet = filter_input_array(INPUT_GET, FILTER_DEFAULT); $listar = new \App\adms\Models\helper\AdmsRead(); $listar->fullRead("select p.id, date_format(p.data, '%d/%m/%Y') data, p.data datai, p.gre_filial_id, f.nome_fantasia nome_filial, d.nome nome_depto, p.gre_fornecedor_id, forn.nome_fantasia nome_forn from gre_cab_pedido p inner join gre_filial f on f.id = p.gre_filial_id inner join gre_fornecedores forn on forn.id = p.gre_fornecedor_id inner join gre_prod_departamento d on d.id = p.gre_departamento_id where p.id = ". $this->DadosGet['id']); $registro['pedido'] = $listar->getResultado(); $listar->fullRead(" Select * from gre_produto where gre_empr_princ_id = ". $_SESSION['id_user'] . " and id not in (select p.gre_produto_id from gre_pedido p where p.gre_cab_pedido_id = ".$this->DadosGet['id']. ") order by id"); $registro['produtos'] = $listar->getResultado(); $this->Resultado = ['pedido' => $registro['pedido'], 'produtos' => $registro['produtos']]; var_dump($this->Resultado['pedido']); return $this->Resultado; } }