<?php
include "../../funcs.php";

$linhap=100;
cssz();
if (isset($_REQUEST['cod']))
{
  if ($_REQUEST['cod']==0) # pagina 0
  {

  	// colocar o select aqui
    $filtro='';
    $sql="SELECT D.DOCITM_SEQ C0,
			   D.PRDCAD_CODIGO C1,
			   D.DOCITM_PRDCADDIGITO C2,
			   D.DOCITM_COORDENADOS C3,
			   D.DOCITM_PRDCADDESCR C4,
			   D.DOCITM_TEMA C5,
			   D.SETOR_CODIGO C6,
			   D.DOCITM_TAMANHO C7,
			   D.DOCITM_SECAO C8,
			   D.DOCITM_FAIXAS C9,
			   D.DOCITM_FAIXAPRECO C10,
			   D.DOCITM_PRECODE C11,
			   D.DOCITM_PRECOPOR C12,
			   D.DOCITM_QDE C13,
			   D.DOCITM_SUBSETOR C14,
			   D.DOCITM_COR C15,
			   D.DOCITM_ENDERECAMENTO C16,
			   D.DOCITM_STATUS C17,
			   S.DITSTS_DESCRICAO C18 
          FROM docitm D
         LEFT JOIN ditsts S
         ON (D.DOCITM_STATUS = S.DOCITM_STATUS)
         WHERE D.DOCCAB_SEQ= '".$_REQUEST["doccab"]."'";
        if ($_REQUEST['acao']=='filtrar'){
           if (isset($_REQUEST['prdcad_codigo']) and strlen($_REQUEST['prdcad_codigo'])>0){
              $sql.=" AND D.PRDCAD_CODIGO like '%".strtoupper($_REQUEST['prdcad_codigo'])."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['docitm_prdcaddigito']) and strlen($_REQUEST['docitm_prdcaddigito'])>0){
              $sql.=" AND D.DOCITM_PRDCADDIGITO like '%".$_REQUEST['docitm_prdcaddigito']."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['docitm_coordenados']) and strlen($_REQUEST['docitm_coordenados'])>0){
              $sql.=" AND D.DOCITM_COORDENADOS like '%".$_REQUEST['docitm_coordenados']."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['docitm_prdcaddescr']) and strlen($_REQUEST['docitm_prdcaddescr'])>0){
              $sql.=" AND D.DOCITM_PRDCADDESCR like '%".$_REQUEST['docitm_prdcaddescr']."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['docitm_tema']) and strlen($_REQUEST['docitm_tema'])>0){
              $sql.=" AND D.DOCITM_TEMA like '%".$_REQUEST['docitm_tema']."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['setor_codigo']) and strlen($_REQUEST['setor_codigo'])>0){
              $sql.=" AND D.SETOR_CODIGO like '%".$_REQUEST['setor_codigo']."%' ";
              $filtro='Filtro Ativado';
           }
           if (isset($_REQUEST['docitm_tamanho']) and strlen($_REQUEST['docitm_tamanho'])>0){
              $sql.=" AND D.DOCITM_TAMANHO like '%".$_REQUEST['docitm_tamanho']."%' ";
              $filtro='Filtro Ativado';
           }
        }
         $sql.=" ORDER BY D.PRDCAD_CODIGO";

    $_SESSION['Ptabseparacao2']=$sql;
    //echo '<pre>'.$sql;
    $resprop1=tw_query($_SESSION['Ptabseparacao2'],$con);
    $regs=tw_num_rows($resprop1);
    $pag=1;
    $npag=round(($regs/$linhap),0);
    if (($npag*$linhap)<$regs) $npag+=1;
    cab1($npag,$pag,$con,$filtro);
    $li=0;
    while (($row=tw_fetch_row($resprop1)) and ($li<$linhap))
    {
      $li=$li+1;
      det1($row,$pag,$con);
    }
	echo '</table> ';
	//echo '</div>';
    //echo '<table border="0" bordercolor="#000000" width="150px"> ';
//	echo $_SESSION['grid'];	
	//echo'</table>';
 }
  else
  {
    $resprop1=tw_query($_SESSION['Ptabseparacao2'],$con);
    $regs=tw_num_rows($resprop1);
    $pag=intval($_REQUEST['cod']);
    $i=(($pag-1)*$linhap);
    if ($i<$regs)
       tw_data_seek($resprop1, $i);
    $npag=round(($regs/$linhap),0);
    if (($npag*$linhap)<$regs) $npag+=1;
    cab1($npag,$pag,$con,$filtro);
    $li=0;
    while (($row=tw_fetch_row($resprop1)) and ($li<$linhap))
    { $li=$li+1;
      det1($row,$pag,$con);
    }
    echo '</table> ';
	//echo '</div>';
	//echo '<table border="0" bordercolor="#000000" width="150px"> ';
	//echo $_SESSION['grid'];	
	//echo'</table>';
  }
}
else
{ echo '<h5>Não foram informados campos para o processo...</h5>';
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../../padrao/css/estilos.css" rel="stylesheet" type="text/css"></style>
<script type="text/javascript"> djConfig = { isDebug: false }; </script>
<script type="text/javascript" src="../../../Comp_WMS/dojo/dojo.js"></script>
	<style type="text/css">
    body {
     margin-left: 0px;
     margin-top: 0px;
     margin-right: 0px;
     margin-bottom: 0px;
    }
    </style>
<?

function cab1($npag,$pag,$con,$filtro)
{
	echo '<body style="margin:0px,0px,0px,0px;">';
	echo '<form name=reimp action=print_etq.php method=post>';
	echo '<input type=hidden value="'.$_REQUEST['doccab'].'" name="doccab">';
	echo '<input type=hidden value="'.$_REQUEST['numero'].'" name="numero">';
	echo '<input type=hidden value="'.$_REQUEST['tip_etq'].'" name="tip_etq">';
	echo '<input type=hidden value="'.$_REQUEST['reimp'].'" name="reimp">';
	echo '<input type=hidden value="'.$_REQUEST['status'].'" name="status">';
	
	echo '    <table style="width: 125%;" border="0" bgcolor="87afed" class=ca4 align="top">';
	echo '    <tr>  ';
    echo '        <td class=ca4 width=55% align=left>';
		if (isset($_REQUEST['sit']) and trim($_REQUEST['sit'])<>'' and $_REQUEST['sit']==0){
			  
		}
    if (tw_get_permissao(810)==1){
        echo '    <a id=bt1 href=javascript:document.reimp.submit()>'.tw_button('Reimprimir').'</a>';
    }
	echo '        </td>';
    echo '      <td class=ca4 align=left height="0" border="0" width="25%" style="color:red;">'.$filtro.'</td>';
    echo '      <td class=ca4 align=right height="0" border="0" width="50%">  ';
    barra1($npag,$pag);
    echo '        </td>';
    echo '        </tr>';
    echo '    <tr>  ';
    echo '    		<td class="ca3" colspan="10">  ';
	echo '				<div align="center">REIMPRESSÃO DE ITENS - Documento : '.$_REQUEST['numero'].'</div> ';
    echo '    		</td>  ';
    echo '    </tr>  ';		
	echo '  </tbody></table>';
	//echo '<div style="width:735px;height:295px;overflow:auto;float:left;display:block;">';
    echo '<table border="0" bordercolor="#000000" align="botton" width="100%"> ';
    echo '    <tr>  ';
	echo '      <td class="ca3" align=center height="5" border="0">';
    echo '        Qtd à Reimprimir';
    echo '      </td>';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Código';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Digito';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Coordenados';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Descrição';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Tema';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Setor';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Tamanho';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Seção';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Faixas';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Faixa Preço';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Preço de';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Preço por';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Quantidade';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Subsetor';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Cor';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Endereçamento';
    echo '      </td>  ';
    echo '      <td class="ca3" align=center height="10" border="0">  ';
    echo '        Status';
    echo '      </td></tr> ';
}
function det1($row,$pag,$con)
{
	if (($row[18]=='Liberado') or ($row[17]==1)){
	$cor='l';
	}else
	if ( ($row[18]=='Cancelado') or ($row[17]==9) ){
	$cor='f';
	}else
	if ( ($row[18]=='Encerrado') or ($row[17]==8) ){
	$cor='e';
	}else
	if (($row[18]=='Finalizado com divergência') or ($row[17]==7)){
	$cor='e';
	}else
	if (($row[18]=='Em execucao') or ($row[17]==2)){
	$cor='ex';
	}
	echo '    <tr>  ';
	echo '<td class="de1'.$cor.'" align=center height="10" border="0" >  ';  
	echo'  <input type=text size=6 maxlength=5 value=0 name='.$row[1].'></td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[1].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[2].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[3].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[4].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[5].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[6].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[7].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[8].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[9].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[10].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0" >  ';

	$preco_de		= number_format($row[11],0);
	$preco_de		= str_replace(',','',$preco_de);
	$preco_de		= str_replace('.','',$preco_de);
	$preco_de		= ($preco_de/100);
	$preco_de		= number_format($preco_de,2);
	echo '        R$ '.$preco_de.'</a> ';

	//echo '        '.$row[11].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';

	$preco_por		= number_format($row[12],0);
	$preco_por		= str_replace(',','',$preco_por);
	$preco_por		= str_replace('.','',$preco_por);
	$preco_por		= ($preco_por/100);
	$preco_por		= number_format($preco_por,2);
	echo '        R$ '.$preco_por.'</a> ';
	
	

	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.number_format($row[13],0).'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0">  ';
	echo '        '.$row[14].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0" >  ';
	echo '        '.$row[15].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=right height="10" border="0" >  ';
	echo '        '.$row[16].'</a> ';
	echo '      </td>' ;
	echo '      <td class="de1'.$cor.'" align=left height="10" border="0" >  ';
	echo '        '.$row[18].'</a> ';
	echo '      </td>' ;
	echo '   </tr>';
}
echo '<table border="0" bordercolor="#000000" align=center width="125%"> ';
    echo '    <tr>';
    echo '      <td class="ca3" align=Left height="10" border="0" width="101.6%">  ';
    echo '         <a href=tabseparacao1.php?cod='.$_REQUEST['pag'].'&pag='.$_REQUEST['pagt'].'><img src="'.$_SESSION['sc_main_path'].'/Comp_WMS/icones/voltar.png" class="iconav" border=0></a> ';
    echo '      </td>  ';
    echo '    </tr>';
    echo '</form>';

function barra1($npag,$pag)
{
    paginacao($npag,$pag,'into_detalhes.php?numero='.$_REQUEST['numero'].'&doccab='.$_REQUEST['doccab'].'&pag='.$_REQUEST['pag'].'&sit='.$_REQUEST['sit'].'&');
}

?>
