<?
/*
Autor: Lic. Carlos Alberto Vaca Coronado
Version: 3.2.0
*/

session_name('portal_absa');
session_start();

$headerNames = explode(",",$_POST['headerNames']);
$optionsCol = explode(";",$_POST['optionsCol']);

for($i = 0; $i < count($optionsCol); $i++){
	$optionCol = explode("|",$optionsCol[$i]);
	$optNameCol[$i]["name"] = trim($optionCol[0]);
	$optNameCol[$i]["options"] = trim($optionCol[1]);
}
$key_grid_datos="";
$optionsForm = explode(";;",$_POST['optionsForm']);
$fieldKeys="";
if($_POST['optionsForm'] != ""){
	for($i = 0; $i < count($optionsForm); $i++){
		$optForm = explode("|",$optionsForm[$i]);
		if($optForm[1] == "true"){
			if($fieldKeys == ""){
				$fieldKeys=$optForm[0];
				$key_grid_datos=$optForm[0];
			}else{
				$fieldKeys.="|".$optForm[0];
			}
		}
	}	
}
 
$hiddenCol = explode(",",$_POST['hiddenCol']);
?>					  
<style>
	th,td{font-size:12px}
		
.btnCSS {
	-moz-box-shadow: 0px 10px 14px -7px #3e7327;
	-webkit-box-shadow: 0px 10px 14px -7px #3e7327;
	box-shadow: 0px 10px 14px -7px #3e7327;
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #77b55a), color-stop(1, #72b352));
	background:-moz-linear-gradient(top, #77b55a 5%, #72b352 100%);
	background:-webkit-linear-gradient(top, #77b55a 5%, #72b352 100%);
	background:-o-linear-gradient(top, #77b55a 5%, #72b352 100%);
	background:-ms-linear-gradient(top, #77b55a 5%, #72b352 100%);
	background:linear-gradient(to bottom, #77b55a 5%, #72b352 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#77b55a', endColorstr='#72b352',GradientType=0);
	background-color:#77b55a;
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
	border-radius:4px;
	border:1px solid #4b8f29;
	display:inline-block;
	cursor:pointer;
	color:#ffffff;
	font-family:Arial;
	font-size:13px;
	font-weight:bold;
	padding:6px 12px;
	text-decoration:none;
	text-shadow:0px 1px 0px #5b8a3c;
}
.btnCSS:hover {
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #72b352), color-stop(1, #77b55a));
	background:-moz-linear-gradient(top, #72b352 5%, #77b55a 100%);
	background:-webkit-linear-gradient(top, #72b352 5%, #77b55a 100%);
	background:-o-linear-gradient(top, #72b352 5%, #77b55a 100%);
	background:-ms-linear-gradient(top, #72b352 5%, #77b55a 100%);
	background:linear-gradient(to bottom, #72b352 5%, #77b55a 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#72b352', endColorstr='#77b55a',GradientType=0);
	background-color:#72b352;
}
.btnCSS:active {
	position:relative;
	top:1px;
}
.formTD{
    border: 1px solid #EEEEEE; 
    padding: 5px 5px 5px 5px;
    
}

	</style>
	<table width="100%" cellspacing="0">
		<tr style="background-color: white">
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_4.png" width="24" height="24" />
			</td>
			<td class="formTD" width="9%">
				<font style="font-size: 10px; border-color: #fbca93">Pago completo</font></b>
			</td>
			<td class="formTD" width="1%" style="vertical-align: middle">
				<img src="Imagenes/circulo_1.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">Con pagos</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_0.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">Sin pagos</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_8.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">No aplica</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_7.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">PUE vencido</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_5.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">PUE pago duplicado</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_6.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">PUE pagado después de vigencia</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_2.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">Pago mayor al documento</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_9.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">Con compensaciones</font></b>
			</td>
			<td class="formTD" width="1%">
				<img src="Imagenes/circulo_10.png" width="24" height="24" /> 
			</td>
			<td class="formTD" width="9%">
				<b><font style="font-size: 10px; border-color: #fbca93">Liquidada por compensación</font></b>
			</td>
		</tr>
		<!--<tr>
			<td align="left" colspan="4">
				<a onclick="iniciaDescargaXLS('form_exportaXLS')" class="btnCSS">Descargar XLS</a>
				<a onclick="exportaZip()" class="btnCSS">Descargar Archivos</a>
			</td>
			<td colspan="6">
				<div id="form_progressbar"></div>
			</td>
		</tr>-->
	</table>
	
	
        <script>
	$j_6(document).ready(function() {
	
		$j_6("#<?=$_POST['idGrid']?>").jqGrid({
				url:"<?=$_POST['urlDatos']?>?key=<?=$key_grid_datos?>&ocultos=<?=$_POST['hiddenCol']?>",
				datatype: "json",
				colNames:[
				<?for($i = 0; $i < count($headerNames); $i++){?>
						<?if($i==count($headerNames)-1){?>
							'<?=$headerNames[$i]?>'
						<?}else{?>
							'<?=$headerNames[$i]?>',
						<?}?>
					<?}?>
				
				],
				colModel:[
					<?for($i = 0; $i < count($optionsCol); $i++){
						$options="";
						$options=$optNameCol[$i]["options"];
						?>
							<?if($i==count($optionsCol)-1){?>
								{name:'<?=$optNameCol[$i]['name']?>',index:'<?=$optNameCol[$i]['name']?>'<?if($options != ""){echo ", ".str_replace("\\","",$options);}?>}
							<?}else{?>
								{name:'<?=$optNameCol[$i]['name']?>',index:'<?=$optNameCol[$i]['name']?>'<?if($options != ""){echo ", ".str_replace("\\","",$options);}?>},
							<?}?>
					<?	
					  }?>
				],
				rowNum:<?=$_POST['rowNum']?>,
				rowTotal: 6000,
				width:<?=$_POST['width']?>,
				rowList:[10,20,30],
				pager: '#<?=$_POST['idPagina']?>',
				sortname: '<?=$_POST['sortname']?>',
				viewrecords: false,
				sortorder: "desc",
				loadonce: false,
				caption: "<?=$_POST['sheetName']?>",
				shrinkToFit: false,
				rownumbers: false,
				gridview: true,
				height:'<?=$_POST['height']?>',
				editurl: 'grids/editurl.php',
				loadError : function(xhr, st, str){
					// alert("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
					alert("Type: "+st+"; Response: "+ xhr.status + " "+xhr.responseText);
					// $j_6("#eventosAjax").html(xhr.responseText);
				},
				 loadBeforeSend: function(jqXHR)  {

					// jqXHR.setRequestHeader("Authorization", basicAuthCredentials);
					<?if($_SESSION["MODULO_PAGOS"] != "1"){?>
									 $j_6(this).jqGrid('hideCol',["totalPagoDocumentosRef"]); 
									 $j_6(this).jqGrid('hideCol',["totalIngresoCompensado"]); 
									 $j_6(this).jqGrid('hideCol',["ImpPagadoComplemento"]); 
									 $j_6(this).jqGrid('hideCol',["totalEgresoCompensado"]); 
									 $j_6(this).jqGrid('hideCol',["status_pagada"]); 
									 $j_6(this).jqGrid('hideCol',["status_compensada"]);
								<?}else{?>
									$j_6(this).jqGrid('hideCol',["status_pago"]);
								<?}?>

				},
				loadComplete: function(data){
						/*<?if($_SESSION["MODULO_PAGOS"] != "1"){?>
							 $j_6(this).jqGrid('hideCol',["totalPagoDocumentosRef"]); 
							 $j_6(this).jqGrid('hideCol',["totalIngresoCompensado"]); 
							 $j_6(this).jqGrid('hideCol',["ImpPagadoComplemento"]); 
							 $j_6(this).jqGrid('hideCol',["totalEgresoCompensado"]); 
							 $j_6(this).jqGrid('hideCol',["status_pagada"]); 
							 $j_6(this).jqGrid('hideCol',["status_compensada"]);
						<?}else{?>
							$j_6(this).jqGrid('hideCol',["status_pago"]);
						<?}?>*/
						/*var total = data.records;
						for(var i=0; i < total; i++){
							if(data.rows[i].cell[2] == "Administrador"){
							$j_6("#" + data.rows[i].id).find("td").css("background-color", "#D6D6D6");
							}
						}*/
								
								
				}
			});
			$j_6("#<?=$_POST['idGrid']?>").jqGrid('navGrid','#<?=$_POST['idPagina']?>',
			{edit:<?=$_POST['edit']?>,add:<?=$_POST['add']?>,del:<?=$_POST['del']?>,excel:true,exceltext:'Excel'},
			{},
			{},
			{},
			{multipleSearch:true, multipleGroup:true, showQuery: true}
			);
			
			/*$j_6("#<?=$_POST['idGrid']?>").jqGrid('navGrid','#<?=$_POST['idPagina']?>',{edit:false,add:false,del:false});
			$j_6("#<?=$_POST['idGrid']?>").jqGrid('gridResize',{minWidth:350,maxWidth:1024,minHeight:80, maxHeight:768});
			*/
			$j_6('#<?=$_POST['idGrid']?>').jqGrid('navButtonAdd','#<?=$_POST['idPagina']?>',{caption:'',title:'Exportar a Excel',onClickButton : function(e){
			exportExcel('<?=$_POST['idGrid']?>','<?=$_POST['headerNames']?>','<?=$_POST['ignoreColNamesExcel']?>','<?=$_POST['sheetName']?>','<?=$_POST['formName']?>','1');
			}});
			
			$j_6('#<?=$_POST['idGrid']?>').jqGrid('filterToolbar',{defaultSearch:'cn',stringResult:true});
			$j_6("#<?=$_POST['idGrid']?>").jqGrid('setFrozenColumns');
			<?if(strtoupper($_POST['add']) == "TRUE"){?>
				$j_6("#add_<?=$_POST['idGrid']?>").click(function(){
					ventanaModal('[<?=$_POST['fileForm']?>,<?=$_POST['widthForm']?>,<?=$_POST['heightForm']?>]','<?=$_POST['optionsForm']?>','','<?=$_POST['captionForm']?>','add','<?=$_POST['tabla']?>','','','<?=$_POST['reloadGridAfterSave']?>');
				});
			<?}?>
			<?if(strtoupper($_POST['edit']) == "TRUE"){?>
				$j_6("#edit_<?=$_POST['idGrid']?>").click(function(){
					var idRow = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getGridParam','selrow');
					var ret = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getRowData',idRow);
					
					var fieldKeys='<?=$fieldKeys?>';
					var valKeys="";
					
					<?
						$keys = explode("|",$fieldKeys);
						for($i = 0; $i < count($keys); $i++){
					?>
					if(valKeys == "")
						valKeys=ret.<?=$keys[$i]?>;
					else
						valKeys=valKeys+"|"+ret.<?=$keys[$i]?>;
					<?}?>
					ventanaModal('[<?=$_POST['fileForm']?>,<?=$_POST['widthForm']?>,<?=$_POST['heightForm']?>]','<?=$_REQUEST['optionsForm']?>','','<?=$_REQUEST['captionForm']?>','edit','<?=$_POST['tabla']?>',valKeys,fieldKeys,'<?=$_POST['reloadGridAfterSave']?>');
				});
			<?}?>
			<?if(strtoupper($_POST['del']) == "TRUE"){?>
				$j_6("#del_<?=$_POST['idGrid']?>").click(function(){
					var idRow = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getGridParam','selrow');
					var ret = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getRowData',idRow);
					
					var fieldKeys='<?=$fieldKeys?>';
					var valKeys="";
					<?
						$keys = explode("|",$fieldKeys);
						for($i = 0; $i < count($keys); $i++){
					?>
					if(valKeys == "")
						valKeys=ret.<?=$keys[$i]?>;
					else
						valKeys=valKeys+"|"+ret.<?=$keys[$i]?>;
					<?}?>
					ventanaModal('[<?=$_POST['delForm']?>,<?=$_POST['widthConfirm']?>,<?=$_POST['heightConfirm']?>]','','','<table><tr><td valign="center"><img src="Imagenes/Help.png" width="35" height="32"/></td><td width="95%" valign="center"><?=$_REQUEST['captionConfirm']?></td></tr></table>','del','<?=$_POST['tabla']?>',valKeys,fieldKeys,'<?=$_POST['reloadGridAfterSave']?>');
				});
			<?}?>
			$j_6('#<?=$_POST['idGrid']?>').jqGrid('navButtonAdd','#<?=$_POST['idPagina']?>',{caption:'<img src=\'Imagenes/relacion.png\' width=\'16\' height=\'16\'>',buttonicon: 'ui-icon-custom',title:'Ver Documentos Relacionados',onClickButton : function(e){
			
				var idRow = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getGridParam','selrow');
				var ret = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getRowData',idRow);
				if(ret.uuid == null || ret.uuid == "undefined"){
					$j_6.messager.alert('Error.','Debe de seleccionar un documento.','error');
					return;
				}
				loadDiv("extras/cfdirelacionados.php","cuerpoPopup",ret.uuid);
				
				open_w();

			}});
			//----------------------------------------
			//----------------------------------------
			//----------------------------------------
			
			<?if($_SESSION["MODULO_PAGOS"] == "1"){?>

			$j_6('#<?=$_POST['idGrid']?>').jqGrid('navButtonAdd','#<?=$_POST['idPagina']?>',{caption:'<img src=\'Imagenes/compensar.png\' width=\'16\' height=\'16\'>',buttonicon: 'ui-icon-custom',title:'Compensar Documentos.',onClickButton : function(e){
			
				var idRow = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getGridParam','selrow');
				var ret = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getRowData',idRow);
				if(ret.uuid == null || ret.uuid == "undefined"){
					$j_6.messager.alert('Error.','Debe de seleccionar un documento.','error');
					return;
				}
				if(ret.tipoComprobante == "I"){
					loadDiv("extras/cfdisrelacionadosEgreso.php","cuerpoPopup",ret.uuid);
				}else if(ret.tipoComprobante == "E"){
					loadDiv("extras/cfdisrelacionadosIngreso.php","cuerpoPopup",ret.uuid);
				}
				
				
				open_w();

			}});
			
			$j_6('#<?=$_POST['idGrid']?>').jqGrid('navButtonAdd','#<?=$_POST['idPagina']?>',{caption:'<img src=\'Imagenes/docs16.png\' width=\'16\' height=\'16\'>',buttonicon: 'ui-icon-custom', title:'Ver Expediente',onClickButton : function(e){
				var idRow = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getGridParam','selrow');
				var ret = jQuery("#<?=$_POST['idGrid']?>").jqGrid('getRowData',idRow);
				
				if (typeof ret.uuid == 'undefined')
						{$j_6.messager.alert("Error.","Debe de seleccionar un documento","error");return false;}
						
				
					var height1 = $j_6(window).height();
					var width1 = $j_6(window).width();
					
					var left = (width1-800)/2;
					var top = (height1-600)/2;
					
					$j_6("body").addClass("loading");
					
					var archivo;
					if(ret.tipodocto == "P CFDI 3.3"){
						archivo="form_expediente_ComplementoPago.php";
					}else if(ret.tipodocto == "I CFDI 3.3"){
						archivo="form_expediente_ICFDI.php";
					}else{
						$j_6.messager.alert("Error.","Debe de seleccionar un documento de complemento de pago o un CFDI de ingreso.","error");
						$j_6("body").removeClass("loading");
						return false;
					}
					
					mipopup = window.open("formularios/"+archivo+"?tbl=recibedoce&uuid="+ret.uuid,"Expediente","directories=0,menubar=0,location=0,status=0,toolbar=0,width="+width1+",height="+height1);
					//mipopup.moveTo(left,top);
					mipopup.moveTo(0,0);
			}});
			<?}?>

			/*$j_6(window).bind('resize', function(){
                                
				//set to 0 so grid does not continually grow
				$j_6('#<?=$_POST['idGrid']?>').setGridWidth(0);
				//resize to our container's width
				$j_6('#<?=$_POST['idGrid']?>').setGridWidth($j_6('#cuerpo').width());
			}).trigger('resize');*/
	
			$j_6('#loading').hide();
			//$j_6("body select").msDropDown();
			
	});
	function getNumPages(){
		return $j_6('#<?=$_POST['idGrid']?>').getGridParam('lastpage');
	}
	function getRowNum(){
		return $j_6('#<?=$_POST['idGrid']?>').getGridParam('rowNum');
	}
	function getTotalRecords(){
		return $j_6('#<?=$_POST['idGrid']?>').jqGrid('getGridParam', 'records');
	}
	
	
	function ver_validaciones(rfcemisor,serie,folio,uuid,tipodocto,fecharecibido){
		loadDiv("extras/preview_validaciones.php","cuerpoPopup",rfcemisor,serie,folio,uuid,tipodocto,fecharecibido);
		open_w();
	}
	
	function ver_comentario_validacion(rfcemisor,tipodocto,serie,folio,uuid,numeroEvento){
		loadDiv("extras/trae_comentario_evento.php","cuerpoPopup",rfcemisor,tipodocto,serie,folio,uuid,numeroEvento);
		open_w();
	}
	
	

function imprSelec(muestra)
{
	var libs = '<ht'+'ml><he'+'ad><scr'+'ipt language="javascript" src="libs/js/jquery.min1.6.2.js"></scr'+'ipt>'+
				'<scr'+'ipt>'+
				"var $j_6 = $.noConflict();"+
				'</scr'+'ipt>'+
				'<link rel="stylesheet" type="text/css" href="libs/jqueryEasy_1.2.5/themes/default/easyui.css">'+
				'<link rel="stylesheet" type="text/css" href="libs/jqueryEasy_1.2.5/themes/icon.css">'+
				'<scr'+'ipt type="text/javascript" src="libs/jqueryEasy_1.2.5/jquery.easyui.min.js"></scr'+'ipt></he'+'ad>'+
				'<sty'+'le>@media print {.imprimir {transform: scale(.80);margin-top:-50px;}}</sty'+'le>'+
				'<bo'+'dy class="imprimir">';
	
				
	var ficha=document.getElementById(muestra);var ventimp=window.open(' ','popimpr');ventimp.document.write(libs+ficha.innerHTML+"<scr"+"ipt>window.print();</scr"+"ipt></bo"+"dy></ht"+"ml>");ventimp.document.close();
}



	</script>
	<script src="grids/funcionesJQGrid.js" type="text/javascript"></script>
	<form name="<?=$_POST['formName']?>" id="<?=$_POST['formName']?>">
		<input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
		<input type="hidden" name="file_name" id="file_name" value="" />
		<input type="hidden" name="header" id="header" value="" />
		<input type="hidden" name="sheetName" id="sheetName" value="" />
		<input type="hidden" name="ignorarCol" id="ignorarCol" value="" />
                <input type="hidden" name="noSesion" id="noSesion" value="" />
		</form>
		<!--<div id="myjqgridwrapper" style="width:100%;">-->
			<table id="<?=$_POST['idGrid']?>"></table>
			<div id="<?=$_POST['idPagina']?>"></div>
		<!--</div>-->
	<form name="form_exportaXLS" id="form_exportaXLS" target="_blank">
		<input type="hidden" name="file_name" />
		<input type="hidden" name="pagos" value="SI" />
		<input type="hidden" name="ignorarCol" value="<?=$_POST['ignoreColNamesExcel']?>"/>
	</form>
	
	<script type="text/javascript" src="libs/jqueryEasy_1.2.5/jquery.easyui.min.js"></script>
		
	<div id="windowVal" class="easyui-window" closed="true" title="Validaciones" iconCls="icon-save" style="width:800px;height:600px;padding:5px;">
		<div class="easyui-layout" fit="true">
			<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">
				<div id="cuerpoPopup"></div>
			</div>
			<div region="south" border="false" style="text-align:right;padding:5px 0;">
				<a class="easyui-linkbutton" iconCls="icon-print" href="javascript:void(0)" onclick="imprSelec('cuerpoPopup')">Imprimir</a>
				<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="close_w()">Cancelar</a>
			</div>
		</div>
	</div>
	<div id="mm" class="easyui-menu" style="width:120px;">
		<div onclick="getFile('XML')"><font style="color: black">XML</font></div>
		<div onclick="getFile('PDF')"><font style="color: black">PDF</font></div>
		<div onclick="getFile('STD')"><font style="color: black">PDF Estandar</font></div>
		
	</div>
	