<?php
//include "clase.conexion.php";
class clsCheckInReserva extends clsConexion{
	public $varTitulo 	= "CHECK-IN CON RESERVA";
	public $varMyTabla  = "_sh_reservacion";
	public $varMyID  	= "id_reservacion";
	function FormuBusqueda() {
		$sqlest	= array("AC"=>"ACTIVA", "AN"=>"ANULADA", "CO"=>"CONFIRMADA", "VE"=>"VENCIDA");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - (UBICAR RESERVA)",
						"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"=>"Numero :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "valor"=>$_POST["cod"], 
											 										 "alinear"=>"center", "ancho"=>"70"),
																			   array("tipo"=>"simple", "valor"=>"Numero de Reserva")
																			   )
															)
											 ),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ecod", "name"=>"ecod", "valor"=>$_POST["ecod"], 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_empresa(this.value)", 
																					 "dclick"=>"fn_cargar_listado_empresa('ecod', 'enom')"),
																			   array("tipo"=>"text", "id"=>"enom", "name"=>"enom", "valor"=>$_POST["enom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$_POST["ccod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(ecod.value, this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente(ecod.value, 'ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$_POST["cnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Trabajador :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod",
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cuartelero(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cuartelero('tcod', 'tnom')"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom",
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Inicial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "valor"=>$varFINI)
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "ancho"=>"130", "valor"=>$varFFIN)
																			   )
														 	)
											 ),
									   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"150", "texto"=>"Buscar Reserva",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varCod = ($varForm[cod]=="")?"NULL":$varForm[cod];
		$varEmp = ($varForm[ecod]=="")?"NULL":$varForm[ecod];
		$varCli = ($varForm[ccod]=="")?"NULL":$varForm[ccod];
		$varTra = ($varForm[tcod]=="")?"NULL":$varForm[tcod];
		$varIni = ($varForm[fini]=="")?"NULL":"'".FechaMySql($varForm[fini])."'";
		$varFin = ($varForm[ffin]=="")?"NULL":"'".FechaMySql($varForm[ffin])."'";
		$sql = "call spQuery_Reservacion($varCod, $varEmp, $varCli, $varTra, $varIni, $varFin, 'AC', $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>utf8_decode($sql),	"pages"=>50,
						"conte"=>array(array("titulo"=>"NUM",   	"ancho"=>"30" , "alinear"=>"center"), 
									   array("titulo"=>"CEMP",   	"ancho"=>"20" , "alinear"=>"center"),									   
									   array("titulo"=>"EMPRESA",	"ancho"=>"200", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CCLI",     	"ancho"=>"20", "alinear"=>"center"), 
									   array("titulo"=>"CLIENTE",	"ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"DNI",    	"ancho"=>"60",  "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"CTRA",     	"ancho"=>"20", "alinear"=>"center"), 
									   array("titulo"=>"TRABAJADOR","ancho"=>"200", "fijo"  =>"SI"),
									   array("titulo"=>"DIAS",     	"ancho"=>"20", "alinear"=>"center"), 
									   array("titulo"=>"INGRESO",  	"ancho"=>"60",  "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"SALIDA",  	"ancho"=>"60",  "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"ESTADO",  	"ancho"=>"60",  "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"ADULT",  	"ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"NINOS",  	"ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"NUMHAB",  	"ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"TOTAL",  	"ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"ACUENTA",  	"ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"REGISTRO",  "ancho"=>"100", "fijo"=>"SI")									   
									   ),
						"boton"=>array(array("cond"=>array(array(11,"=","ACTIVA")),
											 "tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/b_aceptar.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>APLICAR</b> LA RESERVA"),
															 array("valor"=>"<br><b>Nro. Reserva : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b>"),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>4, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Trabajador : </b>"),
															 array("valor"=>6, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>7, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha Ingreso : </b>"),
															 array("valor"=>8, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha Salida : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 ),
											 "click"=>array("funcion"=>"FormuRegistroJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																		   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																		  )
															)										 
											)
									)
						);
		return $this->SetGridTabla2($varTabla);
		}
	
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;
			$varFINI = sumaDia(date( "Y-m-d",time()),1);
			$varFFIN = sumaDia(date( "Y-m-d",time()),2);
			$sql1 = NULL;
			$sql2 = NULL;
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$sql = "select R.id_reservacion as IDE,
					R.id_empresa as CEMP,
					R.id_cliente as CCLI, C.nombre AS CLIENTE, 
					C.id_segmento as CSEG, S.nombre as SEGMENTO,
					R.cant_adultos as ADULTOS, R.cant_ninos AS NINOS,
					R.id_trabajador AS CTRA, CONCAT(T.apellido_paterno,' ',T.apellido_materno,' ',T.nombre) AS TRABAJADOR,
					DATE_FORMAT(R.fecha_ingreso,'%d/%m/%Y') AS FING, DATE_FORMAT(R.fecha_salida,'%d/%m/%Y') AS FSAL,
					R.ESTADO,
					(select count(*) from _sh_reservacion_habitacion HA where HA.id_reservacion = R.id_reservacion and HA._estado='A') AS NUMHAB,
					(select count(*) from _sh_reservacion_huesped HU where HU.id_reservacion = R.id_reservacion and HU._estado='A') AS NUMHUE
					from ".$this->varMyTabla." R
					inner join _sv_cliente C ON R.id_cliente = C.id_cliente
					left join _sh_segmento S ON C.id_segmento = S.id_segmento
					inner join _sv_trabajador T ON R.id_trabajador = T.id_trabajador
					where R._estado = 'A'
					and R.".$this->varMyID." = $varCod;";	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			$varFINI = $Fila["FING"];
			$varFFIN = $Fila["FSAL"];
			$sql1 = "select R.id_habitacion as CHAB, H.NUMERO,
					 CAST(CONCAT(H.id_tipo_habitacion, ' - ', T.nombre) AS CHAR) AS TIPO,
					 CAST(CONCAT(H.id_piso, ' - ', P.nombre) AS CHAR) as PISO,
					 CONCAT(CASE WHEN H.flag_terma='S' THEN 'TERMA / ' ELSE '' END,
						   CASE WHEN H.flag_tv='S' THEN 'TV / ' ELSE '' END,
						   CASE WHEN H.flag_aire='S' THEN 'AIRE / ' ELSE '' END,
						   CASE WHEN H.flag_radio='S' THEN 'RADIO / ' ELSE '' END,
						   CASE WHEN H.flag_friobar='S' THEN 'FRIOBAR' ELSE '' END) AS CARACTERISTICA,
					 R.precio as MONTO,
					 1 as DEL
					 from _sh_reservacion_habitacion R
					 inner join _sh_habitacion H ON R.id_habitacion = H.id_habitacion
					 inner join _sh_tipo_habitacion T ON H.id_tipo_habitacion = T.id_tipo_habitacion
					 inner join _sh_piso P ON H.id_piso = P.id_piso
					 where R.id_reservacion = $varCod;";
			$sql2 = "select R.id_cliente as CCLI, C.nombre as CLIENTE, C.DNI, 1 AS DEL
					 from _sh_reservacion_huesped R
					 inner join _sv_cliente C ON R.id_cliente = C.id_cliente
					 where R.id_reservacion = $varCod;";
			$sql3 = "select A.id_forma_pago AS CTIP, T.nombre AS TIPO, DATE_FORMAT(A.fecha,'%d/%m/%Y') AS FECHA,
					 A.MONTO, 'DEL' AS DEL
					 from _sh_reservacion_acuenta A
					 inner join _sv_forma_pago T ON A.id_forma_pago = T.id_forma_pago
					 where A._estado = 'A'
					 and A.id_reservacion = $varCod;";
			}
		
		$varHINI = "12:00 PM";
		$varHFIN = "12:00 PM";
		
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		
		$varFormu=array("id"=>"form", "name"=>"form", "metodo"=>"POST");
		$varTabla=array("id"=>"table", "name"=>"table", "tamano"=>"470", "clase"=>"FormTitulo", "titulo"=>$SubTit,						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu",  "name"=>"titu",  "valor"=>$SubTit),
									   array("tipo"=>"oculto", "id"=>"opt",   "name"=>"opt",   "valor"=>$varOpt),
									   array("tipo"=>"oculto", "id"=>"emp1",  "name"=>"emp1" , "valor"=>$Fila["CEMP"]),
									   array("tipo"=>"oculto", "id"=>"fini1", "name"=>"fini1", "valor"=>$varFINI),
									   array("tipo"=>"oculto", "id"=>"ffin1", "name"=>"ffin1", "valor"=>$varFFIN),
									   array("tipo"=>"oculto", "id"=>"ccod1", "name"=>"ccod1", "valor"=>$Fila["CCLI"]),
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 										 "valor"=>$Fila["IDE"], "alinear"=>"center", 
																					 "locked"=>"SI", "ancho"=>"80")))),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "sql"=>$sqlemp, 
																					 "ancho"=>"360", "titulo"=>"--[[SELECCIONAR]]--", 
																					 "valor"=>$Fila["CEMP"], "locked"=>$varLock)))),
									   array("titulo"=>"Ingreso :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "locked"=>"SI", "valor"=>$varFINI),
																			   array("tipo"=>"texto", "id"=>"hini", "name"=>"hini", "alinear"=>"center",
																					 "ancho"=>"100", "locked"=>"SI", "valor"=>$varHINI)
																			   )
														 	)
											 ),
									   array("titulo"=>"Salida :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "ancho"=>"130", "locked"=>"SI", "valor"=>$varFFIN),
																			   array("tipo"=>"texto", "id"=>"hfin", "name"=>"hfin", "alinear"=>"center",
																					 "ancho"=>"100", "locked"=>"SI", "valor"=>$varHFIN)
																			   )
														 	)
											 ),
									   array("titulo"=>"Trabajador :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod",
																					 "ancho"=>"65", "alinear"=>"center", "valor"=>$Fila["CTRA"],
																					 "locked"=>"SI", "clase"=>"inputDisable"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "ancho"=>"290",
																			   		 "valor"=>$Fila["TRABAJADOR"], "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$Fila["CCLI"],
																					 "ancho"=>"65", "alinear"=>"center", 
																					 "change"=>"fn_actualiza_dato('ccod1',this.value)",
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(emp.value, this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente(emp.value, 'ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$Fila["CLIENTE"], 
																					 "ancho"=>"290", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Segmento :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"scod", "name"=>"scod", "ancho"=>"65", 
																					 "alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI",
																					 "valor"=>$Fila["CSEG"]),
																			   array("tipo"=>"text", "id"=>"snom", "name"=>"snom", "ancho"=>"290",  
																					 "clase"=>"inputDisable", "locked"=>"SI", "valor"=>$Fila["SEGMENTO"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Personas :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>"Adultos : ", "clase_in"=>"FormCampo1", 
																			   		 "ancho"=>"65"),
																			   array("tipo"=>"texto", "id"=>"adu", "name"=>"adu", "valor"=>$Fila["ADULTOS"],
																					 "alinear"=>"center", "ancho"=>"100", 
																					 "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Ni&ntilde;os : ", "clase_in"=>"FormCampo1", 
																			   		 "ancho"=>"65"),
																			   array("tipo"=>"texto", "id"=>"nin", "name"=>"nin", "valor"=>$Fila["NINOS"],
																					 "alinear"=>"center", "ancho"=>"100", 
																					 "keypress"=>"return SoloEnteros(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()")
									  )
						);
		
		$Titulo1 = "<input id=\"btadd1\" name=\"btadd1\" type=\"button\" class=\"boton_agregar_edificio\" style=\"cursor:pointer; width:150px;\"  
				    value=\"Agregar Habitacion\" onClick=\"AddHabitacion2()\">";
		$Titulo2 = "<input id=\"btadd2\" name=\"btadd2\" type=\"button\" class=\"boton_agregar_cliente\" style=\"cursor:pointer; width:150px;\"  
				    value=\"Agregar Huesped\" onClick=\"AddHuesped()\">";
		$Titulo3 = "<input id=\"btadd3\" name=\"btadd3\" type=\"button\" class=\"boton_agregar_billete\" style=\"cursor:pointer; width:180px;\"  
				    value=\"Agregar Pago a Cuenta\" onClick=\"AddACuenta()\">";						
		$varNum1 = ($varOpt=="NEW")?0:$Fila["NUMHAB"];
		$varNum2 = ($varOpt=="NEW")?0:$Fila["NUMHUE"];
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"700", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"CHAB", "clase"=>"FormTitulo", "tamano"=>"50", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"hab", "name"=>"hab", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_habitacion",
																			"cuerpo" =>array(array("campo"=>0, "tipo"=>"INDEX"), 
																							 array("campo"=>"emp1.value",  "tipo"=>"NUM"),
																							 array("campo"=>"scod.value",  "tipo"=>"NUM"),
																							 array("campo"=>"fini1.value", "tipo"=>"NUM"),
																							 array("campo"=>"ffin1.value", "tipo"=>"NUM")
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_habitacion_reserva",
																			"cuerpo" =>array(array("campo"=>0, "tipo"=>"INDEX"), 
																							 array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>"xajax.getFormValues('form')", "tipo"=>"NUM")
																							 )
																			)
															)
											 ),
									   array("titulo"=>"NUM.", "clase"=>"FormTitulo", "tamano"=>"50",
											 "campo"=>array("tipo"=>"texto", "id"=>"ide", "name"=>"ide", "clase"=>"inputDisable", 
											 				"locked"=>"SI", "ancho"=>"50", "alinear"=>"center")
											),
									   array("titulo"=>"TIPO", "clase"=>"FormTitulo", "tamano"=>"150",
											 "campo"=>array("tipo"=>"texto", "id"=>"tip", "name"=>"tip", "clase"=>"inputDisable", 
											 				"locked"=>"SI", "ancho"=>"150")
											),
									   array("titulo"=>"PISO", "clase"=>"FormTitulo", "tamano"=>"150",
											 "campo"=>array("tipo"=>"texto", "id"=>"pis", "name"=>"pis", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"150")
											),
									   array("titulo"=>"CARACTERISTICA", "clase"=>"FormTitulo", "tamano"=>"200",
											 "campo"=>array("tipo"=>"texto", "id"=>"car", "name"=>"car", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"200", "alinear"=>"center")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"50", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cos", "name"=>"cos", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloNumeros(event)"
															)
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"../images/b_drop.png")
											)
									   )
						);
		
		$varTab_2=array("id"=>"tab2", "name"=>"tab2", "tamano"=>"700", "clase"=>"FormTitulo", "titulo"=>$Titulo2, "sql"=>$sql2,
						"oculto"=>array(array("tipo"=>"oculto", "id"=>"num2", "name"=>"num2", "valor"=>$varNum2)),
						"conte"=>array(array("titulo"=>"IDE", "clase"=>"FormTitulo", "tamano"=>"80", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"per", "name"=>"per", "alinear"=>"center", "ancho"=>"80", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_producto",
																			"cuerpo" =>array(array("campo"=>0), 
																							 array("campo"=>1),
																							 array("campo"=>2)
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_producto_bonif",
																			"cuerpo" =>array(array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>0), 
																							 array("campo"=>1), 
																							 array("campo"=>2)
																							 )
																			)
															)
											 ),
									   array("titulo"=>"NOMBRE DEL HUESPED", "clase"=>"FormTitulo", "tamano"=>"460", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"nom", "name"=>"nom", "clase"=>"inputDisable", 
											 				"locked"=>"SI", "ancho"=>"460")
											),
									   array("titulo"=>"DNI", "clase"=>"FormTitulo", "tamano"=>"100",
											 "campo"=>array("tipo"=>"texto", "id"=>"dni", "name"=>"dni", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"100", "alinear"=>"center")
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"../images/b_drop.png")
											)
									   )
						);
		$varTab_3=array("id"=>"tab3", "name"=>"tab3", "tamano"=>"455", "clase"=>"FormTitulo", "titulo"=>$Titulo3, "sql"=>$sql3,
						"oculto"=>array(array("tipo"=>"oculto", "id"=>"num3", "name"=>"num3", "valor"=>0)),
						"conte"=>array(array("titulo"=>"CFOR", "clase"=>"FormTitulo", "tamano"=>"80", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cfor", "name"=>"cfor", "alinear"=>"center", "ancho"=>"50", 
															"clase"=>"inputDisable", "locked"=>"SI")
											 ),
									   array("titulo"=>"FORMA DE PAGO", "clase"=>"FormTitulo", "tamano"=>"350",
											 "campo"=>array("tipo"=>"texto", "id"=>"dfor", "name"=>"dfor", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"350")
											),
									   array("titulo"=>"FECHA", "clase"=>"FormTitulo", "tamano"=>"80", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"ffor", "name"=>"ffor", "alinear"=>"center", "ancho"=>"100", 
															"clase"=>"inputDisable", "locked"=>"SI")
											 ),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"60",
											 "campo"=>array("tipo"=>"texto", "id"=>"mfor", "name"=>"mfor", 
															"ancho"=>"60", "alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI")
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"../images/b_drop.png")
											)
									   )
						);
		
																		
		$varTabs =array(array("name"=>"Habitaciones Incluidas",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"700", "tabla"=>$varTab_1
							  ),
						array("name"=>"Huespedes Alojados",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"700", "tabla"=>$varTab_2
							  ),
						array("name"=>"Pagos a Cuenta",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"700", "tabla"=>$varTab_3
							  )
						);
		return $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		}
			
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="")? "NULL" : $varForm[cod];
		$varEmp = ($varForm["emp1"]=="" || $varForm["emp1"]=="Ninguno")? "NULL" : $varForm[emp1];
		$varTra = ($varForm["tcod"]=="")? "NULL" : $varForm[tcod];
		$varCli = ($varForm["ccod1"]=="")? "NULL" : $varForm[ccod1];
		$varSeg = ($varForm["scod"]=="")? "NULL" : $varForm[scod];
		$varIng = ($varForm["fini"]=="")? "NULL" : "'".FechaHoraMysql($varForm[fini1]." ".$varForm[hini])."'";
		$varSal = ($varForm["ffin"]=="")? "NULL" : "'".FechaHoraMysql($varForm[ffin]." ".$varForm[hfin])."'";
		$varAdu = ($varForm["adu"]=="")? "0" : $varForm[adu];
		$varNin = ($varForm["nin"]=="")? "0" : $varForm[nin];
		$varEst = "'AC'";	
		$sql = "call spMante_Hospedaje_Reservacion('NEW', $varCod, $varEmp, $varTra, $varCli, $varSeg, $varIng, $varSal, $varAdu, $varNin, $varEst, $varUsr);";
								 
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		$varHos = $Fila[0];
		
		//Insertamos Lista de Habitaciones
		$sqldet = "";
		foreach ($varForm["hab"] as $varIx =>$varLis) {
			$varHab = $varForm["hab"][$varIx];
			$varCos = $varForm["cos"][$varIx];
			if ($varLis<>"Ninguno") {
				$sqldet.= "CALL spMante_Hospedaje_Habitacion($varHos, $varHab, $varIng, $varSal, $varUsr);";
				}
			}
		$this->AbrirConexion();
		$this->Query($sqldet);
		$this->CerrarConexion();

		//Insertamos Lista de Huespedes
		$sqldet = "";
		foreach ($varForm["per"] as $varIx =>$varPer) {
			if ($varPer<>"") {
				$sqldet.= "insert into _sh_hospedaje_huesped values($varHos, $varPer, NOW(), NOW(), $varUsr, $varUsr, 'A');";
				}
			}
		$this->AbrirConexion();
		$this->Query($sqldet);
		$this->CerrarConexion();
		
		//Insertamos Lista de Pagos a Cuenta
		if (count($varForm["cfor"])>0) {
			$sqldet = "";
			foreach ($varForm["cfor"] as $varIx =>$varFor) {
				if ($varFor<>"") {
					$varMon = $varForm["mfor"][$varIx];
					$varFec = FechaMySql($varForm["ffor"][$varIx]);
					$sqldet.= "insert into _sh_hospedaje_acuenta values(NULL, $varHos, $varFor, '$varFec', $varMon, NOW(), NOW(), $varUsr, $varUsr, 'A');";
					}
				}
			$this->AbrirConexion();
			$this->Query($sqldet);
			$this->CerrarConexion();
			}
		return $varHos;
		}
	}
	
?>