|
Directory : /home/zjabogados/public_html/reportes/ |
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT );
session_start();
$motorBD = $_SESSION['motorBD'];
$idusuario = $_SESSION['idusuario'];
require_once("../../../Connections/zyz.php");
require_once("../Libs/functionsextra.php");
require_once("../Libs/functionsjava.htm");
$sql = "SELECT p.`id_permiso`
FROM tb_permiso p
INNER JOIN tb_rel_grupo_rol rgr ON rgr.tb_rol = p.tb_rol
INNER JOIN tb_rel_usuario_grupo rug ON rug.tb_grupo = rgr.tb_grupo
WHERE rug.tb_usuario = $idusuario and p.id_permiso = 90";
$rs_permiso = mysqli_query($zyz, $sql) or die(mysqli_error());
$row_rs_permiso = mysqli_fetch_assoc($rs_permiso);
$totalRows_rs_permiso = mysqli_num_rows($rs_permiso);
mysqli_free_result($rs_permiso);
function ConstruirSQL($ranking, $filtro_periodo, $where) {
if ($ranking == 1) {
$select = ", IFNULL(COUNT(Distinct (CASE WHEN $filtro_periodo THEN c.id_caso ELSE NULL END)), 0) orden";
}
if ($ranking == 2) {
$select = ", IFNULL(COUNT(Distinct (CASE WHEN $filtro_periodo THEN re.id_reclamo_extrajudicial ELSE NULL END)), 0) orden";
}
if ($ranking == 3) {
$select = ", IFNULL(COUNT(Distinct (CASE WHEN $filtro_periodo THEN dao.id_damnificado_accionado_ofrecimiento ELSE NULL END)), 0) orden";
}
if ($ranking == 4) {
$select = ", IFNULL(SUM((CASE WHEN $filtro_periodo THEN (re.monto_honorarios_profesionales_por_cliente + re.monto_honorarios_profesionales_por_cia) ELSE NULL END)), 0) orden";
}
$sql = "SELECT distinct p.id_personal, CONCAT(p.nombre, ' ', p.apellido) personal
$select
FROM tb_personal p
INNER JOIN tb_usuario u ON u.tb_personal = p.id_personal
INNER JOIN tb_rel_usuario_grupo rug ON rug.tb_usuario = u.id_usuario
INNER JOIN tb_rel_grupo_rol rgr ON rgr.tb_grupo = rug.tb_grupo
LEFT JOIN tb_caso c ON p.id_personal = c.tb_personal0negociador
LEFT JOIN tb_damnificado d ON d.tb_caso = c.id_caso
LEFT JOIN tb_damnificado_accionado da ON da.tb_damnificado = d.id_damnificado
LEFT JOIN tb_damnificado_accionado_ofrecimiento dao ON dao.tb_damnificado_accionado = da.id_damnificado_accionado and dao.aceptacion_del_damnificado_de_la_oferta = 'SI'
LEFT JOIN tb_reclamo_extrajudicial re ON re.id_reclamo_extrajudicial = da.tb_reclamo_extrajudicial
$where
GROUP BY p.id_personal, personal
ORDER BY orden DESC";
//echo $sql.'<br><br><br>';
return $sql;
}
$rol = $_POST['rol'];
$periodo = $_POST['periodo'];
$ranking = $_POST['ranking'];
if ($rol == 1) {
$texto_rol = 'REGISTRADORES';
$where = "WHERE rgr.tb_rol = 9";
}
if ($rol == 2) {
$texto_rol = 'NEGOCIADORES';
$where = "WHERE rgr.tb_rol = 1";
}
if ($rol == 3) {
$texto_rol = 'MEDICOS';
$where = "WHERE rgr.tb_rol = 4";
}
if ($rol == 4) {
$texto_rol = 'PUNTEROS';
$where = "WHERE rgr.tb_grupo = 5";
}
if ($ranking == 1) {
$texto_ranking = 'CASOS CERRADOS';
}
if ($ranking == 2) {
$texto_ranking = 'RECLAMOS EXTRAJUDCIALES CERRADOS';
}
if ($ranking == 3) {
$texto_ranking = 'DAMNIFICADOS CERRADOS';
}
if ($ranking == 4) {
$texto_ranking = 'HONORARIOS DEL ESTUDIO';
}
if ($periodo == 1) {
$texto_periodo = 'MENSUAL';
}
if ($periodo == 2) {
$texto_periodo = 'TRIMESTRAL';
$t_trimestre1 = $_POST['t_trimestre1'];
$t_trimestre2 = $_POST['t_trimestre2'];
$t_trimestre3 = $_POST['t_trimestre3'];
$t_anio1 = $_POST['t_anio1'];
$t_anio2 = $_POST['t_anio2'];
$t_anio3 = $_POST['t_anio3'];
}
if ($periodo == 3) {
$texto_periodo = 'ANUAL';
$a_anio1 = $_POST['a_anio1'];
$a_anio2 = $_POST['a_anio2'];
$a_anio3 = $_POST['a_anio3'];
}
$contador_sql = 0;
if ($periodo == 1) {
for ($i=1; $i<=3; $i++) {
$mes = intval($_POST['m_mes'.$i]);
$anio = intval($_POST['m_anio'.$i]);
if (is_int($mes) and is_int($anio)) {
$contador_sql++;
$detalle_periodo[$contador_sql-1] = 'Mes: '.$mes.'/'.$anio;
$filtro_periodo = "MONTH(re.fecha_de_cierre) = $mes and YEAR(re.fecha_de_cierre) = $anio";
$asql[$contador_sql-1] = ConstruirSQL($ranking, $filtro_periodo, $where);
}
}
}
if ($periodo == 2) {
for ($i=1; $i<=3; $i++) {
$trimestre = intval($_POST['t_trimestre'.$i]);
$anio = intval($_POST['t_anio'.$i]);
if (is_int($trimestre) and is_int($anio)) {
$contador_sql++;
$detalle_periodo[$contador_sql-1] = $trimestre.'° Trimestre / '.$anio;
if ($trimestre == 1) {
$in = '(1, 2, 3)';
}
if ($trimestre == 2) {
$in = '(4, 5, 6)';
}
if ($trimestre == 3) {
$in = '(7, 8, 9)';
}
if ($trimestre == 4) {
$in = '(10, 11, 12)';
}
$filtro_periodo = "MONTH(re.fecha_de_cierre) in $in and YEAR(re.fecha_de_cierre) = $anio";
$asql[$contador_sql-1] = ConstruirSQL($ranking, $filtro_periodo, $where);
}
}
}
if ($periodo == 3) {
for ($i=1; $i<=3; $i++) {
$anio = intval($_POST['a_anio'.$i]);
if (is_int($anio)) {
$contador_sql++;
$detalle_periodo[$contador_sql-1] = 'Año: '.$anio;
$filtro_periodo = "YEAR(re.fecha_de_cierre) = $anio";
$asql[$contador_sql-1] = ConstruirSQL($ranking, $filtro_periodo, $where);
}
}
}
?>
<!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"><!-- InstanceBegin template="/Templates/reporte.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento sin tÃtulo</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../css/reportes.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php if ($totalRows_rs_permiso >= 1) { ?>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="TablaReporteCelda1"> </td>
<td class="TablaReporteCelda2"><table cellspacing="0" cellpadding="0">
<tr>
<td><img src="../img/solapa_1.gif" width="8" height="17" /></td>
<td background="../img/solapa_2.gif" class="TituloSolapaReporte"><!-- InstanceBeginEditable name="titulo" -->RANKING <?php echo $texto_periodo ?> DE <?php echo $texto_rol ?> SEGUN <?php echo $texto_ranking ?><!-- InstanceEndEditable --></td>
<td><img src="../img/solapa_3.gif" width="8" height="17" /></td>
</tr>
</table></td>
<td class="TablaReporteCelda3"> </td>
</tr>
<tr>
<td class="TablaReporteCelda4"> </td>
<td class="TablaReporteCelda5"><table border="0" cellspacing="2" cellpadding="2" id="reporte">
<tr>
<td><table width="100%" cellpadding="3" cellspacing="3">
<tr>
<td><img src="../img/logo_2.gif" width="211" height="43" /></td>
<td align="right"><img src="../img/estadisticas.jpg" width="65" height="51" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="Contenido" -->
<?php
if (count($asql) > 0) {
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<?php
for ($i=0; $i<count($asql); $i++) {
$sql = $asql[$i];
$rs_casos = mysqli_query($zyz, $sql) or die(mysqli_error());
$row_rs_casos = mysqli_fetch_assoc($rs_casos);
$totalRows_rs_casos = mysqli_num_rows($rs_casos);
?>
<td>
<table border="0" cellspacing="2" cellpadding="2">
<tr class="CeldaTituloPrincipalTabla">
<td>Puesto</td>
<td>Personal</td>
<td><?php echo $detalle_periodo[$i]; ?></td>
</tr>
<?php $j = 0;?>
<?php do { ?>
<?php $j++;?>
<tr class="CeldaDatosTabla">
<td><?php echo $j; ?></td>
<td><?php echo $row_rs_casos['personal'] ?></td>
<td align="right"><?php echo $row_rs_casos['orden'] ?></td>
</tr>
<?php } while ($row_rs_casos = mysqli_fetch_assoc($rs_casos)); ?>
</table>
</td>
<?php } ?>
</tr>
</table>
<?php
mysqli_free_result($rs_casos);
}
else {
?>
SIN REGISTROS DE CASOS QUE MOSTRAR
<?php
}
?>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
<td class="TablaReporteCelda6"> </td>
</tr>
<tr>
<td class="TablaReporteCelda7"> </td>
<td class="TablaReporteCelda8"> </td>
<td class="TablaReporteCelda9"> </td>
</tr>
<tr>
<td colspan="3"><table width="100%" cellspacing="2" cellpadding="2">
<tr>
<td><img src="../img/btn_cerrar.jpg" width="76" height="33" onclick="window.close()" style="cursor:pointer" /></td>
<td><div align="right"> <img src="../img/btn_imp.jpg" width="81" height="33" onclick="javascript:accion('reporte', 'print')" style="cursor:pointer" /></div></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3"><hr /></td>
</tr>
</table>
<p>
<?php }
else { ?>
ERROR!! NO TIENE PERMISOS PARA VER ESTA PAGIINA!!
</p>
<?php } ?>
</body>
<!-- InstanceEnd --></html>