<?php
//include "clase.conexion.php";
class clsRegistroCambios extends clsConexion{
	public $varTitulo = "REGISTRO DE CAMBIOS";
	public $varMyTabla  = "_sv_pedido";
	public $varMyID  	  = "id_pedido";
	function FormuBusqueda() {
		$varEst = array("IN" => "INGRESADO", "AN" => "ANULADO", "FA" => "FACTURADO");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "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",
											 "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")
																			   )
															)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente_simple(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente_simple('ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_ruta(this.value)", 
																					 "dclick"=>"fn_cargar_listado_ruta('rcod', 'rnom')"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Inicio :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "valor"=>date("01/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Fin :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "ancho"=>"130", "valor"=>date("d/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select_simple", "id"=>"est", "name"=>"est",
																					 "combo"=>array("sql"=>$varEst, "sincod"=>"SI", "ancho"=>"130")))
														 	)
											 )
									   ),
					  "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"=>"120", "texto"=>"Nuevo Cambio", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('NEW','')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = (isset($varForm["ecod"]) && $varForm["ecod"]<>'')? $varForm["ecod"]:"NULL";
		$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>'')? $varForm["vcod"]:"NULL";
		$varCli = (isset($varForm["ccod"]) && $varForm["ccod"]<>'')? $varForm["ccod"]:"NULL";
		$varRut = (isset($varForm["rcod"]) && $varForm["rcod"]<>'')? $varForm["rcod"]:"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')? "'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')? "'".FechaMySql($varForm["ffin"])."'":"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";		
		$sql = "call spQuery_Registro_Pedidos_Cambios($varEmp, NULL, $varVen, $varCli, $varRut, $varIni, $varFin, '$varForm[est]', $varFie, $varOrd);";
		
		$varTabla=array("id"=>"example", "name"=>"example", "sql_cab"=>$sql, "tamano"=>"900",
						"conte"=>array(array("titulo"=>"NUM", "alinear"=>"center"),
									   array("titulo"=>"CEMP", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"EMPRESA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("titulo"=>"CAGE", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"AGENCIA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("titulo"=>"CALM", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"ALMACEN", "fijo"=>"SI", "oculto"=>"SI"),
									   array("titulo"=>"FECHA", "alinear"=>"center"),
									   array("titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"TIPO", "fijo"=>"SI"),
									   array("titulo"=>"CCON", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"CONDICION", "fijo"=>"SI"),
									   array("titulo"=>"EST", "alinear"=>"center"),
									   array("titulo"=>"CCLI", "alinear"=>"center"),
									   array("titulo"=>"CLIENTE", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CVEN", "alinear"=>"center"),
									   array("titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("titulo"=>"CRUT", "alinear"=>"center"),
									   array("titulo"=>"RUTA", "fijo"=>"SI"),
									   array("titulo"=>"CLIS", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"LISTA", "fijo"=>"SI"),
									   array("titulo"=>"PEDIDO", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"TOTAL", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("titulo"=>"FCREADO", "oculto"=>"SI"),
									   array("titulo"=>"FMODIFI", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO", "oculto"=>"SI"),
									   array("titulo"=>"UMODIFI", "oculto"=>"SI")
									   ),
						 "boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table.png",  "tamano"=>"100%",
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER DETALLE</b> DEL PEDIDO<br><b>Nro. Pedido : </b>"),
															 array("valor"=>0, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b>"),
															 array("valor"=>7, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>8, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Vendedor : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Ruta : </b>"),
															 array("valor"=>11, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>12, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"FormuDetalleJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
															)
											 
											),
									)						
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function FormuRegistro($varOpt=NULL, $varCod=NULL) {
		$sqldoc = "call spQuery_Lista_Tipo_Doc_Cambio(NULL,NULL);";
		$sqlcon = "call spQuery_Combo_Condicion_Venta($_SESSION[_CUSE]);";
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		
		$varReturn= "<form id=\"form\" name=\"form\" method=\"POST\"  onSubmit=\"return validaRegistroPedidoCambio(this)\">";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo." - NUEVO PEDIDO",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion),
									   array("tipo"=>"oculto", "id"=>"emp1", "name"=>"emp1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"age1", "name"=>"age1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"alm1", "name"=>"alm1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"vcod1", "name"=>"vcod1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"ccod1", "name"=>"ccod1", "valor"=>NULL)
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"emp", "name"=>"emp",
																					 "sql"=>$sqlemp, "ancho"=>"327",
																					 "titulo"=>"--[[SELECCIONAR]]--", 
																					 "reload"=>"xajax_ComboListaAgenciaPed(this.value,327,ccod.value)")
																			   )
														 	)
											 ),
									   array("titulo"=>"Agencia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"age", "name"=>"age", "sql"=>"", 
																					 "div"=>"divAge", "ancho"=>"327", "titulo"=>" --[[SELECCIONAR]]-- ")
																			   )
														 	)
											 ),
									   array("titulo"=>"Almacen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"alm", "name"=>"alm", "sql"=>"", 
																					 "div"=>"divAlm", "ancho"=>"327", "titulo"=>" --[[SELECCIONAR]]-- ")
																			   )
														 	)
											 ),
									   array("titulo"=>"Doc. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"tdcod", "name"=>"tdcod", "valor"=>3, 
																					 "sql"=>$sqldoc, "ancho"=>"120", "sincod"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"Condici&oacute;n : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"70"),
																			   array("tipo"=>"select", "id"=>"cond", "name"=>"cond",  
																					 "sql"=>$sqlcon, "ancho"=>"120", "sincod"=>"SI"),
																			   )
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod",
																					 "ancho"=>"55", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", 
																					 "ancho"=>"267", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"N&deg; Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"nped", "name"=>"nped", "valor"=>$_POST["nped"], "ancho"=>"120", 
											 				"alinear"=>"center" )),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "ancho"=>"328", "alto"=>"50"))
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		
		$varTabla=array("id"=>"tabla_cli", "name"=>"table_cli", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>"DATOS DEL CLIENTE",						
						"conte"=>array(array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"70",
											 "campo"=>array("tipo"=>"varios", 
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", 
																					 "valor"=>$_POST["ccod"], "ancho"=>"55", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(emp.value, this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente_lp(emp.value, 'ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", 
																			   		 "valor"=>$_POST["cnom"], 
																					 "ancho"=>"267", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"DNI / RUC :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"dni", "name"=>"dni", 
																					 "valor"=>$_POST["dni"], "ancho"=>"161", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"ruc", "name"=>"ruc", 
																			   		 "valor"=>$_POST["ruc"], "ancho"=>"161", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Direcci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"txtdir", "name"=>"txtdir", "valor"=>$_POST["txtdir"], 
											 				"ancho"=>"328", "clase"=>"inputDisable", "locked"=>"SI")),
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", 
																					 "valor"=>$_POST["rcod"], "ancho"=>"55", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", 
																			   		 "valor"=>$_POST["rnom"], "ancho"=>"267", 
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Lista P. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"lcod", "name"=>"lcod", 
																					 "valor"=>$_POST["lcod"], "ancho"=>"55", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lnom", "name"=>"lnom", 
																			   		 "valor"=>$_POST["lnom"], "ancho"=>"208", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lmin", "name"=>"lmin", 
																			   		 "valor"=>$_POST["lmin"], "ancho"=>"55", "alinear"=>"right", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_agregar", "texto"=>"Agregar", "click"=>"javascrip:addProductoCambio()"),
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()")
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		$varReturn.= "<br>";
		$varReturn.= "<table id=\"tblSample\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$varReturn.= "width=750 align=center cellpadding=0 cellspacing=0>";
		$varReturn.= "<tr>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"90\">Codigo";
		$varReturn.= "<input name=\"num\" type=\"hidden\" class=\"input\" id=\"num\" value=\"0\"/>";
		$varReturn.= "</td>";	
		$varReturn.= "<td class=\"FormCampo2\" width=\"300\">Descripcion</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">UM Venta</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Stock</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Lote</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Fecha Venc.</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Cant.</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"10\"></td>";
		$varReturn.= "</tr>";
		$varReturn.= "<tbody id=cuerpoTabla>";
		$varReturn.= "</tbody>";
		$varReturn.= "<tr>";
		$varReturn.= "<tr>";
		$varReturn.= "<td height=25 colspan=10 valign=top aling=\"center\" class=\"FormTitulo\">";	
		$varReturn.= "<input id=\"bsav\" class=\"boton_guardar\" type=\"button\" style=\"cursor:pointer; width:160px;\" ";
		$varReturn.= "onclick=\"javascrip:xGrabarJS()\" value=\"Registrar Pedido\" name=\"bsav\">";
		$varReturn.= "</td>";
		$varReturn.= "</tr>";
		$varReturn.= "</table>";	
		$varReturn.= "</form>";
		return $varReturn;
		}
		
	function FormuDetalle($varCod=NULL) {
		$sql = "CALL spQuery_Registro_Pedidos_Cabecera($varCod)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);

		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DETALLE",					
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo." - ".$Fila["LISTA"]),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt",   "valor"=>"DET")
									  ),
						"conte"=>array(array("titulo"=>"Nro. Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["IDE"], "tamano"=>"100"),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CEMP"].' - '.$Fila["EMPRESA"]),
									   array("titulo"=>"Almacen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CALM"].' - '.$Fila["ALMACEN"]),
									   array("titulo"=>"Fecha Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
									   		 "texto"=>$Fila["FECHA"]),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CCLI"].' - '.$Fila["CLIENTE"]),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CVEN"].' - '.$Fila["VENDEDOR"]),
									   array("titulo"=>"Condici&oacute;n Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CCON"].' - '.$Fila["CONDICION"]),
									   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CLIS"].' - '.$Fila["LISTA"]),
									   array("titulo"=>"Sub Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["SUBTOTAL"], 2,'.',',')),
									   array("titulo"=>"IGV :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["IGV"], 2,'.',',')),
									   array("titulo"=>"Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["TOTAL"], 2,'.',',')),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["ESTADO"]),
									   array("titulo"=>"U/F Creado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_CREATE"]." / ".$Fila["DATE_CREATE"]),
									   array("titulo"=>"U/F Modificado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_UPDATE"]." / ".$Fila["DATE_UPDATE"]),
									   array("titulo"=>"Nota Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["PEDIDO"]),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["GLOSA"])
									   ),
						  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cerrar", "click"=>"window.close()")
										)
						);		
		$varReturn = $this->setTablaForm($varTabla);
		
		$sql = "call spQuery_Registro_Pedidos_Contenido($varCod);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"700", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>50, "titulo"=>"CITEM", "n	egrita"=>"SI", "alinear"=>"center"),
									   array("tamano"=>350, "titulo"=>"NOMBRE DE ARTICULO", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TIPO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"UM", "alinear"=>"center"),
									   array("tamano"=>60, "titulo"=>"PRECIO", "alinear"=>"right", "oculto"=>"SI"),
									   array("tamano"=>70, "titulo"=>"CANTIDAD", "alinear"=>"right"),
									   array("tamano"=>70, "titulo"=>"IMPORTE", "alinear"=>"right", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"LOTE", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"FVENC.", "alinear"=>"center"),
									   array("tamano"=>70, "titulo"=>"STOCK", "alinear"=>"right")
									   )
						);
		$varReturn.= "<div id=\"divDatos\">";
		$varReturn.= $this->SetGridTabla($varTabla);
		$varReturn.= "</div>";
		
		return $varReturn;
		}
		
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$vnum = $varForm["num"];
		$varCli = (isset($varForm["ccod1"]) && $varForm["ccod1"]<>"")?$varForm["ccod1"]:"NULL";
		
		$varRut = (isset($varForm["rcod"]) && $varForm["rcod"]<>"")?"'".$varForm["rcod"]."'":"'0'";
		$varLis = (isset($varForm["lcod"]) && $varForm["lcod"]<>"")?$varForm["lcod"]:"0";
		
		$varCon = (isset($varForm["cond"]) && $varForm["cond"]<>"")?$varForm["cond"]:"NULL";
		$varVen = (isset($varForm["vcod1"])&& $varForm["vcod1"]<>"")?$varForm["vcod1"]:0;
		$varEmp = (isset($varForm["emp1"]) && $varForm["emp1"]<>"")?$varForm["emp1"]:0;
		$varAge = (isset($varForm["age1"])  && $varForm["age1"]<>"") ?$varForm["age1"]:"NULL";
		$varAlm = (isset($varForm["alm1"]) && $varForm["alm1"]<>"")?$varForm["alm1"]:0;
		$varPed = (isset($varForm["nped"]) && $varForm["nped"]<>"")?"'".$varForm["nped"]."'":"NULL";
		$varGlo = (isset($varForm["glos"]) && $varForm["glos"]<>"")?"'".$varForm["glos"]."'":"NULL";
		
		$varTip = $varForm["tdcod"];
		$varTot = $varForm["tot"];
		$sql = "call spMante_Pedido_Cambio_Cab('NEW', NULL, $varEmp, $varAge, $varAlm, $varTip, $varCon, $varCli, $varRut, $varLis, 
												$varVen, $varPed, $varGlo,0, $varUsr);";	
		$varError = $sql;
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		$NumVenta = $Fila[0];
		for($i=1; $i<=$vnum; $i++) {	
			$varCod = str_pad($varForm["icod"][$i],6,"0",STR_PAD_LEFT);
			$varCan = (isset($varForm["ican"][$i]) && $varForm["ican"][$i]<>"")?$varForm["ican"][$i]:0;
			$varUni = (isset($varForm["iuni"][$i]) && $varForm["iuni"][$i]<>"")?"'".$varForm["iuni"][$i]."'":"NULL";
			$varLot = (isset($varForm["ilot"][$i]) && $varForm["ilot"][$i]<>"")?"'".$varForm["ilot"][$i]."'":"NULL";
			$varFec = (isset($varForm["ifec"][$i]) && $varForm["ifec"][$i]<>"")?"'".FechaMySql($varForm["ifec"][$i])."'":"NULL";
			
			$sql = "call spMante_Pedido_Cambio_Det($NumVenta, '$varCod', $varCan, $varUni, $varLot, $varFec, $varUsr);";
			$varError.=$sql;	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			}
		$varReturn[0] = "OK";
		$varReturn[1] = $NumVenta;
		return $varReturn;
		}
	}
	
?>