<?
/*
Autor: Lic. Carlos Alberto Vaca Coronado
Version: 3.2.2
Cambio: Se agregan 3 status extras para la verificacion SAT
*/

session_name('portal_absa');
session_start();

require "../conexion/conectar.php";

$conexion = new CONDB();
$conexion->conectar();

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
$id = $_GET['id'];
if(!$sidx) $sidx =1;

$_SESSION['queryC']="Select numeroevento,evento,fechaevento,status,comentario from detallerecibedoce 
where rfcEmisor='".urldecode($_GET['rfcEmisor'])."' and tipoDocto='".urldecode($_GET['doc'])."' and serie='".urldecode($_GET['serie'])."' and folio='".urldecode($_GET['folio'])."' and uuid='".urldecode($_GET['uuid'])."' and
fecharecibido='".str_replace("A",":",str_replace("--"," ",$id))."'";

$SQL_1="select COUNT(*) as count from (".$_SESSION['queryC'].") as temp";
//$SQL_1="select COUNT(*) as count from (select rfcemisor,tipodocto,serie,folio from doce) as temp";

$result = mysqli_query($conexion->CONEXION,$SQL_1) or die(mysqli_num_rows($conexion->CONEXION));

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = $row['count'];

if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;

$SQL = $_SESSION['queryC']." order by $sidx $sord LIMIT $start , $limit";
//$SQL = "select rfcemisor,tipodocto,serie,folio from doce order by $sidx $sord LIMIT $start , $limit";

$result = mysqli_query($conexion->CONEXION, $SQL ) or die(mysqli_num_rows($conexion->CONEXION));

$responce=new stdClass();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
$responce->rows[0]['cell']=array($SQL);
$_SESSION['datosGrid2']="";
unset($_SESSION['datosGrid2']);
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){

    //$responce->rows[$i]['id']=$row[$_GET['key']];
	
				if(trim($row['status']) == "A"){
					$img="acceptHand.png";
					$title="Aceptado";
				}else if(trim($row['status']) == "?"){
					$img="about.png";
					$title="Verificado Erroneo";
				}else if(trim($row['status']) == "V"){
					$img="verificadoSAT.png";
					$title="Verificado Correctamente";
				}else if(trim($row['status']) == "W"){
					$title="Advertencia";
					$img="Attention.png";
				}else if(trim($row['status']) == "WS"){
					$title="Advertencia y Sector Primario";
					$img="WS.png";
				}else if(trim($row['status']) == "S"){
					$title="Sector Primario";
					$img="pendienteAceptar.png";
				}else if(trim($row['status']) == "E"){
					$title="En proceso validacion del ERP";
					$img="pendienteERP.png";
				}else if(trim($row['status']) == "ES"){
					$title="En proceso validacion del ERP y Sector Primario";
					$img="pendienteERPS.png";
				}else if(trim($row['status']) == "P"){
					$title="En Proceso";
					$img="watch.png";
				}else{
					$img="rejectHand.png";
					$title="Rechazado";
				}
	
	$status = "<center><img title='$title' src='grids/Imagenes/$img' width='17' height='16'/>";
	
	$status.='&nbsp;&nbsp;<img title="'.$title.'" onclick="ver_comentario_validacion(\''.urldecode($_GET['rfcEmisor']).'\',\''.urldecode($_GET['doc']).'\',\''.urldecode($_GET['serie']).'\',\''.urldecode($_GET['folio']).'\',\''.urldecode($_GET['uuid']).'\',\''.$row['numeroevento'].'\'); return false;" src="grids/Imagenes/search32.png" style="cursor: pointer" width="17" height="16"/></center>';
	
        $_SESSION['datosGrid2'].=" \t".$row['numeroevento']."\t".$row['fechaevento']."\t".$row['evento']."\n";
        
	$responce->rows[$i]['cell']=array($status,$row['numeroevento'],$row['fechaevento'],$row['evento']);
	$i++;
}
echo json_encode($responce);

?>