<?php
//include "clase.conexion.php";
class clsAsignacionVenta extends clsConexion{
	public $varTitulo = "GENERAR ASIGNACION DE REPARTO";
	public $varMyTabla  = "_sv_asigncion";
	public $varMyID  	  = "id_asignacion";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"430", "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",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", 
																					 "alinear"=>"center", "ancho"=>"80"),
																			   array("tipo"=>"simple", "valor"=>"Nro. Asignacion"))
														 	)
											 ),									   
									   array("titulo"=>"Vehiculo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod1", "name"=>"vcod1", "valor"=>NULL, 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_vehiculo(this.value,'vcod1','vnom1')", 
																					 "dclick"=>"fn_cargar_listado_vehiculo('vcod1', 'vnom1')"),
																			   array("tipo"=>"text", "id"=>"vnom1", "name"=>"vnom1", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),	
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"text", "id"=>"ccod1", "name"=>"ccod1", "valor"=>NULL, 
																					"ancho"=>"50",  "alinear"=>"center", 
																					"blur"=>"xajax_seleccionar_conductor(this.value, 'ccod1', 'cnom1')", 
																					"dclick"=>"fn_cargar_listado_conductor('ccod1', 'cnom1')"),
																			  array("tipo"=>"text", "id"=>"cnom1", "name"=>"cnom1", 
																					"ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			  )
														   )
										   ),
									 array("titulo"=>"F.Inicial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center"))
														 	)
											 ),
									   array("titulo"=>"F.Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center"))
														 	)
											 ),					   
								   ),
					  "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"=>"150", "texto"=>"Nueva Asignacion", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroBusquedaJS('', 'NEW')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   )  {
						  
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varCod = (isset($varForm["cod"]) && $varForm["cod"]<>'')?$varForm["cod"]:"NULL";
		$varVeh = (isset($varForm["vcod1"]) && $varForm["vcod1"]<>'')?$varForm["vcod1"]:"NULL";
		$varCon = (isset($varForm["ccod1"]) && $varForm["ccod1"]<>'')?$varForm["ccod1"]:"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')?"'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')?"'".FechaMySql($varForm["ffin"])."'":"NULL";
		
		$sql = "call spQuery_Asignacion($varCod, $varVeh, $varCon, $varIni, $varFin, $varFie, $varOrd);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"IDE",    "ancho"=>"30" , "alinear"=>"center"), 
									   array("titulo"=>"FECHA", "ancho"=>"80", "fijo"  =>"SI"),
									   array("titulo"=>"CVEH",  "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"PLACA", "ancho"=>"50"),
									   array("titulo"=>"VEHICULO", "ancho"=>"200", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CCON", "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"CONDUCTOR","ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"DOC'S", "ancho"=>"50", "alinear"=>"right", "decimal"=>"2"),
									   array("titulo"=>"MONTO", "ancho"=>"50", "alinear"=>"right", "decimal"=>"2", "funcion"=>array("autosuma")),
									   array("titulo"=>"FCREADO", "ancho"=>"100", "fijo"=>"SI"),
									   array("titulo"=>"FUPDATE", "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO", "ancho"=>"100", "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"UUPDATE", "ancho"=>"100", "alinear"=>"center", "oculto"=>"SI")
									   ), 
						"boton"=>array(array("tipo"=>"img", "img"=>"images/b_table.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER EL DETALLE</b> DE LA ASIGNACION<br><b>Nro. Asignacion :</b> "),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha : </b>"),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Monto : </b>"),
															 array("valor"=>8, "tipo"=>"INDEX"),
															 ),
											 "click"=>array("funcion"=>"xajax_xFormuDetalle",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"))
															)
											),
									  array("tipo"=>"img", "img"=>"images/b_table_edit.png", 
											"toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> LA ASIGNACION<br><b>Nro. Asignacion :</b> "),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha : </b>"),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Monto : </b>"),
															 array("valor"=>8, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"xFormuRegistroEditJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"))
															)
											)
										)
							);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistroBusqueda() {
		$sqlven = "call spQuery_Lista_Vendedor('','','');";
		$sqlrut = "call spQuery_Lista_Ruta('','%');";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"630", "clase"=>"FormTitulo", "titulo"=>"PASO 1 : ".$this->varTitulo." - UBICAR DOCUMENTOS",
						"formu"=>array("id"=>"formBusqueda", "name"=>"formBusqueda", "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"=>"F. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fven", "name"=>"fven", "alinear"=>"center", "alto"=>"18"))
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"250", "sql"=>$sqlven,
											 				"id1"=>"ven", "name1"=>"ven", "id2"=>"pcod", "name2"=>"pcod",
															"dclick1"=>"mover_lista('right','ven','pcod')", "dclick2"=>"mover_lista('left','ven','pcod')"															
															)
											),									   
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"250", "sql"=>$sqlrut,
											 				"id1"=>"rut", "name1"=>"rut", "id2"=>"rcod", "name2"=>"rcod",
															"dclick1"=>"mover_lista('right','rut','rcod')", "dclick2"=>"mover_lista('left','rut','rcod')"															
															)
											),
									   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"160", "texto"=>"Buscar Documentos ",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xFormuRegistroNewJS()"),
									  array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarPrincipal()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function FormuRegistro($varDia = NULL, 
						   $varVen = NULL, 
						   $varRut = NULL
						   ) {
		
		$varFormu=array("id"=>"formAsignacion", "name"=>"formAsignacion", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"550", "clase"=>"FormTitulo", "titulo"=>"PASO 2 : ".$this->varTitulo." - DETALLE DE LA ASIGNACION",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"NEW")
									  ),
						"conte"=>array(array("titulo"=>"Nro Asig. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"text", "id"=>"cod", "name"=>"cod", "alinear"=>"center", "valor"=>$fila["ASIG"], 
															"ancho"=>"80", "clase"=>"inputDisable", "locked"=>"SI"),
											 ),
									   array("titulo"=>"F.Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "id"=>"femi", "name"=>"femi", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI"))
														 	)
											 ),
									   array("titulo"=>"Vehiculo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>NULL, 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_vehiculo(this.value, 'vcod', 'vnom')", 
																					 "dclick"=>"fn_cargar_listado_vehiculo('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"70"),
																			   array("tipo"=>"text", "id"=>"vcos", "name"=>"vcos", "valor"=>NULL,
																					 "ancho"=>"60", "keypress"=>"return SoloNumeros(event)", "alinear"=>"right")
																			   )
															)
											 ),	
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>NULL, 
																					"ancho"=>"50",  "alinear"=>"center", 
																					"blur"=>"xajax_seleccionar_conductor(this.value, 'ccod', 'cnom')", 
																					"dclick"=>"fn_cargar_listado_conductor('ccod', 'cnom')"),
																			  array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", 
																					"ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI"),
																			  array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"70"),
																			  array("tipo"=>"text", "id"=>"ccos", "name"=>"ccos", 
																					 "ancho"=>"60", "keypress"=>"return SoloNumeros(event)", "alinear"=>"right")
																			  )
														   )
										   ),
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Registrar Asignacion", "click"=>"javascrip:xGuardarJS('NEW')"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresar()")
									 )
					);
		
		//$varReturn.= "<input type=\"checkbox\" name=\"ped[]\" id=\"ped\" style=\"visibility:hidden\" />";
		
		$Titulo1 = "<a href=\"javascript:marcar_todo('formAsignacion')\">Seleccionar Todos</a> | 
					<a href=\"javascript:marcar_ninguno('formAsignacion')\">Seleccionar Ninguno</a>";
							
		$Titulo2 = "<input id=\"btadd2\" name=\"btadd2\" type=\"button\" class=\"boton_agregar_cliente\" style=\"cursor:pointer; width:190px;\"  
				    value=\"Agregar Personal Reparto\" onClick=\"AddPersonalReparto()\">";

		$Titulo3 = "<input id=\"btadd3\" name=\"btadd3\" type=\"button\" class=\"boton_agregar_producto\" style=\"cursor:pointer; width:190px;\"  
				    value=\"Agregar Gasto Reparto\" onClick=\"AddCostoReparto()\">";

		
		$varDia1 = (isset($varDia) && $varDia<>"")?"'".FechaMySql($varDia)."'":"NULL";
		$varVen1  = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varRut1  = ($varRut<>"")?"\"(".str_replace("\\","",$varRut).")\"":"NULL";
		
		$sql1 = "call spQuery_Asignacion_Documentos($varDia1,$varVen1,$varRut1);";

		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"840", "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"=>"30", "alinear"=>"center", "alto"=>"25",
											 "campo"=>array("tipo"=>"check", "id"=>"ven1", "name"=>"ven1", "alinear"=>"center")
											 ),
									   array("titulo"=>"DOCUMENTO", "clase"=>"FormTitulo", "tamano"=>"80", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple", "alinear"=>"center")
											),
									   array("titulo"=>"CLIENTE", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI", "funcion"=>array("contar"),
											 "campo"=>array("tipo"=>"simple")
											),										   
									   array("titulo"=>"DIRECCION", "clase"=>"FormTitulo", "tamano"=>"250", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"RUTA", "clase"=>"FormTitulo", "tamano"=>"150", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"VEND", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right", "funcion"=>array("autosuma"),
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);


		$varTab_2=array("id"=>"tab2", "name"=>"tab2", "tamano"=>"660", "clase"=>"FormTitulo", "titulo"=>$Titulo2, "sql"=>$sql2,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num2", "name"=>"num2", "valor"=>0)),
						"conte"=>array(array("titulo"=>"CODIGO", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cod2", "name"=>"cod2", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_producto",
																			"cuerpo" =>array(array("campo"=>0), 
																							 array("campo"=>1),
																							 array("campo"=>2)
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_repartidor_asignacion",
																			"cuerpo" =>array(array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>0), 
																							 array("campo"=>1), 
																							 array("campo"=>2),
																							 array("campo"=>3)
																							 )
																			)
															)
											 ),
									   array("titulo"=>"NOMBRE PERSONAL REPARTO", "clase"=>"FormTitulo", "tamano"=>"410",
											 "campo"=>array("tipo"=>"texto", "id"=>"nom2", "name"=>"nom2", "clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"400")
											),
									   array("titulo"=>"NRO. DNI", "clase"=>"FormTitulo", "tamano"=>"100",
											 "campo"=>array("tipo"=>"texto", "id"=>"dni2", "name"=>"dni2", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"90", "alinear"=>"center")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cos2", "name"=>"cos2", "alinear"=>"center", "ancho"=>"60", 
															"keypress"=>"return SoloNumeros(event)"
															)
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"images/b_drop.png")
											)
									   )
						);
		
		$varTab_3=array("id"=>"tab3", "name"=>"tab3", "tamano"=>"660", "clase"=>"FormTitulo", "titulo"=>$Titulo3, "sql"=>$sql3,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num3", "name"=>"num3", "valor"=>0)),
						"conte"=>array(array("titulo"=>"CCOS", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cod3", "name"=>"cod3", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_cliente",
																			"cuerpo" =>array(array("campo"=>0), 
																							 array("campo"=>1)
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_cliente_bonif",
																			"cuerpo" =>array(array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>0), 
																							 array("campo"=>1)
																							 )
																			)
															)
											 ),
									   array("titulo"=>"DESCRIPCION DEL COSTO", "clase"=>"FormTitulo", "tamano"=>"410",
											 "campo"=>array("tipo"=>"texto", "id"=>"nom3", "name"=>"nom3", "clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"400")
											),
									   array("titulo"=>"ABREV.", "clase"=>"FormTitulo", "tamano"=>"100",
											 "campo"=>array("tipo"=>"texto", "id"=>"abr3", "name"=>"abr3", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"90", "alinear"=>"center")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cos3", "name"=>"cos3", "alinear"=>"center", "ancho"=>"60", 
															"keypress"=>"return SoloNumeros(event)"
															)
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"images/b_drop.png")
											)
									   )
						);
		
		
		$varTabs =array(array("name"=>"Documentos de Venta a Asignar",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_1
							  ),
						array("name"=>"Personal de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_2
							  ),	
						array("name"=>"Gastos de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_3
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)
			return $varReturn;
		else
			return "ERROR";
		}
	
	function FormuDetalle($varCod = NULL) 
		{
		$sql = "CALL spQuery_Asignacion_Detalle($varCod);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);		
		$varFormu=array("id"=>"form", "name"=>"form", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DETALLE DE LA ASIGNACION",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo)
									  ),
						"conte"=>array(array("titulo"=>"Nro Asig. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"90",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["ASIG"]),
											 ),
									   array("titulo"=>"F.Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["FECHA"])
											 ),
									   array("titulo"=>"Vehiculo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"200",
																					 "valor"=>$fila["CVEH"]." - ".$fila["PLACA"]." : ".$fila["VEHICULO"]),
																			   array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"70"),
																			   array("tipo"=>"simple", "valor"=>number_format($fila["MONTO_VEHICULO"],"2",".",","),
																			   		 "alinear"=>"right")
																			   )
															)
											 ),	
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"simple",  "ancho"=>"200", 
														   							"valor"=>$fila["CCON"]." - ".$fila["CONDUCTOR"]),
																			   array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"70"),
																			   array("tipo"=>"simple", "valor"=>number_format($fila["MONTO_CONDUCTOR"],"2",".",","),
																			   		 "alinear"=>"right")
																			   )
														   )
										   ),
									   array("titulo"=>"Cant.Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["NUM_DOC"],"2",".",","))
											 ),	
									   array("titulo"=>"Monto Asig. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"simple", "valor"=>number_format($fila["MON_DOC"],"2",".",","))
										   ),
									   array("titulo"=>"Fecha Creado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"simple", "valor"=>$fila["FECHA_CREADO"])
										   ),
									   array("titulo"=>"Usuario :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"simple", "valor"=>$fila["USER_CREADO"])
										   ),
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresarPrincipal()")
									 )
					);
		
		
		$sql1 = "CALL spQuery_Asignacion_Documentos_Detalle($varCod);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"840", "clase"=>"FormTitulo", "titulo"=>"LISTADO DE DOCUMENTOS ASIGNADOS", "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"IDE", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple", "alinear"=>"center")
											),
									   array("titulo"=>"DOCUMENTO", "clase"=>"FormTitulo", "tamano"=>"80", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple", "alinear"=>"center")
											),
									   array("titulo"=>"CLIENTE", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),										   
									   array("titulo"=>"DIRECCION", "clase"=>"FormTitulo", "tamano"=>"250", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"RUTA", "clase"=>"FormTitulo", "tamano"=>"150", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"VEND", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"SALDO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);

		$sql2 = "CALL spQuery_Asignacion_Repartidor($varCod);";
		$varTab_2=array("id"=>"tab2", "name"=>"tab2", "tamano"=>"660", "clase"=>"FormTitulo", "titulo"=>"LISTADO DE REPARTIDORES ASIGNADOS", "sql"=>$sql2,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num2", "name"=>"num2", "valor"=>0)),
						"conte"=>array(array("titulo"=>"CODIGO", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											 ),
									   array("titulo"=>"NOMBRE PERSONAL REPARTO", "clase"=>"FormTitulo", "tamano"=>"410",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"NRO. DNI", "clase"=>"FormTitulo", "tamano"=>"100",
											 "campo"=>array("tipo"=>"simple")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);
		$sql3 = "CALL spQuery_Asignacion_Gasto($varCod, NULL, NULL);";
		$varTab_3=array("id"=>"tab3", "name"=>"tab3", "tamano"=>"660", "clase"=>"FormTitulo", "titulo"=>"LISTADO DE COSTOS ASIGNADOS", "sql"=>$sql3,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num3", "name"=>"num3", "valor"=>0)),
						"conte"=>array(array("titulo"=>"CCOS", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											 ),
									   array("titulo"=>"DESCRIPCION DEL COSTO", "clase"=>"FormTitulo", "tamano"=>"410",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"ABREV.", "clase"=>"FormTitulo", "tamano"=>"100",
											 "campo"=>array("tipo"=>"simple")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);
		
		
		$varTabs =array(array("name"=>"Documentos de Venta a Asignar",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_1
							  ),
						array("name"=>"Personal de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_2
							  ),	
						array("name"=>"Gastos de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_3
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)
			return $varReturn;
		else
			return "ERROR";
		}
		
	function FormuRegistroEdit($varCod = NULL) 
		{
		$sql = "select A.id_asignacion as ASIG, date_format(A.id_fecha, '%d/%m/%Y') as FECHA,
				A.id_vehiculo as CVEH, CONCAT(V.PLACA, ' : ', V.descripcion) as VEHICULO, A.monto_vehiculo AS MVEH,
				A.id_conductor as CCON, C.nombre as CONDUCTOR, A.monto_conductor AS MCON
				from _sv_asignacion A
				inner join _sv_vehiculo V ON A.id_vehiculo = V.id_vehiculo
				inner join _sv_conductor C ON A.id_conductor = C.id_conductor
				WHERE A._estado = 'A'
				and A.id_asignacion = $varCod;";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$varFormu=array("id"=>"formAsignacion", "name"=>"formAsignacion", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"550", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DETALLE DE LA ASIGNACION",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"EDIT"),
									   array("tipo"=>"oculto", "id"=>"femi", "name"=>"femi", "valor"=>$fila["FECHA"])
									  ),
						"conte"=>array(array("titulo"=>"Nro Asig. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo"=>array("tipo"=>"text", "id"=>"cod", "name"=>"cod", "alinear"=>"center", "valor"=>$fila["ASIG"], 
															"ancho"=>"80", "clase"=>"inputDisable", "locked"=>"SI"),
											 ),
										array("titulo"=>"F. Reparto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"simple", "valor"=>$fila["FECHA"])
											 ),
									   array("titulo"=>"Vehiculo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>$fila["CVEH"], 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_vehiculo(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vehiculo('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>$fila["VEHICULO"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"text", "id"=>"vcos", "name"=>"vcos", "valor"=>$fila["MVEH"],
																					 "ancho"=>"60", "keypress"=>"return SoloNumeros(event)", "alinear"=>"right")
																			   )
															)
											 ),	
									   array("titulo"=>"Conductor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$fila["CCON"], 
																					"ancho"=>"50",  "alinear"=>"center", 
																					"blur"=>"xajax_seleccionar_conductor(this.value)", 
																					"dclick"=>"fn_cargar_listado_conductor('ccod', 'cnom')"),
																			  array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom",  "valor"=>$fila["CONDUCTOR"], 
																					"ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI"),
																			  array("tipo"=>"simple", "valor"=>"Costo S/. : ", "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			  array("tipo"=>"text", "id"=>"ccos", "name"=>"ccos",  "valor"=>$fila["MCON"], 
																					 "ancho"=>"60", "keypress"=>"return SoloNumeros(event)", "alinear"=>"right")
																			  )
														   )
										   )
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Actualizar Asignacion", "click"=>"javascrip:xGuardarJS('EDIT')"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresarPrincipal()")
									 )
					);

		$Titulo1 = "<input id=\"btadd1\" name=\"btadd1\" type=\"button\" class=\"boton_agregar_venta\" style=\"cursor:pointer; width:200px;\"  
				    value=\"Agregar Documento Venta\" onClick=\"AddDocumentoVenta()\">";
							
		$Titulo2 = "<input id=\"btadd2\" name=\"btadd2\" type=\"button\" class=\"boton_agregar_persona\" style=\"cursor:pointer; width:200px;\"  
				    value=\"Agregar Personal Reparto\" onClick=\"AddPersonalReparto()\">";

		$Titulo3 = "<input id=\"btadd3\" name=\"btadd3\" type=\"button\" class=\"boton_agregar_producto\" style=\"cursor:pointer; width:200px;\"  
				    value=\"Agregar Gasto Reparto\" onClick=\"AddCostoReparto()\">";

		
		$sql1 = "call spQuery_Asignacion_Venta($varCod)";
		$sql2 = "CALL spQuery_Asignacion_Repartidor($varCod);";
		$sql3 = "CALL spQuery_Asignacion_Gasto($varCod, NULL, NULL);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$this->AbrirConexion();
		$rs2 = $this->Query($sql2);
		$this->CerrarConexion();
		$this->AbrirConexion();
		$rs3 = $this->Query($sql3);
		$this->CerrarConexion();
		$varNum1 = $this->NumFilas($rs1);
		$varNum2 = $this->NumFilas($rs2);
		$varNum3 = $this->NumFilas($rs3);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"850", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"IDE", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"ide1", "name"=>"ide1", "alinear"=>"center", "ancho"=>"50")
											),
									   array("titulo"=>"DOCUMENTO", "clase"=>"FormTitulo", "tamano"=>"110", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"doc1", "name"=>"doc1", "alinear"=>"center",
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"110")
											),
									   array("titulo"=>"CLIENTE", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"cli1", "name"=>"cli1",
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"210")
											),										   
									   array("titulo"=>"DIRECCION", "clase"=>"FormTitulo", "tamano"=>"200", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"dir1", "name"=>"dir1",
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"210")
											),
									   array("titulo"=>"RUTA", "clase"=>"FormTitulo", "tamano"=>"100", "fijo"=>"SI",
											 "campo"=>array("tipo"=>"texto", "id"=>"rut1", "name"=>"rut1",
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"100")
											),
									   array("titulo"=>"VEND", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", 
											 "campo"=>array("tipo"=>"texto", "id"=>"ven1", "name"=>"ven1", "alinear"=>"center",
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"30")
											),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"mon1", "name"=>"mon1", "alinear"=>"right", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"70")
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"images/b_drop.png")
											)
									   )
						);


		$varTab_2=array("id"=>"tab2", "name"=>"tab2", "tamano"=>"700", "clase"=>"FormTitulo", "titulo"=>$Titulo2, "sql"=>$sql2,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num2", "name"=>"num2", "valor"=>$varNum2)),
						"conte"=>array(array("titulo"=>"CODIGO", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cod2", "name"=>"cod2", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_repartidor",
																			"cuerpo" =>array(array("campo"=>0), 
																							 array("campo"=>1),
																							 array("campo"=>2),
																							 array("campo"=>3)
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_repartidor_asignacion",
																			"cuerpo" =>array(array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>0), 
																							 array("campo"=>1), 
																							 array("campo"=>2),
																							 array("campo"=>3),
																							 array("campo"=>"cod2", "tipo"=>"TEXTO"),
																							 array("campo"=>$varNum2, "tipo"=>"NUM"),
																							 array("campo"=>"xajax.getFormValues('form')", "tipo"=>"NUM")
																							 )
																			)
															)
											 ),
									   array("titulo"=>"NOMBRE PERSONAL REPARTO", "clase"=>"FormTitulo", "tamano"=>"410", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"nom2", "name"=>"nom2", "clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"400")
											),
									   array("titulo"=>"NRO. DNI", "clase"=>"FormTitulo", "tamano"=>"100", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"dni2", "name"=>"dni2", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"90", "alinear"=>"center")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cos2", "name"=>"cos2", "alinear"=>"center", "ancho"=>"60", 
															"keypress"=>"return SoloNumeros(event)"
															)
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"images/b_drop.png")
											)
									   )
						);
		
		$varTab_3=array("id"=>"tab3", "name"=>"tab3", "tamano"=>"700", "clase"=>"FormTitulo", "titulo"=>$Titulo3, "sql"=>$sql3,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num3", "name"=>"num3", "valor"=>$varNum3)),
						"conte"=>array(array("titulo"=>"CCOS", "clase"=>"FormTitulo", "tamano"=>"60", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cod3", "name"=>"cod3", "alinear"=>"center", "ancho"=>"50", 
															"keypress"=>"return SoloEnteros(event)",
															"dclick"=>array("funcion"=>"fn_cargar_listado_gasto",
																			"cuerpo" =>array(array("campo"=>0), 
																							 array("campo"=>1),
																							 array("campo"=>2),
																							 array("campo"=>3)
																							 )
																			),
															"blur"  =>array("funcion"=>"xajax_seleccionar_cliente_bonif",
																			"cuerpo" =>array(array("campo"=>"this.value", "tipo"=>"NUM"), 
																							 array("campo"=>0), 
																							 array("campo"=>1)
																							 )
																			)
															)
											 ),
									   array("titulo"=>"DESCRIPCION DEL COSTO", "clase"=>"FormTitulo", "tamano"=>"410", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"nom3", "name"=>"nom3", "clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"400")
											),
									   array("titulo"=>"ABREV.", "clase"=>"FormTitulo", "tamano"=>"100", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"abr3", "name"=>"abr3", "clase"=>"inputDisable", 
															"locked"=>"SI", "ancho"=>"90", "alinear"=>"center")
											),										   
									   array("titulo"=>"COSTO", "clase"=>"FormTitulo", "tamano"=>"70", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"cos3", "name"=>"cos3", "alinear"=>"center", "ancho"=>"60", 
															"keypress"=>"return SoloNumeros(event)"
															)
											),
									   array("titulo"=>"DEL", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"center",
											 "campo"=>array("tipo"=>"imagen", "click"=>"EliminarFilaTabla(this)", "img"=>"images/b_drop.png")
											)
									   )
						);
		
		
		$varTabs =array(array("name"=>"Documentos de Venta a Asignar",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_1
							  ),
						array("name"=>"Personal de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_2
							  ),	
						array("name"=>"Gastos de Reparto",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_3
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		
		return $varReturn;
		}
					
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$varCod = (isset($varForm["cod"]) && $varForm["cod"]<>"")?$varForm["cod"]:"NULL";
		$varEmi = "'".FechaMySql($varForm["femi"])."'";
		$varVeh = (isset($varForm["vcod"]) && $varForm["vcod"]<>"")?$varForm["vcod"]:"NULL";
		$varCoV = (isset($varForm["vcos"]) && $varForm["vcos"]<>"")?$varForm["vcos"]:"NULL";
		$varCon = (isset($varForm["ccod"]) && $varForm["ccod"]<>"")?$varForm["ccod"]:"NULL";
		$varCoC = (isset($varForm["ccos"]) && $varForm["ccos"]<>"")?$varForm["ccos"]:"NULL";

		//Registramos cabecera de la asignación
		$sql = "call spMante_Asignacion('$varForm[opt]', $varCod, $varEmi, $varVeh, $varCon, $varCoV, $varCoC, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$varIde = $fila[0];
		
		//Eliminamos asignacion de documentos
		$sql = "update _sv_venta set id_asignacion=0 where id_asignacion=$varIde;";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$sql = "delete from _sv_asignacion_venta where id_asignacion=$varIde;";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		
		//Registramos el Detalle de la Venta Asignada
		if($varForm["opt"]=="NEW") {
			$sqldet = "";
			foreach ($varForm["ven1"] as $varVen) {
				$sqldet = "call spMante_Asignacion_Venta('NEW', $varIde, $varVen, $varUsr);";
				$varsql.=$sqldet;	
				$this->AbrirConexion();
				$this->Query($sqldet);
				$this->CerrarConexion();
				}
			$varMsj = "GENERO";
			}
		else {
			foreach ($varForm["ide1"] as $varVen) {
				$sqldet = "call spMante_Asignacion_Venta('NEW', $varIde, $varVen, $varUsr);";
				$varsql.=$sqldet;	
				$this->AbrirConexion();
				$this->Query($sqldet);
				$this->CerrarConexion();
				}
			$this->AbrirConexion();
			$sqldel = "delete from _sv_asignacion_repartidor where id_asignacion=$varIde;";
			$this->Query($sqldel);
			$sqldel = "delete from _sv_asignacion_gasto where id_asignacion=$varIde;";
			$this->Query($sqldel);
			$this->CerrarConexion();
			$varMsj = "ACTUALIZO";
			}
		//Registramos el Detalle de los Repartidores
		$varCantRep = $varForm["num2"];
		$sqldet = "";
		for($i=0; $i<$varCantRep;$i++) {
			$varRep = $varForm["cod2"][$i];
			$varMon = ($varForm["cos2"][$i]=="")?0:$varForm["cos2"][$i];
			$sqldet = "call spMante_Asignacion_Repartidor('NEW', $varIde, $varRep, $varMon, $varUsr);";
			$this->AbrirConexion();
			$this->Query($sqldet);
			$this->CerrarConexion();
			}
		
		//Registramos el Detalle de los Costos
		$varCantCos = $varForm["num3"];
		$sqldet = "";
		for($i=0; $i<$varCantCos;$i++) {
			$varCos = $varForm["cod3"][$i];
			$varMon = ($varForm["cos3"][$i]=="")?0:$varForm["cos3"][$i];
			$sqldet = "call spMante_Asignacion_Gasto('NEW', $varIde, $varCos, $varMon, $varUsr);";
			
			$this->AbrirConexion();
			$this->Query($sqldet);
			$this->CerrarConexion();
			}
		return "SE $varMsj LA ASIGNACION Nro. << ".$varIde." >> .... CORRECTAMENTE";
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Asignacion_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();	
		$Fila = $this->FetchaArray($rs);
		return "OK";
		}
	}
	
?>