<?php
//include "clase.conexion.php";
class clsImprimirVentas extends clsConexion{
	public $varTitulo = "IMPRESION DE DOCUMENTOS DE VENTAS";
	public $varMyTabla  = "_sv_venta";
	public $varMyID  	  = "id_venta";
	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"=>$_POST["ecod"], 
																					 "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"=>$_POST["enom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Serie :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ser", "name"=>"ser",
																					 "ancho"=>"50", "alinear"=>"center", "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Nro. de Serie")
																			   )
														 	)
											 ),
									   array("titulo"=>"Preimpreso :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"nini", "name"=>"nini",
																					 "ancho"=>"80", "alinear"=>"center", "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"text", "id"=>"nfin", "name"=>"nfin",
																					 "ancho"=>"80", "alinear"=>"center", "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Rango de Preimpreso")
																			   )
														 	)
											 ),									   
									   array("titulo"=>"Fecha Inicial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "valor"=>date("d/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Final :", "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()))
																			   )
														 	)
											 )
									   ),
					  "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"=>"Imprimir",
									 	   "clase"=>"boton_imprimir", "click"=>"javascript:xImprimirJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		
		
		$varEmp = (isset($varForm["ecod"]) && $varForm["ecod"]<>'')? $varForm["ecod"]:"NULL";
		$varSer = str_pad($varForm["ser"],3,"0",STR_PAD_LEFT);
		$varNin = str_pad($varForm["nini"],7,"0",STR_PAD_LEFT);
		$varNfi = str_pad($varForm["nfin"],7,"0",STR_PAD_LEFT);
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')? "'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')? "'".FechaMySql($varForm["ffin"])."'":"NULL";
		
		$varFEMI   = ($_POST["femi"]=="") ? "NULL" : "'".FechaMySql($_POST["femi"])."'";
		$varDocIni = str_pad($_POST["sini"],3,"0",STR_PAD_LEFT)."-".str_pad($_POST["nini"],7,"0",STR_PAD_LEFT);
		$varDocFin = str_pad($_POST["sfin"],3,"0",STR_PAD_LEFT)."-".str_pad($_POST["nfin"],7,"0",STR_PAD_LEFT);
		
		$sql = "call spQuery_Impresion_Boleta($varEmp, '$varSer', '$varNin', '$varNfi', $varIni, $varFin);";
				
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1100", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"IDE", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"EMISION", "alinear"=>"center"),
									   array("tamano"=>80, "titulo"=>"DOCUMENTO", "alinear"=>"center", "funcion"=>array("contar"), "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCON", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>150,"titulo"=>"CONDICION", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>40, "titulo"=>"EST.", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCLI", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CVEN", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CRUT", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"RUTA", "fijo"=>"SI"),
									   array("tamano"=>40, "titulo"=>"PEDIDO", "alinear"=>"center"),
									   array("tamano"=>40, "titulo"=>"GUIA", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TOTAL", "alinear"=>"right", "autosuma"=>"SI"),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"50",  "alinear"=>"center"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"50",  "oculto"=>"SI")
									   )					
						);
		return $this->SetGridTabla2($varTabla);
		}
	
	function FormuRegistro($varOpt=NULL, $varCod=NULL) {
		$sqldoc = "select id_tipo_doc, nombre from _sv_tipo_doc_venta where _estado='A'; ";
		$sqlcon = "call spQuery_Combo_Condicion_Venta($_SESSION[_CUSE]);";
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		
		$varReturn= "<form id=\"form\" name=\"form\" method=\"POST\" >";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo." - NUEVA VENTA",						
						"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"=>"alm1", "name"=>"alm1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"pun1", "name"=>"pun1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"tip1", "name"=>"tip1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"ser1", "name"=>"ser1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"con1", "name"=>"con1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"emi1", "name"=>"emi1", "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", "tamano"=>"80",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "sql"=>$sqlemp, "ancho"=>"397",
																					 "titulo"=>"--[[SELECCIONAR]]--", 
																					 "reload"=>"xajax_ComboListaVenta(this.value,$_SESSION[_CUSE])")
																			   )
														 	)
											 ),
									   array("titulo"=>"Almacen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"alm", "name"=>"alm", "sql"=>"", "div"=>"divAlm",
											 										 "ancho"=>"150", "titulo"=>" --[[SELECCIONAR]]-- "),
																			   array("tipo"=>"simple", "valor"=>"Pto.Venta : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"select", "id"=>"pun", "name"=>"pun", "sql"=>"", "div"=>"divPun",
																					 "ancho"=>"150", "titulo"=>"--[[SELECCIONAR]]--",
																					 "reload"=>"xajax_ComboNroSerie(document.getElementById('emp').value,
																					 								this.value,
																													document.getElementById('tip').value, 
																													$_SESSION[_CUSE])")
																			   )
														 	)
											 ),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"tip", "name"=>"tip",
																					 "sql"=>$sqldoc, "ancho"=>"150", "sincod"=>"SI",
																					 "titulo"=>"--[[SELECCIONAR]]--", 
																					 "reload"=>"xajax_ComboNroSerie(document.getElementById('emp').value,
																					 								document.getElementById('pun').value, 
																					 								this.value,
																													$_SESSION[_CUSE])"),
																			   array("tipo"=>"simple", "valor"=>"Serie : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"select", "id"=>"ser", "name"=>"ser", "sql"=>"", "div"=>"divSer",
																					 "ancho"=>"150", "titulo"=>"--[[SELECCIONAR]]--")
																			   )
														 	)
											 ),
									   array("titulo"=>"Condicion :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"con", "name"=>"con", 
																					 "sql"=>$sqlcon, "ancho"=>"150", "sincod"=>"SI", "valor"=>"2"),
																			   array("tipo"=>"simple", "valor"=>"F. Emision : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"texto", "id"=>"femi", "name"=>"femi", "alinear"=>"center",
																					 "ancho"=>"130", "locked"=>"SI", "valor"=>date("d/m/Y",time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>$_POST["vcod"],
																					 "ancho"=>"72", "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"=>"320", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ped", "name"=>"ped", 
																			   "ancho"=>"72", "alinear"=>"center"))
														 	)
											 ),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "ancho"=>"395", 
																					 "alto"=>"40")
																			   )
														 	)
											 ),
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		
		$varTabla=array("id"=>"tabla_cli", "name"=>"table_cli", "tamano"=>"500", "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"=>$_POST["ccod"], "ancho"=>"72", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(emp.value, this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente(emp.value, 'ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", 
																			   		 "valor"=>$_POST["cnom"], 
																					 "ancho"=>"320", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"DNI :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"dni", "name"=>"dni", 
																					 "ancho"=>"150", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"simple", "valor"=>"RUC : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"text", "id"=>"ruc", "name"=>"ruc", 
																			   		 "ancho"=>"150", "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Direccion :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"txtdir", "name"=>"txtdir", 
																					 "ancho"=>"395", "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"=>"72", "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", 
																			   		 "valor"=>$_POST["rnom"], "ancho"=>"320", 
																					 "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", "alinear"=>"center",  
																					 "ancho"=>"72", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lnom", "name"=>"lnom", 
																			   		 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"lmin", "name"=>"lmin", "alinear"=>"right", 
																					 "ancho"=>"65",  "clase"=>"inputDisable", "locked"=>"SI"),
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_agregar", "texto"=>"Agregar", "click"=>"javascrip:addProductoVenta()"),
									   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=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=\"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\">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>";
		$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=0 />";
		$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:xGrabarJS()\" value=\"Registrar Documento\" name=\"bsav\">";
		$varReturn.= "</td>";
		$varReturn.= "</tr>";
		$varReturn.= "</table>";	
		$varReturn.= "</form>";
		return $varReturn;
		}
	
	function FormuEditar($varCod=NULL) {
		$sql = "CALL spQuery_Registro_Ventas_Detalle($varCod);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		
		$sqldoc = "select id_tipo_doc, nombre from _sv_tipo_doc_venta where _estado='A' and id_tipo_doc IN (1,2,3,5)";
		$sqlcon = "call spQuery_Combo_Condicion_Venta($_SESSION[_CUSE]);";
		$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 VENTA",						
						"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"=>"tdcod1", "name"=>"tdcod1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"femi1", "name"=>"femi1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"con1", "name"=>"con1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"vcod1", "name"=>"vcod1", "valor"=>NULL),
									   array("tipo"=>"oculto", "id"=>"ccod1", "name"=>"ccod1", "valor"=>NULL)
									  ),
						"conte"=>array(array("titulo"=>"IDE Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"ide", "name"=>"ide", "valor"=>$Fila["IDE"], "ancho"=>"135", 
											 				"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", "ancho"=>"100",
																					 "valor"=>$Fila["CTIPD"],
																					 "combo"=>array("sql"=>$sqldoc, "ancho"=>"150", "sincod"=>"SI",
																					 				"locked"=>"SI"
																									)
																			   		),
																			   array("tipo"=>"text", "id"=>"tdnom", "name"=>"tdnom", 
																			   		 "valor"=>$Fila["NDOC"], "ancho"=>"150",  "alinear"=>"center",
																					 "clase"=>"inputDisable", "locked"=>"SI"
																					 )
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Emisi&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"texto", "id"=>"femi", "name"=>"femi",
															"clase"=>"inputDisable", "ancho"=>"100", "locked"=>"SI", "alinear"=>"center",
															"valor"=>$Fila["NDOC"])
															),
									   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", "locked"=>"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"=>"N&uacute;mero Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"text", "id"=>"nped", "name"=>"nped", "valor"=>$Fila["NPED"], "ancho"=>"135", 
											 				"alinear"=>"center", "clase"=>"inputDisable", "locked"=>"SI"
															)
											 ),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "valor"=>$Fila["GLOSA"], "ancho"=>"309", 
											 				"alto"=>"50", "clase"=>"inputDisable", "locked"=>"SI"
															)
											 )
									   )
						);
		$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",  "ancho"=>"55", 
																					 "valor"=>$Fila["CCLI"], "alinear"=>"center", 
																					 "clase"=>"inputDisable", "locked"=>"SI"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "ancho"=>"258", 
																			   		 "valor"=>$Fila["CLIENTE"],  "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["DIRECCION"], 
											 				"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["MINIMO"], 
																					 "ancho"=>"55", "alinear"=>"right", "clase"=>"inputDisable", "locked"=>"SI"),
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"170",
											 "clase"=>"boton_guardar", "texto"=>"Actualizar Documento", "click"=>"javascrip:xActualizarJS()"),
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()")
									   )
						);
		$varReturn.= $this->setTablaForm($varTabla);
		
		$sql = "call spQuery_Registro_Ventas_Contenido($varCod);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>50, "titulo"=>"CITEM", "negrita"=>"SI", "alinear"=>"center"),
									   array("tamano"=>350, "titulo"=>"NOMBRE DE ARTICULO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>50, "titulo"=>"TIPO", "alinear"=>"center", "oculto"=>"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", "autosuma"=>"SI"),
									   array("tamano"=>50, "titulo"=>"LOTE", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"FVENC.", "alinear"=>"center")
									   )
						);
		$varReturn.= $this->SetGridTabla($varTabla);
		return $varReturn;
		}
			
	function FormuDetalle($varCod=NULL, $varOpt=NULL) {
		$sql = "CALL spQuery_Registro_Ventas_Detalle($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"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["EMISION"], "tamano"=>"100"),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CTIPD"]." - ".$Fila["CTIP"]),
																			   array("tipo"=>"simple", "valor"=>"Nro. Doc. : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", "valor"=>$Fila["NDOC"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cond. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CCON"]." - ".$Fila["CONDICION"]),
																			   array("tipo"=>"simple", "valor"=>"Estado : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", 
																			   		 "valor"=>$Fila["CEST"]." - ".$Fila["ESTADO"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CCLI"]." - ".$Fila["CLIENTE"]))
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CVEN"]." - ".$Fila["VENDEDOR"]))
														 	)
											 ),
									    array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>number_format($Fila["TOTAL"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Pagos : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"60", 
																			   		 "valor"=>number_format($Fila["PAGOS"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Saldo : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", 
																			   		 "valor"=>number_format($Fila["SALDO"], 2,'.',','))
																			   )
														 	)
											 ),
									   array("titulo"=>"Pedido :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["PEDIDO"])))),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["GLOSA"])))),
									   array("titulo"=>"Creado Por :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>$Fila["USER_CREATE"]),
																			   array("tipo"=>"simple", "valor"=>"Fecha/Hora : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "valor"=>$Fila["DATE_CREATE"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Modific. Por :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>$Fila["USER_UPDATE"]),
																			   array("tipo"=>"simple", "valor"=>"Fecha/Hora : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "valor"=>$Fila["DATE_UPDATE"])
																			   )
														 	)
											 )
									   ),
						  "boton"=>array(array("tipo"=>"button", "id"=>"bimp", "name"=>"bimp", "ancho"=>"100",
									   		   "clase"=>"boton_imprimir", "texto"=>"Imprimir", 
											   "click"=>"javascript:ImprimirDoc($Fila[IDE],$Fila[CTIPD])"),
						  				 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cerrar", "click"=>"window.close()")
										)
						);
		if($varOpt=="NEW") {
			$varTabla["boton"][1] =	 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"120", "texto"=>"Nueva Venta", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('NEW','')");
			$varTabla["boton"][2] =	 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
										   "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()");
			}
		$varReturn = $this->setTablaForm($varTabla);
		
		$sql = "call spQuery_Registro_Ventas_Contenido($varCod);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"95%", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>50, "titulo"=>"CITEM", "negrita"=>"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"),
									   array("tamano"=>70, "titulo"=>"CANTIDAD", "alinear"=>"right"),									   
									   array("tamano"=>70, "titulo"=>"IMPORTE", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"LOTE", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"FVENC.", "alinear"=>"center")
									   )
						);
		$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"];
		
		$varEmp = (isset($varForm["emp1"]) && $varForm["emp1"]<>"")?$varForm["emp1"]:"NULL";
		$varAlm = (isset($varForm["alm1"]) && $varForm["alm1"]<>"")?$varForm["alm1"]:"NULL";
		$varPun = (isset($varForm["pun"]) && $varForm["pun"]<>"")?$varForm["pun"]:"NULL";
		$varTip = (isset($varForm["tip"]) && $varForm["tip"]<>"")?$varForm["tip"]:"NULL";
		$varSer = (isset($varForm["ser"]) && $varForm["ser"]<>"")?$varForm["ser"]:"NULL";
		$varCon = (isset($varForm["con"]) && $varForm["con"]<>"")?$varForm["con"]:"NULL";
		$varEmi = "'".FechaMySql($varForm["femi"])."'";
		$varVen = (isset($varForm["vcod1"]) && $varForm["vcod1"]<>"")?$varForm["vcod1"]:"NULL";
		$varPed = (isset($varForm["ped"]) && $varForm["ped"]<>"")?"'".$varForm["ped"]."'":"NULL";
		$varGlo = (isset($varForm["glo"]) && $varForm["glo"]<>"")?"'".$varForm["glo"]."'":"NULL";
		$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";
		$varTot = $varForm["tot"];
		
		$sql = "call spMante_Venta_Cab($varEmp, $varPun, $varTip, $varSer, $varCon, $varEmi, $varCli, $varRut, $varLis, 
									   $varVen, $varPed, $varGlo, $varTot, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		$NumVenta = $Fila[0];
		$NumDoc	  = $Fila[1];
		$sql_det="";
		if ($NumVenta<>"") {
			foreach ($varForm["icod"] as $varIde=>$varPro) {
				$varPro = str_pad($varForm["icod"][$varIde], 6, "0", STR_PAD_LEFT);
				$varPre = $varForm["ipre"][$varIde];
				$varCan = $varForm["ican"][$varIde];
				$varUme = "'".$varForm["iuni"][$varIde]."'";
				$sql_det.= "call spMante_Venta_Det($NumVenta, $varEmp, $varAlm, '$varPro',  $varCan, $varPre, $varUme, 'V', $varEmi, $varUsr);";		
				}			
			}
		$this->AbrirConexion();
		$rs = $this->Query($sql_det);
		$this->CerrarConexion();
		
		
		$sql = "call spMante_Venta_Update($NumVenta);
    			call spMante_Bonificacion_Facturar($NumVenta, $varEmp, $varAlm, $varCli,  $varRut, $varLis, $varEmi, $varUsr);";	
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		
		$varReturn[0] = $NumVenta;
		$varReturn[1] = $NumDoc;
		return $varReturn;
		}
	
	function ProcesoActualizar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$varIde = $varForm["ide"];
		$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>"")?$varForm["vcod"]:0;
		
		$sql = "call spMante_Venta_Actualizar($varIde, $varVen, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		return "OK";
		}
		
	function ProcesoGeneraDocumento($varCod=NULL, $varTipDoc=NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$sql = "CALL spProceso_Genera_Nueva_Venta($varCod, '$varTipDoc', $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		$varReturn[0] = $fila[0];
		$varReturn[1] = $fila[1];
		return $varReturn;
		
		}
	function ProcesoEliminar($varEmp, $varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Venta_Anular($varEmp, $varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);	
		return $fila[0];
		}
	}
	
?>