<?php
//include "clase.conexion.php";
class clsPlanilla extends clsConexion{
	public $varTitulo 	= "INDICADORES DE PAGO";
	public $varMyTabla  = "_sind_indicador";
	public $varMyID  	= "id_indicador";
	function FormuBusqueda() {
		$sqlume = "call spQuery_Lista_Unidad_Medida_IP(NULL,NULL);";
		$sqltab = "call spQuery_Lista_Tabla_IP(NULL,NULL);";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"430", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 	 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "alinear"=>"center", "ancho"=>"70")),								   
									   array("titulo"=>"Descripci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"nom", "name"=>"nom", "ancho"=>"306")),	
									   array("titulo"=>"Unid. Medida :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 	 "campo"=>array("tipo"=>"select", "id"=>"ume", "name"=>"ume", 
															"titulo"=>"--[[SELECCIONAR]]--", "sql"=>$sqlume, "ancho"=>"306")),
									   array("titulo"=>"Tabla :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 	 "campo"=>array("tipo"=>"select", "id"=>"tab", "name"=>"tab", 
															"titulo"=>"--[[SELECCIONAR]]--", "sql"=>$sqltab, "ancho"=>"306"))								   
								   	   ),
						"boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
											 "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									   array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
											 "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									   array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"100", "texto"=>"Nuevo", 
											 "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('', 'NEW')"),
									   )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varCod = (isset($varForm["cod"]) && $varForm["cod"]<>"")?$varForm["cod"]:"NULL";
		$varNom = (isset($varForm["nom"]) && $varForm["nom"]<>"")?"'".$varForm["nom"]."'":"NULL";
		$varUme = (isset($varForm["ume"]) && $varForm["ume"]<>"Ninguno")?$varForm["ume"]:"NULL";
		$varTab = (isset($varForm["tab"]) && $varForm["tab"]<>"Ninguno")?$varForm["tab"]:"NULL";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"'CIND'";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"'DESC'";		
		$sql = "call spQuery_Indicador($varCod, $varNom, $varUme, $varTab, NULL, $varFie, $varOrd);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"550", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"CIND",     	"ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"INDICADOR",	"ancho"=>"350", "fijo"=>"SI", "maxchar"=>"50", "funcion"=>array("contar")),
									   array("titulo"=>"ABREV",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"CUM",     	"ancho"=>"40" , "oculto"=>"SI", "alinear"=>"center"), 
									   array("titulo"=>"UNIDMEDIDA","ancho"=>"150", "fijo"=>"SI"),
									   array("titulo"=>"CTAB",     	"ancho"=>"40" , "oculto"=>"SI", "alinear"=>"center"), 
									   array("titulo"=>"TABLA",		"ancho"=>"150", "fijo"=>"SI","maxchar"=>"20"),
									   array("titulo"=>"DESCRIPCION","ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"FCABECERA", "ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"FCONDICION","ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"FLLEGARON", "ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"FFALTA", 	"ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"FUNIVERSO", "ancho"=>"150","oculto"=>"SI"),
									   array("titulo"=>"ORD",    	"ancho"=>"40" , "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"MATRIZ",    "ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"EST",    	"ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"FCREADO",  	"ancho"=>"100","oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  	"ancho"=>"100","oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  	"ancho"=>"50", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  	"ancho"=>"50", "oculto"=>"SI")
									   ), 
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br><b>"),
																	 array("valor"=>0, "tipo"=>"INDEX"),
																	 array("valor"=>" - "),
																	 array("valor"=>1, "tipo"=>"INDEX"),
																	 array("valor"=>"</b>")
																	),
												 "click"=>array("funcion"=>"FormuRegistroJS",
																"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																			   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																			  )
																)
												 
												),
										   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"../images/16x16/table_delete.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br><b>"),
																	 array("valor"=>0, "tipo"=>"INDEX"),
																	 array("valor"=>" - "),
																	 array("valor"=>1, "tipo"=>"INDEX"),
																	 array("valor"=>"</b>")
																	),
												 "click"=>array("funcion"=>"xEliminarJS",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>1, "tipo"=>"INDEX"),
																			   array("valor"=>"this", "tipo"=>"NUM"),
																			   )
																)
												 )
										)
							);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$varClass = "";
			$Fila = NULL;
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$varClass = "inputDisable";
			$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = '$varCod';";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqlume = "call spQuery_Lista_Unidad_Medida_IP(NULL,NULL);";
		$sqlcon = "call spQuery_Lista_Tabla_IP(NULL,NULL);";
		$sqlest	= array("A"=>"ACTIVO", "I"=>"INACTIVO");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$SubTit,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$varOpt)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"110",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),
									   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"nom", "name"=>"nom", 
															"valor"=>$Fila["nombre"], "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Abrev. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"abr", "name"=>"abr", 
															"valor"=>$Fila["abrev"], "ancho"=>"100", "maxchar"=>20))
														 	)
											 ),
									   array("titulo"=>"Unid.Medida :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"ume", "name"=>"ume", 
																					 "valor"=>$Fila["id_um"],
															 						 "sql"=>$sqlume, "titulo"=>" --[[SELECCIONAR]]-- ", "ancho"=>"250"))
														 	)
											 ),
									   array("titulo"=>"Tabla Cond. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"con", "name"=>"con", 
																					 "valor"=>$Fila["id_tabla"],
															 						 "sql"=>$sqlcon, "titulo"=>" --[[SELECCIONAR]]-- ", "ancho"=>"250"))
														 	)
											 ),
									   array("titulo"=>"Descripci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"des", "name"=>"des", "valor"=>$Fila["descripcion"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Formu Cabecera :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"fcab", "name"=>"fcab", "valor"=>$Fila["formu_cabecera"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Formu Condici&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"fcon", "name"=>"fcon", "valor"=>$Fila["formu_condicion"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Formu Llegar&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"flle", "name"=>"flle", "valor"=>$Fila["formu_llegaron"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Formu Falta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"ffal", "name"=>"ffal", "valor"=>$Fila["formu_falta"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									  array("titulo"=>"Formu Universo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"funi", "name"=>"funi", "valor"=>$Fila["formu_condicion"], 
																					 "alto"=>"45", "ancho"=>"350"))
														 	)
											 ),
									   array("titulo"=>"Orden :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ord", "name"=>"ord", 
															"valor"=>$Fila["orden"], "ancho"=>"50", "maxchar"=>20, "keypress"=>"return SoloEnteros(event)"))
														 	)
											 ),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select_simple", "id"=>"est", "name"=>"est", "valor"=>$Fila["estado"],
														    				  		 "combo"=>array("sql"=>$sqlest, "ancho"=>"100"))
																			   )
														 	)
											 ),
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_guardar", "texto"=>"Grabar", "click"=>"javascrip:xGrabarJS()"),			  
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		return $this->setTablaForm($varTabla);	
		}
		
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="")?"NULL":$varForm["cod"];
		$varUme = ($varForm["ume"]=="Ninguno")?"0":$varForm["ume"];
		$varCon = ($varForm["con"]=="Ninguno")?"0":$varForm["con"];
		$varNom = ($varForm["nom"]=="")?"NULL":"'".$varForm["nom"]."'";
		$varAbr = ($varForm["abr"]=="")?"NULL":"'".$varForm["abr"]."'";
		$varDes = ($varForm["des"]=="")?"NULL":"'".$varForm["des"]."'";
		$varFCab = ($varForm["fcab"]=="")?"NULL":"'".$varForm["fcab"]."'";
		$varFCon = ($varForm["fcon"]=="")?"NULL":"'".$varForm["fcon"]."'";
		$varFLle = ($varForm["flle"]=="")?"NULL":"'".$varForm["flle"]."'";
		$varFFal = ($varForm["ffal"]=="")?"NULL":"'".$varForm["ffal"]."'";
		$varFUni = ($varForm["funi"]=="")?"NULL":"'".$varForm["funi"]."'";
		$varOrd = ($varForm["ord"]=="")?"NULL":$varForm["ord"];
		$varEst = ($varForm["est"]=="")?"NULL":"'".$varForm["est"]."'";
		$sql = "call spMante_Indicadores('$varForm[opt]', $varCod, $varUme, $varCon, $varNom, $varAbr, $varDes, 
										 $varFCab, $varFCon, $varFLle, $varFFal, $varFUni, $varOrd, $varEst, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr where ".$this->varMyID."= '".$varCod."';";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>