<?php
//include "clase.conexion.php";
class clsListaPreciosGenerar extends clsConexion{
	public $varTitulo = "GENERAR LISTA DE PRECIOS";
	function FormuBusqueda() {
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		$sqltip	= array("T"=>"TODOS LOS PRODUCTOS", "S"=>"SOLO PRODUCTOS CON STOCK");
		$sqlmet	= array("U"=>"PRECIO DE ULTIMA COMPRA", "P"=>"PRECIO PROMEDIO DE COMPRA");
		$sqllis = "call spQuery_Lista_LP($Fila[id_empresa]);";
		$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"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPro",
										     "campo"=>array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "sql"=>$sqlemp,
														    "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300",
															"reload"=>"xajax_comboListaLP(this.value)")
										    ),
									   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100", "div"=>"divLis",
											 "campo"=>array("tipo"=>"select", "id"=>"lis", "name"=>"lis",
															"titulo"=>"--[[SELECCIONAR]]--","sql"=>"", "ancho"=>"300")),
									   array("titulo"=>"Opcion Producto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select_simple", "id"=>"tip", "name"=>"tip",
											 				"combo"=>array("sql"=>$sqltip, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--"))),
									   array("titulo"=>"Metodo Calculo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select_simple", "id"=>"met", "name"=>"met",
											 				"combo"=>array("sql"=>$sqlmet, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--"))),
									   array("titulo"=>"Aumentar 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))
									 ),
					  "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"=>"bsav", "name"=>"bsav", "ancho"=>"120",
											 "clase"=>"boton_guardar", "texto"=>"Generar L.P.", "click"=>"javascrip:xGrabarJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = ($varForm["emp"]<>"Ninguno" && $varForm["emp"]<>"")? $varForm["emp"]:"NULL";
		$varLis = ($varForm["lis"]<>"Ninguno" && $varForm["lis"]<>"")? $varForm["lis"]:"NULL";
		$varTip = ($varForm["tip"]<>"Ninguno" && $varForm["tip"]<>"")? "'".$varForm["tip"]."'":"NULL";
		$varMet = ($varForm["met"]<>"Ninguno" && $varForm["met"]<>"")? "'".$varForm["met"]."'":"NULL";
		$varInc = ($varForm["inc"]<>"")? $varForm["inc"]:"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spMante_Lista_Precios_Generar($varEmp, $varLis, $varTip, $varMet, $varInc, 'Q', $varUsr);";
		$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"=>"STOCK",    "ancho"=>"40",  "alinear"=>"right"), 
									   array("titulo"=>"PPC",      "ancho"=>"100", "alinear"=>"right", "decimal"=>"5"), 
									   array("titulo"=>"PVL",      "ancho"=>"40",  "alinear"=>"right", "decimal"=>"5"), 
									   array("titulo"=>"TTC",      "ancho"=>"100", "alinear"=>"right", "funcion"=>array("autosuma")), 
									   array("titulo"=>"TTV",      "ancho"=>"40",  "alinear"=>"right", "funcion"=>array("autosuma")), 
									   ),
						
						);
		return $this->SetGridTabla2($varTabla);
		}
		
	function ProcesoGrabar($varForm = NULL) {
		$varEmp = ($varForm["emp"]<>"Ninguno" && $varForm["emp"]<>"")? $varForm["emp"]:"NULL";
		$varLis = ($varForm["lis"]<>"Ninguno" && $varForm["lis"]<>"")? $varForm["lis"]:"NULL";
		$varTip = ($varForm["tip"]<>"Ninguno" && $varForm["tip"]<>"")? "'".$varForm["tip"]."'":"NULL";
		$varMet = ($varForm["met"]<>"Ninguno" && $varForm["met"]<>"")? "'".$varForm["met"]."'":"NULL";
		$varInc = ($varForm["inc"]<>"")? $varForm["inc"]:"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spMante_Lista_Precios_Generar($varEmp, $varLis, $varTip, $varMet, $varInc, 'P', $varUsr);";
		$this->AbrirConexion();
		$this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		return "OK";
		}
	}
	
?>