<?php require_once('../topo.php');?>
<?php require_once('../lateral.php');?>
<br><br><br>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="50" colspan="4" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="40"><span class="TituloPagina" style="padding-left: 5px;">COMPRAS</span></td>
        <td align="right">&nbsp;</td>
        <td width="80" align="right" style="padding-right: 8px;">&nbsp;</td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="top">
     <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" id="tabela_obra" class="display">
      <thead>
       <tr class="TextoCinzaEscuro">
        <td width="2%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>CÓD.</strong></td>
        <td width="5%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>Nº PROP.</strong></td>
        <td width="20%" height="30" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>TITÚLO</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>CLIENTE</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>DATA INICIO</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>DATA FIM</strong></td>
        <td width="20%" align="left" bgcolor="#A6A6A6"><strong>DATA LIBERAÇÃO</strong></td>
        <td width="20%" align="left" bgcolor="#A6A6A6"><strong>STATUS COMPRA</strong></td>
        <td width="5%" align="center" bgcolor="#A6A6A6">&nbsp;</td>
      </tr>
      </thead>
      <tbody>
      <?php
		$busca = $_POST['busca'];
			$cor_fundo = "#FFFFFF";		
			  if($_SESSION['idfilial_usuario'] == 1){
			 	$seleciona = Seleciona("obras", "WHERE planilhadecompras='Concluida' AND oculta IS NULL", "ORDER BY idobra DESC");
			  }else{
				 $seleciona = Seleciona("obras", "WHERE idfilial='".$_SESSION['idfilial_usuario']."' AND planilhadecompras='Concluida' AND oculta IS NULL", "ORDER BY idobra DESC"); 
			  }			  				  
			while($linha=mysql_fetch_array($seleciona)){
				$id_obra = $linha['idobra'];
				$id_cliente = $linha['idcliente'];
				
				//SELECIONA NOME CATEGORIA
				
			 	$SelecionaCliente = Seleciona("clientes", "WHERE CodCli='$id_cliente'", "");	
				while($clientes=mysql_fetch_array($SelecionaCliente)){
					$NomeCliente = $clientes['Fantasia'];
				}
						
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}						
		?>
      <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>" onmouseover="javascript:this.style.backgroundColor='#CCCCCC'" onmouseout="javascript:this.style.backgroundColor='<?php echo $cor_fundo;?>'" style="cursor:pointer;" onclick="location.href='listar_compras_obra.php?idobra=<?php echo $linha['idobra'];?>';">
        <td width="2%"><?php echo $linha['codmax'];?></td>
        <td width="2%"><?php echo $linha['idvenda'];?></td>
        <td width="20%" height="30"><?php echo $linha['titulo'];?></td>
        <td width="10%" align="left"><?php echo $NomeCliente;?></td>
        <td width="10%" align="left"><?php echo InverteDataNovoSeparador($linha['datainicio'], "-", "/");?></td>
        <td width="10%" align="left"><?php echo InverteDataNovoSeparador($linha['datafim'], "-", "/");?></td>
        <td width="20%" align="left"><?php echo date('d/m/Y H:i:s', strtotime($linha['datahora_planilhacompras']));?></td>
        <td width="20%" align="left"><?php if($linha['status_compra'] == ""){ echo "Solicitada";}else{ echo $linha['status_compra'];}?></td>
        <td width="5%" align="right"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></td>
      </tr>
      <?php 
		}?>
       </tbody>
    </table>
    </td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="middle">
</td>
  </tr>
</table>
<?php require_once('../rodape.php');?>