<?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;">CONTAS GERAL</span></td>
        <td align="right"><table border="0" align="right" cellpadding="2" cellspacing="0">
          <tr>
            <td width="167" align="left"><table width="150" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='manutencao_contas.php?tipo=<?php echo $_GET['tipo'];?>';">
              <tr>
                <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                <td align="left" class="TextoMenuBranco" style="font-weight:normal;">Nova Conta</td>
                </tr>
              </table></td>
            <td width="167" align="left"><table width="160" border="0" cellspacing="0" cellpadding="2" class="BoxMenuAzul" onclick="location.href='listar_contas.php?tipo=<?php echo $_GET['tipo'];?>';">
              <tr>
                <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                <td align="left"><span class="TextoMenuBranco">Todas as Contas</span></td>
                </tr>
            </table></td>
            </tr>
          </table></td>
        <td width="79" align="right" style="padding-right: 8px;"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinza" onclick="history.go(-1);">
          <tr>
            <td height="25" align="center" class="TextoMenuBranco">Voltar</td>
            </tr>
          </table></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_padrao" class="display">
      <thead>
       <tr class="TextoCinzaEscuro">
        <td width="5%" bgcolor="#A6A6A6"><strong>CÓD. </strong></td>
        <td width="10%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>NF</strong></td>
        <td width="10%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>CATEGORIA</strong></td>
        <td width="20%" height="30" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>TITULO</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>DATA CONTA</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>STATUS</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>VALOR CONTA</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>VALOR PAGO</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>FALTA</strong></td>
        <td width="10%" align="left" bgcolor="#A6A6A6"><strong>TIPO</strong></td>
        <td width="5%" align="center" bgcolor="#A6A6A6">&nbsp;</td>
        </tr>
         </thead>
         <tbody>
      <?php
		$busca = $_POST['busca'];
			$cor_fundo = "#FFFFFF";		
			
			if($_GET['tipo'] != ""){
				$seleciona = Seleciona("contas", "WHERE tipo_conta='".$_GET['tipo']."' AND status_conta='Aberto'", "ORDER BY idconta DESC");
			}else{				  
				$seleciona = Seleciona("contas", "WHERE status_conta='Aberto'", "ORDER BY idconta DESC");				
			}
			
		  
			while($linha=mysql_fetch_array($seleciona)){
				
				$idconta = $linha['idconta'];
				
			$SomaPagamentos = mysql_query("SELECT sum(valor_total) FROM pagamentos WHERE idconta='$idconta' AND status='Pago'") or die(mysql_error());
			
			while($sum = mysql_fetch_array($SomaPagamentos)){
				$SomaPagamento = $sum['sum(valor_total)'];
				}			
			
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}
			
			$Falta = $linha['valor_conta'] - $SomaPagamento;
			
			if($linha['tipo_conta'] == "Pagar"){
				$TipoAtual = "Contas a Pagar";
			}else{
				$TipoAtual = "Contas a Receber";				
			}
			
			
				
		?>
      <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='manutencao_contas.php?idconta=<?php echo $linha['idconta'];?>';">
        <td align="left"><?php echo $linha['idconta'];?></td>
        <td><?php echo $linha['nf'];?></td>
        <td>
		<?php 
		echo RetornaCampoGeral("categorias_contas", $linha['categoria'], "idcategoria_conta", "titulo");
		?>
        </td>
        <td width="20%" height="30"><?php echo $linha['titulo_conta'];?></td>
        <td width="10%" align="left"><?php echo InverteDataNovoSeparador($linha['data_conta'], "-", "/");?></td>
        <td width="10%" align="left"><?php echo $linha['status_conta'];?></td>
        <td width="10%" align="left"><?php echo "R$ " . $linha['valor_conta'];?></td>
        <td width="10%" align="left"><?php echo "R$ " . number_format($SomaPagamento, 2, ',', '.');?></td>
        <td width="10%" align="left"><?php echo "R$ " . number_format($Falta, 2, ',', '.');?></td>
        <td width="10%" align="left"><?php echo $TipoAtual;?></td>
        <td align="right"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></td>
        </tr>
      <?php 
		$SomaPagamento = "";
		}?>
         </tbody>
    </table></td>
  </tr>
</table>
<?php require_once('../rodape.php');?>