<?php
//include "clase.conexion.php";
class clsDevengeRegimen extends clsConexion{
	public $varTitulo 	= "DEVENGE MENSUAL POR REGIMEN";
	public $varMyTabla  = "_srh_devenge_regimen";
	public $varMyID  	= "id_periodo_afp";
	function FormuBusqueda() {
		$sqlper = "call spQuery_Lista_Periodo_Afp(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"=>"Regimen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_regimen(this.value)", 
																					 "dclick"=>"fn_cargar_listado_regimen('rcod', 'rnom')"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom",
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
										array("titulo"=>"Periodo AFP :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"per", "name"=>"per", 
																					 "titulo"=>"--[[SELECCIONAR]]--",
															  						 "sql"=>$sqlper, "sincod"=>"SI", "ancho"=>"200", "valor"=>$Fila["id_periodo_afp"])
																			   )
														 	)
											 )								   
								   	   ),
						"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
					   ) {
		$varReg = (isset($varForm["rcod"]) && $varForm["rcod"]<>"")?"'".$varForm["rcod"]."'":"NULL";
		$varPer = (isset($varForm["per"]) && $varForm["per"]<>"Ninguno")?$varForm["per"]:"NULL";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";		
		$sql = "call spQuery_DevengeRegimen($varReg, $varPer, $varFie, $varOrd)";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"550", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"CPER",     "ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"PERIODO",  "ancho"=>"200", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CREG",     "ancho"=>"50",  "fijo"=>"SI", "alinear"=>"center"),
									   array("titulo"=>"REGIMEN",  "ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"COMISION", "ancho"=>"50",  "fijo"=>"SI", "alinear"=>"right"),
									   array("titulo"=>"PRIMA",    "ancho"=>"50",  "fijo"=>"SI", "alinear"=>"right"),
									   array("titulo"=>"FONDO",    "ancho"=>"50",  "fijo"=>"SI", "alinear"=>"right"),
									   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>"),
																 array("valor"=>"<b>Periodo : </b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Regimen : </b>"),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>3, "tipo"=>"INDEX"),
																),
												 "click"=>array("funcion"=>"FormuRegistroJS",
																"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																			   array("valor"=>2, 	  "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"=>"<b>Periodo : </b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Regimen : </b>"),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>3, "tipo"=>"INDEX"),
																 ),
												 "click"=>array("funcion"=>"xEliminarJS",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>2, "tipo"=>"INDEX"),
																			   array("valor"=>"this", "tipo"=>"NUM"),
																			   )
																)
												 )
										)
							);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistro($varPer=NULL, $varReg=NULL, $varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$varClass = "";
			$Fila = NULL;
			$Fila["porc_comision"] = 0;
			$Fila["porc_prima"] = 0;
			$Fila["porc_fondo"] = 0;
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$varClass = "inputDisable";
			$sql = "select * from ".$this->varMyTabla." where id_periodo_afp = $varPer and id_regimen = $varReg;";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqlreg = "call spQuery_Lista_Regimen('T', NULL,NULL);";
		$sqlper = "call spQuery_Lista_Periodo_Afp(NULL,NULL);";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "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"=>"Regimen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"reg", "name"=>"reg",
															  						 "sql"=>$sqlreg, "sincod"=>"SI", "ancho"=>"300", "valor"=>$Fila["id_regimen"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Periodo AFP :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"per", "name"=>"per",
															  						 "sql"=>$sqlper, "sincod"=>"SI", "ancho"=>"200", "valor"=>$Fila["id_periodo_afp"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Comision :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"com", "name"=>"com", "ancho"=>"100",
																					 "valor"=>$Fila["porc_comision"], "keypress"=>"return SoloNumeros(event)")
																			   )
														 	)
											 ),
									   array("titulo"=>"Prima :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"pri", "name"=>"pri", "ancho"=>"100",
																					 "valor"=>$Fila["porc_prima"], "keypress"=>"return SoloNumeros(event)")
																			   )
														 	)
											 ),
									   array("titulo"=>"Fondo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fon", "name"=>"fon", "ancho"=>"100",
																					 "valor"=>$Fila["porc_fondo"], "keypress"=>"return SoloNumeros(event)")
																			   )
														 	)
											 ),
									   ),
						"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;
		$varReg = ($varForm["reg"]=="Ninguno")?"NULL":"'".$varForm["reg"]."'";
		$varPer = ($varForm["per"]=="Ninguno")?"NULL":$varForm["per"];
		$varCom = ($varForm["com"]=="")?0:$varForm["com"];
		$varPri = ($varForm["pri"]=="")?0:$varForm["pri"];
		$varFon = ($varForm["fon"]=="")?0:$varForm["fon"];
		$sql = "call spMante_DevengeRegimen('$varForm[opt]', $varReg, $varPer, $varCom, $varPri, $varFon, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
		
	function ProcesoEliminar($varPer, $varReg) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr 
				where id_periodo_afp = $varPer
				and id_regimen		 = $varReg;";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>