<?php
//include "clase.conexion.php";
class clsListaPrecios extends clsConexion{
	public $varTitulo = "MAESTRO LISTA DE PRECIOS";
	public $varMyTabla  = "_sv_lista";
	public $varMyID  	  = "id_lista";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"460", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", 
											 "alinear"=>"center","valor"=>$_POST["cod"], "ancho"=>"70")),
									   array("titulo"=>"Descripci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											  "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam",
											  "valor"=>$_POST["nam"],  "ancho"=>"306")),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ecod", "name"=>"ecod", 
																					 "valor"=>NULL, "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"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									 ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"100", "texto"=>"Nuevo", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('NEW','')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = ($varForm["ecod"]<>"")? $varForm["ecod"]:"NULL";
		$varCod = (isset($varForm["cod"]) && $varForm["cod"]<>'')? $varForm["cod"]:"NULL";
		$varNom = $varForm["nam"];
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spQuery_Lista_Precios($varEmp, $varCod, '$varNom', $varUsr, $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("titulo"=>"CEMP",	   	 "ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"EMPRESA",	 "ancho"=>"300", "fijo"=>"SI"),
									   array("titulo"=>"CLIS",	   	 "ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"LISTA PRECIOS","ancho"=>"300", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"PESO",     "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"MONT.MIN.",     "ancho"=>"100", "alinear"=>"right"), 
									   array("titulo"=>"CANT.",    "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"100", "oculto"=>"SI")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nombre L.P. : </b>"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>3, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"FormuRegistroJS",
															"param"=>array(array("valor"=>"EDIT", "tipo"=>"TEXTO"),
																		   array("valor"=>0, 	  "tipo"=>"INDEX"),
																		   array("valor"=>2, 	  "tipo"=>"INDEX")
																		   )
															)
											 
											),
									   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"../images/16x16/table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nombre L.P. : </b>"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>3, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>3, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUM"),
																		   )
															)
											 ),
									   array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/cart_add.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>AGREGAR PRODUCTOS</b> A LA LISTA DE PRECIOS"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nombre L.P. : </b>"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>3, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"FormuDetalleJS",
											 				"param"=>array(array("valor"=>"P"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"))
															)
											 
											),
									   array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/tag_blue_add.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>AGREGAR SERVICIOS</b> A LA LISTA DE PRECIOS"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nombre L.P. : </b>"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>3, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"FormuDetalleJS",
											 				"param"=>array(array("valor"=>"S"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"))
															)
											 
											)
									)
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function GridDatosDetalle($varProSer = 'P',
							  $varEmp  	 = NULL, 
							  $varCod  	 = NULL, 
							  $varPro	 = NULL,
							  $varField  = NULL, 
							  $varOrder  = NULL
							  ) 
		{
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varPro = (isset($varPro) && $varPro<>'')?$varPro:"NULL";
		
		$sql = "call spQuery_Lista_Precios_Detalle('$varProSer', $varEmp, $varCod, $varPro, $varFie, $varOrd)";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("titulo"=>"CPRO",	   "ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"PRODUCTO", "ancho"=>"300", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"UM",       "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"PRECIO",   "ancho"=>"40", "alinear"=>"right", "decimal"=>5), 
									   array("titulo"=>"FCREADO",   "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",   "ancho"=>"100", "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"UCREADO",   "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",   "ancho"=>"100", "alinear"=>"center", "fijo"=>"SI")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"xajax_xFormuRegistroDetalle",
															"param"=>array(array("valor"=>"document.getElementById('ecod').value","tipo"=>"NUMERO"),
																		   array("valor"=>"document.getElementById('lcod').value","tipo"=>"NUMERO"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																		  )
															)
											 
											),
									   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"../images/16x16/table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"xEliminarDetalleJS",
															"param"=>array(array("valor"=>"ecod.value", "tipo"=>"NUMERO"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>$varCod, "tipo"=>"NUM"),
																		   array("valor"=>"this", "tipo"=>"NUM")
																		   )
															)
											 )
									)
						);
		
		return $this->SetGridTabla2($varTabla);
		}
	
	function FormuRegistro($varOpt=NULL, $varEmp=NULL, $varCod=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;			
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			
			$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = '$varCod' and id_empresa = $varEmp;";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		$varReturn = "<form id=\"form\" onsubmit=\"return false;\" method=\"POST\" name=\"form\">";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$SubTit,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"emp1",  "name"=>"emp1",  "valor"=>$Fila["id_empresa"]),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$varOpt)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPro",
										     "campo"=>array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "valor"=>$Fila["id_empresa"], 
											 				"sql"=>$sqlemp,
														    "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock)
										    ),		   
									   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], 
											 				 "ancho"=>"300")),
									   array("titulo"=>"Peso % :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"pes", "name"=>"pes", "valor"=>$Fila["peso"], 
											 				 "ancho"=>"80", "alinear"=>"right", "keypress"=>"return SoloNumeros(event)")),
									   array("titulo"=>"Monto Min. Ped. (S/.) :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"min", "name"=>"min", "valor"=>$Fila["monto_minimo"], 
											 				 "ancho"=>"80", "alinear"=>"right", "keypress"=>"return SoloNumeros(event)"))
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		$sqltip	= array("I"=>"INCREMENTAR", "D"=>"DISMINUIR");
		$varTit = "<input type=\"checkbox\" style=\"width:12px; height:12px\" id=\"optcopia\" name=\"optcopia\" ";
		$varTit.= ($varOpt<>"NEW")?"disabled ":"";
		$varTit.= ">&nbsp;COPIAR PRODUCTOS DE OTRA LISTA (Opcional)";
		$sqllis = "call spQuery_Lista_LP($Fila[id_empresa]);";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$varTit,
						"conte"=>array(array("titulo"=>"Empresa Origen :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPro",
										     "campo"=>array("tipo"=>"select", "id"=>"empo", "name"=>"empo", "sql"=>$sqlemp,
														    "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock,
															"reload"=>"xajax_comboListaLP(this.value)")
										    ),
									   array("titulo"=>"L.P. Origen:", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100", "div"=>"divLis",
											 "campo"=>array("tipo"=>"select", "id"=>"lis", "name"=>"lis", "valor"=>$Fila["id_lista"], "locked"=>$varLock,
															"sql"=>"", "ancho"=>"300")),
									   array("titulo"=>"Opcion Copia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select_simple", "id"=>"tip", "name"=>"tip",
											 				"combo"=>array("sql"=>$sqltip, "ancho"=>"150", "locked"=>$varLock))),
									   array("titulo"=>"En % :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo" =>array("tipo"=>"texto", "id"=>"inc", "name"=>"inc", "valor"=>NULL, "ancho"=>"80",
															 "alinear"=>"right", "keypress"=>"return SoloNumeros(event)", "bloqueado"=>$varLock))
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo",
						"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()"),
									)
						);
		$varReturn.= $this->setTablaForm($varTabla);
		$varReturn.= "</form>";
		return $varReturn;	
		}
			
	function FormuDetalle($varTip = 'P', $varEmp=NULL, $varCod=NULL) {
		$sql = "call spQuery_Lista_Precios($varEmp, $varCod, NULL, '$_SESSION[_CUSE]', NULL, NULL)";
		if ($varTip == "P") {
			$varTit = "PRODUCTOS";
			$varCam = "Producto";
			}
		elseif ($varTip == "S") {
			$varTit = "SERVICIOS";
			$varCam = "Servicio";
			}
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);

		$varReturn = "<form id=\"form\" onsubmit=\"return false;\" method=\"POST\" name=\"form\">";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - ASIGNACION DE ".$varTit,					
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"tip", "name"=>"tip", "valor"=>$varTip),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"DET"),
									   array("tipo"=>"oculto", "id"=>"optdet", "name"=>"optdet", "valor"=>"NEW")
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ecod", "name"=>"ecod", "ancho"=>"65",
											 										 "valor"=>$Fila["CEMP"], "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"texto", "id"=>"enom", "name"=>"enom", "ancho"=>"320",
											 										 "valor"=>$Fila["EMPRESA"],
																					 "clase"=>"inputDisable", "locked"=>"SI")))
															),	
									   array("titulo"=>"Nombre L.P. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"lcod", "name"=>"lcod", "ancho"=>"65",
											 										 "valor"=>$Fila["CLIS"], "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"texto", "id"=>"lnom", "name"=>"lnom", "ancho"=>"320",
											 										 "valor"=>$Fila["LISTA"],
																					 "clase"=>"inputDisable", "locked"=>"SI")))
															),
									   array("titulo"=>"Cant. Prod. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"cans", "name"=>"cans", "ancho"=>"65",
											 										 "valor"=>$Fila["CANT_PRO"], "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"Cantidad de Productos Agregados")))
															),
									   array("titulo"=>"Cant. Serv. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"cans", "name"=>"cans", "ancho"=>"65",
											 										 "valor"=>$Fila["CANT_SER"], "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"Cantidad de Servicios Agregados ")))
															),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"xcod", "name"=>"xcod",
																					 "ancho"=>"65", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor('PR', this.value, 'xcod', 'xnom')", 
																					 "dclick"=>"fn_cargar_listado_proveedor('xcod', 'xnom', 'PR')"),
																			   array("tipo"=>"text", "id"=>"xnom", "name"=>"xnom", 
																					 "ancho"=>"320", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bact", "name"=>"bact", "ancho"=>"150",
											 "clase"=>"boton_actualizar", "texto"=>"Actualizar Listado", "click"=>"javascrip:xActualizarListadoJS()")
									)
						);		
		$varReturn.= $this->setTablaForm($varTabla);
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>"AGREGAR ".$varTit,					
						"conte"=>array(
									  array("titulo"=>$varCam." :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod",
																					 "ancho"=>"60", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_producto_listap(this.value, '".$varTip."', ecod.value)", 
																					 "dclick"=>"fn_cargar_listado_producto_listap('".$varTip."','pcod', 'pnom', 'pum', ecod.value)"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", "valor"=>$_POST["pnom"], 
																					 "ancho"=>"260", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"pum", "name"=>"pum", "valor"=>$_POST["pum"], 
																					 "ancho"=>"60", "alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									  array("titulo"=>"Precio :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pre", "name"=>"pre", "valor"=>$_POST["pre"],
																					 "ancho"=>"100", "alinear"=>"right", 
																					 "keypress"=>"return SoloNumeros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Ingresar Precio a Agregar")
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_agregar", "texto"=>"Agregar", "click"=>"javascrip:xGrabarDetalleJS()"),			  
									   array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarDetalleJS()"),	
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		
		$varReturn.= $this->setTablaForm($varTabla);

		$varReturn.= "<div id=\"divDatos\">";
		$varReturn.= $this->GridDatosDetalle($varTip, $varEmp, $varCod, NULL);	
		$varReturn.= "</div>";
		return $varReturn;
		}
			
	function ProcesoGrabar($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="")? "NULL" : "'$varForm[cod]'";
		$varEmp = ($varForm["opt"]=="NEW")?$varForm["emp"]:$varForm["emp1"];
		$varNam = ($varForm["nam"]=="")? "NULL" : "'$varForm[nam]'";
		$varPes = ($varForm["pes"]=="")? "NULL" : $varForm["pes"];
		$varMin = ($varForm["min"]=="")? "NULL" : $varForm["min"];
		
		$varFlg = ($varForm["optcopia"])?"'S'":"'N'";
		$varEmo = ($varForm["empo"]=="Ninguno")? "NULL" : $varForm["empo"];
		$varEmo = (isset($varEmo))?$varEmo:"NULL";
		$varLis = ($varForm["lis"]=="")? "NULL" : $varForm["lis"];
		$varTip = ($varForm["tip"]=="")? "NULL" : "'".$varForm["tip"]."'";
		$varInc = ($varForm["inc"]=="")? "NULL" : $varForm["inc"];
		$sql = "call spMante_Lista_Precios('$varForm[opt]', $varCod, $varEmp, $varNam, $varPes, $varMin, $varFlg, $varEmo, $varLis, $varTip, $varInc, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
	
	function ProcesoGrabarDetalle($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;		
		$sql = "call spMante_Lista_Precios_Detalle('$varForm[optdet]', $varForm[ecod], $varForm[lcod], '".str_pad($varForm[pcod], 6, "0", STR_PAD_LEFT)."', 
												  '$varForm[pum]', $varForm[pre], $varUsr);";	
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}	
		
	function ProcesoEliminar($varEmp, $varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr 
				where ".$this->varMyID."= '".$varCod."' and id_empresa = $varEmp;";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	function ProcesoEliminarDetalle($varEmp, $varCod, $varLis) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "delete from _sv_lista_producto where id_producto = '$varCod' and id_lista = $varLis and id_empresa = $varEmp;";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>