<?php require_once('topo.php');?>
<?php require_once('lateral.php');?>
      <!-- Right side column. Contains the navbar and content of the page -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Fluxo Mensal
            <small>listagem de contas e pagamento</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="fluxo_mensal.php">Fluxo Mensal</a></li>
            <li class="active">Listagem</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12"><!-- /.box -->

              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">Fluxo Mensal</h3>
                </div><!-- /.box-header -->
                <div class="box-body">


<?php

if($_GET['ano'] == ""){
	$ano_atual = date('Y');
}else{
	$ano_atual = $_GET['ano'];	
}


//MES ATUA
if($_GET['mes'] == ""){
	$mes = date('m');
}else{
	$mes = $_GET['mes'];	
}

$datainicio = $_GET['datainicio'];

if($datainicio == ""){
	$datainicio = date('Y-m') . "-01";
}

$datafim = $_GET['datafim'];

if($datafim == ""){
	$datafim = date('Y-m') . "-30";
}

$tipo = $_GET['tipo'];
$status = $_GET['status'];
$categoria = $_GET['categoria'];

$tipo_pagar = "Pagar";
$tipo_receber = "Receber";
$selec_pagar = "select sum(valor) AS soma FROM pagamentos WHERE tipo_conta='$tipo_pagar' AND MONTH(data)='$mes' AND YEAR(data)='$ano_atual'";

$exec_pagar = mysql_query($selec_pagar, $conexao) or die(mysql_error());
/* exibindo o resultado */
while($somapagar=mysql_fetch_array($exec_pagar)) {
$soma_pagar = $somapagar['soma'];

}

$selec_receber = "select sum(valor) AS soma FROM pagamentos WHERE tipo_conta='$tipo_receber' AND MONTH(data)='$mes' AND YEAR(data)='$ano_atual'";
$exec_receber = mysql_query($selec_receber, $conexao) or die(mysql_error());

/* exibindo o resultado */
while($somareceber=mysql_fetch_array($exec_receber)) {
$soma_receber = $somareceber['soma'];

}

?>

<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
    <td height="50" valign="middle" bgcolor="#FFFFFF" class="style1">Selecione as Opções</td>
    <td width="17%" valign="middle" bgcolor="#FFFFFF" class="style1"><select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)" style="width: 250px; height: 30px; background-color: #F6F4F0; font-size: 11px; color: #2E3F44; border: 0px; padding-left: 10px;">
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;status=<?php echo $status;?>">Todas as Contas</option>
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&tipo=Pagar&amp;status=<?php echo $status;?>&categoria=<?php echo $categoria;?>" <?php if($tipo == "Pagar"){ echo "selected";}?>>Contas a Pagar</option>
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&tipo=Receber&amp;status=<?php echo $status;?>&categoria=<?php echo $categoria;?>" <?php if($tipo == "Receber"){ echo "selected";}?>>Contas a Receber</option>
    </select></td>
    <td width="17%" valign="middle" bgcolor="#FFFFFF" class="style1"><select name="jumpMenu3" id="jumpMenu3" onchange="MM_jumpMenu('parent',this,0)" style="width: 250px; height: 30px; background-color: #F6F4F0; font-size: 11px; color: #2E3F44; border: 0px; padding-left: 10px;">
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&categoria=<?php echo $categoria;?>">Todos os Status</option>
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&status=Pago&categoria=<?php echo $categoria;?>" <?php if($status == "Pago"){ echo "selected";}?>>Contas Pagas</option>
      <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&status=Aberto&categoria=<?php echo $categoria;?>" <?php if($status == "Aberto"){ echo "selected";}?>>Contas em Aberto</option>
    </select></td>
    <td width="17%" valign="middle" bgcolor="#FFFFFF" class="style1">
      <select name="jumpMenu4" id="jumpMenu4" onchange="MM_jumpMenu('parent',this,0)" style="width: 250px; height: 30px; background-color: #F6F4F0; font-size: 11px; color: #2E3F44; border: 0px; padding-left: 10px;">
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>">Todas as Categorias</option>
        
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Despesas" <?php if($categoria == "Despesas"){ echo "selected";}?>>Despesas</option>
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Outros" <?php if($categoria == "Outros"){ echo "selected";}?>>Outros</option>
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Venda" <?php if($categoria == "Venda"){ echo "selected";}?>>Vendas</option>            
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Funcionario" <?php if($categoria == "Funcionario"){ echo "selected";}?>>Pagamento de Funcionário</option>
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Clientes" <?php if($categoria == "Clientes"){ echo "selected";}?>>Recebimentos de Clientes</option>                  
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Fornecedores" <?php if($categoria == "Fornecedores"){ echo "selected";}?>>Pagamento de Fornecedores</option>                        
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Consumo" <?php if($categoria == "Consumo"){ echo "selected";}?>>Contas de Consumo</option>                        
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=ConsumoCasa" <?php if($categoria == "ConsumoCasa"){ echo "selected";}?>>Contas de Consumo Casa</option>                                                        
        <option value="fluxo_mensal.php?mes=<?php echo $mes;?>&amp;ano=<?php echo $ano_atual;?>&amp;tipo=<?php echo $tipo;?>&amp;status=<?php echo $status;?>&categoria=Impostos" <?php if($categoria == "Impostos"){ echo "selected";}?>>Impostos</option>                                      
      </select>
    </td>
    <td bgcolor="#FFFFFF">
      <form name="form" id="form" method="get" action="fluxo_mensal.php">       
        <input type="hidden" name="tipo"  value="<?php echo $tipo;?>" />
        <input type="hidden" name="status"  value="<?php echo $status;?>" />      
        <input type="hidden" name="categoria"  value="<?php echo $categoria;?>" /> 
        <input type="hidden" name="datafim"  value="<?php echo $datafim;?>" />            
        <input name="datainicio" type="date" id="datainicio"   style="width: 200px; height: 30px; background-color: #F6F4F0; font-size: 11px; color: #2E3F44; border: 0px; padding-left: 10px;"  value="<?php echo $datainicio;?>" onchange="this.form.submit()" />
    </form></td>
    <td bgcolor="#FFFFFF">
    <form name="form" id="form" method="get" action="fluxo_mensal.php">
      <input type="hidden" name="tipo"  value="<?php echo $tipo;?>" />
      <input type="hidden" name="status"  value="<?php echo $status;?>" />      
	  <input type="hidden" name="categoria"  value="<?php echo $categoria;?>" /> 
	  <input type="hidden" name="datainicio"  value="<?php echo $datainicio;?>" />            
      <input name="datafim" type="date" id="datafim"   style="width: 200px; height: 30px; background-color: #F6F4F0; font-size: 11px; color: #2E3F44; border: 0px; padding-left: 10px;"  value="<?php echo $datafim;?>" onchange="this.form.submit()" />
    </form></td>
    <td align="right" valign="middle" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="7" valign="top" bgcolor="#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="6" bgcolor="#E2E2E2">
      <tr>
        <td width="47%" align="left" class="style1"><strong>Fluxo Mensal</strong></td>
        <td colspan="4" align="right" class="style1">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="center" valign="middle"><table width="100%" border="0" cellspacing="1" cellpadding="2">
          <tr>
            <td width="5%"><span class="style1">Data</span></td>
            <td width="30%"><span class="style1">Titulo</span></td>
            <td width="10%"><span class="style1">Categoria</span></td>
            <td width="10%"><span class="style1">Valor Conta</span></td>
            <td width="10%"><span class="style1">Valor</span></td>
            <td width="10%"><span class="style1">Data Pagamento</span></td>
            <td width="10%"><span class="style1">Crédito</span></td>
            <td width="10%"><span class="style1">Débito</span></td>
            <td width="10%"><span class="style1">Status</span></td>
            </tr>
          <?php
				$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') ORDER BY data", $conexao) or die (mysql_error());			
				
				
				if($tipo != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo_conta='$tipo' ORDER BY data", $conexao) or die (mysql_error());
					echo "1";
				}

				if($categoria != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND categoria='$categoria' ORDER BY data", $conexao) or die (mysql_error());
					echo "2";					
				}	
				
				if($status != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND status='$status' ORDER BY data", $conexao) or die (mysql_error());
					echo "3";				
				}				
				
				if($tipo != "" and $status != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo_conta='$tipo'  AND status='$status' ORDER BY data", $conexao) or die (mysql_error());
					echo "3";					
				}
				
				
				if($status != "" and $categoria != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND status='$status' AND categoria='$categoria' ORDER BY data", $conexao) or die (mysql_error());				
					echo "4";					
				}				
				
				
				if($tipo != "" and $categoria != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND categoria='$categoria' AND tipo_conta='$tipo' ORDER BY data", $conexao) or die (mysql_error());
					echo "5";					
				}											
				
				if($tipo != "" and $status != "" and $categoria != ""){
					$seleciona = mysql_query("SELECT * FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo_conta='$tipo' AND categoria='$categoria') AND status='$status' ORDER BY data", $conexao) or die (mysql_error());
					echo "6";					
				}								
				
				while($linha=mysql_fetch_array($seleciona)){  
				
				$idconta_atual = $linha['idconta'];
				
				$SelecionaTituloConta = Seleciona("contas", "WHERE idconta='$idconta_atual'", "LIMIT 0,1");
				while($Conta = mysql_fetch_array($SelecionaTituloConta)){
				
					$NomeConta = $Conta['titulo_conta'];
					$ValorConta = $Conta['valor_conta'];
					
				}

				if($linha['tipo_conta'] == "Pagar"){
					$corfundo = "#FFE6E6";
				}else{
					$corfundo = "#E8FBFF";
				}

				if($linha['status'] == "Pago"){
					$corfundo		= "#5BFF5B";
				}
				
				if($linha['data'] < date('Y-m-d') and $linha['status'] != "Pago"){
					$corfundo = "#FF2626";
				}
				?>
          <tr bgcolor="<?php echo $corfundo;?>">
            <td class="style1" width="20"><?php echo InverteDataNovoSeparador($linha['data'], '-', '/');?></td>
            <td height="30" class="style1"><a href="manutencao_contas.php?idconta=<?php echo $linha['idconta'];?>" style="color:#333; font-weight:bold;"><?php echo $NomeConta;?></a></td>
            <td class="style1"><a href="index.php?pagina=manutencao_contas.php&amp;idconta=<?php echo $linha['idconta'];?>" style="color:#333; font-weight:bold;"><?php echo $linha['categoria'];?></a></td>
            <td class="style1"><a href="manutencao_contas.php?idconta=<?php echo $linha['idconta'];?>" style="color:#333; font-weight:bold;"><?php echo "R$ " . number_format($ValorConta, 2, ',', '.');?></a></td>
            <td class="style1"><?php echo "R$ " . number_format($linha['valor'], 2, ',', '.');?></td>
            <td class="style1"><?php echo InverteDataNovoSeparador($linha['data'], '-', '/');?></td>
            <td class="style1"><?php if($linha['tipo_conta'] == "Receber"){ echo "R$ " . number_format($linha['valor'], 2, ',', '.');}?></td>
            <td class="style1"><?php if($linha['tipo_conta'] == "Pagar"){ echo "R$ " . number_format($linha['valor'], 2, ',', '.');}?></td>
            <td class="style1" bgcolor="<?php echo $cor_status;?>" width="10"><?php echo $linha['status'];?></td>
            </tr>
          <?php
                }
                ?>
        </table></td>
      </tr>
      <tr>
        <td align="right" valign="middle" class="style1">&nbsp;</td>
        <td width="15%" align="right" valign="middle" class="style1">&nbsp;</td>
        <td width="11%" align="right" valign="middle" class="style1"><strong>Total à Receber:
            <?php
		$selec = "select sum(valor) AS soma FROM pagamentos WHERE tipo_conta='$tipo_receber' AND data BETWEEN ('$datainicio') AND ('$datafim')";

		$exec = mysql_query($selec, $conexao) or die(mysql_error());    

        /* exibindo o resultado */
        while($areceberreceber=mysql_fetch_array($exec)) {
        $receber = $areceberreceber['soma'];
		echo "R$ " . number_format($receber, 2, ',', '.');
        }
		?>
        </strong></td>
        <td width="14%" align="right" valign="middle" class="style1"><strong>Total à Pagar:
            <?php
        $selec = "select sum(valor) AS soma FROM pagamentos WHERE tipo_conta='$tipo_pagar' AND data BETWEEN ('$datainicio') AND ('$datafim')";

        $exec = mysql_query($selec, $conexao) or die(mysql_error());       

        /* exibindo o resultado */

        while($areceberpago=mysql_fetch_array($exec)) {
        $pago = $areceberpago['soma'];
		echo "R$ " . number_format($pago, 2, ',', '.');		
        }
		?>
        </strong></td>
        <td width="13%" align="right" valign="middle" class="style1"><strong>Saldo R$ 
		<?php
		$Total = $receber - $pago;
		echo "R$ " . number_format($Total, 2, ',', '.');	
		?>
        </strong></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4" style="border: 1px solid #666;">
  <tr>
    <td colspan="10" bgcolor="#00C462"><strong>Pagamentos Ocorridos entre: <?php InverteDataNovoSeparador($datainicio, "-", "/");?> à <?php InverteDataNovoSeparador($datafim, "-", "/");?></strong></td>
  </tr>
  <tr class="style1" style="font-weight:bold;">
    <td align="center" bgcolor="#999999">Dinheiro</td>
    <td align="center" bgcolor="#999999">Cartão de Crédito</td>
    <td align="center" bgcolor="#999999">Cartão de Débito</td>
    <td align="center" bgcolor="#999999">Cheque</td>
    <td align="center" bgcolor="#999999">Boleto Bancário</td>
    <td align="center" bgcolor="#999999">Fatura</td>
    <td align="center" bgcolor="#999999">Cheques Terceiros</td>
    <td align="center" bgcolor="#999999">Cheques Próprios</td>
    <td align="center" bgcolor="#999999">Transferência/Depósito</td>
    <td align="center" bgcolor="#999999">Débito em Conta</td>
  </tr>
  <tr>
    <td align="center">
<?php
//DINHEIRO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='dinheiro' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='dinheiro' AND status='Pago' AND tipo_conta='$tipo'";
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>  
    </td>
    <td align="center">
<?php
//CREDITO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='credito' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='credito' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//DEBITO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='debito' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='debito' AND status='Pago' AND tipo_conta='$tipo'";
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//CHEQUE 
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='cheque' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='cheque' AND status='Pago' AND tipo_conta='$tipo'";
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//BOLETO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='boleto' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='boleto' AND status='Pago' AND tipo_conta='$tipo'";
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//FATURA
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='fatura' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='fatura' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//CHEQUE BASE
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='ChequeBase' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='ChequeBase' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//CHEQUE PRÓPRIO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='ChequeProprio' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='ChequeProprio' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//TRANSFERENCIA / DEPOSITO
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='TransferenciaDeposito' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='TransferenciaDeposito' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
    <td align="center">
<?php
//DEBITO EM CONTA
if($tipo == ""){
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='DebitoConta' AND status='Pago'";
}else{
	$SelecionaPagamento = "select sum(valor) AS soma FROM pagamentos WHERE data BETWEEN ('$datainicio') AND ('$datafim') AND tipo='DebitoConta' AND status='Pago' AND tipo_conta='$tipo'";	
}
$exec = mysql_query($SelecionaPagamento, $conexao) or die(mysql_error());       

/* exibindo o resultado */
while($areceberpago=mysql_fetch_array($exec)) {
$Pagamento = $areceberpago['soma'];
echo "R$ " . number_format($Pagamento, 2, ',', '.');		
}
?>    
    </td>
  </tr>
</table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
<?php require_once('rodape.php');?>