<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Parametros Reporte Ventas Anuales</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />

<link href="../../chosen/chosen.css" rel="stylesheet" />
<link href="../../tcal.css" rel="stylesheet" type="text/css" />
<!--
<script language="javascript" src="js/jquery-1.3.min.js"></script>
<script language="javascript" src="../../js/tcal.js" type="text/javascript"></script>
-->
<script language="javascript" src="../../js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../../chosen/chosen.jquery.js"></script>

<script language="javascript">
	$(document).ready(function(){
		$("#cbx_elegido1").change(function () {

			$('#cbx_elegido3').find('option').remove().end().append('<option value="0">Todos</option>').val('0');
			$('#cbx_elegido4').find('option').remove().end().append('<option value="0">Todos</option>').val('0');
			
			$("#cbx_elegido1 option:selected").each(function () {
				elegido1 = $(this).val();
				$.post("elegido1.php", { elegido1: elegido1 }, function(data){
					$("#cbx_elegido2").html(data);
				});            
			});
		})
	});
	
	$(document).ready(function(){
		$("#cbx_elegido2").change(function () {

			$('#cbx_elegido4').find('option').remove().end().append('<option value="0">Todos</option>').val('0');

			$("#cbx_elegido2 option:selected").each(function () {
				elegido2 = $(this).val();
				$.post("elegido2.php", { elegido2: elegido2 }, function(data){
					$("#cbx_elegido3").html(data);
				});            
			});
		})
	});

	$(document).ready(function(){
		$("#cbx_elegido3").change(function () {
			$("#cbx_elegido3 option:selected").each(function () {
				elegido3 = $(this).val();
				$.post("elegido3.php", { elegido3: elegido3 }, function(data){
					$("#cbx_elegido4").html(data);
				});            
			});
		})
	});

</script>

<script language="JavaScript"> 
 
function oculta(id){
	 var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
	 elDiv.style.display='none'; //damos un atributo display:none que oculta el div	 
	}
 
function muestra(id){
	 var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
	 elDiv.style.display='block';//damos un atributo display:block que  el div	 
	}
 
window.onload = function(){/*hace que se cargue la función */
/* "Mandamos como parametro el nombre de la Div para ocultar" */
muestra('Pitem');
oculta('Pcliente'); /*Ocultamos Pmoral*/
oculta('Pvendedor');
oculta('Palmacen');
oculta('Plocal');
oculta('Pciudad');
/*oculta('Pfamilia');*/
oculta('Pagrupado');
}
</script>
</head>
<?php

include "../../conn.php";
include "../../general.php";
include "../../token.php";

//$usuario = $_GET["user"];
?>
<body>

	<?php
	
//Inicio reporte ventas anuales

//listado de vendedores
$result = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as vendedor
from agnPerson
where
fldIsEmployee = 1 and
fldCanSell = 1 and 
sysEnabled = 1 and sysAuthorized = 1
order by vendedor;");

//listado de clientes
$result2 = mysqli_query($link, "select pkyCompany as codigo, fldName as cliente
from agnCompany
where
fldIsClient = 1 and
sysEnabled = 1 and sysAuthorized = 1
order by cliente;");

//monedas para el reporte
$result1 = mysqli_query($link, "select pkyCurrency as codigo, fldName as moneda
from actCurrency
where
sysEnabled = 1 and sysAuthorized = 1;");

//listado de items
$result3 = mysqli_query($link, "select pkyItem as codigo, fldName as item, fldFactoryKey as cod_fabrica
from 
invItem
where
sysEnabled = 1 and sysAuthorized = 1
order by item;");

//listado de almacenes
$result4 = mysqli_query($link, "select pkyWarehouse as codigo, fldName as almacen
from invWarehouse
where
sysEnabled = 1 and sysAuthorized = 1
order by almacen;");

//listado de local o punto de venta
$result5 = mysqli_query($link, "select pkySalesPlace as codigo, fldName as local
from slsSalesPlace
where
sysEnabled = 1 and sysAuthorized = 1
order by local;");

//listado de ciudad en base a los clientes
$result6 = mysqli_query($link, "select a.codCityLocation as codigo, b.fldName as ciudad
from
agnCompany a, regCity b
where
a.fldIsClient = 1 and 
a.codCityLocation = b.pkyCity and 
a.sysEnabled = 1 and a.sysAuthorized = 1 
group by codigo 
order by ciudad;");

//listado de tipos de venta
$result7 = mysqli_query($link, "select pkySalesNoteType as codigo, fldName as tipo
from 
slsSalesNoteType
where
sysEnabled = 1 and sysAuthorized = 1
order by tipo;");

//canal
$result8 = mysqli_query($link, "select pkyChannel as codigo, fldName as canal
from agnChannel 
where 
sysEnabled = 1 and sysAuthorized = 1
order by fldName;");

//lista contexto
$result9 = mysqli_query($link, "select pkyContext as cod_contexto, fldName as contexto, codCostCenter as cod_cc 
from srvContext
where 
sysEnabled = 1 and sysAuthorized = 1;");

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><b>Empresa: <?php echo $nombre_empresa; ?><br/>NIT: <?php echo $mi_nit; ?></b>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?><br/>FH</b>
</td></tr></table><br/>
<table border="0" align="center" cellpadding="5"><tr><td colspan="2" align="center">
<b>Par&aacute;metros Reporte Ventas Anuales</b></td></tr><tr><td>
<form id="miform" name="miform" method="post" action="report.php?rep=14&tipo=1">
<br/><b>Usuario: </b></td><td> <br/><input type="text" name="usuario" value="<?php echo $usuario; ?>" size="20" readonly="readonly" class="formulario" style="color:#999;">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</td></tr><tr><td>
<br/><b>Asiento con CC: </b></td><td> <br/><input type="radio" name="asientocc" checked="checked" value="0" class="formulario"> No
<br/><input type="radio" name="asientocc" value="1" class="formulario"> Si
</td></tr><tr><td>
<br/><b>Ver Bonificaci&oacute;n: </b></td><td> <br/><input type="radio" name="verbono" checked="checked" value="0" class="formulario"> No
<br/><input type="radio" name="verbono" value="1" class="formulario"> Si
</td></tr><tr><td>
<br/><b>Agrupado: </b></td><td> <br/><input type="radio" name="agrupado" checked="checked" value="0" class="formulario" onClick="oculta('Pagrupado'); muestra('Pfamilia'); muestra('Psubfamilia'); muestra('Pgrupo'); muestra('Psubgrupo')"> No
<br/><input type="radio" name="agrupado" value="1" class="formulario" onClick="muestra('Pagrupado'); muestra('Pfamilia'); oculta('Psubfamilia'); oculta('Pgrupo'); oculta('Psubgrupo')"> Si

</td></tr><tr><td colspan="2">
<table border="0" id="Pagrupado">
<tr><td width="100">
<br/><b>Agrupado por: </b></td><td> 
<br/>&nbsp;&nbsp;<input type="radio" name="porfamilia" checked="checked" value="0" class="formulario" onClick="muestra('Pfamilia'); oculta('Psubfamilia'); oculta('Pgrupo'); oculta('Psubgrupo')"> Familia 
<br/>&nbsp;&nbsp;<input type="radio" name="porfamilia" value="1" class="formulario" onClick="muestra('Pfamilia'); muestra('Psubfamilia'); oculta('Pgrupo'); oculta('Psubgrupo')"> Sub Familia
<br/>&nbsp;&nbsp;<input type="radio" name="porfamilia" value="2" class="formulario" onClick="muestra('Pfamilia'); muestra('Psubfamilia'); muestra('Pgrupo'); oculta('Psubgrupo')"> Grupo
<br/>&nbsp;&nbsp;<input type="radio" name="porfamilia" value="3" class="formulario" onClick="muestra('Pfamilia'); muestra('Psubfamilia'); muestra('Pgrupo'); muestra('Psubgrupo')"> Sub Grupo
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
<br/><input type="radio" name="porfamiliacon" checked="checked" value="0" class="formulario"> Detalle 
<br/><input type="radio" name="porfamiliacon" value="1" class="formulario"> Consolidado

</td></tr>
</table>
</td></tr><tr><td>
<br/><b>Contexto: </b></td><td> <br/><!--<SELECT NAME="concepto_pago" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="contexto">
    <option value="-1">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result9)) {   
	?> 
	<option value="<?php echo $row['cod_contexto']?>"><?php echo $row['cod_contexto']?> - <?php echo $row['contexto']?></option> 
	<?php 
	}  
	mysqli_free_result($result9);
	?> 
    </select>

</td></tr><tr><td>
<br/><b>Tipo: </b></td><td> <br/><!--<SELECT NAME="tiponota" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="tiponota">
	<option value="0">Todos</option>
    <?php 
	while ($row = mysqli_fetch_array($result7)) {   
	?> 
    
	<option value="<?php echo $row['codigo']?>"><?php echo $row['tipo']?></option> 
	<?php 
	}  
	mysqli_free_result($result7);
	?> 
    </SELECT>
</td></tr><tr><td width="100">

<br/><b>Ventas anuales por: </b></td><td> 
<br/><input type="radio" name="ventas" checked="checked" value="0" class="formulario" onClick="muestra('Pitem'); oculta('Pvendedor'); oculta('Pcliente'); oculta('Palmacen'); oculta('Plocal'); oculta('Pciudad')"> Item
<br/><input type="radio" name="ventas" value="1" class="formulario" onClick="muestra('Pvendedor'); oculta('Pitem'); oculta('Pcliente'); oculta('Palmacen'); oculta('Plocal'); oculta('Pciudad')"> Vendedor
<br/><input type="radio" name="ventas" value="2" class="formulario" onClick="muestra('Pcliente'); oculta('Pitem'); oculta('Pvendedor'); oculta('Palmacen'); oculta('Plocal'); oculta('Pciudad')"> Cliente
<br/><input type="radio" name="ventas" value="3" class="formulario" onClick="muestra('Palmacen'); oculta('Pitem'); oculta('Pvendedor'); oculta('Pcliente'); oculta('Plocal'); oculta('Pciudad')"> Almacen
<br/><input type="radio" name="ventas" value="4" class="formulario" onClick="muestra('Plocal'); oculta('Pvendedor'); oculta('Pitem'); oculta('Pcliente'); oculta('Palmacen'); oculta('Pciudad')"> Punto o local de venta
<br/><input type="radio" name="ventas" value="5" class="formulario" onClick="muestra('Pciudad'); oculta('Pvendedor'); oculta('Pitem'); oculta('Pcliente'); oculta('Palmacen'); oculta('Plocal')"> Ciudad (en base al cliente)

</td></tr><tr><td colspan="2">
<table border="0" id="Pitem">
<tr><td width="95">
<br/><b>Item: </b></td><td> <br/>&nbsp;&nbsp;<!--<SELECT NAME="item" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:450px;" NAME="item">
	<option value="0">Todos</option>
    <?php 
	while ($row = mysqli_fetch_array($result3)) {   
	?> 
    
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['cod_fabrica']?> - <?php echo $row['item']?></option> 
	<?php 
	}  
	mysqli_free_result($result3);
	?> 
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Pcliente">
<tr><td width="95">
<br/><b>Cliente: </b></td><td><br/>&nbsp;&nbsp;<!--<SELECT NAME="cliente" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="cliente">
	<option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result2)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['cliente']?></option> 
	<?php 
	}  
	mysqli_free_result($result2);
	
	?>
    </select>
</td></tr><tr><td>

<br/><b>Canal (solo para empresas): </b></td><td><br/>&nbsp;&nbsp;<!--<SELECT NAME="concepto_cobro" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="canal_venta">
    <option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result8)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['canal']?></option> 
	<?php 
	}  
	mysqli_free_result($result8);
	?> 
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Pvendedor">
<tr><td width="95">
<br/><b>Vendedor: </b></td><td> <br/>&nbsp;&nbsp;<!--<SELECT NAME="vendedor" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="vendedor">
	<option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result)) {   
	?> 
    
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['vendedor']?></option> 
	<?php 
	}  
	mysqli_free_result($result);
	?> 
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Palmacen">
<tr><td width="95">
<br/><b>Almacen: </b></td><td><br/>&nbsp;&nbsp;<!--<SELECT NAME="almacen" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="almacen">
	<option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result4)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['almacen']?></option> 
	<?php 
	}  
	mysqli_free_result($result4);
	?>
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Plocal">
<tr><td width="95">
<br/><b>Punto o Local de venta: </b></td><td><br/>&nbsp;&nbsp;<!--<SELECT NAME="local" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="local">
	<option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result5)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['local']?></option> 
	<?php 
	}  
	mysqli_free_result($result5);
	?>
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Pciudad">
<tr><td width="95">
<br/><b>Ciudad: </b></td><td><br/>&nbsp;&nbsp;<!--<SELECT NAME="ciudad" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="ciudad">
	<option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result6)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['ciudad']?></option> 
	<?php 
	}  
	mysqli_free_result($result6);
	?>
    </select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Pfamilia">
<tr><td width="105">

<br/><b>Familia: </b></td><td> <br/><!--<SELECT NAME="familia" id="combo1" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="familia" id="cbx_elegido1">
	<?php 
	$query = "select pkyItemCategory as cod, fldName as categoria
	from
	invItemCategory
	where
	fldLevel = 1 and
	sysEnabled = 1 and sysAuthorized = 1 
	order by categoria";
	$resultado=$mysqli->query($query);
	?>
	<option value="0">Todos</option>
	<?php while($row = $resultado->fetch_assoc()) { ?>
		<option value="<?php echo $row['cod']; ?>"><?php echo $row['cod'].' - '.$row['categoria']; ?></option>
	<?php } 
	$resultado->close(); ?> 
	</select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Psubfamilia">
<tr><td width="105">
<br/><b>Sub Familia: </b></td><td> <br/><SELECT NAME="subfamilia" id="cbx_elegido2" style="width:300px;" class="select-css">	
<option value="0">Todos</option>
</select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Pgrupo">
<tr><td width="105">

<br/><b>Grupo: </b></td><td> <br/><SELECT NAME="grupo" id="cbx_elegido3" style="width:300px;" class="select-css">	
<option value="0">Todos</option>
</select>
</td></tr>
</table>

</td></tr><tr><td colspan="2">
<table border="0" id="Psubgrupo">
<tr><td width="105">

<br/><b>Sub Grupo: </b></td><td> <br/><SELECT NAME="subgrupo" id="cbx_elegido4" style="width:300px;" class="select-css">
<option value="0">Todos</option>
</select>
</td></tr>
</table>

</td></tr><tr><td>

<br/><b>Mes A&ntilde;o Inicial: </b></td><td> <br/><div>
<select name="mesini" class="formulario">
  <?php
      //$mes=date("n"); 
	  $mes=$mes_ini;
      $rango=11; 
      for ($i=1;$i<=12;$i++){ 
         if($mes>12) { $mes=1; }
		 $meses=nombreMes($mes);
		 echo "<option value='$mes'>$meses</option>";
		 $mes++; 
      } 
  ?> 
</select>
<input type="text" name="anoini" value="<?php echo $ano_ini; ?>" size="4" length="4" maxlength="4" title="aaaa"> </div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
aaaa

</td></tr><tr><td>
<br/><b>Mostrar Por: </b></td><td><input type="radio" name="mostrar_mes" checked="checked" value="0" class="formulario"> Mes 
<br/><input type="radio" name="mostrar_mes" value="1" class="formulario"> Semanas Completas (Lun-Dom)
<br/><input type="radio" name="mostrar_mes" value="2" class="formulario"> Semanas Incompletas (Lun-Dom)
    
</td></tr><tr><td>
<br/><b>Valorar en: </b></td><td> <br/>
<!--<input name="otra_moneda" type="radio" value="0" checked="checked">Moneda original<br>-->
<?php 
$i = 1;
while($row = mysqli_fetch_array($result1)){ 
 if($i == 1) {
 echo "<input name='otra_moneda' type='radio' checked='checked' value='".$row['codigo']."'> ".$row['moneda']."<br>";
 $i++;
 } else {
 echo "<input name='otra_moneda' type='radio' value='".$row['codigo']."'> ".$row['moneda']."<br>";	 } 
}
mysqli_free_result($result1);
	
	?>
</td></tr>
<tr><td colspan="2" align="center">
<br/><br/><INPUT TYPE="submit" VALUE="Generar Reporte" class="boton_generar"></td></tr>

<script type="text/javascript"> $(".chzn-select").chosen({no_results_text: "No se encontraron resultados con "}); $(".chzn-select-deselect").chosen({allow_single_deselect:true}); </script>
</form>
</table>

</body>
</html>
