<?php
error_reporting(0);
ini_set("display_errors", 0 );
header('Content-Type: text/html; charset=utf-8');
include("configuracao.php");//confirma no banco de dados
include("inclusos/funcoes.php");
include("seguranca.php"); // Inclui o arquivo com o sistema de seguran?a
protegePagina(); // Protege a página
?>
<!doctype html>
<html ng-app="myApp">
<head>
<title>RELATÓRIO DE TAREFAS</title>

        <link href="<?php echo $DiretorioVirtual;?>bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $DiretorioVirtual;?>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $DiretorioVirtual;?>css/ionicons.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $DiretorioVirtual;?>css/jquery-ui.min.css" type="text/css" rel="stylesheet">
        <link rel="stylesheet" href="<?php echo $DiretorioVirtual;?>css/bootstrap-select.min.css" />   
        <link href="<?php echo $DiretorioVirtual;?>inclusos/folhaestilo.css" rel="stylesheet">                                            
                       
        <!--CSS OPCIONAL-->
        <link href="<?php echo $DiretorioVirtual;?>/antigo/inclusos/styles.css" rel="stylesheet">
        <link href="<?php echo $DiretorioVirtual;?>/antigo/inclusos/css_precopratico.css" rel="stylesheet" type="text/css">         
        <link href="<?php echo $DiretorioVirtual;?>plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />

		<script src="<?php echo $DiretorioVirtual;?>plugins/jQuery/jQuery-2.1.3.min.js" type="text/javascript"></script>
        <script src="<?php echo $DiretorioVirtual;?>js/bootstrap-select.min.js"></script> 
        <script src="<?php echo $DiretorioVirtual;?>bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        

<style type="text/css">
@media print {
  #naoimprimir {
    visibility: hidden;
  }
  #printable, #printable * {
    visibility: visible;
  }
}
        </style> 


</head>
<body>
<?php
//SELECIONA E BUSCA
$datainicio = $_GET['datainicio'];
$datafim = $_GET['datafim'];
$status_orcamento = $_GET['status_orcamento'];
$idprofissional = $_GET['idprofissional'];
$idcliente = $_GET['idcliente'];

$cor_fundo = "#FFFFFF";			  
		
		//APENAS STATUS
		if($datainicio == "" and $datafim == "" and $status_orcamento != "" and $idprofissional == ""){
		echo "2";
			$seleciona_vendas = Seleciona("tarefas", "WHERE status='$status_orcamento'", "ORDER BY datainicio ASC") or die(mysql_error());
		}		
		
		//APENAS COLABORADOR
		if($datainicio == "" and $datafim == "" and $status_orcamento == "" and $idprofissional != ""){
echo "3";			
			$seleciona_vendas = Seleciona("tarefas", "WHERE idusuario='$idprofissional'", "ORDER BY datainicio ASC") or die(mysql_error());		
		}				
		
		//APENAS DATA INICIO E DATA FIM
		if($datainicio != "" and $datafim != "" and $status_orcamento == "" and $idprofissional == "" and $idcliente == ""){
		echo "4";
			$seleciona_vendas = Seleciona("tarefas", "WHERE datafim <= '$fim' AND datainicio >= '$datainicio'", "ORDER BY datainicio ASC") or die(mysql_error());
		
		}				
		
		//APENAS DATA INICIO E DATA FIM E CLIENTE
		if($datainicio != "" and $datafim != "" and $status_orcamento == "" and $idprofissional == "" and $idcliente != ""){
		echo "5";
			$seleciona_vendas = Seleciona("tarefas", "WHERE idcliente='$idcliente' AND datafim <= '$fim' AND datainicio >= '$datainicio'", "ORDER BY datainicio ASC") or die(mysql_error());
		
		}
		
		//APENAS DATA INICIO E DATA FIM E CLIENTE E VENDEDOR
		if($datainicio != "" and $datafim != "" and $status_orcamento == "" and $idprofissional != "" and $idcliente != ""){
		echo "6";
			$seleciona_vendas = Seleciona("tarefas", "WHERE idcliente='$idcliente' AND idusuario='$idprofissional' AND datafim <= '$fim' AND datainicio >= '$datainicio'", "ORDER BY datainicio ASC") or die(mysql_error());
		
		}	
		
		//APENAS DATA INICIO E DATA FIM E CLIENTE E VENDEDOR E STATUS
		if($datainicio != "" and $datafim != "" and $status_orcamento != "" and $idprofissional != "" and $idcliente != ""){
		echo "7";
			$seleciona_vendas = Seleciona("tarefas", "WHERE idcliente='$idcliente' AND idusuario='$idprofissional' AND status='$status_orcamento' AND datafim <= '$fim' AND datainicio >= '$datainicio'", "ORDER BY datainicio ASC") or die(mysql_error());
		
		}					
		
		//APENAS CLIENTE
		if($busca == "" and $datainicio == "" and $datafim == "" and $status_orcamento == "" and $idprofissional == "" and $idcliente != ""){
		echo "9";
			$seleciona_vendas = Seleciona("tarefas", "WHERE idcliente='$idcliente'", "ORDER BY datainicio ASC") or die(mysql_error());
		
		}		
$TotalVendas = mysql_num_rows($seleciona_vendas);
?>
<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" id="naoimprimir"  >
      <tr>
        <td width="80" height="40" class="TituloPagina" style="padding-left: 5px;"><a href="index.php"><img src="img/logo.png" width="110" height="40" id="printable"></a></td>
        <td align="left" class="TituloPagina" style="padding-left: 5px;"><span class="TituloPagina" style="padding-left: 5px; text-align:right" id="printable">TAREFAS</span></td>
        <td align="right">
          
          <form method="get" action="relatorio_tarefas.php" enctype="multipart/form-data">
            <table width="100%" border="0" align="center" cellpadding="2" cellspacing="2" >
              <tr>
                <td align="center"><strong>DATA</strong></td>
                <td align="left"><input name="datainicio" type="date" class="InputBranco" id="datainicio" value="<?php echo $_GET['datainicio'];?>" placeholder="Data Inicio" style="width: 100%; height: 30px; background-color: #D3D3D3;"></td>
                <td align="left"><input name="datafim" type="date" class="InputBranco" id="datafim" value="<?php echo $_GET['datafim'];?>" placeholder="Data Fim" style="width: 100%; height: 30px; background-color: #D3D3D3;" ></td>
                <td align="center"><strong>COLABORADOR</strong></td>
                <td align="center">
                  <select name="idprofissional" size="1" id="idprofissional" class="form-control selectpicker" data-live-search="true" style="width:100%; height: 30px;">
                    <option value="">Selecione Colaborador</option>
                    <?php
						$SelecionaProfissionais = Seleciona("usuarios", "WHERE excluido IS NULL", "ORDER BY Nome ASC") or die(mysql_error());
							while($linha_profissionais=mysql_fetch_array($SelecionaProfissionais)){
								$id_profissional = $linha_profissionais['idusuario'];					  
					  ?>
                    <option value="<?php echo $linha_profissionais['idusuario'];?>" <?php if($idprofissional == $id_profissional){ echo "Selected";}?>><?php echo $linha_profissionais['nome'];?></option>
                    <?php
                      }
					  ?>
                  </select>
                </td>
                <td align="center"><strong>CLIENTE</strong></td>
                <td align="center"><span style="color: #676767;  font-size: 12px;">
                  <select name="idcliente" size="1" id="idcliente" class="form-control selectpicker" data-live-search="true" style="width:100%; height: 30px;">
                    <option value="">Selecione o Cliente</option>
                    <?php
						$SelecionaProfissionais = Seleciona("clientes", "WHERE excluido IS NULL", "ORDER BY nome ASC") or die(mysql_error());
							while($linha_profissionais=mysql_fetch_array($SelecionaProfissionais)){					  
					  ?>
                    <option value="<?php echo $linha_profissionais['idcliente'];?>" <?php if($linha_profissionais['idcliente'] == $_GET['idcliente']){ echo "Selected";}?>><?php echo $linha_profissionais['nome'];?></option>
                    <?php
                      }
					  ?>
                  </select>
                </span></td>
                <td align="center"><strong>STATUS</strong></td>
                <td align="left">
                  <select name="status_orcamento" size="1" id="status_orcamento" class="form-control selectpicker" data-live-search="true" style="width:100%; ">
                    <option value="">Selecione Status</option>
                    <option value="Pendente" <?php if($_GET['status_orcamento'] == "Pendente"){ echo "Selected";}?>>Pendente</option>
                    <option value="Andamento" <?php if($_GET['status_orcamento'] == "Andamento"){ echo "Selected";}?>>Andamento</option>
                    <option value="Concluido" <?php if($_GET['status_orcamento'] == "Concluido"){ echo "Selected";}?>>Concluido</option>
                    </select>
                </td>
                <td width="200" align="right"><table width="100%" border="0" align="right" cellpadding="0" cellspacing="0" class="BoxMenuBranco">
                  
                  <tr>
                    <td width="28" align="center" bgcolor="#FFFFFF"><input type="image" src="img/icone_buscar.gif" /></td>
                    </tr>
                  
                  </table>
                  
                </td>
                </tr>
              </table>
            </form>
        </td>
        </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="top">
    <table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" id="printable">
      <tr class="TextoCinzaEscuro">
        <td width="120" align="left" bgcolor="#A6A6A6"><strong>CÓD.</strong></td>
        <td height="30" align="left" bgcolor="#A6A6A6"><strong>CLIENTE</strong></td>
        <td align="left" bgcolor="#A6A6A6"><strong>TITULO</strong></td>
        <td align="left" bgcolor="#A6A6A6"><strong>DATA INICIO</strong></td>
        <td width="100" align="left" bgcolor="#A6A6A6"><strong>DATA FIM</strong></td>   
        <td width="100" align="left" bgcolor="#A6A6A6"><strong>TEXTO</strong></td>      
        <td align="left" bgcolor="#A6A6A6"><strong>STATUS</strong></td>
        <td align="center" bgcolor="#A6A6A6"><strong>COLABORADOR</strong></td>
        </tr>
      <?php			  
			while($linha=mysql_fetch_array($seleciona_vendas)){
				
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}			
		?>
      <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>">
        <td align="left" style="font-size:10px; font-weight:bold;"><?php echo $linha['idtarefa'];?>
        </td>
        <td height="30" align="left"><?php if($linha['idcliente'] != ""){ echo NomeCliente($linha['idcliente']);};?></td>
        <td align="left"><?php echo $linha['titulo'];?></td>
        <td align="left"><?php echo InverteDataNovoSeparador($linha['datainicio'], "-", "/");?></td>
        <td align="left"><?php echo InverteDataNovoSeparador($linha['datafim'], "-", "/");?></td>
        <td align="left" style="font-size:9px;"><?php echo $linha['texto'];?></td>
        <td align="left"><?php if($linha['status'] == ""){ echo "Sem Status"; }else{ echo $linha['status'];}?></td>
        <td align="center"><?php echo NomeColaborador($linha['idusuario']);?></td>
        </tr>
      <?php 
	  $NomeCliente = "";
		}?>
    </table>
    </td>
  </tr>
</table>
</body>
</html>