D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Models
/
Filename :
ModVendaSemestreProdListar.php
back
Copy
<?php namespace App\gre\Models; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of ModRupturaListarProduto * * @copyright (c) year, Carlos Marques - CM */ class ModVendaSemestreProdListar { private $Resultado; private $Dados; private $DadosEst; private $DadoG; private $diase; private $data1; private $mes1; private $mes2; private $mes3; private $mes4; private $mes5; private $mes6; public function listProdVenSem() { $this->Dados = filter_input_array(INPUT_GET, FILTER_DEFAULT); $lerLanc = new \App\adms\Models\helper\AdmsRead(); $this->mes1 = strftime("%m",strtotime(date("Y-m-d")."-6 month")); $this->mes2 = strftime("%m",strtotime(date("Y-m-d")."-5 month")); $this->mes3 = strftime("%m",strtotime(date("Y-m-d")."-4 month")); $this->mes4 = strftime("%m",strtotime(date("Y-m-d")."-3 month")); $this->mes5 = strftime("%m",strtotime(date("Y-m-d")."-2 month")); $this->mes6 = strftime("%m",strtotime(date("Y-m-d")."-1 month")); $lerLanc->fullRead("SELECT date_format(ro_venda_mes.data, '%Y') ano ,ro_venda_mes.filial_id , MASK(ean.id, '###.####.#####-#') ean_id ,fili.nome fili_nome ,ro_venda_mes.produto_id ,ean.id ean ,p.nome prod_nome ,date_format(p.data_inclusao, '%d/%m/%Y') data_inclusao ,p.secao_id ,sec.nome secao_nome ,p.grupo_id ,gru.nome grupo_nome ,p.subgrupo_id ,sgru.nome subgrupo_nome ,p.classe_id ,cla.nome classe_nome , case when datediff( date_sub(curdate(), interval 1 day),p.data_inclusao) < 180 then datediff( date_sub(curdate(), interval 1 day),p.data_inclusao) else datediff( curdate(),date_sub(concat(date_format(curdate(), '%Y-%m-'),'01'), interval 6 month)) end dias , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes1} THEN ro_venda_mes.qtde END),0) 'sem_1' , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes2} THEN ro_venda_mes.qtde END),0) 'sem_2' , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes3} THEN ro_venda_mes.qtde END),0) 'sem_3' , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes4} THEN ro_venda_mes.qtde END),0) 'sem_4' , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes5} THEN ro_venda_mes.qtde END),0) 'sem_5' , coalesce(SUM(CASE WHEN date_format(ro_venda_mes.data, '%m') = {$this->mes6} THEN ro_venda_mes.qtde END),0) 'sem_6' , sum(qtde) ven_total , case when (select coalesce(sum(qtde),0) from ro_venda ven where ven.filial_id = ro_venda_mes.filial_id and ven.produto_id = ro_venda_mes.produto_id and data > last_day(date_sub(curdate(), interval 1 month)) group by filial_id, produto_id) is null THEN 0 else (select coalesce(sum(qtde),0) from ro_venda ven where ven.filial_id = ro_venda_mes.filial_id and ven.produto_id = ro_venda_mes.produto_id and data > last_day(date_sub(curdate(), interval 1 month)) group by filial_id, produto_id) end ven_curso FROM (SELECT ro_venda_mes.* FROM ro_venda_mes ) ro_venda_mes join ro_produto p on p.id = ro_venda_mes.produto_id join ro_secao sec on p.secao_id = sec.id join ro_grupo gru on p.grupo_id = gru.id join ro_subgrupo sgru on p.subgrupo_id = sgru.id left join ro_classe cla on p.classe_id = cla.id join ro_ean ean on p.id = ean.produto_id join ro_filial fili on ro_venda_mes.filial_id = fili.id where ro_venda_mes.filial_id = :filial_id and ean.id =:ean_id and date_format(ro_venda_mes.data, '%Y-%m') >= date_format(date_sub(curdate(), interval 6 month) ,'%Y-%m') GROUP BY date_format(ro_venda_mes.data, '%Y'), ro_venda_mes.filial_id,ro_venda_mes.produto_id", "filial_id={$this->Dados['filial_id']}&ean_id={$this->Dados['ean_id']}"); $this->Resultado= $lerLanc->getResultado(); if($this->Resultado) { setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese'); $this->Resultado[0]['data1'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-6 month")))); $this->Resultado[0]['data2'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-5 month")))); $this->Resultado[0]['data3'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-4 month")))); $this->Resultado[0]['data4'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-3 month")))); $this->Resultado[0]['data5'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-2 month")))); $this->Resultado[0]['data6'] = ucfirst( utf8_encode( strftime("%b/%Y",strtotime(date("Y-m-d")."-1 month")))); return $this->Resultado; }else{ $this->Resultado = false; } } public function lerProd(){ $this->Dados = filter_input_array(INPUT_GET, FILTER_DEFAULT); $lerProd = new \App\adms\Models\helper\AdmsRead(); $lerProd->fullRead("SELECT p.nome prod_nome, p.id prod_id from ro_ean ean join ro_produto p on p.id = ean.produto_id where ean.id =:ean_id", "ean_id={$this->Dados['ean_id']}"); $this->Resultado= $lerProd->getResultado(); if(empty($this->Resultado)) { $this->Resultado = false; } return $this->Resultado; } public function lerEst($Dados = null){ $this->DadosEst = $Dados; //var_dump($this->DadosEst); $lerEst = new \App\adms\Models\helper\AdmsRead(); $lerEst->fullRead("SELECT date_format(e.data, '%d/%m/%Y') data_estoque, e.filial_id est_filial_id, f.nome est_filial_nome, e.produto_id est_produto_id, date_format(p.data_inclusao, '%d/%m/%Y') est_data_inclusao, concat(p.id,' - ',p.nome) est_produto_nome, (SELECT date_format(min(w.data), '%d/%m/%Y') FROM ro_estoque w where w.produto_id = :prod_id and w.filial_id = :filial_id and w.qtde > 0) est_estoque_desde, e.qtde qtde_estoque FROM ro_estoque e join ro_filial f on f.id = e.filial_id join ro_produto p on p.id = e.produto_id where e.produto_id = :prod_id and e.filial_id = :filial_id -- and e.qtde > 0 and e.data = (select max(a.data) from ro_estoque a)", "prod_id={$this->DadosEst['prod_id']}&filial_id={$this->DadosEst['filial_id']} "); $this->Resultado= $lerEst->getResultado(); // var_dump($this->Resultado); if(empty($this->Resultado)) { $this->Resultado = false; } return $this->Resultado; } }