Created
April 17, 2013 14:34
-
-
Save viniciusss/5404798 to your computer and use it in GitHub Desktop.
Relatórios de produtos de uma carga.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// head | |
session_start(); | |
require(dirname(__FILE__)."/../fpdf/fpdf.php"); | |
require(dirname(__FILE__)."/../includes/funcoes.inc.php"); | |
include(dirname(__FILE__)."/../includes/global.php"); | |
require(dirname(__FILE__)."/../includes/geral.class.php"); | |
require(dirname(__FILE__)."/includes/relatorios.inc.php"); | |
require(dirname(__FILE__)."/includes/gestao_estoque.inc.php"); | |
require(dirname(__FILE__)."/../produtos/includes/produtos.inc.php"); | |
require(dirname(__FILE__)."/includes/transbordo.inc.php"); | |
require(dirname(__FILE__)."/../assistencia/includes/assistencia.class.php"); | |
$Assistencia = new Assistencia; | |
/* | |
* classe do relatorio | |
*/ | |
class produto_carga_transbordo extends FPDF | |
{ | |
function Header() | |
{ | |
//Select Arial bold 8 | |
$this->SetFont('Arial','B',10); | |
$this->Cell(20, 10, "RELATÓRIO DE PRODUTOS ".$this->tipo, 0, 1); | |
} | |
function Footer() | |
{ | |
// font | |
$this->SetFont('Arial','B',7); | |
// totais | |
$this->Cell(120, 5, "", "T", 0); | |
$this->Cell(45, 5, "TOTAL QUANT.: ".$this->total_qtty, "T", 0); | |
$this->Cell(45, 5, "QUANT. VOLUME: ".$this->total_qtty_volume, "T", 0); | |
$this->Cell(45, 5, "TOTAL QUANT. VOLUME: ".$this->total_qtty_total_volumes, "T", 0); | |
$this->Ln(); | |
//Go to 1.5 cm from bottom | |
$this->SetY(-20); | |
$this->Cell(270, 10, "Relatório gerado por:". $_SESSION['nome_usuario']." em ".date('d/m/Y')." ás ".date('H:i:s'), 0, 0, "L"); | |
// font | |
$this->SetFont('Arial','',8); | |
$this->Cell(0,15,'Página '.$this->PageNo(),0,0,'R'); | |
} | |
} | |
// busca de carga | |
if(!empty($_REQUEST['f_int_id_carga'])) | |
{ | |
// caso solicitado todos os produtos | |
if(isset($_REQUEST['f_bln_todos_produtos']) && (1 == $_REQUEST['f_bln_todos_produtos'])) | |
$l_bln_etiqueta = false; | |
else | |
$l_bln_etiqueta = true; | |
$l_arr_produtos = g_arr_relatorio_prod_carga($_REQUEST['f_int_id_carga'], $l_bln_etiqueta); | |
// qro apenas as de troca | |
$_REQUEST['f_int_tipo_visita'] = 5; | |
// produtos de assistencias | |
$l_arr_produtos_assistencias = $Assistencia->buscarProdutosCargaTransbordo($_REQUEST); | |
if(0 < count($l_arr_produtos_assistencias)) | |
{ | |
foreach($l_arr_produtos_assistencias as $l_arr_produto_assistencia) | |
{ | |
// ajuste qtty | |
$l_arr_produto_assistencia['qtty'] = ($l_arr_produto_assistencia['qtty']*1000); | |
// adapto fornecedor | |
$l_arr_produto_assistencia['sname'] = "ASSISTÊNCIA"; | |
// agrego | |
array_push($l_arr_produtos, $l_arr_produto_assistencia); | |
} | |
} | |
if(is_array($_REQUEST['f_int_id_carga'])) | |
$l_str_tipo = "CARGAS No.: ".implode(', ',$_REQUEST['f_int_id_carga']).""; | |
else | |
$l_str_tipo = "CARGA No. ".$_REQUEST['f_int_id_carga'].""; | |
// inicio geracao de pdf | |
$pdf = new produto_carga_transbordo("L", 'mm', 'A4'); | |
$pdf->tipo = $l_str_tipo; | |
$pdf->AddPage(); | |
$pdf->SetFont('Arial', '', 8); | |
if(0 == count($l_arr_produtos)) | |
{ | |
$pdf->Cell(255, 5, "Não retornou registros.", 1); | |
$pdf->Ln(); | |
} | |
else | |
{ | |
// controle centro de lucro inicial | |
$l_int_clno = $l_arr_produtos[0]['cl_separado']; | |
$l_str_prdno = ''; | |
// totais | |
$pdf->total_qtty = 0; | |
$pdf->total_qtty_volume = 0; | |
$pdf->total_qtty_total_volumes = 0; | |
// Nome do grande centro de lucro | |
$l_str_query = "SELECT name FROM sqldados.cl WHERE no = ".$l_arr_produtos[0]['clno']; | |
$l_str_cl_nome = g_arr_executa_query($l_str_query, 'getOne'); | |
// font | |
$pdf->SetFont('Arial', 'B', 10); | |
// grande cl | |
$pdf->Cell(190, 5, $l_str_cl_nome, "B", 1); | |
// font | |
$pdf->SetFont('Arial','B',8); | |
$pdf->Cell(15, 5, "Produto", 1); | |
$pdf->Cell(75, 5, "Descrição", 1); | |
$pdf->Cell(22, 5, "Mapa", 1); | |
$pdf->Cell(20, 5, "Grade", 1); | |
$pdf->Cell(5, 5, "X", 1); | |
$pdf->Cell(12, 5, "Quant.", 1); | |
$pdf->Cell(23, 5, "Fabricante", 1); | |
$pdf->Cell(15, 5, "Peso", 1); | |
$pdf->Cell(28, 5, "Larg x Alt x Comp", 1); | |
$pdf->Cell(65, 5, "Descrição/Anotação", 1); | |
$pdf->Ln(); | |
$l_str_grupo_mapa_anterior = $l_arr_produtos[0]['grupo_mapa']; | |
foreach($l_arr_produtos as $l_arr_busca) | |
{ | |
if($l_arr_busca['grupo_mapa'] != $l_str_grupo_mapa_anterior) | |
$pdf->AddPage(); | |
// caso seja um novo | |
if($l_int_clno != $l_arr_busca['cl_separado']) | |
{ | |
// qlqr um dos dois era pra ser separado | |
if((1 == $l_int_clno) || (1 == $l_arr_busca['cl_separado'])) | |
{ | |
$pdf->AddPage(); | |
// novo clno | |
$l_int_clno = $l_arr_busca['cl_separado']; | |
// Nome do grande centro de lucro | |
$l_str_query = "SELECT name FROM sqldados.cl WHERE no = ".$l_arr_busca['clno']; | |
$l_str_cl_nome = g_arr_executa_query($l_str_query, 'getOne'); | |
// font | |
$pdf->SetFont('Arial', 'B', 10); | |
$pdf->Cell(190, 5, $l_str_cl_nome, "B", 1); | |
// font | |
$pdf->SetFont('Arial','B',8); | |
$pdf->Cell(15, 5, "Produto", 1); | |
$pdf->Cell(75, 5, "Descrição", 1); | |
$pdf->Cell(22, 5, "Mapa", 1); | |
$pdf->Cell(20, 5, "Grade", 1); | |
$pdf->Cell(5, 5, "X", 1); | |
$pdf->Cell(12, 5, "Quant.", 1); | |
$pdf->Cell(23, 5, "Fabricante", 1); | |
$pdf->Cell(15, 5, "Peso", 1); | |
$pdf->Cell(28, 5, "Larg x Alt x Comp", 1); | |
$pdf->Cell(65, 5, "Descrição/Anotação", 1); | |
// zero os totais | |
$pdf->total_qtty = 0; | |
$pdf->total_qtty_volume = 0; | |
$pdf->total_qtty_total_volumes = 0; | |
$pdf->Ln(); | |
} | |
} | |
// font | |
$pdf->SetFont('Arial', '', 8); | |
// dados dos produtos | |
$pdf->Cell(15, 5, $l_arr_busca['prdno'], 1); | |
$pdf->Cell(75, 5, $l_arr_busca['name'], 1); | |
$pdf->Cell(22, 5, $l_arr_busca['nome_mapa'], 1); | |
$pdf->Cell(20, 5, $l_arr_busca['grade'], 1); | |
$pdf->Cell(5, 5, "", 1); | |
$pdf->Cell(12, 5, ($l_arr_busca['qtty']/1000), 1, 0, 'C'); | |
$pdf->Cell(23, 5, $l_arr_busca['sname'], 1); | |
$l_arr_busca_produtos_volumes = g_arr_busca_volumes_produto_lote($l_arr_busca['prdno']); | |
// contador | |
$l_int_cont = 0; | |
if(!g_bln_isset($l_arr_busca_produtos_volumes[$l_int_cont]['largura'])) | |
{ | |
$pdf->Cell(60, 5, "Sem dados logísticos", 1); | |
$pdf->Cell(55, 5, "", 1); | |
$pdf->Ln(); | |
// calculo do volume total | |
$pdf->total_qtty_volume += 1; | |
$pdf->total_qtty_total_volumes += 1; | |
} | |
else | |
{ | |
$pdf->Cell(108, 5, "", 1); | |
$pdf->Ln(); | |
// calculo do volume total | |
$pdf->total_qtty_volume += count($l_arr_busca_produtos_volumes); | |
$pdf->total_qtty_total_volumes += (($l_arr_busca['qtty']/1000) * count($l_arr_busca_produtos_volumes)); | |
// loop | |
while($l_int_cont < count($l_arr_busca_produtos_volumes)) | |
{ | |
$pdf->Cell(172, 5, "", 0); | |
$pdf->Cell(15, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['peso_bruto'], "TB"); | |
$pdf->Cell(28, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['largura']." x ".$l_arr_busca_produtos_volumes[$l_int_cont]['altura']." x ".$l_arr_busca_produtos_volumes[$l_int_cont]['comprimento'], "TB"); | |
$pdf->Cell(65, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['descricao_volume'], "TB"); | |
$pdf->Ln(); | |
// incrementa | |
$l_int_cont++; | |
} | |
// limpo o array dos dados de volumes do produto | |
unset($l_arr_busca_produtos_volumes); | |
} | |
$pdf->total_qtty += ($l_arr_busca['qtty']/1000); | |
// Para cada produto, verifico suas informações de detalhamento | |
$l_arr_detalhamentos_produto = g_arr_detalhamentos_produto_carga($l_arr_busca); | |
foreach($l_arr_detalhamentos_produto as $l_arr_detalhamento_produto) | |
{ | |
$pdf->Cell(172, 5, "", 0); | |
$pdf->Cell(88, 5, 'Carga: '.$l_arr_detalhamento_produto['id_carga'].' / '.$l_arr_detalhamento_produto['nome_itinerario'], "TB"); | |
$pdf->Cell(20, 5, 'Qntde: '.number_format($l_arr_detalhamento_produto['qtty']/1000, 0, '', ''), "TB"); | |
$pdf->Ln(); | |
} | |
$l_str_grupo_mapa_anterior = $l_arr_busca['grupo_mapa']; | |
} | |
} | |
} | |
// busca de produtos do transbordo | |
else | |
{ | |
$pdf = new produto_carga_transbordo("L", 'mm', 'A4'); | |
$l_int_data_incio = g_str_limpa_numero(g_str_formata_data_banco($_REQUEST['f_str_data_finalizacao_inicial'])); | |
$l_int_data_fim = g_str_limpa_numero(g_str_formata_data_banco($_REQUEST['f_str_data_finalizacao_final'])); | |
// Quantidade de dias no periodo | |
$strQuery = "SELECT ABS(TO_DAYS('".$l_int_data_fim."')-TO_DAYS('".$l_int_data_incio."')) AS intervalo"; | |
// String com query | |
$arrExecuta = g_arr_executa_query($strQuery, 'getOne'); | |
// Se periodo ultrapassar 30 dias, a busca nao e executada e retorno array com mensagem | |
if(10 < $arrExecuta) | |
return array('type'=>'alert', 'message'=>"O período deve ser menor ou igual a 10 dias."); | |
else | |
$l_arr_produtos = g_arr_relatorio_prod_transbordo($_REQUEST); | |
$l_str_tipo= ''; | |
if(!empty($_REQUEST['f_int_id_transbordo'])) | |
$l_str_tipo .= " - TRANSBORDO No.: ".$_REQUEST['f_int_id_transbordo']; | |
else | |
$l_str_tipo .= " - TRANSBORDOS - Período: ".$_REQUEST['f_str_data_finalizacao_inicial']. " à ".$_REQUEST['f_str_data_finalizacao_final']; | |
$pdf->tipo = $l_str_tipo; | |
$pdf->AddPage(); | |
//Select Arial bold 8 | |
$pdf->SetFont('Arial','B',8); | |
$pdf->Cell(15, 5, "Produto", 1); | |
$pdf->Cell(75, 5, "Descrição", 1); | |
$pdf->Cell(22, 5, "Mapa", 1); | |
$pdf->Cell(20, 5, "Grade", 1); | |
$pdf->Cell(5, 5, "X", 1); | |
$pdf->Cell(12, 5, "Quant.", 1); | |
$pdf->Cell(23, 5, "Fabricante", 1); | |
$pdf->Cell(15, 5, "Peso", 1); | |
$pdf->Cell(28, 5, "Larg x Alt x Comp", 1); | |
$pdf->Cell(65, 5, "Descrição/Anotação", 1); | |
$pdf->Ln(); | |
$pdf->SetFont('Arial', '', 8); | |
if(0 == count($l_arr_produtos)) | |
{ | |
$pdf->Cell(280, 5, "Não retornou registros.", 1); | |
$pdf->Ln(); | |
} | |
else | |
{ | |
// totais | |
$pdf->total_qtty = 0; | |
$pdf->total_qtty_total_volumes = 0; | |
$l_str_grupo_mapa_anterior = $l_arr_produtos[0]['grupo_mapa']; | |
foreach($l_arr_produtos as $l_arr_busca) | |
{ | |
if($l_arr_busca['grupo_mapa'] != $l_str_grupo_mapa_anterior) | |
$pdf->AddPage(); | |
$l_arr_busca_produtos_volumes = g_arr_busca_produtos_volumes(array('f_str_prdno'=>$l_arr_busca['prdno'])); | |
$l_int_cont = 0; // contador | |
$pdf->Cell(15, 5, $l_arr_busca['prdno'], 1); | |
$pdf->Cell(75, 5, $l_arr_busca['name'], 1); | |
$pdf->Cell(22, 5, $l_arr_busca['nome_mapa'], 1); | |
$pdf->Cell(20, 5, $l_arr_busca['grade'], 1); | |
$pdf->Cell(5, 5, "", 1); | |
$pdf->Cell(12, 5, ($l_arr_busca['qtty']/1000), 1, 0, 'C'); | |
$pdf->Cell(23, 5, $l_arr_busca['sname'], "TBL"); | |
if(!isset($l_arr_busca_produtos_volumes[$l_int_cont]['largura'])) | |
{ | |
$pdf->Cell(60, 5, "Sem dados logísticos", "TBL"); | |
$pdf->Cell(55, 5, "", "TBR"); | |
$pdf->Ln(); | |
} | |
else | |
{ | |
$pdf->Cell(108, 5, "", 1); | |
$pdf->Ln(); | |
$pdf->total_qtty_volume += count($l_arr_busca_produtos_volumes); | |
$pdf->total_qtty_total_volumes += (($l_arr_busca['qtty']/1000) * count($l_arr_busca_produtos_volumes)); | |
// loop | |
while($l_int_cont < count($l_arr_busca_produtos_volumes)) | |
{ | |
$pdf->Cell(172, 5, "", 0); | |
$pdf->Cell(15, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['peso_bruto'], "TB"); | |
$pdf->Cell(28, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['largura']." x ".$l_arr_busca_produtos_volumes[$l_int_cont]['altura']." x ".$l_arr_busca_produtos_volumes[$l_int_cont]['comprimento'], "TB"); | |
$pdf->Cell(65, 5, $l_arr_busca_produtos_volumes[$l_int_cont]['descricao_volume'], "TBR"); | |
$pdf->Ln(); | |
$l_int_cont++; // incrementa | |
} | |
unset($l_arr_busca_produtos_volumes); // limpo o array dos dados de volumes do produto | |
} | |
$pdf->total_qtty += ($l_arr_busca['qtty']/1000); | |
// Para cada produto, verifico suas informações de detalhamento | |
$l_arr_detalhamentos_produto = g_arr_detalhamentos_produto_tranbordo($l_arr_busca['id_transbordo_xroute_produto']); | |
foreach($l_arr_detalhamentos_produto as $l_arr_detalhamento_produto) | |
{ | |
$pdf->Cell(172, 5, "", 0); | |
$pdf->Cell(88, 5, 'Tipo/Itinerário: '.$l_arr_detalhamento_produto['nome_itinerario'], "TB"); | |
$pdf->Cell(20, 5, 'Qtde: '.number_format($l_arr_detalhamento_produto['qtty']/1000, 0, '', ''), "TB"); | |
$pdf->Ln(); | |
} | |
$l_str_grupo_mapa_anterior = $l_arr_busca['grupo_mapa']; | |
} | |
} | |
} | |
$pdf->OutPut(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment