<?php
//include "clase.conexion.php";
class clsDescuentoPersonal extends clsConexion{
	public $varTitulo = "REGISTRO DE DESCUENTOS AL PERSONAL";
	public $varMyTabla  = "_sv_asigncion";
	public $varMyID  	  = "id_asignacion";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"300", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo,
						"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"=>"N&deg; Asignacion :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"120",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ide", "name"=>"ide", "valor"=>NULL,
																					 "ancho"=>"100", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)")
																			   )
														 	)
											 )				   
								   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"160", "texto"=>"Buscar Documentos",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xFormDescuentoJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
	
	function FormDescuento($varForm  = NULL)  {
		$varIde = ($varForm["ide"]=="")?"NULL":$varForm["ide"];
		$sqlcab = "call spQuery_Asignacion($varIde, NULL, NULL, NULL, NULL, NULL, NULL);";
		$this->AbrirConexion();
		$rscab = $this->Query($sqlcab);
		$this->CerrarConexion();
		$filacab = $this->FetchArray($rscab);
		$varExiste = $this->NumFilas($rscab);
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 1) DESCUENTOS REGISTRADOS",
						"formu"=>array("id"=>"formDescuento", "name"=>"formDescuento", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"ide2", "name"=>"ide2", "valor"=>$filacab["ASIG"])
									  ),
						"conte"=>array(array("titulo"=>"N&deg; Asignaci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["ASIG"])))
											 ),
									   array("titulo"=>"F. Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["FECHA"])))
											 ),
									   array("titulo"=>"Veh&iacute;culo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["PLACA"]." - ".$filacab["VEHICULO"])))
											 ),
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["CCON"]." - ".$filacab["CONDUCTOR"])))
											 )			   
									   ),
						  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"150",
											   "clase"=>"boton_nuevo", "texto"=>"Nuevo Descuento", "click"=>"javascrip:xFormDocumentoJS()"),
										 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarBusqueda()")
										 )
					);
		if($varExiste>0)
			return $this->setTablaForm($varTabla);
		else
			return "ERROR";
		}
	
	function GridDescuento($varIde   = NULL, 
						   $varField = NULL, 
						   $varOrder = NULL
						   )  {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varIde = ($varIde=="")?"NULL":$varIde;		
		$sql = "call spQuery_Asignacion_Descuentos($varIde,$varFie,$varOrd);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql,	"pages"=>20, "orderfun"=>"xGridDescuentoJS",
					    "conte"=>array(array("tamano"=>50, "titulo"=>"IDE", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"DOCUMENTO", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"MOTIVO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>20, "titulo"=>"GLOSA", "fijo"=>"SI"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI"),
									   array("tamano"=>250,"titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("tamano"=>60, "titulo"=>"MONTO", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>120,"titulo"=>"CONTADO", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"CREDITO", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"PARCIAL", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"RECHAZO", "oculto"=>"SI")
									   ), 
						"boton"=>array(array("tipo"=>"img", "img"=>"images/16x16/font_red_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR EL DESCUENTO</b>"),
											 				 array("valor"=>"<br><b>Documento : </b> "),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Motivo : </b> "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Glosa : </b> "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b> "),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Vendedor : </b> "),
															 array("valor"=>4, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>$varIde, "tipo"=>"NUMBER"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUMBER")
																		   )
															)
											),
									   array("tipo"=>"img", "img"=>"images/16x16/font_red.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR EL DESCUENTO</b>"),
											 				 array("valor"=>"<br><b>Documento : </b> "),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Motivo : </b> "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Glosa : </b> "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b> "),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Vendedor : </b> "),
															 array("valor"=>4, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"xFormuRegistroEditarJS",
															"param"=>array(array("valor"=>$varIde, "tipo"=>"NUMBER"),
																		   array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUMBER")
																		   )
															)
											)
										)
							);
		return $this->SetGridTabla2($varTabla);
		
		}
				
	function FormDocumento($varForm  = NULL)  {
		$varIde = ($varForm["ide2"]=="")?"NULL":$varForm["ide2"];
		$sqlcab = "call spQuery_Asignacion($varIde, NULL, NULL, NULL, NULL, NULL, NULL);";
		$this->AbrirConexion();
		$rscab = $this->Query($sqlcab);
		$this->CerrarConexion();
		$filacab = $this->FetchArray($rscab);
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 2) DOCUMENTOS DISPONIBLES",
						"formu"=>array("id"=>"formDocumento", "name"=>"formDocumento", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"ide3", "name"=>"ide3", "valor"=>$filacab["ASIG"])
									  ),
						"conte"=>array(array("titulo"=>"N&deg; Asignaci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["ASIG"])))
											 ),
									   array("titulo"=>"F. Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["FECHA"])))
											 ),
									   array("titulo"=>"Veh&iacute;culo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["PLACA"]." - ".$filacab["VEHICULO"])))
											 ),
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$filacab["CCON"]." - ".$filacab["CONDUCTOR"])))
											 )			   
									   ),
						  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarDescuento()")
										 )
					);
		return $this->setTablaForm($varTabla);
		}
		
	
	
	function GridDocumento($varIde  = NULL, 
						   $varField = NULL, 
						   $varOrder = NULL
						   )  {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varIde = ($varIde=="")?"NULL":$varIde;	
		$sql = "call spQuery_LiqReparto_Documentos_Para_Devolver($varIde, NULL, $varFie, $varOrd);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql, "pages"=>20, "orderfun"=>"xGridDocumentoJS",
					    "conte"=>array(array("tamano"=>50, "titulo"=>"VENTA", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"FEMI", "alinear"=>"center"),
									   array("tamano"=>20, "titulo"=>"DOCUMENTO", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCLI", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI"),
									   array("tamano"=>250,"titulo"=>"DIRECCION", "fijo"=>"SI", "largo"=>"30"),
									   array("tamano"=>10, "titulo"=>"CVEN", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CRUT", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"RUTA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"PEDIDO", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCON", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"COND", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CMOT", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"MOTIVO", "oculto"=>"SI"),
									   array("tamano"=>60, "titulo"=>"FACTU", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"EFECT", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>120,"titulo"=>"CONTADO", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"CREDITO", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"PARCIAL", "oculto"=>"SI"),
									   array("tamano"=>120,"titulo"=>"RECHAZO", "oculto"=>"SI")
									   ), 
						"boton"=>array(array("tipo"=>"img", "img"=>"images/16x16/elements.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>REALIZAR UN DESCUENTO</b>"),
											 				 array("valor"=>"<br><b>Documento : </b> "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>" "),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha : </b> "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b> "),
															 array("valor"=>5, "tipo"=>"INDEX"),
															 array("valor"=>" "),
															 array("valor"=>6, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Vendedor : </b> "),
															 array("valor"=>7, "tipo"=>"INDEX"),
															 array("valor"=>" "),
															 array("valor"=>8, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"xFormRegistroJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>4, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUMBER")
																		   )
															)
											)
										)
							);
		return $this->SetGridTabla2($varTabla);
		}
		
	function FormRegistro($varIde = NULL) {
		
		$sql = "CALL spQuery_Registro_Ventas_Detalle($varIde);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$sqlmot = "call spQuery_Combo_Motivo_Descuento();";
		$varFormu=array("id"=>"formDevolver", "name"=>"formDevolver", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 3) REGISTRAR DESCUENTO",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"DES"),
									   array("tipo"=>"oculto", "id"=>"asi", "name"=>"asi", "valor"=>$fila["CASI"]),
									   array("tipo"=>"oculto", "id"=>"ven", "name"=>"ven", "valor"=>$fila["CVEN"]),
									   array("tipo"=>"oculto", "id"=>"cli", "name"=>"cli", "valor"=>$fila["CCLI"])
									  ),
						"conte"=>array(array("titulo"=>"Id Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"text", "id"=>"cod", "name"=>"cod", "alinear"=>"center", "valor"=>$fila["IDE"], 
															"ancho"=>"80", "clase"=>"inputDisable", "locked"=>"SI"),
											 ),
										array("titulo"=>"Documento :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CTIP"]." => ".$fila["NDOC"]),
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CCLI"]." => ".$fila["CLIENTE"]),
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CVEN"]." => ".$fila["VENDEDOR"]),
											 ),
									   array("titulo"=>"Cond.Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CCON"]." => ".$fila["CONDICION"]),
											 ),
									   array("titulo"=>"Lista P. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CLIS"]." => ".$fila["LISTA"]),
											 ),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CEST"]." => ".$fila["ESTADO"]),
											 ),
									   array("titulo"=>"Sub Total :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["SUBTOTAL"],2,".",",")),
											 ),
									   array("titulo"=>"Igv :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["IGV"],2,".",",")),
											 ),
									   array("titulo"=>"Total :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["TOTAL"],2,".",","))
											 ),
									   array("titulo"=>"Mot. Descuento :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"mot", "name"=>"mot", "valor"=>NULL,
															"combo"=>array("sql"=>$sqlmot, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"300"))
											 ),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "valor"=>NULL, "ancho"=>"300", "alto"=>"40")
											 ),
									   array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"texto", "id"=>"mon", "name"=>"mon", "valor"=>NULL, "ancho"=>"100",
											 				"keypress"=>"return SoloNumeros(event)")
											 ),
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Grabar Devoluci&oacute;n", "click"=>"javascrip:xGuardarJS()"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresarDocumento()")
									 )
					);
		
		$Titulo1 = "<a href=\"javascript:marcar_todo('formDevolver')\">Seleccionar Todos</a> | 
					<a href=\"javascript:marcar_ninguno('formDevolver')\">Seleccionar Ninguno</a>";
							
		$sql1 = "call spQuery_LiqReparto_Contenido_Venta($varIde);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"600", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"SEL", "clase"=>"FormTitulo", "tamano"=>"40", "oculto"=>"SI"
											 ),
									   array("titulo"=>"DESCUENTO", "clase"=>"FormTitulo", "oculto"=>"SI"
											 ),
									   array("titulo"=>"CPRO", "clase"=>"FormTitulo", "tamano"=>"20", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"ide", "name"=>"ide", "ancho"=>"50", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"PRODUCTO", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI", "funcion"=>array("contar"),
											 "campo"=>array("tipo"=>"texto", "id"=>"des", "name"=>"des", "ancho"=>"300", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),										   
									   array("titulo"=>"TIP", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"tip", "name"=>"tip", "ancho"=>"20", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"U.M.", "clase"=>"FormTitulo", "tamano"=>"50",  "alinear"=>"center", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"ume", "name"=>"ume", "ancho"=>"50", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"PRECIO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "decimal"=>"5",
											 "campo"=>array("tipo"=>"texto", "id"=>"pre", "name"=>"pre", "ancho"=>"60", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"CANT.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"can", "name"=>"can", "ancho"=>"50", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"TOTAL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"tot", "name"=>"tot", "ancho"=>"60", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputLogro", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"LOTE", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"F.VEN.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);
		
		$varTabs =array(array("name"=>"Detalle de Productos del Documento",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"630", "tabla"=>$varTab_1
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)
			return $varReturn;
		else
			return "ERROR";
		}
	
	function FormRegistroEditar($varAsi = NULL, $varVen = NULL) {
		$sql = "CALL spQuery_Registro_Ventas_Detalle($varVen);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$sqlmot = "call spQuery_Combo_Motivo_Descuento();";

		$sqldes = "select * from _sv_asignacion_descuento where id_asignacion=$varAsi and id_venta=$varVen;";
		$this->AbrirConexion();
		$rsdes = $this->Query($sqldes);
		$this->CerrarConexion();
		$filades = $this->FetchArray($rsdes);
		$varFormu=array("id"=>"formDevolver", "name"=>"formDevolver", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo."<br>=> 3) EDITAR DESCUENTO",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"DES"),
									   array("tipo"=>"oculto", "id"=>"asi", "name"=>"asi", "valor"=>$fila["CASI"]),
									   array("tipo"=>"oculto", "id"=>"ven", "name"=>"ven", "valor"=>$fila["CVEN"]),
									   array("tipo"=>"oculto", "id"=>"cli", "name"=>"cli", "valor"=>$fila["CCLI"])
									  ),
						"conte"=>array(array("titulo"=>"Id Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"text", "id"=>"cod", "name"=>"cod", "alinear"=>"center", "valor"=>$fila["IDE"], 
															"ancho"=>"80", "clase"=>"inputDisable", "locked"=>"SI"),
											 ),
										array("titulo"=>"Documento :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CTIP"]." => ".$fila["NDOC"]),
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CCLI"]." => ".$fila["CLIENTE"]),
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CVEN"]." => ".$fila["VENDEDOR"]),
											 ),
									   array("titulo"=>"Cond.Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CCON"]." => ".$fila["CONDICION"]),
											 ),
									   array("titulo"=>"Lista P. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CLIS"]." => ".$fila["LISTA"]),
											 ),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["CEST"]." => ".$fila["ESTADO"]),
											 ),
									   array("titulo"=>"Sub Total :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["SUBTOTAL"],2,".",",")),
											 ),
									   array("titulo"=>"Igv :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["IGV"],2,".",",")),
											 ),
									   array("titulo"=>"Total :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["TOTAL"],2,".",","))
											 ),
									   array("titulo"=>"Mot. Descuento :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"mot", "name"=>"mot", "valor"=>$filades["id_tipo_descuento"],
															"combo"=>array("sql"=>$sqlmot, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"300"))
											 ),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "valor"=>$filades["glosa"], "ancho"=>"300", "alto"=>"40")
											 ),
									   array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"texto", "id"=>"mon", "name"=>"mon", "valor"=>$filades["monto"], "ancho"=>"100",
											 				"keypress"=>"return SoloNumeros(event)")
											 ),
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Grabar Devoluci&oacute;n", "click"=>"javascrip:xGuardarJS()"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresarDescuento2()")
									 )
					);
		
		$Titulo1 = "<a href=\"javascript:marcar_todo('formDevolver')\">Seleccionar Todos</a> | 
					<a href=\"javascript:marcar_ninguno('formDevolver')\">Seleccionar Ninguno</a>";
							
		$sql1 = "call spQuery_LiqReparto_Contenido_Venta($varVen);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"600", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"SEL", "clase"=>"FormTitulo", "tamano"=>"40", "oculto"=>"SI"
											 ),
									   array("titulo"=>"DESCUENTO", "clase"=>"FormTitulo", "oculto"=>"SI"
											 ),
									   array("titulo"=>"CPRO", "clase"=>"FormTitulo", "tamano"=>"20", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"ide", "name"=>"ide", "ancho"=>"50", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"PRODUCTO", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI", "funcion"=>array("contar"),
											 "campo"=>array("tipo"=>"texto", "id"=>"des", "name"=>"des", "ancho"=>"300", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),										   
									   array("titulo"=>"TIP", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"tip", "name"=>"tip", "ancho"=>"20", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"U.M.", "clase"=>"FormTitulo", "tamano"=>"50",  "alinear"=>"center", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"ume", "name"=>"ume", "ancho"=>"50", "alinear"=>"center", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"PRECIO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "decimal"=>"5",
											 "campo"=>array("tipo"=>"texto", "id"=>"pre", "name"=>"pre", "ancho"=>"60", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"CANT.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"can", "name"=>"can", "ancho"=>"50", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputDisable", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"TOTAL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"tot", "name"=>"tot", "ancho"=>"60", "alinear"=>"right", 
											 				"locked"=>"SI", "clase"=>"inputLogro", "name_in"=>0, "id_in"=>0)
											),
									   array("titulo"=>"LOTE", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"F.VEN.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);
		
		$varTabs =array(array("name"=>"Detalle de Productos del Documento",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"630", "tabla"=>$varTab_1
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)

			return $varReturn;
		else
			return "ERROR";
		}
							
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$varAsi = (isset($varForm["asi"]) && $varForm["asi"]<>"")?$varForm["asi"]:"NULL";
		$varIde = (isset($varForm["cod"]) && $varForm["cod"]<>"")?$varForm["cod"]:"NULL";
		$varVen = (isset($varForm["ven"]) && $varForm["ven"]<>"")?$varForm["ven"]:"NULL";
		$varCli = (isset($varForm["cli"]) && $varForm["cli"]<>"")?$varForm["cli"]:"NULL";
		$varMot = (isset($varForm["mot"]) && $varForm["mot"]<>"Ninguno")?$varForm["mot"]:"NULL";
		$varGlo = (isset($varForm["glo"]) && $varForm["glo"]<>"")?"'".$varForm["glo"]."'":"NULL";
		$varMon = (isset($varForm["mon"]) && $varForm["mon"]<>"")?$varForm["mon"]:"NULL";
		$sqldel = "delete from _sv_asignacion_descuento where id_asignacion=$varAsi and id_venta=$varIde;";
		$this->AbrirConexion();
		$rs = $this->Query($sqldel);
		$this->CerrarConexion();
		
		$sql = "call spMante_LiqReparto_Descuento_Personal($varAsi, $varIde, $varVen, $varCli, $varMot, $varGlo, $varMon, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		return $fila[0];
		}
		
	function ProcesoEliminar($varAsi, $varVen) {
		$sql = "delete from _sv_asignacion_descuento where id_asignacion=$varAsi and id_venta=$varVen;";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();	
		return $sql;
		}
	}
	
?>