<?php
//KRSC 20/12/2014
function seleccionar_producto_compra($varIde, //Index del Detalle 
									 $varPro, //Codigo del Proveedor
									 $varCod, //Codigo del Producto
									 $varForm //Nombre del Formulario
									 ) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$objResponse = new xajaxResponse();
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Compra($varPro, $varCod, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$varCod = str_pad($varCod, 6, "0", STR_PAD_LEFT);
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num"];
		/*
		$objResponse->alert($Fila["CPRO"]."--".$varForm["icod"][$i]."--".$Fila["UM_COMPRA"]."--".$varForm["iuni"][$i]."-mov>-".$varForm["imov"][$varIde]."--".$varForm["imov"][$i]."--".($i+1)."--".$varIde);
		for($i=0; $i<$varCant;$i++) {
			if($Fila["CPRO"]==$varForm["icod"][$i] && 
			   $Fila["UM_COMPRA"]==$varForm["iuni"][$i] && 
			   $varForm["imov"][$varIde]==$varForm["imov"][$i] && 
			   $i+1 <> $varIde) {
				$varExiste = "SI";
				}
			}
		*/
		if($varExiste=="NO") {
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("icod$varIde", "value", $Fila["CPRO"]);
				$objResponse->assign("inom$varIde", "value", utf8_encode($Fila["PRODUCTO"]));
				//$objResponse->assign("iuni$varIde", "value", $Fila["UM_COMPRA"]);
				if ($Fila["PRECIO"]) $objResponse->assign("ipre$varIde", "value", $Fila["PRECIO"]);
				$sqlum = "select id_um_venta  from _sv_producto where id_producto='$varCod' union
						  select id_um_compra from _sv_producto where id_producto='$varCod' union
						  select id_um_stock  from _sv_producto where id_producto='$varCod';";
				$obj->AbrirConexion();
				$rsum = $obj->Query($sqlum);
				$obj->CerrarConexion();
				$varPos = 0;
				$varCombo = "iuni".$varIde;
				$varScript =$varCombo.".options.length = 0;";
				while($rowum = $obj->FetchArray($rsum)) {
					if($rowum[0]==$Fila["UM_COMPRA"]) $varSel = "S";
					else $varSel = "N";					
					$varScript.= "addValorComboJS('".$varCombo."', '".$varPos."', '".$rowum[0]."', '".$rowum[0]."','".$varSel."');";
					$varPos++;
					}
				
				$objResponse->script($varScript);
				}
			else {
				$objResponse->assign("icod$varIde", "value", "");
				$objResponse->assign("inom$varIde", "value", "NO EXISTE");
				//$objResponse->assign("iuni$varIde", "value", "");
				$objResponse->assign("ipre$varIde", "value", "");
				$varCombo = "iuni".$varIde;
				$varScript =$varCombo.".options.length = 0;";
				$objResponse->script($varScript);
				}
			}
		else {
			$objResponse->assign("icod$varIde", "value", "");
			$objResponse->alert("ERROR AL AGREGAR PRODUCTO : \nCODIGO\t\t: ".$Fila[0]."\nDESCRIPCION\t: ".$Fila[1]."\nU.M.\t\t\t: ".$Fila[2]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("icod$varIde", "value", "");
		$objResponse->assign("inom$varIde", "value", "");
		$objResponse->assign("iuni$varIde", "value", "");
		$objResponse->assign("ipre$varIde", "value", "");
		return $objResponse;
		}
	}
	
//KRSC 13/09/2012
function seleccionar_producto_compra_ant($varIde, $varCod, $varForm) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$varPro = 0; //Cambiar Esto para Limitar al Proveedor
		$objResponse = new xajaxResponse();
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Compra($varPro, $varCod, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num"];
		for($i=0; $i<$varCant;$i++) {
			if($varCod==$varForm["icod"][$i] && $i+1 <> $varIde) {
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("icod$varIde", "value", $Fila[0]);
				$objResponse->assign("inom$varIde", "value", $Fila[1]);
				$objResponse->assign("iuni$varIde", "value", $Fila[2]);
				$objResponse->assign("ipre$varIde", "value", $Fila[4]);
				}
			else {
				$objResponse->assign("icod$varIde", "value", "");
				$objResponse->assign("nom$varIde", "value", "NO EXISTE");
				$objResponse->assign("iuni$varIde", "value", "");
				$objResponse->assign("ipre$varIde", "value", "");
				}
			}
		else {
			$objResponse->assign("icod$varIde", "value", "");
			$objResponse->alert("ERROR AL AGREGAR PRODUCTO : \nCODIGO\t\t: ".$Fila[0]."\nDESCRIPCION\t: ".$Fila[1]."\nU.M.\t\t\t: ".$Fila[2]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("icod$varIde", "value", "");
		$objResponse->assign("inom$varIde", "value", "");
		$objResponse->assign("iuni$varIde", "value", "");
		$objResponse->assign("ipre$varIde", "value", "");
		return $objResponse;
		}
	}
	
// RKSC 20/12/2014
function addValorComboMovCompra($varCombo) {
	if($varCombo<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Mov_Compra(NULL, NULL, 'ING');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$varPos = 0;
		$objResponse = new xajaxResponse();
		while($Fila = $obj->FetchArray($rs)) {
			$varScript.= "addValorComboJS('".$varCombo."', '".$varPos."', '".$Fila[0]."', '".utf8_encode($Fila[1])."', 'N');";
			$varPos++;
			}
		$objResponse->script($varScript); 
		return $objResponse;
		}
	}
	
// KRSC 04/03/2014
function seleccionar_tipo_doc_venta_nc($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Doc_Nota_Credito('$varCod',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			//$objResponse1 = new xajaxResponse();
			$objResponse->assign("tcod", "value", "");
			//return $objResponse1;
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}

//KRSC 03/03/2014
function add_detalle_nc_venta($varVen) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "select D.id_producto AS CPRO, P.descripcion AS PRODUCTO, D.id_um AS UM, D.precio AS PRECIO, D.cantidad AS CANTIDAD, TOTAL
			from _sv_venta_detalle D
			inner join _sv_producto P on D.id_producto = P.id_producto
			where D.id_venta = $varVen;";
	$obj->AbrirConexion();
	$rs = $obj->Query($sql);
	$obj->CerrarConexion();
	
	$varReturn= "<table id=\"tblSample\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
	$varReturn.= "width=680 align=center cellpadding=0 cellspacing=0>";
	$varReturn.= "<tr>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"90\">Codigo";
	$varReturn.= "<input name=\"num\" type=\"hidden\" class=\"input\" id=\"num\" value=\"".$obj->NumFilas($rs)."\"/>";
	$varReturn.= "</td>";	
	$varReturn.= "<td class=\"FormCampo2\" width=\"300\">Descripcion</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">UM Venta</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">CantV</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Precio</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">TotalV</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Cantidad</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Total</td>";
	$varReturn.= "<td class=\"FormCampo2\" width=\"10\"></td>";
	$varReturn.= "</tr>";
	$varReturn.= "<tbody id=cuerpoTabla>";
	$varNum = 0;
	while($fila = $obj->FetchArray($rs)) {
		$varNum++;
		$varReturn.= "<tr>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='icod".$varNum."' name='icod[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:center; width:60px;' value=\"".$fila["CPRO"]."\"/>";	
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='inom".$varNum."' name='inom[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='width:300px' value=\"".$fila["PRODUCTO"]."\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='iuni".$varNum."' name='iuni[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:center; width:50px' value=\"".$fila["UM"]."\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='icav".$varNum."' name='icav[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:right;width:50px' width:50px' value=\"".$fila["CANTIDAD"]."\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='ipre".$varNum."' name='ipre[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:right;width:50px' width:50px' value=\"".$fila["PRECIO"]."\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='tem2".$varNum."' name='tem2[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:right;width:50px' width:50px' value=\"".$fila["TOTAL"]."\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='ican".$varNum."' name='ican[".$varNum."]' autocomplete='off' type='text' class='inputNormal' onkeypress=\"return SoloNumeros(event)\" ";
		$varReturn.= "onkeyup=\"CalcularItem('".$varNum."')\" style='text-align:right;width:50px' tabindex=\"".$varNum."\" width:50px' value=\"\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<input id='itot".$varNum."' name='itot[".$varNum."]' type='text' class='inputDisable' readonly ";
		$varReturn.= "style='text-align:right;width:50px' width:50px' value=\"0\"/>";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\" align=\"center\">";
		$varReturn.= "<a hre='#' style=\"cursor:pointer\" onClick='EliminarFilaTabla(this)'> <img src='../images/16x16/delete.png' border='0'></a></td>";
		$varReturn.= "</tr>";
		}
	$varReturn.= "</tbody>";
	$varReturn.= "<tr>";
	$varReturn.= "<td height=19 class=\"interior\" colspan=7 align=\"right\"><b>Total :</b></td>";	
	$varReturn.= "<td align=\"left\" class=\"interior\">";
	$varReturn.= "<input name='tot' id='tot' type='text' class='inputDisable' readonly style='text-align:right;width:50px' value=0 />";
	$varReturn.= "</td>";
	$varReturn.= "<td class=\"interior\"></td>";
	$varReturn.= "</tr>";
	$varReturn.= "<tr>";
	$varReturn.= "<td height=25 colspan=10 valign=top aling=\"center\" class=\"FormTitulo\">";	
	$varReturn.= "<input id=\"bsav\" class=\"boton_guardar\" type=\"button\" style=\"cursor:pointer; width:100px;\" ";
	$varReturn.= "onclick=\"javascrip:xGrabarJS()\" value=\"Grabar\" name=\"bsav\">";
	$varReturn.= "</td>";
	$varReturn.= "</tr>";
	$varReturn.= "</table>";
	$objResponse = new xajaxResponse();
	$objResponse->assign("divDetalleNC", "innerHTML", $varReturn);
	return $objResponse;
	}

//KRSC 03/03/2014
function seleccionar_docref_venta($varVen, $varEmp, $varCli) {	
	if($varVen<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$objResponse = new xajaxResponse();
		
		$varError = "";
		if ($varEmp=="" or $varEmp=="Ninguno") {
			$varError.= "=> DEBE SELECCIONAR UNA EMPRESA\n"; 
			}
		if ($varCli=="" or $varCli=="Ninguno") {
			$varError.= "=> DEBE SELECCIONAR UN CLIENTE\n"; 
			}
			
		if ($varError<>"") {
			$objResponse->alert($varError);
			}
		else {
			$obj->AbrirConexion();
			$varEmp = (isset($varEmp) && $varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
			$sql = "call spQuery_Lista_Cliente_LP($varEmp, $varCli, NULL, NULL);";
			$sql = 	"select V.id_venta as IDE,
					 date_format(V.fecha_emision,'%d/%m/%Y') as FEMI,
					 V.id_tipo_doc as CTIP, 
					 T.nombre as TIPODOC, 
					 CONCAT(V.nro_serie,'-',V.nro_preimpreso) AS NDOC,
					 V.ESTADO, V.total as MONTO
					 from _sv_venta V
					 inner join _sv_tipo_doc_venta T ON T.id_tipo_doc = V.id_tipo_doc
					 where V._estado = 'A'
					 and V.id_empresa = $varEmp
					 and V.id_cliente = $varCli
					 and V.id_venta	  = $varVen
					 and V.id_tipo_doc= 2
					 and V.estado <> 'AN';";
			$rs = $obj->Query($sql);
			$obj->CerrarConexion();
			$Fila = $obj->FetchArray($rs);
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("femiref", "value", $Fila["FEMI"]);
				$objResponse->assign("ctipref", "value", $Fila["CTIP"]);
				$objResponse->assign("ntipref", "value", $Fila["TIPODOC"]);
				$objResponse->assign("ndocref", "value", $Fila["NDOC"]);
				$objResponse->assign("estref",  "value", $Fila["ESTADO"]);
				$objResponse->assign("monref",  "value", $Fila["MONTO"]);
				}
			else {
				$objResponse->assign("iven", "value", "");
				$objResponse->assign("femiref", "value", "");
				$objResponse->assign("ctipref", "value", "");
				$objResponse->assign("ntipref", "value", "");
				$objResponse->assign("ndocref", "value", "");
				$objResponse->assign("estref",  "value", "");
				$objResponse->assign("monref",  "value", "");
				$objResponse->alert("NO EXISTE DOCUMENTO DE VENTA");
				}
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("iven", "value", "");
		$objResponse->assign("femiref", "value", "");
		$objResponse->assign("ctipref", "value", "");
		$objResponse->assign("ntipref", "value", "");
		$objResponse->assign("ndocref", "value", "");
		$objResponse->assign("estref",  "value", "");
		$objResponse->assign("monref",  "value", "");
		return $objResponse;
		}		
	}

// KRSC 19/02/2014 ComboListaAlmacen	
function ComboListaAlmacen($varEmp, $varUsr, $varTam=327){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Almacen($varEmp,NULL,NULL, $varUsr);";	
	$varComb = $obj->SetCombo("alm", $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAlm", "innerHTML", $varComb);
	$sqlemp = "call spQuery_Lista_Empresa($varUsr, $varEmp, NULL);";
	$obj->AbrirConexion();
	$rsemp = $obj->Query($sqlemp);
	$obj->CerrarConexion();
	$filaemp = $obj->FetchArray($rsemp);
	$respuestaXajax->assign("fpere", "value", $filaemp["FPER"]);
	return $respuestaXajax;
	}
	
function ComboListaPuntoVentaImp($varEmp, $varAge, $varTam=327){
	$varUsr = $_SESSION["_CUSE"];
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Punto_Venta_Age($varEmp, $varAge, NULL, NULL);";	
	$varComb = $obj->SetCombo("pun", $sql, NULL, $varTam, "xajax_ComboNroSerieFacturar(document.getElementById('emp').value, this.value, $varUsr)", "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divPun", "innerHTML", $varComb);
	return $respuestaXajax;
	}
// KRSC 13/01/2014 ComboListaAgenciaImp
function ComboListaAgenciaImp($varEmp, $varTam=327){
	$varUsr = $_SESSION["_CUSE"];
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sqlage = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	$varComAge = $obj->SetCombo("age", $sqlage, NULL, $varTam, "xajax_ComboListaPuntoVentaImp($varEmp, this.value, $varTam)", "--[[SELECCIONAR]]--");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAge", "innerHTML", $varComAge);
	return $respuestaXajax;
	}
	
// KRSC 07/01/2014 ComboListaAgencia
function ComboListaAgencia($varEmp, $varTam=327, $varCli=NULL){
	$varUsr = $_SESSION["_CUSE"];
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sqlage = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	$varComAge = $obj->SetCombo("age", $sqlage, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAge", "innerHTML", $varComAge);
	return $respuestaXajax;
	}

// KRSC 29/12/2013
function seleccionar_tipo_doc_cambio($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Doc_Cambio('$varCod',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			//$objResponse1 = new xajaxResponse();
			$objResponse->assign("tcod", "value", "");
			//return $objResponse1;
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}

// KRSC 29/12/2013
function seleccionar_tipo_doc_venta($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Doc_Venta('$varCod',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			//$objResponse1 = new xajaxResponse();
			$objResponse->assign("tcod", "value", "");
			//return $objResponse1;
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}

// KRSC 19/12/2013 ComboNroSerie
function ComboNroSerie($varEmp, $varPun, $varTip, $varTam=327, $varNom="ser", $varDiv="divSer"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = $_SESSION["_CUSE"];
	if ($varEmp<>"Ninguno" && $varPun<>"Ninguno" && $varTip<>"Ninguno")
		$sql = "call spQuery_Lista_Serie($varEmp, $varPun, $varTip, $varUsr);";	
	else
		$sql = "";
	$varComb = $obj->SetCombo($varNom, $sql, NULL, $varTam, NULL, NULL, NULL, "SI");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 19/12/2013 ComboListaAlmacenVen	
function ComboListaDatosVen($varEmp, $varAge, $varTam=327, $varNom="alm", $varDiv="divAlm"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = $_SESSION["_CUSE"];
	$sqlalm = "call spQuery_Lista_Almacen_Age($varUsr, $varEmp, $varAge, NULL, NULL);";	
	$sqlpun = "call spQuery_Lista_Punto_Venta_Age($varEmp, $varAge, NULL, NULL);";	
	$varComAlm = $obj->SetCombo("alm", $sqlalm, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$varComPun = $obj->SetCombo("pun", $sqlpun, NULL, $varTam, "xajax_ComboNroSerie(document.getElementById('emp').value,
																					this.value,
																					document.getElementById('tip').value, 
																					$varTam)", 
																					"--[[SELECCIONAR]]--");	
																					
	$varComSer = $obj->SetCombo("ser", NULL, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAlm", "innerHTML", $varComAlm);
	$respuestaXajax->assign("divPun", "innerHTML", $varComPun);
	$respuestaXajax->assign("divSer", "innerHTML", $varComSer);
	return $respuestaXajax;
	}
	
// KRSC 19/12/2013 ComboListaAgenciaVen
function ComboListaAgenciaVen($varEmp, $varTam=327, $varCli){
	$varUsr = $_SESSION["_CUSE"];
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sqlage = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	$sqlpun = "call spQuery_Lista_Punto_Venta($varEmp, NULL, NULL, $varUsr);";	
	$varComAge = $obj->SetCombo("age", $sqlage, NULL, $varTam, "xajax_ComboListaDatosVen($varEmp, this.value, $varTam)", "--[[SELECCIONAR]]--");
	$varComAlm = $obj->SetCombo("alm", NULL, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$varComSer = $obj->SetCombo("ser", NULL, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAge", "innerHTML", $varComAge);
	$respuestaXajax->assign("divAlm", "innerHTML", $varComAlm);
	$respuestaXajax->assign("divSer", "innerHTML", $varComSer);
	$varScr = "xajax_seleccionar_cliente($varEmp, $varCli)";
	$respuestaXajax->script($varScr);
	return $respuestaXajax;
	}

//KRSC 15/12/25013
function seleccionar_cliente_simple($varCli) {	
	if($varCli<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		
		$objResponse = new xajaxResponse();
		
		$obj->AbrirConexion();
		$varEmp = (isset($varEmp) && $varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
		$sql = "call spQuery_Lista_Cliente_Simple($varCli, NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
			
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign("cnom", "value", $Fila["CLIENTE"]);
			}
		else {
			$objResponse->assign("cnom", "value", "NO EXISTE");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("cnom", "value", "");
		return $objResponse;
		}		
	}

// KRSC 08/12/2013 ComboListaAlmacenAge	
function ComboListaAlmacenAge($varEmp, $varAge, $varTam=327, $varNom="alm", $varDiv="divAlm"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = $_SESSION["_CUSE"];
	$sql = "call spQuery_Lista_Almacen_Age($varUsr, $varEmp, $varAge, NULL, NULL);";	
	$varComb = $obj->SetCombo("alm", $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAlm", "innerHTML", $varComb);
	return $respuestaXajax;
	}
// KRSC 08/12/2013 ComboListaAgenciaPed
function ComboListaAgenciaPed($varEmp, $varTam=327, $varCli){
	$varUsr = $_SESSION["_CUSE"];
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sqlage = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	$varComAge = $obj->SetCombo("age", $sqlage, NULL, $varTam, "xajax_ComboListaAlmacenAge($varEmp, this.value, $varTam)", "--[[SELECCIONAR]]--");
	$varComAlm = $obj->SetCombo("alm", NULL, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAge", "innerHTML", $varComAge);
	$respuestaXajax->assign("divAlm", "innerHTML", $varComAlm);
	$varScr = "xajax_seleccionar_cliente($varEmp, $varCli)";
	$respuestaXajax->script($varScr);
	return $respuestaXajax;
	}
	
// KRSC 06/12/2013
function comboCuotaCompraProveedor($varEmp, $varAnio, $varMes){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"" && $varEmp<>"Ninguno" && $varAnio<>"" && $varAnio<>"Ninguno" && $varMes<>"" && $varMes<>"Ninguno")
		$sql = "call spQuery_Lista_CuotaCompra_Proveedor($varEmp, '$varAnio','$varMes');";	
	else 
		$sql = "";
	$comboTip = $obj->SetCombo("pro", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divPro","innerHTML",$comboTip);
	return $respuestaXajax;
	}
//KRSC 06/12/2013
function comboMesCuotaCompra($varAnio){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_CuotaCompra_Mes('$varAnio');";	
	$combo = $obj->SetCombo("mes", $sql, NULL, "160", NULL, "--[[ MES ]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divMes","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}
// KRSC 02/12/2013
function Combo_Producto_Tipo_Prov($varPro, $varNom="tip", $varTam="250", $varDiv="divTip"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Producto_Tipo_Prov($varPro);";	
	$combo = $obj->SetCombo($varNom, $sql, NULL, $varTam, "xajax_Combo_Producto_Familia_Prov($varPro, this.value, 'fam', $varTam)", " --[[ SELECCIONAR ]]-- ", NULL, "SI");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv,"innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}

// KRSC 02/12/2013
function Combo_Producto_Familia_Prov($varPro, $varTip, $varNom="fam", $varTam="250", $varDiv="divFam"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Producto_Familia_Prov($varPro, '$varTip');";	
	$combo = $obj->SetCombo($varNom, $sql, NULL, $varTam, "xajax_Combo_Producto_SubFamilia_Prov($varPro, this.value, 'sub', $varTam)", " --[[ SELECCIONAR ]]-- ", NULL, "SI");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv,"innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}

// KRSC 02/12/2013
function Combo_Producto_SubFamilia_Prov($varPro, $varFam, $varNom="sub", $varTam="250", $varDiv="divSub"){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Producto_SubFamilia_Prov($varPro, '$varFam');";	
	$combo = $obj->SetCombo($varNom, $sql, NULL, $varTam, NULL, " --[[ SELECCIONAR ]]-- ", NULL, "SI");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv,"innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}

// KRSC 02/12/2013
function seleccionar_vendedor($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Trabajador('VEN', '$varCod', NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("vcod", "value", "");
			}
		$objResponse->assign("vnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("vnom", "value", "");
		return $objResponse;
		}
	}

// KRSC 01/12/2013
function comboCuotaVentaVendedor($varEmp, $varAnio, $varMes, $varPro){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"" && $varEmp<>"Ninguno" && 
	   $varAnio<>"" && $varAnio<>"Ninguno" && 
	   $varMes<>"" && $varMes<>"Ninguno" &&
	   $varPro<>"" && $varPro<>"Ninguno")
		$sql = "call spQuery_Lista_CuotaVenta_Vendedor($varEmp, '$varAnio','$varMes',  $varPro);";
	else
		$sql = "";	
	$varCombo = $obj->SetCombo("ven", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divVen","innerHTML",$varCombo);
	return $respuestaXajax;
	}
// KRSC 01/12/2013
function comboCuotaVentaProveedor($varEmp, $varAnio, $varMes){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"" && $varEmp<>"Ninguno" && $varAnio<>"" && $varAnio<>"Ninguno" && $varMes<>"" && $varMes<>"Ninguno")
		$sql = "call spQuery_Lista_CuotaVenta_Proveedor($varEmp, '$varAnio','$varMes');";	
	else 
		$sql = "";
	$varAjax ="xajax_comboCuotaVentaVendedor(document.getElementById('emp').value, document.getElementById('anio').value, document.getElementById('mes').value, this.value)";
	$comboTip = $obj->SetCombo("pro", $sql, NULL, "300", $varAjax, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divPro","innerHTML",$comboTip);
	return $respuestaXajax;
	}
	
// KRSC 29/11/2013
function seleccionar_producto_simple($ide, $varCod, $varNom, $varUMe) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Simple('P','$ide', NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "");
			$objResponse->assign($varUMe, "value", "");
			}
		$objResponse->assign($varNom, "value", $retorna);
		$objResponse->assign($varUMe, "value", $Fila["UM_VENTA"]);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign($varNom, "value", "");
		$objResponse->assign($varUMe, "value", "");
		return $objResponse;
		}	
	}

// KRSC 22/11/2013
function liscomboListaPrecios($varEmp, $varDiv, $varCom1, $varCom2, $varTam=180) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"" && $varEmp<>"Ninguno")
		$sql = "call spQuery_Lista_LP($varEmp, NULL, NULL);";
	else
		$sql = "";
	
	$varComb = $obj->SetCampo(array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>$varTam, "sql"=>$sql,
								    "id1"=>$varCom1, "name1"=>$varCom1, "id2"=>$varCom2, "name2"=>$varCom2,
								    "dclick1"=>"mover_lista('right','$varCom1','$varCom2')", 
								    "dclick2"=>"mover_lista('left','$varCom1','$varCom2')"															
									));	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}

//KRSC 26/04/2013
function TrabajadorMatriz($varPer, $varEmp, $varAge, $varAre, $varTra){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varPer = ($varPer=="Ninguno")?"NULL":$varPer;
	$varEmp = ($varEmp=="Ninguno")?"NULL":$varEmp;
	$varAge = ($varAge=="Ninguno")?"NULL":$varAge;
	$varAre = ($varAre=="Ninguno")?"NULL":$varAre;
	if ($varPer<>"NULL" && $varEmp<>"NULL") {
		$sql = "call spQuery_Matriz_Trabajador_Asignar($varPer, $varEmp, $varAge, $varAre, '$varTra', 'TRABAJADOR', 'ASC');";
		$sqlmat = "call spQuery_Lista_Matriz_IP($varAre,NULL,NULL);";
		$Titulo = "<a href=\"javascript:marcar_todo('form')\">Seleccionar Todos</a> | <a href=\"javascript:marcar_ninguno('form')\">Seleccionar Ninguno</a>";
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"600", "clase"=>"FormTitulo", "titulo"=>$Titulo, "sql"=>$sql,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"SEL", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", "alto"=>"25",
											 "campo"=>array("tipo"=>"check", "id"=>"tra1", "name"=>"tra1", "alinear"=>"center", 
															"id_name"=>array("0"))
											 ),
									   array("titulo"=>"CEMP", "clase"=>"FormTitulo", "tamano"=>"40", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"texto", "id"=>"emp1", "name"=>"emp1", "alinear"=>"center", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"35", "id_name"=>array("0"))
											),
									   
									   array("titulo"=>"CAGE", "clase"=>"FormTitulo", "tamano"=>"40", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"texto", "id"=>"age1", "name"=>"age1", "alinear"=>"center", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"35", "id_name"=>array("0"))
											),
									   array("titulo"=>"CARE", "clase"=>"FormTitulo", "tamano"=>"40", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"texto", "id"=>"are1", "name"=>"are1", "alinear"=>"center", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"35", "id_name"=>array("0"))
											),
									   array("titulo"=>"CTRA", "clase"=>"FormTitulo", "tamano"=>"40", "tipodat"=>"texto", 
											 "campo"=>array("tipo"=>"simple", "alinear"=>"center")
											),
									   array("titulo"=>"TRABAJADOR", "clase"=>"FormTitulo", "tamano"=>"300", "fijo"=>"SI", 
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"CCAR", "clase"=>"FormTitulo", "tamano"=>"40", "tipodat"=>"texto", 
											 "campo"=>array("tipo"=>"texto", "id"=>"car1", "name"=>"car1", "alinear"=>"center", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"35", "id_name"=>array("0"))
											),
									   array("titulo"=>"CARGO", "clase"=>"FormTitulo", "tamano"=>"300", "fijo"=>"SI", 
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"BASE.RH", "clase"=>"FormTitulo", "tamano"=>"300", "fijo"=>"SI", "alinear"=>"right", 
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"MATRIZ", "clase"=>"FormTitulo", "tamano"=>"250", 									   		 
												 "campo"=>array("tipo"=>"select", "id"=>"mat1", "name"=>"mat1", "alinear"=>"center", "valor"=>2,					 				
																"sql"=>$sqlmat, "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "sincod"=>"SI",
																"var"  =>array("varSis"=>0), "id_name"=>array("0"))
												)							   
									   )
						);
		$varMyTable = $obj->setTablaFormDet($varTab_1);
		$respuestaXajax = new xajaxResponse();
		$respuestaXajax->assign("divTra","innerHTML", $varMyTable);	
		$variable="PMA_markRowsInit()";
		$respuestaXajax->script($variable); 
		}
	else {
		$respuestaXajax = new xajaxResponse();
		$respuestaXajax->assign("divTra","innerHTML", "");	
		}
	return $respuestaXajax;
	}
// KRSC 26/04/2012
function comboAgenciaMatriz($varEmp, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"" && $varEmp<>"Ninguno")
		$sql = "call spQuery_Lista_Agencia($varEmp,NULL,NULL);";
	else
		$sql = "";
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, "xajax_TrabajadorMatriz(document.getElementById('per').value, 
																				     document.getElementById('emp').value, 
																				     this.value,
																				     document.getElementById('are').value,
																				     document.getElementById('tra').value)", "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
//KRSC 18/03/2013
function comboConceptoRemunerativo($varTip, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varTip=="" || $varTip=="Ninguno")
		$sql = "";
	else
		$sql = "call spQuery_Lista_Concepto_Remunerativo('$varTip', NULL, NULL);";
	
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 29/01/2013
function comboAgenciaPlanilla($varEmp, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
	if($varEmp=="" || $varEmp=="Ninguno")
		$sql = "";
	else
		$sql = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, "javascrip:xGridTrabajadorJS()", "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	$respuestaXajax->assign("divDatos", "innerHTML", "");
	return $respuestaXajax;
	}
	
// KRSC 18/03/2013
function comboAgenciaPlanillaAdelanto($varEmp, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
	if($varEmp=="" || $varEmp=="Ninguno")
		$sql = "";
	else
		$sql = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, "javascrip:xGridTrabajadorAdelantoJS()", "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	$respuestaXajax->assign("divDatos", "innerHTML", "");
	return $respuestaXajax;
	}

function comboAgenciaPlanillaFinal($varEmp, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
	if($varEmp=="" || $varEmp=="Ninguno")
		$sql = "";
	else
		$sql = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, "javascrip:xGridTrabajadorPlanillaFinalJS()", "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	$respuestaXajax->assign("divDatos", "innerHTML", "");
	return $respuestaXajax;
	}
			
// KRSC 19/12/2012
function seleccionar_regimen($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Regimen('T', '$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("rcod", "value", "");
			}
		$objResponse->assign("rnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("rnom", "value", "");
		return $objResponse;
		}	
	}

// KRSC 29/09/2012
function comboRegimen($varTip, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Regimen('$varTip',NULL,NULL);";
	
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
// KRSC 02/10/2012
function ComboBanco($varTip, $varTam=250){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Bancos('$varTip',NULL,NULL);";	
	$varComb = $obj->SetCombo("tban", $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divBan", "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 29/09/2012
function comboAgencia($varEmp, $varDiv, $varComb, $varTam=250) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
	if($varEmp<>"" && $varEmp<>"Ninguno")
		$sql = "call spQuery_Lista_Agencia($varUsr, $varEmp, NULL, NULL);";
	else
		$sql = "";
	$varComb = $obj->SetCombo($varComb, $sql, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
//KRSC 29/09/2012
function seleccionar_trabajador_rrhh($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Trabajador_RRHH($varCod, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("tcod", "value", "");
			}
		$objResponse->assign("apat", "value", $Fila["APAT"]);
		$objResponse->assign("amat", "value", $Fila["AMAT"]);
		$objResponse->assign("nom", "value", $Fila["NOMBRE"]);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}
	
// KRSC 28/09/2012
function ComboNroSerieFacturar($varEmp, $varPun, $varUsr){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if ($varEmp<>"Ninguno" && $varPun<>"Ninguno" && $varEmp<>"" && $varPun<>"" && $varUsr<>"") {
		$sqlint = "call spQuery_Lista_Serie($varEmp, $varPun, 1, $varUsr);";
		$sqlfac = "call spQuery_Lista_Serie($varEmp, $varPun, 2, $varUsr);";
		$sqlbol = "call spQuery_Lista_Serie($varEmp, $varPun, 3, $varUsr);";
		$sqlcam = "call spQuery_Lista_Serie($varEmp, $varPun, 5, $varUsr);";
		$varCombInt = $obj->SetCombo("gui", $sqlint, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombFac = $obj->SetCombo("fac", $sqlfac, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombBol = $obj->SetCombo("bol", $sqlbol, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombCam = $obj->SetCombo("cam", $sqlcam, NULL, "120", NULL, NULL, NULL, "SI");
		}
	else {
		$sql = "";
		$varCombInt = $obj->SetCombo("gui", $sql, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombFac = $obj->SetCombo("fac", $sql, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombBol = $obj->SetCombo("bol", $sql, NULL, "120", NULL, NULL, NULL, "SI");
		$varCombCam = $obj->SetCombo("cam", $sql, NULL, "120", NULL, NULL, NULL, "SI");
		}
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divInt", "innerHTML", $varCombInt);
	$respuestaXajax->assign("divFac", "innerHTML", $varCombFac);
	$respuestaXajax->assign("divBol", "innerHTML", $varCombBol);
	$respuestaXajax->assign("divCam", "innerHTML", $varCombCam);
	return $respuestaXajax;
	}
	
//KRSC 25/09/2012
function seleccionar_producto($varCod) {
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Simple('P', '$varCod',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign("pcod","value", $Fila["CPRO"]);
			$objResponse->assign("pnom","value", $Fila["PRODUCTO"]);
			$objResponse->assign("umv", "value", $Fila["UM_VENTA"]);
			$objResponse->assign("umc", "value", $Fila["UM_COMPRA"]);
			$objResponse->assign("ums", "value", $Fila["UM_STOCK"]);
			}
		else {
			$objResponse->assign("pcod","value", "");
			$objResponse->assign("pnom","value", "NO EXISTE");
			$objResponse->assign("umv", "value", "");
			$objResponse->assign("umc", "value", "");
			$objResponse->assign("ums", "value", "");
			}
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("pcod","value", "");
		$objResponse->assign("pnom","value", "");
		$objResponse->assign("umv", "value", "");
		$objResponse->assign("umc", "value", "");
		$objResponse->assign("ums", "value", "");
		return $objResponse;
		}	
	}
//KRSC 13/09/2012
function seleccionar_producto_venta($varIde, $varCod, $varForm) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$varPro = 0; //Cambiar Esto para Limitar al Proveedor
		$objResponse = new xajaxResponse();
		$obj->AbrirConexion();
		$varEmp = (isset($varForm["emp1"]))?$varForm["emp1"]:$varForm["ecod"];
		$varAlm = (isset( $varForm["alm1"]))?$varForm["alm1"]:$varForm["kcod"];
		$varLis = $varForm["lcod"];
		
		
		$sql = "call spQuery_Lista_Producto_Venta('$varEmp', '$varAlm', '$varLis', 'P', $varCod, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num"];
		for($i=1; $i<=$varCant;$i++) {	
			if(str_pad($varCod,6,"0",STR_PAD_LEFT)==$varForm["icod"][$i] && $i <> $varIde) {
				
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("icod$varIde", "value", $Fila["CPRO"]);
				$objResponse->assign("inom$varIde", "value", $Fila["PRODUCTO"]);
				$objResponse->assign("iuni$varIde", "value", $Fila["UM"]);
				$objResponse->assign("ipre$varIde", "value", $Fila["PRECIO"]);
				$objResponse->assign("istk$varIde", "value", $Fila["STOCK"]);
				}
			else {
				$objResponse->assign("icod$varIde", "value", "");
				$objResponse->assign("inom$varIde", "value", "NO EXISTE");
				$objResponse->assign("iuni$varIde", "value", "");
				$objResponse->assign("ipre$varIde", "value", "");
				$objResponse->assign("istk$varIde", "value", "");
				}
			}
		else {
			$objResponse->assign("icod$varIde", "value", "");
			$objResponse->assign("inom$varIde", "value", "");
			$objResponse->assign("iuni$varIde", "value", "");
			$objResponse->assign("ipre$varIde", "value", "");
			$objResponse->assign("istk$varIde", "value", "");
			$objResponse->alert("ERROR AL AGREGAR PRODUCTO : \nCODIGO\t\t: ".$Fila[0]."\nDESCRIPCION\t: ".$Fila[1]."\nU.M.\t\t\t: ".$Fila[2]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("icod$varIde", "value", "");
		$objResponse->assign("inom$varIde", "value", "");
		$objResponse->assign("iuni$varIde", "value", "");
		$objResponse->assign("ipre$varIde", "value", "");
		$objResponse->assign("istk$varIde", "value", "");
		return $objResponse;
		}
	}

// RKSC 21/09/2012
function addValorComboModoParticipacion($varCombo) {
	if($varCombo<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Participante(NULL,NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$varPos = 0;
		$objResponse = new xajaxResponse();
		while($Fila = $obj->FetchArray($rs)) {
			$varScript.= "addValorComboJS('".$varCombo."', '".$varPos."', '".$Fila[0]."', '".$Fila[1]."');";
			$varPos++;
			}
		$objResponse->script($varScript); 
		return $objResponse;
		}
	}

// KRSC 20/09/2012
function comboInstituto($varDep, $varDiv, $varComb) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Instituto('$varDep', NULL,NULL);";
	$varComb = $obj->SetCombo($varComb, $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
		
// KRSC 20/09/2012
function comboUniversidad($varDep, $varDiv, $varComb) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Universidad('$varDep', NULL,NULL);";
	$varComb = $obj->SetCombo($varComb, $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 20/09/2012
function comboColegio($varDep, $varDiv, $varComb) {
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Colegio('$varDep', NULL,NULL);";
	$varComb = $obj->SetCombo($varComb, $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign($varDiv, "innerHTML", $varComb);
	return $respuestaXajax;
	}

// KRSC 09/08/2012 ComboCargo
function ComboAreaCargo($varAre, $varTam=160){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql1 = "call spQuery_Lista_Cargo($varAre,NULL,NULL);";	
	$sql2 = "call spQuery_Lista_Sub_Area($varAre, NULL,NULL);";
	$varComb1 = $obj->SetCombo("car", $sql1, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$varComb2 = $obj->SetCombo("sub", $sql2, NULL, $varTam, NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divCar", "innerHTML", $varComb1);
	$respuestaXajax->assign("divSub", "innerHTML", $varComb2);
	return $respuestaXajax;
	}
//KRSC 13/09/2012
function seleccionar_producto_pedido($varIde, $varPro, $varForm) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$varPro = 0; //Cambiar Esto para Limitar al Proveedor
		$objResponse = new xajaxResponse();
		$obj->AbrirConexion();
		$varEmp = $varForm["emp1"];
		$varAlm = $varForm["alm1"];
		$varLis = $varForm["lcod"];
		$sql = "call spQuery_Lista_Producto_Venta($varEmp, $varAlm, $varLis, 'P', $varPro, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num"];
		for($i=0; $i<$varCant;$i++) {
			if($varCod==$varForm["icod"][$i] && $i+1 <> $varIde) {
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("icod$varIde", "value", $Fila[0]);
				$objResponse->assign("inom$varIde", "value", $Fila[1]);
				$objResponse->assign("iuni$varIde", "value", $Fila[2]);
				$objResponse->assign("ipre$varIde", "value", $Fila[4]);
				$objResponse->assign("istk$varIde", "value", $Fila[4]);
				}
			else {
				$objResponse->assign("icod$varIde", "value", "");
				$objResponse->assign("nom$varIde", "value", "NO EXISTE");
				$objResponse->assign("iuni$varIde", "value", "");
				$objResponse->assign("ipre$varIde", "value", "");
				}
			}
		else {
			$objResponse->assign("icod$varIde", "value", "");
			$objResponse->alert("ERROR AL AGREGAR PRODUCTO : \nCODIGO\t\t: ".$Fila[0]."\nDESCRIPCION\t: ".$Fila[1]."\nU.M.\t\t\t: ".$Fila[2]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("icod$varIde", "value", "");
		$objResponse->assign("inom$varIde", "value", "");
		$objResponse->assign("iuni$varIde", "value", "");
		$objResponse->assign("ipre$varIde", "value", "");
		return $objResponse;
		}
	}

// KRSC 14/09/2012 ComboListaAlmacen	
function ComboListaAlmacenTrans($varEmp, $varUsr){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Almacen($varEmp, NULL,NULL, $varUsr);";	
	$varCombO = $obj->SetCombo("almo", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--");	
	$varCombD = $obj->SetCombo("almd", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divAlmOri", "innerHTML", $varCombO);
	$respuestaXajax->assign("divAlmDes", "innerHTML", $varCombD);
	return $respuestaXajax;
	}
	
function seleccionar_producto_compra1($ide, $varForm) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "");
			$objResponse->assign($varUMe, "value", "");
			}
		$objResponse->assign($varNom, "value", $retorna);
		$sql = "select id_um, id_um as um
				from
				(
				select id_um_compra as id_um from _sv_producto where id_producto='$varCod'
				union
				select id_um_venta from _sv_producto where id_producto='$varCod'
				union
				select id_um_stock from _sv_producto where id_producto='$varCod'
				) A;";
		
		$comboUM = $obj->SetCombo($varUMe, $sql, NULL, "50", NULL, NULL);
	
		$objResponse->assign($varUMe, "value", $comboUM);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign($varNom, "value", "");
		$objResponse->assign($varUMe, "value", "");
		return $objResponse;
		}	
	}


//KRSC 10/09/2012
function seleccionar_trabajador($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Trabajador(NULL, '$varCod', NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("tcod", "value", "");
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}

//KRSC 28/08/2012
function seleccionar_servicio($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Servicio('$ide',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("pcod", "value", "");
			}
		$objResponse->assign("pnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("pnom", "value", "");
		return $objResponse;
		}	
	}

//KRSC 28/08/2012
function seleccionar_linea($varTip, $varCod) {
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Linea('$varTip', '$varCod', NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("tnom", "value", $retorna);
	return $objResponse;		
	}
	
//KRSC 22/08/2012
function seleccionar_huesped($varIde, $varCli, $varForm) {	
	if($varCli<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		
		$objResponse = new xajaxResponse();
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Cliente(NULL, $varCli, NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num2"];
		for($i=0; $i<$varCant;$i++) {
			if($varCli==$varForm["per"][$i] && $i+1 <> $varIde) {
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("nom$varIde", "value", $Fila[1]);
				$objResponse->assign("dni$varIde", "value", $Fila[3]);
				}
			else {
				$objResponse->assign("per$varIde", "value", "");
				$objResponse->assign("nom$varIde", "value", "NO EXISTE");
				$objResponse->assign("dni$varIde", "value", "");
				}
			}
		else {
			$objResponse->assign("per$varIde", "value", "");
			$objResponse->alert("ERROR AL AGREGAR HUESPED : \nCODIGO\t: ".$Fila[0]."\nNOMBRE\t: ".$Fila[1]."\nDNI\t\t\t: ".$Fila[3]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("per$varIde", "value", "");
		$objResponse->assign("nom$varIde", "value", "");
		$objResponse->assign("dni$varIde", "value", "");
		return $objResponse;
		}
	}

//KRSC 22/08/2012
function seleccionar_cuartelero($varCod) {	
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Trabajador('H', '$varCod', NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("tcod", "value", "");
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}

//KRSC 22/08/2012
function seleccionar_habitacion_reserva($varIde, $varCod, $varForm) {	
	$varEmp = (isset($varForm["emp1"]) && $varForm["emp1"]<>"" && $varForm["emp1"]<>"Ninguno")?$varForm["emp1"]:"NULL";
	$varSeg = (isset($varForm["scod"]) && $varForm["scod"]<>"" && $varForm["scod"]<>"Ninguno")?$varForm["scod"]:"NULL";
	$varIni = FechaMysql($varForm["fini1"]);
	$varFin = FechaMysql($varForm["ffin1"]);
	$varEmp = (isset($varEmp) && $varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
	$varUse = $_SESSION[_CUSE];
			
	if($varCod<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		
		$objResponse = new xajaxResponse();
		if ($varEmp=="" or $varEmp=="Ninguno") {
			$objResponse->assign("hab$varIde", "value", "");
			$objResponse->alert("SELECCIONE UNA EMPRESA ANTES DE CONTINUAR");
			}
		else {
			$obj->AbrirConexion();
			$sql = "call spQuery_Lista_Habitacion_Reserva($varEmp, $varSeg, '$varIni', '$varFin', $varCod, $varUse);";
			$rs = $obj->Query($sql);
			$obj->CerrarConexion();
			$Fila = $obj->FetchArray($rs);
			
			//Verificamos si Ya esta Agregado el Item seleccionado
			$varExiste = "NO";
			$varCant = $varForm["num1"];
			for($i=0; $i<$varCant;$i++) {
				if($varCod==$varForm["hab"][$i] && $i+1 <> $varIde) {
					$varExiste = "SI";
					}
				}
			if($varExiste=="NO") {
				if($obj->NumFilas($rs)>0) {
					$objResponse->assign("ide$varIde", "value", $Fila["NUM"]);
					$objResponse->assign("tip$varIde", "value", $Fila["TIPO"]);
					$objResponse->assign("pis$varIde", "value", $Fila["PISO"]);
					$objResponse->assign("car$varIde", "value", $Fila["CARACTERISTICA"]);
					$objResponse->assign("cos$varIde", "value", $Fila["COSTO"]);
					}
				else {
					$objResponse->assign("hab$varIde", "value", "");
					$objResponse->assign("ide$varIde", "value", "");
					$objResponse->assign("tip$varIde", "value", "");
					$objResponse->assign("pis$varIde", "value", "");
					$objResponse->assign("car$varIde", "value", "");
					$objResponse->assign("cos$varIde", "value", "");
					}
				}
			else {
				$objResponse->assign("hab$varIde", "value", "");
				$objResponse->alert("ERROR AL AGREGAR LA HABITACION : \nNUMERO\t: ".$Fila["NUM"]."\nTIPO\t\t: ".$Fila["TIPO"]."\nPISO\t\t :".$Fila["PISO"]."\nYA SE ENCUENTRA DENTRO DE LA LISTA, SELECCIONE OTRA POR FAVOR");
				}
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("hab$varIde", "value", "");
		$objResponse->assign("ide$varIde", "value", "");
		$objResponse->assign("tip$varIde", "value", "");
		$objResponse->assign("pis$varIde", "value", "");
		$objResponse->assign("car$varIde", "value", "");
		$objResponse->assign("cos$varIde", "value", "");
		return $objResponse;
		}		
	}
	
function seleccionar_gasto_asignacion($ide, $varCod, $varNom, $varAbr, $varCos, $varIde, $varNum, $varForm=NULL) {
	$objResponse = new xajaxResponse();
	if($ide<>"") {
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num3"];
		for($i=0; $i<$varCant;$i++) {
			if($ide==$varForm[$varIde][$i] && $i+1 <> $varNum) {
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {		
			$var = VarServer("MYSQLI");
			$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
			$obj->AbrirConexion();
			$sql = "call spQuery_Lista_Gasto('$ide','','');";
			$rs = $obj->Query($sql);
			$obj->CerrarConexion();
			$Fila = $obj->FetchArray($rs);
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign($varNom, "value", utf8_encode($Fila[1]));
				$objResponse->assign($varAbr, "value", utf8_encode($Fila[2]));
				$objResponse->assign($varCos, "value", number_format($Fila[3],2,".",","));
				}
			else {
				$objResponse->assign($varCod, "value", "");
				$objResponse->assign($varNom, "value", "NO EXISTE");
				$objResponse->assign($varAbr, "value", "");
				$objResponse->assign($varCos, "value", "");
				}
			}
		else {
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "EL CODIGO ".$ide." YA ESTA AGREGADO");
			$objResponse->assign($varDni, "value", "");
			$objResponse->assign($varCos, "value", "");
			}
		}
	else {
		$objResponse->assign($varCod, "value", "");
		$objResponse->assign($varNom, "value", "");
		$objResponse->assign($varAbr, "value", "");
		$objResponse->assign($varCos, "value", "");		
		}
	return $objResponse;
	}


function seleccionar_repartidor_asignacion($ide, $varCod, $varNom, $varDni, $varCos, $varIde, $varNum, $varForm=NULL) {
	$objResponse = new xajaxResponse();
	if($ide<>"") {
		//Verificamos si Ya esta Agregado el Item seleccionado
		$varExiste = "NO";
		$varCant = $varForm["num2"];
		for($i=0; $i<$varCant;$i++) {
			if($ide==$varForm[$varIde][$i] && $i+1 <> $varNum) {
				$varExiste = "SI";
				}
			}
		if($varExiste=="NO") {		
			$var = VarServer("MYSQLI");
			$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
			$obj->AbrirConexion();
			$sql = "call spQuery_Lista_Repartidor('$ide','','');";
			$rs = $obj->Query($sql);
			$obj->CerrarConexion();
			$Fila = $obj->FetchArray($rs);
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign($varNom, "value", utf8_encode($Fila[1]));
				$objResponse->assign($varDni, "value", utf8_encode($Fila[2]));
				$objResponse->assign($varCos, "value", number_format($Fila[3],2,".",","));
				}
			else {
				$objResponse->assign($varCod, "value", "");
				$objResponse->assign($varNom, "value", "NO EXISTE");
				$objResponse->assign($varDni, "value", "");
				$objResponse->assign($varCos, "value", "");
				}
			}
		else {
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "EL CODIGO ".$ide." YA ESTA AGREGADO");
			$objResponse->assign($varDni, "value", "");
			$objResponse->assign($varCos, "value", "");
			}
		}
	else {
		$objResponse->assign($varCod, "value", "");
		$objResponse->assign($varNom, "value", "");
		$objResponse->assign($varDni, "value", "");
		$objResponse->assign($varCos, "value", "");		
		}
	return $objResponse;
	}

function seleccionar_conductor($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Conductor('$ide','','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign("cnom", "value", utf8_encode($Fila[1]));
			$objResponse->assign("ccos", "value", number_format($Fila[3],2,".",","));
			}
		else {
			$objResponse->assign("cnom", "value", "NO EXISTE");
			$objResponse->assign("ccod", "value", "");
			$objResponse->assign("ccos", "value", "");
			}		
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("cnom", "value", "");
		$objResponse->assign("ccos", "value", "");
		return $objResponse;
		}
	}

function seleccionar_vehiculo($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Vehiculo('$ide','','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign("vnom", "value", utf8_encode($Fila[2]." : ".$Fila[1]));
			$objResponse->assign("vcos", "value", number_format($Fila[3],2,".",","));
			}
		else {
			$objResponse->assign("vnom", "value", "NO EXISTE");
			$objResponse->assign("vcod", "value", "");
			$objResponse->assign("vcos", "value", "");
			}		
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("vnom", "value", "");
		$objResponse->assign("vcos", "value", "");
		return $objResponse;
		}
	}

function comboHabitacion($varEmp, $varSeg){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Habitacion_Tarifario($varEmp, $varSeg);";	
	$varCombo = $obj->SetCombo("hab", $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divHab","innerHTML",$varCombo);
	return $respuestaXajax;
	}
	
function comboComisionLis($varAnio, $varMes, $varEmp, $varProv){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_Lista_Precios_Comision('$varAnio', '$varMes', '$varEmp', '$varProv');";	
	$comboTip = $obj->SetCombo("lis", $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divTip","innerHTML",$comboTip);
	return $respuestaXajax;
	}
function seleccionar_cliente_bonif($ide, $varCod, $varNom) {	
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Cliente('$ide',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign($varNom, "value", utf8_encode($Fila["CLIENTE"]));
			}
		else {
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "NO EXISTE");
			}
		
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign($varCod, "value", "");
		$objResponse->assign($varNom, "value", "");
		return $objResponse;
		}		
	}

// 16/01/2012
function seleccionar_producto_bonif($ide, $varCod, $varNom, $varUMe, $varEmp) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto('P','$ide','',$varEmp);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign($varCod, "value", "");
			$objResponse->assign($varNom, "value", "");
			$objResponse->assign($varUMe, "value", "");
			}
		$objResponse->assign($varNom, "value", $retorna);
		$objResponse->assign($varUMe, "value", $Fila["UM_VENTA"]);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign($varNom, "value", "");
		$objResponse->assign($varUMe, "value", "");
		return $objResponse;
		}	
	}
	
/* 	=========================================================================================
	Combos para Funciones xajax
   	=========================================================================================*/
// KRSC 10/08/2012 ComboListaPuntoVenta	
function ComboListaPuntoVenta($varEmp, $varUsr){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Punto_Venta($varEmp, NULL, NULL, $varUsr);";	
	$varComb = $obj->SetCombo("pun", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divPun", "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 10/08/2012 ComboListaVenta	
function ComboListaVenta($varEmp, $varUsr){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($varEmp<>"Ninguno") {
		$sqlpun = "call spQuery_Lista_Punto_Venta($varEmp, NULL, NULL, $varUsr);";	
		$sqlalm = "call spQuery_Lista_Almacen($varEmp,NULL,NULL, $varUsr);";
		}
	else {
		$sqlpun = "";
		$sqlalm = "";
		}
	$varCombPun = $obj->SetCombo("pun", $sqlpun, NULL, "160", "xajax_ComboNroSerie(document.getElementById('emp').value,
																					this.value,
																					document.getElementById('tip').value, 
																					$_SESSION[_CUSE])", "--[[SELECCIONAR]]--");	
	$varCombAlm = $obj->SetCombo("alm", $sqlalm, NULL, "160", NULL, "--[[SELECCIONAR]]--");	
	$varCombSer = $obj->SetCombo("ser", "", NULL, "160", NULL, NULL, NULL, "SI");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divPun", "innerHTML", $varCombPun);
	$respuestaXajax->assign("divAlm", "innerHTML", $varCombAlm);
	$respuestaXajax->assign("divSer", "innerHTML", $varCombSer);
	return $respuestaXajax;
	}
	
// KRSC 09/08/2012 ComboCargo
function ComboCargo($varAre){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Cargo($varAre,NULL,NULL);";	
	$varComb = $obj->SetCombo("car", $sql, NULL, "160", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divCar", "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
// KRSC 21/07/2012 ComboListaLP	
function ComboListaLP($varEmp){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_LP($varEmp, NULL, NULL);";	
	$varComb = $obj->SetCombo("lis", $sql, NULL, "300", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divLis", "innerHTML", $varComb);
	return $respuestaXajax;
	}
	
function comboSeleccion($varEmp=NULL, $varEmp1=NULL, $tipo){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	if($tipo=="R") {
		$sql = "call spQuery_Lista_Ruta('','%');";	
		$combo = $obj->SetCombo("sel", $sql, NULL, "280", NULL);	
		}
	elseif($tipo=="P") {
		$varCod = ($varEmp<>"")?$varEmp:$varEmp1;
		//$sql = "call spQuery_Combo_Lista_Precios();";	
		$sql = "call spQuery_Lista_LP($varCod,NULL,NULL);";
		$combo = $obj->SetCombo("lp", $sql, NULL, "280", NULL);	
		}
	else {
		$combo="";
		}
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divSel","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}
	
function comboMesComision($varAnio){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_ComboMesComision('$varAnio');";	
	$combo = $obj->SetCombo("mes", $sql, NULL, "160", NULL, "--[[ MES ]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divMes","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}
	
function comboMesMetas($varAnio){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_ComboMesMetas('$varAnio');";	
	$combo = $obj->SetCombo("mes", $sql, NULL, "160", NULL, "--[[ MES ]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divMes","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}		
	
function comboComisionTip($varAnio, $varMes, $varProv){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_Tipo_Vendedor_Comision('$varAnio','$varMes', '$varProv');";	
	$comboTip = $obj->SetCombo("tip", $sql, NULL, "250", NULL, "--[[SELECCIONAR]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divTip","innerHTML",utf8_encode($comboTip));
	return $respuestaXajax;
	}
	
function comboNivel1($varSis){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "select id_menu, nombre from _sys_menu where length(id_menu)=2 and id_sistema = $varSis;";
	$combo1 = $obj->SetCombo("niv1", $sql, NULL, "300", "xajax_comboNivel2(sis.value, this.value)", " --[[ SELECCIONAR ]]-- ");
	$combo2 = $obj->SetCombo("niv2", NULL, NULL, "300", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divNiv1","innerHTML", $combo1);	
	$respuestaXajax->assign("divNiv2","innerHTML", $combo2);
	return $respuestaXajax;
	}
	
function comboNivel2($varSis, $varNiv1){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "select id_menu, nombre 
			from _sys_menu 
			where length(id_menu)=4 and substring(id_menu,1,2)=substring('".$varNiv1."',1,2)
			and id_sistema = $varSis;";
	$combo = $obj->SetCombo("niv2", $sql, NULL, "300", NULL, " --[[ SELECCIONAR ]]-- ");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divNiv2","innerHTML",$combo);	
	return $respuestaXajax;
	}
	
function comboFamilia($varTip){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql1 = "call spQuery_Combo_Producto_Familia('$varTip');";	
	$sql2 = "call spQuery_Combo_Producto_Sub_Familia('$varTip');";
	$combo1 = $obj->SetCombo("fam", $sql1, NULL, "300", "xajax_comboSubFamilia(this.value)", " --[[ SELECCIONAR ]]-- ", NULL, "SI");	
	$combo2 = $obj->SetCombo("sub", $sql2, NULL, "300", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divFam","innerHTML",$combo1);
	$respuestaXajax->assign("divSub","innerHTML",$combo2);	
	return $respuestaXajax;
	}

function comboSubFamilia($varTip){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_Producto_Sub_Familia('$varTip');";	
	$combo = $obj->SetCombo("sub", $sql, NULL, "300", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divSub","innerHTML",$combo);	
	return $respuestaXajax;
	}

function comboDepa($varPai){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Ubigeo_Dep('$varPai');";	
	$combo1 = $obj->SetCombo("dep", $sql, NULL, "160", "xajax_comboProv(pai.value, this.value)", " --[[ SELECCIONAR ]]-- ", NULL, "NO");
	$combo2 = $obj->SetCombo("pro", NULL, NULL, "160", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");
	$combo3 = $obj->SetCombo("dis", NULL, NULL, "160", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divDepa","innerHTML", $combo1);	
	$respuestaXajax->assign("divProv","innerHTML", $combo2);	
	$respuestaXajax->assign("divDist","innerHTML", $combo3);	
	return $respuestaXajax;
	}
		
function comboProv($varPai, $varDep){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Ubigeo_Pro('$varPai', '$varDep');";	
	$combo = $obj->SetCombo("pro", $sql, NULL, "160", "xajax_comboDist(pai.value, this.value)", " --[[ SELECCIONAR ]]-- ", NULL, "NO");
	$combo2 = $obj->SetCombo("dis", NULL, NULL, "160", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divProv","innerHTML", $combo);	
	$respuestaXajax->assign("divDist","innerHTML", $combo2);	
	return $respuestaXajax;
	}
	
function comboDist($varPai, $varPro){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Lista_Ubigeo_Dis('$varPai', '$varPro');";	
	$combo = $obj->SetCombo("dis", $sql, NULL, "180", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divDist","innerHTML",$combo);	
	return $respuestaXajax;
	}

function comboModulo($varRuta){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_Modulo('$varRuta');";	
	$combo = $obj->SetCombo("mod", $sql, NULL, "180", NULL, " --[[ SELECCIONAR ]]-- ", NULL, "NO");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divMod","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}

function seleccionar_unidad_medida_factor($ide, $padre) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Unidad_Medida_Factor('$ide','','$padre');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	if ($retorna=="NO EXISTE") {
		$objResponse->assign("ucod", "value", "");
		}
	$objResponse->assign("unom", "value", $retorna);
	
	
	return $objResponse;		
	}
function seleccionar_lista_precios($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Precios('$ide','', NULL, NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	if ($retorna=="NO EXISTE") {
		$objResponse->assign("lcod", "value", "");
		}
	$objResponse->assign("lnom", "value", $retorna);
	
	
	return $objResponse;		
	}
	
function comboUM($varUM){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_Combo_UM('$varUM');";
	$varUMV = $obj->SetCombo("umv", $sql, NULL, "200", NULL, NULL);
	$varUMS = $obj->SetCombo("ums", $sql, NULL, "200", NULL, NULL);	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divUMV", "innerHTML", utf8_encode($varUMV));
	$respuestaXajax->assign("divUMS", "innerHTML", utf8_encode($varUMS));
	return $respuestaXajax;
	}

function comboMes($varAnio){
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$sql = "call spQuery_ComboMes('$varAnio');";	
	$combo = $obj->SetCombo("mes", $sql, NULL, "160", NULL, "--[[ MES ]]--");	
	$respuestaXajax = new xajaxResponse();
	$respuestaXajax->assign("divMes","innerHTML",utf8_encode($combo));	
	return $respuestaXajax;
	}

function seleccionar_tipo_habitacion($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Habitacion('$ide',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("hnom", "value", $retorna);
	return $objResponse;		
	}

function seleccionar_tipo($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Tipo('$ide',NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("tnom", "value", $retorna);
	return $objResponse;		
	}

function seleccionar_familia($varTip, $ide) {
	if($ide<>"" && $varTip<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Familia('$varTip', '$ide', NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("fnom", "value", $retorna);
	return $objResponse;		
	}

function seleccionar_subfamilia($varTip, $varFam, $ide) {
	if($ide<>"" && $varTip<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto_Sub_Familia('$varTip', '$varFam', '$ide', NULL);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("snom", "value", $retorna);
	return $objResponse;		
	}
			
function seleccionar_material($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Material('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("xnom", "value", $retorna);
	return $objResponse;		
	}

function seleccionar_marca($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Marca('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else $retorna = "NO EXISTE";		
		}
	else $retorna = "";
	
	$objResponse = new xajaxResponse();
	$objResponse->assign("mnom", "value", $retorna);
	return $objResponse;		
	}


function seleccionar_ruta($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Ruta('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("rcod", "value", "");
			$objResponse->assign("rnom", "value", "");
			$objResponse->assign("mcod", "value", "");
			$objResponse->assign("mnom", "value", "");
			}
		$objResponse->assign("rnom", "value", $retorna);
		$objResponse->assign("mcod", "value", "");
		$objResponse->assign("mnom", "value", "");
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("rnom", "value", "");
		$objResponse->assign("mcod", "value", "");
		$objResponse->assign("mnom", "value", "");
		return $objResponse;
		}
	}
		
function seleccionar_producto_listap($varPro, $varTip, $varEmp) {
	if($varPro<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto('$varTip', '$varPro', NULL, $varEmp);";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("pcod", "value", "");
			$objResponse->assign("pum", "value", "");
			}
		$objResponse->assign("pnom", "value", $retorna);
		$objResponse->assign("pum", "value", $Fila["UM_VENTA"]);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("pnom", "value", "");
		$objResponse->assign("pum", "value", "");
		return $objResponse;
		}	
	}

function seleccionar_articulo($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Producto('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("acod", "value", "");
			$objResponse->assign("aum", "value", "");
			}
		$objResponse->assign("anom", "value", $retorna);
		$objResponse->assign("aum", "value", $Fila["UM_VENTA"]);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("anom", "value", "");
		$objResponse->assign("aum", "value", "");
		return $objResponse;
		}	
	}

function seleccionar_lp($varEmp, $ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_LP($varEmp, '$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("lcod", "value", "");
			}
		$objResponse->assign("lnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("lnom", "value", "");
		return $objResponse;
		}	
	}

function seleccionar_empresa($ide) {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = $Fila[1];
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("ecod", "value", "");
			}
		$objResponse->assign("enom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("enom", "value", "");
		return $objResponse;
		}	
	}
	
function seleccionar_proveedor($varTip="PR", $ide, $varCod="pcod", $varNom="pnom") {
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Proveedor('$varTip', '$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) {
			$objResponse->assign($varNom, "value", $Fila["PROVEEDOR"]);
			$objResponse->assign("fper", "value", utf8_encode($Fila["FPER"]));
			}
		else {
			$objResponse->assign($varNom, "value", "NO EXISTE");	
			$objResponse->assign($varCod, "value", "");
			}
		
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign($varCod, "value", "");
		$objResponse->assign($varNom, "value", "");
		return $objResponse;
		}	
	}
// KRSC 02/08/2012
function seleccionar_tipo_doc_compra($ide) {	
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_DocCompra('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			//$objResponse1 = new xajaxResponse();
			$objResponse->assign("tcod", "value", "");
			//return $objResponse1;
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}
		
function seleccionar_tipo_docpago($ide) {	
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_DocPago('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			//$objResponse1 = new xajaxResponse();
			$objResponse->assign("tcod", "value", "");
			//return $objResponse1;
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}


function seleccionar_tipo_vendedor($ide) {	
	if($ide<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		$obj->AbrirConexion();
		$sql = "call spQuery_Lista_Tipo_Vendedor('$ide','');";
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$Fila = $obj->FetchArray($rs);
		
		$objResponse = new xajaxResponse();
		if($obj->NumFilas($rs)>0) $retorna = utf8_encode($Fila[1]);
		else {
			$retorna = "NO EXISTE";		
			$objResponse->assign("tcod", "value", "");
			}
		$objResponse->assign("tnom", "value", $retorna);
		return $objResponse;
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("tnom", "value", "");
		return $objResponse;
		}
	}
	
function seleccionar_cliente($varEmp, $varCli) {	
	if($varCli<>"") {
		$var = VarServer("MYSQLI");
		$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
		
		$objResponse = new xajaxResponse();
		if ($varEmp=="" or $varEmp=="Ninguno") {
			$objResponse->assign("ccod", "value", "");
			$objResponse->alert("SELECCIONE UNA EMPRESA ANTES DE CONTINUAR");
			}
		else {
			$obj->AbrirConexion();
			$varEmp = (isset($varEmp) && $varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
			$sql = "call spQuery_Lista_Cliente_LP($varEmp, $varCli, NULL, NULL);";
			$rs = $obj->Query($sql);
			$obj->CerrarConexion();
			$Fila = $obj->FetchArray($rs);
			
			
			
			if($obj->NumFilas($rs)>0) {
				$objResponse->assign("cnom", "value", $Fila["CLIENTE"]);
				$objResponse->assign("txtdir", "value", utf8_encode($Fila["DIRECCION"]));
				$objResponse->assign("dni", "value", $Fila["DNI"]);
				$objResponse->assign("ruc", "value", $Fila["RUC"]);
				$objResponse->assign("lcod", "value", $Fila["CLIS"]);
				$objResponse->assign("lnom", "value", $Fila["LISTA"]);
				$objResponse->assign("rcod", "value", $Fila["CRUT"]);
				$objResponse->assign("rnom", "value", $Fila["RUTA"]);
				$objResponse->assign("lmin", "value", number_format($Fila["MMIN"],"2",".",","));
				$objResponse->assign("scod", "value", $Fila["CSEG"]);
				$objResponse->assign("snom", "value", $Fila["SEGMENTO"]);
				}
			else {
				$objResponse->assign("cnom", "value", "NO EXISTE");
				$objResponse->assign("ccod", "value", "");
				$objResponse->assign("txtdir", "value", "");
				$objResponse->assign("dni", "value", "");
				$objResponse->assign("ruc", "value", "");
				$objResponse->assign("lcod", "value", "");
				$objResponse->assign("lnom", "value", "");
				$objResponse->assign("rcod", "value", "");
				$objResponse->assign("rnom", "value", "");
				$objResponse->assign("scod", "value", "");
				$objResponse->assign("snom", "value", "");
				$objResponse->assign("lmin", "value", "");
				}
			}
		return $objResponse;		
		}
	else {
		$objResponse = new xajaxResponse();
		$objResponse->assign("cnom", "value", "");
		$objResponse->assign("txtdir", "value", "");
		$objResponse->assign("dni", "value", "");
		$objResponse->assign("ruc", "value", "");
		$objResponse->assign("lcod", "value", "");
		$objResponse->assign("lnom", "value", "");
		$objResponse->assign("rcod", "value", "");
		$objResponse->assign("rnom", "value", "");
		$objResponse->assign("scod", "value", "");
		$objResponse->assign("snom", "value", "");
		$objResponse->assign("lmin", "value", "");
		return $objResponse;
		}		
	}

?>