<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Cobranzas</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"> 
 
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" */
oculta('Pcobrador'); /*Ocultamos Pproveedor*/
}
</script>

</head>
<?php
include "../../conn.php";
include "../../general.php";
include "../../token.php";

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

	<?php
	
//Inicio reporte cobros

//listado de empresas
$result = 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
$result2 = 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;");

//via
$result3 = mysqli_query($link, "select pkyCollectionRoute as codigo, fldName as nombre
from colCollectionRoute
where
sysEnabled = 1 and sysAuthorized = 1
order by nombre;");

//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 cobradores
$result4 = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as cobrador
from agnPerson
where
sysEnabled = 1 and sysAuthorized = 1
order by cobrador;");

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

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

//concepto de cuentas por cobrar
$result7 = mysqli_query($link, "select pkyAccountsReceivableConcept as codigo, fldName as nombre
from colAccountsReceivableConcept
where
sysEnabled = 1 and sysAuthorized = 1
order by nombre;");

//listado de cuentas contables ligadas al concepto de CxC
$result8 = mysqli_query($link, "select distinct a.codAccount as cod_cuenta, b.fldName as cuenta 
from colAccountsReceivableConcept a, actAccount b
where 
a.codAccount = b.pkyAccount and 
b.sysEnabled = 1 and b.sysAuthorized = 1 
order by cod_cuenta, cuenta;");

?>
<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 Cobranzas</b></td></tr><tr><td>
<form id="miform" name="miform" method="post" action="report.php?rep=6&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>Ver Saldos: </b></td><td> <br/><input type="radio" name="mostrar" checked="checked" value="0" class="formulario"> Todos
<br/><input type="radio" name="mostrar" value="1" class="formulario"> Saldos igual a cero
<br/><input type="radio" name="mostrar" value="2" class="formulario"> Saldos diferentes a cero

</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($result)) {   
	?> 
	<option value="<?php echo $row['codigo']?>,-1"><?php echo $row['codigo']?> - <?php echo $row['empresa']?> (<?php echo $row['tipo']?>)</option> 
	<?php 
	}  
	mysqli_free_result($result);
	?> 
    </optgroup>
    <!--<option value="">----------------------</option>-->
    <optgroup label="Empleado">
    <?php 
	while ($row = mysqli_fetch_array($result2)) {   
	?> 
    <option value="<?php echo $row['codigo']?>,-2"><?php echo $row['codigo']?> - <?php echo $row['empleado']?> (<?php echo $row['tipo']?>)</option> 
	<?php 
	}  
	mysqli_free_result($result2);
	
	?>
    </optgroup>
    </select>
</td></tr><tr><td>

<br/><b>Canal (solo para empresas): </b></td><td> <br/><!--<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($result5)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['canal']?></option> 
	<?php 
	}  
	mysqli_free_result($result5);
	?> 
    </select>
</td></tr><tr><td>

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

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

<br/><b>V&iacute;a: </b></td><td> <br/><!--<SELECT NAME="concepto_cobro" class="formulario">-->
<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="via_cobro">
	<option value="0">Todos</option>
    <option value="-1">Liquidaci&oacute;n</option>
	<?php 
	while ($row = mysqli_fetch_array($result3)) {   
	?> 
	<option value="<?php echo $row['codigo']?>"><?php echo $row['codigo']?> - <?php echo $row['nombre']?></option> 
	<?php 
	}  
	mysqli_free_result($result3);
	?> 
    </select>

</td></tr><tr><td>
<br/><b>Cobrador: </b></td><td><br/>
	<select data-placeholder="Seleccione..." class="chzn-select" style="width:300px;" NAME="cobrador">
	<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['cobrador']?></option> 
	<?php 
	}  
	mysqli_free_result($result4);
	?>
    </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($result6)) {   
	?> 
	<option value="<?php echo $row['cod_contexto']?>"><?php echo $row['cod_contexto']?> - <?php echo $row['contexto']?></option> 
	<?php 
	}  
	mysqli_free_result($result6);
	?> 
    </select>
</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>
<br/><b>Ordenar por: </b></td><td> <br/><input type="radio" name="ordenar" checked="checked" value="0" class="formulario"> Fecha
<br/><input type="radio" name="ordenar" value="1" class="formulario"> C&oacute;digo
<br/><input type="radio" name="ordenar" value="2" class="formulario"> Nro. Documento
<br/><input type="radio" name="ordenar" value="3" class="formulario"> V&iacute;a
<br/><input type="radio" name="ordenar" value="4" class="formulario"> Empresa / Empleado
<br/><input type="radio" name="ordenar" value="5" class="formulario"> Cobrador

</td></tr><tr><td>
<br/><b>Mostrar: </b></td><td> 
<br/><input type="checkbox" name="glosa_ver" value="1" class="formulario"> Glosa

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

<br/><b>Valorar en: </b></td><td> <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>
