<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Parametros Reporte Gastos</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" src="../../js/validar.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('Pdetalle'); /*Mostramos Pdetalle*/
muestra('Pdetalle2');
muestra('Pdetalle4');
oculta('Pdetalle3');
}
</script>

</head>
<?php

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

//$usuario = $_GET["user"];

?>
<body>

<?php 

//concepto de gasto en el detalle
$result = mysqli_query($link, "select pkyExpensesConcept as codigo, fldName as gasto
from payExpensesConcept 
where 
pkyExpensesConcept <> 20 and 
sysEnabled = 1 and sysAuthorized = 1 
order by fldName;");

//concepto de egreso de mercaderia
$result4 = mysqli_query($link, "select pkyItemMovementTypeConcept as codigo, fldName as egreso
from
invItemMovementTypeConcept
where
codItemMovementType = 2 and 
fldItemControl = 1 and 
sysEnabled = 1 and sysAuthorized = 1  
order by fldName;");

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

//tipo de documento
$result2 = mysqli_query($link, "select pkyDocumentType as codigo, fldName as dcto
from txsDocumentType 
where 
sysEnabled = 1 and sysAuthorized = 1 
order by fldName;");

//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 fldName;");

//listado de cuentas contables ligadas al gasto
$result5 = mysqli_query($link, "select distinct a.codAccount as cod_cuenta, b.fldName as cuenta 
from payExpensesConcept a, actAccount b
where 
a.codAccount = b.pkyAccount and 
a.sysEditable != 0 and
a.sysEnabled = 1 and a.sysAuthorized = 1 
order by cod_cuenta, cuenta;");

//listado de ciudad en base a los proveedores, empleados y almacen origen
$result6 = mysqli_query($link, "select t.codigo as codigo, t.ciudad as ciudad
from (
select a.codCityLocation as codigo, b.fldName as ciudad
from
agnCompany a, regCity b
where
a.fldIsSupplier = 1 and 
a.codCityLocation = b.pkyCity and 
a.sysEnabled = 1 and a.sysAuthorized = 1 

union all

select a.codCityLocation as codigo, b.fldName as ciudad
from
agnPerson a, regCity b
where
a.fldIsEmployee = 1 and 
a.codCityLocation = b.pkyCity and 
a.sysEnabled = 1 and a.sysAuthorized = 1

union all 

select a.codCity as codigo, b.fldName as ciudad
from 
invWarehouse a, regCity b, invItemMovement c 
where 
c.codSourceWarehouse = a.pkyWarehouse and 
a.codCity = b.pkyCity and 
c.sysEnabled = 1 and c.sysAuthorized = 1) t 
group by t.codigo 
order by t.ciudad;");

//listado de empresas
$result7 = mysqli_query($link, "select pkyCompany as codigo, fldName as empresa, 'Empresa' as tipo
from agnCompany
where
sysEnabled = 1 and sysAuthorized = 1
order by empresa;");

//listado de empleados
$result8 = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as empleado, 'Empleado' as tipo
from agnPerson
where
sysEnabled = 1 and sysAuthorized = 1
order by empleado;");

//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/>F</b>
</td></tr></table><br/>
<table border="0" align="center" cellpadding="5"><tr><td colspan="2" align="center">
<b>Par&aacute;metros Reporte Gastos</b></td></tr><tr><td>
<form id="miform" name="miform" method="post" action="report.php?rep=5&tipo=1" onsubmit="return Validar()">
<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>Agrupar por Concepto: </b></td><td> 
<br/><input type="radio" name="agrupar" checked="checked" value="0" class="formulario" onClick="muestra('Pdetalle'); muestra('Pdetalle2'); muestra('Pdetalle4'); oculta('Pdetalle3');"> No
<br/><input type="radio" name="agrupar" value="1" class="formulario" onClick="oculta('Pdetalle'); oculta('Pdetalle2'); oculta('Pdetalle4'); muestra('Pdetalle3');"> Si

</td></tr><tr><td>
<br/><b>Retención separada<br />en impuesto: </b></td><td> 
<br/><input type="radio" name="retencion_separada" checked="checked" value="1" class="formulario"> Si
<br/><input type="radio" name="retencion_separada" value="0" class="formulario"> No

</td></tr><tr><td>
<br/><b>Cuenta Contable del<br />Concepto de Gasto:</b></td><td> <br/><!--<SELECT NAME="almacen" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="cuenta_gasto">
    <option value="0">Todos</option>
	<?php 
	while ($row = mysqli_fetch_array($result5)) {   
	?> 
	<option value="<?php echo $row['cod_cuenta']?>"><?php echo $row['cod_cuenta']?> - <?php echo $row['cuenta']?></option> 
	<?php 
	}  
	mysqli_free_result($result5);
	?>
    </select>

</td></tr><tr><td>
<br/><b>Concepto de Gasto: </b></td><td><br/><!--<SELECT NAME="gasto" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="gasto">
    <option value="0">Todos</option>
    <option value="-1">Solo Concepto de Egreso (Mov. Merc.)</option>
	<?php 
	while ($row = mysqli_fetch_array($result)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['gasto']?></option> 
	<?php 
	}  
	mysqli_free_result($result);
	
	?>
	</select>

</td></tr><tr><td>
<br/><b>Concepto de Egreso <br />(Mov. Merc.): </b></td><td><br/><!--<SELECT NAME="gasto" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="egreso">
    <option value="0">Todos</option>
    <option value="-1">Solo Concepto de Gasto</option>
	<?php 
	while ($row = mysqli_fetch_array($result4)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['egreso']?></option> 
	<?php 
	}  
	mysqli_free_result($result4);
	
	?>
	</select>

</td></tr><tr><td>
<br/><b>Empresa / Empleado: </b></td><td> <br/><!--<SELECT NAME="nombre" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="nombre">
    <option value="0,-3">Todos</option>
    <option value="0,-1">Empresas</option>
    <option value="0,-2">Empleados</option> 
    <!--<option value="">----------------------</option>-->
    <optgroup label="Empresa">
    <?php 
	while ($row = mysqli_fetch_array($result7)) {   
	?> 
	<option value="<?php echo $row['codigo']?>,-1"><?php echo $row['codigo']?> - <?php echo $row['empresa']?> (<?php echo $row['tipo']?>)</option> 
	<?php 
	}  
	mysqli_free_result($result7);
	?> 
    </optgroup>
    <!--<option value="">----------------------</option>-->
    <optgroup label="Empleado">
    <?php 
	while ($row = mysqli_fetch_array($result8)) {   
	?> 
    <option value="<?php echo $row['codigo']?>,-2"><?php echo $row['codigo']?> - <?php echo $row['empleado']?> (<?php echo $row['tipo']?>)</option> 
	<?php 
	}  
	mysqli_free_result($result8);
	
	?>
    </optgroup>
    </SELECT>

</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 colspan="2">
<table border="0" id="Pdetalle4">
<tr><td width="200">
<br/><b>Ciudad (Prov. / Emp. / Alm. Orig.): </b></td><td><br/><!--<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="Pdetalle3">
<tr><td width="135">
<br/><b>Mostrar detalle en moneda original: </b></td><td> <br/>
<input name="det_orig" type="radio" value="0" checked="checked">No<br/>
<input name="det_orig" type="radio" value="1">Si<br/>
</td></tr>
</table>

</td></tr><tr><td>
<br/><b>Valorar en: </b></td><td> <br/>
<table border="0" id="Pdetalle2"><tr><td>
<input name="otra_moneda" type="radio" value="0" checked="checked">Moneda original<br/>
</td></tr></table>
<?php 
$i = 1;
while($row = mysqli_fetch_array($result1)){ 
 echo "<input name='otra_moneda' type='radio' value='".$row['codigo']."'> ".$row['moneda']."<br/>";
 $i++;
}
mysqli_free_result($result1);
	
	?>
</td></tr><tr><td colspan="2">
<table border="0" id="Pdetalle">
<tr><td width="200">
<br/><b>Tipo de Documento: </b></td><td> <br/><!--<SELECT NAME="documento" class="formulario">-->
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="documento">
    <option value="0">Todos</option>
    <option value="999">Egresos</option><!-- es 999 para que no use el primer query -->
	<?php 
	while ($row = mysqli_fetch_array($result2)) {   
	?> 
    
	<option value="<?php echo $row['codigo']?>"><?php echo $row['dcto']?></option> 
	<?php 
	}  
	mysqli_free_result($result2);
	?> 
    </select>
</td></tr>

<tr><td width="180">
<br/><b>Item asociado: </b></td><td> <br/><!--<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>

<tr><td width="180">
<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><tr><td>
<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><tr><td>

<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><tr><td>

<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>De Fecha: </b></td><td> <br/><div><input type="text" id="fechaini" name="fechaini" value="<?php echo $fechaini_gest; ?>" length="10" maxlength="10" class="tcal" title="aaaa-mm-dd"> </div>aaaa-mm-dd
</td></tr><tr><td>
<br/><b>A Fecha: </b></td><td> <br/><div><input type="text" id="fechafin" name="fechafin" value="<?php echo $fecha_hoy; ?>" length="10" maxlength="10" class="tcal" title="aaaa-mm-dd"> </div>aaaa-mm-dd
</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>
