<?php
//include "clase.conexion.php";
class clsFacturarPedidos extends clsConexion{
	public $varTitulo = "FACTURACION DE PEDIDOS";
	public $varMyTabla  = "_sv_pedido";
	public $varMyID  	  = "id_pedido";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"formu"=>array("id"=>"form1", "name"=>"form1", "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"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$_POST["ccod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente('ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$_POST["cnom"], 
																					 "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"=>$_POST["vcod"],
																					 "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"=>$_POST["vnom"], 
																					 "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 Incial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "id"=>"fini", "name"=>"fini", "alinear"=>"center"))
														 	)
											 ),								  							  
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "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()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		
		
		$sqldoc = "select id_tipo_doc, nombre from _sv_tipo_doc_venta where _estado='A' and id_tipo_doc IN (1,2,3)";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>"DATOS DE FACTURACION",						
						"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"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "id"=>"femi", "name"=>"femi", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI"))
														 	)
											 )	
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"130",
											 "clase"=>"boton_guardar", "texto"=>"Facturar Pedidos", "click"=>"javascrip:xFacturarJS()"),
									 )
					);
		$varReturn= "<form id=\"form\" name=\"form\" method=\"POST\"  onSubmit=\"return false;\">";
		$varReturn.= $this->setTablaForm($varTabla);
		$varReturn.= "<a href=\"javascript:marcar_todo('form')\"><b>Todos</b></a> | <a href=\"javascript:marcar_ninguno('form')\"><b>Ninguno</b></a> ";
		$varReturn.= "<input type=\"checkbox\" name=\"ped[]\" id=\"ped\" style=\"visibility:hidden\" />";
		$varCli = (isset($varForm["ccod"]) && $varForm["ccod"]<>'')? $varForm["ccod"]:"NULL";
		$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>'')? $varForm["vcod"]:"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($varCli, $varVen, $varRut, $varIni, $varFin, 'IN', $varFie, $varOrd);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"NUM", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"FECHA", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TIPODOC", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCON", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"CONDICION", "fijo"=>"SI"),
									   array("tamano"=>90, "titulo"=>"ESTADO", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CCLI", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>250,"titulo"=>"DIRECCION", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CVEN", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CRUT", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"RUTA", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CLIS", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"LISTA", "fijo"=>"SI"),
									   array("tamano"=>60, "titulo"=>"PEDIDO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>60, "titulo"=>"TOTAL", "alinear"=>"right", "autosuma"=>"SI"),
									   array("tamano"=>120, "titulo"=>"FCREADO", "alinear"=>"center", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>100, "titulo"=>"FMODIFI", "alinear"=>"center", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>100, "titulo"=>"UCREADO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>100, "titulo"=>"UMODIFI", "alinear"=>"center", "oculto"=>"SI")
									   ),
						 "boton"=>array(array("tipo"=>"check", "id"=>"ped", "name"=>"ped[]", "checked"=>"NO", 
										 	  "valor"=>array(array("valor"=>0, "tipo"=>"INDEX"))
										 	 ),
						 				array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table.png", 
											 "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"=>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"),
															 array("valor"=>"<br><b>Ruta : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"FormuDetalleJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
															)
											 
											),
										array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>MODIFICAR</b> DEL PEDIDO<br><b>Nro. Pedido : </b>"),
															 array("valor"=>0, "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"),
															 array("valor"=>"<br><b>Ruta : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"FormuEditarJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
															)
											 
											),
										array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ANULAR</b> EL PEDIDO<br><b>Nro. Pedido : </b>"),
															 array("valor"=>0, "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"),
															 array("valor"=>"<br><b>Ruta : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"xEliminarJS",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>5, "tipo"=>"INDEX"),
																			   array("valor"=>6, "tipo"=>"INDEX"),
																			   array("valor"=>7, "tipo"=>"INDEX"),
																			   array("valor"=>8, "tipo"=>"INDEX"),
																			   array("valor"=>9, "tipo"=>"INDEX"),
																			   array("valor"=>10, "tipo"=>"INDEX"),
																			   array("valor"=>"this", "tipo"=>"NUM") 
																			  )
																)
											)
									)						
						);
		$varReturn.= $this->SetGridTabla2($varTabla);
		$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"=>"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 = "select D.id_producto AS CPRO, A.descripcion AS PRODUCTO, D.id_um as UM, D.PRECIO, 
				D.CANTIDAD_PED,
				D.TOTAL
				from _sv_pedido_detalle D
				inner join _sv_producto A ON D.id_producto = A.id_producto
				where D.id_pedido=$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"=>"UM", "alinear"=>"center"),
										array("tamano"=>60, "titulo"=>"PRECIO", "alinear"=>"right"),
										array("tamano"=>70, "titulo"=>"CANTIDAD", "alinear"=>"right"),
										array("tamano"=>70, "titulo"=>"IMPORTE", "alinear"=>"right")
									   )
						);
		$varReturn.= "<div id=\"divDatos\">";
		$varReturn.= $this->SetGridTabla($varTabla);
		$varReturn.= "</div>";
		
		return $varReturn;
		}
	
	function FormuEditar($varCod=NULL) {
		$sqldoc = "select id_tipo_doc, nombre from _sv_tipo_doc_venta where _estado='A' and id_tipo_doc IN (1,2,3)";
		$sqlcon = "call spQuery_Combo_Condicion_Venta($_SESSION[_CUSE]);";
		
		$sql = "CALL spQuery_Registro_Pedidos_Cabecera($varCod);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$varReturn= "<form id=\"form\" name=\"form\" method=\"POST\"  onSubmit=\"return validaRegistroPedido(this)\">";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo." - EDITAR PEDIDO REGISTRADO",						
						"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"=>"cond1", "name"=>"cond1", "valor"=>$fila["CCON"]),
									   array("tipo"=>"oculto", "id"=>"vcod1", "name"=>"vcod1", "valor"=>$fila["CVEN"]),
									   array("tipo"=>"oculto", "id"=>"ccod1", "name"=>"ccod1", "valor"=>$fila["CCLI"])
									  ),
						"conte"=>array(array("titulo"=>"IDE Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"ide", "name"=>"ide", "valor"=>$fila["IDE"], "ancho"=>"100", 
											 				"alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI")),
									   array("titulo"=>"Doc. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"tdcod", "name"=>"tdcod", 
																					 "valor"=>$fila["CTIP"], "ancho"=>"100",
																					 "combo"=>array("sql"=>$sqldoc, "ancho"=>"200", "sincod"=>"SI"))
																			   )
														 	)
											 ),
									   array("titulo"=>"Condici&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"cond", "name"=>"cond", 
																					 "valor"=>$fila["CCON"], 
																					 "combo"=>array("sql"=>$sqlcon, "ancho"=>"200", "sincod"=>"SI"))
																			   )
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>$fila["CVEN"],
																					 "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"=>$fila["VENDEDOR"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Nota Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"nped", "name"=>"nped", "valor"=>$fila["PEDIDO"], "ancho"=>"135", 
											 				"alinear"=>"center" )),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "ancho"=>"309",  "valor"=>$fila["GLOSA"], "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"=>"100",
											 "campo"=>array("tipo"=>"varios", 
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", 
																					 "valor"=>$fila["CCLI"], "ancho"=>"55", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente('ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", 
																			   		 "valor"=>$fila["CLIENTE"], 
																					 "ancho"=>"258", "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"=>$fila["DNI"], "ancho"=>"157", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"ruc", "name"=>"ruc", 
																			   		 "valor"=>$fila["RUC"], "ancho"=>"157", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Direcci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"txtdir", "name"=>"txtdir", "valor"=>$fila["DIRE_CLI"], 
											 				"ancho"=>"320", "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"=>$fila["CRUT"], "ancho"=>"55", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", 
																			   		 "valor"=>$fila["RUTA"], "ancho"=>"258", 
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"lcod", "name"=>"lcod", "valor"=>$fila["CLIS"], 
																					 "ancho"=>"55", "alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lnom", "name"=>"lnom", "valor"=>$fila["LISTA"], 
																			   		 "ancho"=>"200", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lmin", "name"=>"lmin", "valor"=>$fila["MMINIMO"], 
																					 "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:addProductoPedido()"),
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()")
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);

		$sqldet = "call spQuery_Registro_Pedidos_Contenido($varCod);";
		$this->AbrirConexion();
		$rsdet = $this->Query($sqldet);
		$this->CerrarConexion();
		$numfilas = $this->NumFilas($rsdet);
		$varReturn.= "<br>";
		$varReturn.= "<table id=\"tblSample\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$varReturn.= "width=680 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=\"".$numfilas."\"/>";
		$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\">Precio</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Cantidad</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Total</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"10\"></td>";
		$varReturn.= "</tr>";
		$varReturn.= "<tbody id=cuerpoTabla>";
		
		$varPos = 0;
		while($filadet = $this->FetchArray($rsdet)) {
			if($filadet["TIPO"]=="V") {
				$varPos = $varPos + 1;
				$varReturn.= "<tr>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"icod[$varPos]\" id=\"icod[$varPos]\" tabindex=\"$varPos\" onkeypress=\"return SoloNumeros(event)\"  ";
				$varReturn.= "onblur=\"select_producto('$varPos', '1')\" ondblclick=\"fn_cargar_listado_producto_venta('$varPos', '1')\" ";
				$varReturn.= "style=\"text-align:center; width:60px;\" autocomplete=\"off\" value=\"".$filadet["CPRO"]."\" >";
				$varReturn.= "</td>";
				$varReturn.= "<td class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"inom[$varPos]\" id=\"inom[$varPos]\" style=\"width:300px\" ";
				$varReturn.= "value=\"".$filadet["PRODUCTO"]."\" class=\"inputDisable\" readonly>";
				$varReturn.= "</td>";
				$varReturn.= "<td class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"iuni[$varPos]\" id=\"iuni[$varPos]\" style=\"text-align:center;width:50px\" ";
				$varReturn.= "value=\"".$filadet["UM"]."\" class=\"inputDisable\" readonly>";
				$varReturn.= "</td>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"istk[$varPos]\" id=\"istk[$varPos]\" style=\"text-align:right;width:50px\" ";
				$varReturn.= "value=\"".$filadet["STOCK"]."\" class=\"inputDisable\" readonly>";
				$varReturn.= "</td>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"ipre[$varPos]\" id=\"ipre[$varPos]\" style=\"text-align:right;width:50px\" ";
				$varReturn.= "value=\"".$filadet["PRECIO"]."\" class=\"inputDisable\" readonly> ";
				$varReturn.= "</td>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"ican[$varPos]\" id=\"ican[$varPos]\" tabindex=\"$varPos\" ";
				$varReturn.= "style=\"text-align:right;width:50px\" onkeyup=\"CalcularItem('$varPos')\" onkeypress=\"return SoloNumeros(event)\" ";
				$varReturn.= "value=\"".$filadet["CANTIDAD"]."\" autocomplete=\"off\" >";
				$varReturn.= "</td>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<input type=\"text\" name=\"itot[$varPos]\" id=\"itot[$varPos]\" style=\"text-align:right;width:50px\" ";
				$varReturn.= "value=\"".$filadet["TOTAL"]."\"class=\"inputDisable\" readonly>";
				$varReturn.= "</td>";
				$varReturn.= "<td align=\"center\" class=\"interior\">";
				$varReturn.= "<a onclick=\"DeleteRow(this)\" hre=\"#\"><img border=\"0\" src=\"images/b_drop.png\"></a>";
				$varReturn.= "</td>";
				$varReturn.= "</tr>";
				}
			}
		$varReturn.= "</tbody>";
		$varReturn.= "<tr>";
		$varReturn.= "<td height=19 class=\"interior\" colspan=6 align=\"right\"><b>Total :</b></td>";	
		$varReturn.= "<td align=\"left\" class=\"interior\">";
		$varReturn.= "<input name='tot' id='tot' type='text' class='inputDisable' readonly style='text-align:right;width:50px' value=\"".$fila["TOTAL"]."\" />";
		$varReturn.= "</td>";
		$varReturn.= "<td class=\"interior\"></td>";
		$varReturn.= "</tr>";
		$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:xActualizarJS()\" value=\"Actualizar Pedido\" name=\"bsav\">";
		$varReturn.= "</td>";
		$varReturn.= "</tr>";
		$varReturn.= "</table>";	
		$varReturn.= "</form>";
		return $varReturn;
		}
			
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$varEmi = "'".FechaMySql($varForm["femi"])."'";
		//$varTip = $varForm["tip"];
		foreach ($varForm["ped"] as $Codigo) {
			$sql = "call spMante_Pedido($Codigo, $varEmi, $varUsr);";
			$this->AbrirConexion();
			$this->Query($sql);
			$this->CerrarConexion();
			}
		return "OK";
		}
	
	function ProcesoActualizar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$vnum = $varForm["num"];
		$varIde = $varForm["ide"];
		
		$varRut = (isset($varForm["rcod"]) && $varForm["rcod"]<>"")?"'".$varForm["rcod"]."'":"'0'";
		$varLis = (isset($varForm["lcod"]) && $varForm["lcod"]<>"")?$varForm["lcod"]:"0";
		
		//Cliente
		if(isset($varForm["ccod"]))
			$varCli = (isset($varForm["ccod"]) && $varForm["ccod"]<>"")?$varForm["ccod"]:"NULL";
		else
			$varCli = (isset($varForm["ccod1"]) && $varForm["ccod1"]<>"")?$varForm["ccod1"]:"NULL";
		//Condicion de Venta
		if(isset($varForm["cond"]))
			$varCon = (isset($varForm["cond"]) && $varForm["cond"]<>"")?$varForm[cond]:"NULL";
		else
			$varCon = (isset($varForm["cond1"]) && $varForm["cond1"]<>"")?$varForm[cond1]:"NULL";		
		//Vendedor
		if(isset($varForm["vcod"]))
			$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>"")?$varForm[vcod]:0;
		else
			$varVen = (isset($varForm["vcod1"]) && $varForm["vcod1"]<>"")?$varForm[vcod1]: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"];
		$varLoc = 1;		
		$sql = "call spMante_Pedido_Cab('EDIT', $varIde, $varLoc, $varTip, $varCon, $varCli, $varRut, $varLis, $varVen, $varPed, $varGlo, $varTot, $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);
			$varPre = (isset($varForm["ipre"][$i]) && $varForm["ipre"][$i]<>"")?$varForm["ipre"][$i]:0;			
			$varCan = (isset($varForm["ican"][$i]) && $varForm["ican"][$i]<>"")?$varForm["ican"][$i]:0;
			$varUni = (isset($varForm["iuni"][$i]) && $varForm["iuni"][$i]<>"")?"'".$varForm["iuni"][$i]."'":"NULL";
			
			$sql = "call spMante_Pedido_Det($NumVenta, '$varCod', $varLoc, $varCan, $varPre, $varUni, $varUsr);";
			$varError.=$sql;	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			}				
		$sql = "call spMante_Bonificacion_Aplicar($NumVenta, $varUsr);";	
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		return "OK";
		}
			
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Pedido_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();	
		$Fila = $this->FetchaArray($rs);
		return $Fila[0];
		}
	}
	
?>