<?php require_once('Connections/paivaconex.php'); 

//USING
require_once 'controls/verifylogin.php';

?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_paivaconex, $paivaconex);
$query_ano = "Select distinct year(datafluxo) as ano from dashboard where year(datafluxo) > 2012 order by year(datafluxo) Desc";
$ano = mysql_query($query_ano, $paivaconex) or die(mysql_error());
$row_ano = mysql_fetch_assoc($ano);
$totalRows_ano = mysql_num_rows($ano);
?>
<?php require_once('Connections/paivaconex.php'); 
require_once('funcoes.php'); 

?>
<?php
include("FusionCharts_Enterprise/Code/PHP/Includes/FusionCharts.php");
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">



<title>DashBoard de Lucro</title>
<script language="javascript" src="FusionCharts_Enterprise/JSClass/FusionCharts.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	
	//Pegar Graficos sem Modificação
    $.post("dashboard_faturamento_grafico1.php",function(data){ $("#grafico1").html(data) })
	$.post("dashboard_faturamento_grafico2.php",function(data){ $("#grafico2").html(data) })
	$.post("dashboard_faturamento_grafico3.php",function(data){ $("#grafico3").html(data) })
	$.post("dashboard_faturamento_grafico4.php",function(data){ $("#grafico4").html(data) })
	$.post("dashboard_faturamento_total.php",function(data){ $("#total").html(data) })
	
	
	//Criação de Arrays
	$("#filtrar").click(function(){
		var dia = [];
		var mes = [];
		var ano = [];
		var status = [];
		var cliente = [];
		var pasta = [];
		var detalhe = [];
	
	//Pegar Variaveis
		$.each($("input[name=mes_]:checked"), function(){
			mes.push($(this).val());
		})
		$.each($("input[name=ano_]:checked"), function(){
			ano.push($(this).val());
		})
		$.each($("input[name=dia_]:checked"), function(){
			dia.push($(this).val());
		})
		$.each($("input[name=status]:checked"), function(){
			status.push($(this).val());
		})
		$.each($("input[name=cliente]:checked"), function(){
			cliente.push($(this).val());
		})
		$.each($("input[name=pasta]:checked"), function(){
			pasta.push($(this).val());
		})
		$.each($("input[name=det]:checked"), function(){
			detalhe.push($(this).val());
		})
		
		
	
	// Colocação dos Graficos	
		$.post("dashboard_faturamento_grafico1.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("#grafico1").html(data) ;
		})
		$.post("dashboard_faturamento_grafico2.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("#grafico2").html(data) ;
		})
		$.post("dashboard_faturamento_grafico3.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("#grafico3").html(data) ;
		})
		$.post("dashboard_faturamento_grafico4.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("#grafico4").html(data) ;
		})
		$.post("dashboard_faturamento_total.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("#total").html(data) ;
		})
	
	})
	
	
	//imprimir
		$("#imprimir").click(function(){
		var dia = [];
		var mes = [];
		var ano = [];
		var status = [];
		var cliente = [];
		var pasta = [];
		var detalhe = [];
	
	//Pegar Variaveis
		$.each($("input[name=mes_]:checked"), function(){
			mes.push($(this).val());
		})
		$.each($("input[name=ano_]:checked"), function(){
			ano.push($(this).val());
		})
		$.each($("input[name=dia_]:checked"), function(){
			dia.push($(this).val());
		})
		$.each($("input[name=status]:checked"), function(){
			status.push($(this).val());
		})
		$.each($("input[name=cliente]:checked"), function(){
			cliente.push($(this).val());
		})
		$.each($("input[name=pasta]:checked"), function(){
			pasta.push($(this).val());
		})
		$.each($("input[name=det]:checked"), function(){
			detalhe.push($(this).val());
		})
		
		
	
	// na body
		$.post("dashboard_faturamento_imprimir.php",{dia: dia, mes: mes, ano: ano, status: status, cliente: cliente, pasta: pasta, detalhe:detalhe},function(data){ 
			$("body").html(data) ;
		})
	})
	
	//Selecionar Todos.
	

	$("#todos_clientes").live("click", function(){
		if($(this).attr("checked")){
			$.each($("input[name=cliente]"), function(){
				$(this).attr("checked", true);
			})
		}else{
			$.each($("input[name=cliente]"), function(){
				$(this).attr("checked", false);
			})
		
		}
	})
	
	
	$("#todos_pastas").live("click", function(){
		if($(this).attr("checked")){
			$.each($("input[name=pasta]"), function(){
				$(this).attr("checked", true);
			})
		}else{
			$.each($("input[name=pasta]"), function(){
				$(this).attr("checked", false);
			})
		
		}
	})
	
	
	$("#todos_detalhes").live("click", function(){
		if($(this).attr("checked")){
			$.each($("input[name=det]"), function(){
				$(this).attr("checked", true);
			})
		}else{
			$.each($("input[name=det]"), function(){
				$(this).attr("checked", false);
			})
		
		}
	})
	
});


</script>


</head>

<body>
<form action="" method="post">
<table width="1200" height="764" border="1" style="border-collapse: collapse; font-size: 12px;">
  <tr>
    <td width="589" height="36" align="left"><table border="0">
  <tr>
    <td width="258" height="28">Lucro
      <input type="button" name="filtrar" id="filtrar" value="Filtrar" />
      <input type="button" name="imprimir" id="imprimir" value="Imprimir" /></td>
    <td width="205" align="center"><a href="index.php">Voltar ao Sistema</a></td>
  </tr>
</table></td>
    <td width="600" height="36" align="left"><table width="583" border="0">
          <tr>
            <td width="29" height="23">Anos:</td>
            <td width="544">
            <div style="overflow:auto; width:540px; ">
              <?php do { ?>
                <input type="checkbox" name="ano_" value="<?php echo $row_ano['ano']; ?>" id="ano" />
                <?php echo $row_ano['ano']; ?>
                <?php } while ($row_ano = mysql_fetch_assoc($ano)); ?>
            </div>
            </td>
          </tr>
      </table></td>
    </tr>
    <tr>
    <td height="25" align="left" style="font-size: 12px">M&ecirc;s:     
       <label>
          <input type="checkbox" name="mes_" value="1" id="mes_0" />
          Jan</label>
       <label>
          <input type="checkbox" name="mes_" value="2" id="mes_1" />
          Fev</label>
        
        <label>
          <input type="checkbox" name="mes_" value="3" id="mes_2" />
          Mar</label>
        
        <label>
          <input type="checkbox" name="mes_" value="4" id="mes_3" />
          Abr</label>
        
        <label>
          <input type="checkbox" name="mes_" value="5" id="mes_4" />
          Mai</label>
        
        <label>
          <input type="checkbox" name="mes_" value="6" id="mes_5" />
          Jun</label>
        
        <label>
          <input type="checkbox" name="mes_" value="7" id="mes_6" />
          Jul</label>
        
        <label>
          <input type="checkbox" name="mes_" value="8" id="mes_7" />
          Ago</label>
        
        <label>
          <input type="checkbox" name="mes_" value="9" id="mes_8" />
          Set</label>
        
        <label>
          <input type="checkbox" name="mes_" value="10" id="mes_9" />
          Out</label>
        
        <label>
          <input type="checkbox" name="mes_" value="11" id="mes_10" />
          Nov</label>
        
        <label>
          <input type="checkbox" name="mes_" value="12" id="mes_11" />
          Dez</label>
      </td>
    <td height="25" align="left" style="font-size: 12px"><table width="591" border="0" style="border-collapse: collapse; font-size: 12px;">
      <tr>
        <td width="353">Status 
        <input type="checkbox" name="status" value="1" id="status" />
        Aberto  
        <input type="checkbox" name="status" value="2" id="status" />
        Baixado  
        </td>
        <td width="215" align="right" id="total" style="color:#F00">Valor Total</td>
      </tr>
    </table></td>
    </tr>
  <tr>
    <td height="19" colspan="2" align="left" style="font-size: 12px">Dias:
    <?php for ($i = 1; $i <= 31; $i++) {?>
     
      <input type="checkbox" name="dia_" value="<?php echo $i; ?>"/>
      
      <?php echo $i; 
	  }   ?>
      </td>
    </tr>
  <tr>
    <td height="271" colspan="2" align="center" id="grafico1" style="font-size: 12px">&nbsp;</td>
    </tr>
  	<tr>
        <td colspan="2" height="372" id="grafico2">&nbsp;</td>
    </tr>
    <tr>    
        <td colspan="2" id="grafico3">&nbsp;</td>
    </tr>
    <tr>
    <td height="372" colspan="2" id="grafico4">
    </td>
    <tr>
  </table>
</form>
</body>

<HEAD>

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

</HEAD>



</html>
<?php
mysql_free_result($ano);
?>
