<?php
//include "clase.conexion.php";
class clsRegistroVentas extends clsConexion{
	public $varTitulo = "ANULACI&Oacute;N DE VENTAS";
	public $varMyTabla  = "_sv_venta";
	public $varMyID  	  = "id_venta";
	function FormuBusqueda() {
		$varEst = array("AC"=>"ACTIVO", "PP"=>"PAGADO PARCIAL","CA"=>"CANCELADO","AN"=>"ANULADO");
		$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"=>"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"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_tipo_docventa(this.value)", 
																					 "dclick"=>"fn_cargar_listado_tipo_docventa('tcod', 'tnom')"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Incial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"fini", "name"=>"fini", "alinear"=>"center"))
														 	)
											 ),								  							  
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center"))
														 	)
											 ),
									   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"=>"140", "titulo"=>"--[[SELECCIONAR]]--"))
																			   )
														 	)
											 )
									   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"160", "texto"=>"Buscar Documentos",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$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";
		$varTip = (isset($varForm["tcod"]) && $varForm["tcod"]<>'')? $varForm["tcod"]:"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')? "'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')? "'".FechaMySql($varForm["ffin"])."'":"NULL";
		$varEst = (isset($varForm["est"]) && $varForm["est"]<>'Ninguno')?"'".$varForm["est"]."'":"NULL";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		
		$sql = "call spQuery_Registro_Ventas($varCli, $varVen, $varRut, $varTip, $varIni, $varFin, $varEst, $varFie, $varOrd);";
				
		$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"=>"FEMI", "alinear"=>"center"),
									   array("tamano"=>80, "titulo"=>"DOCUMENTO", "alinear"=>"center", "funcion"=>array("contar")),
									   array("tamano"=>10, "titulo"=>"CCON", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>150,"titulo"=>"CON.", "fijo"=>"SI"),
									   array("tamano"=>40, "titulo"=>"EST.", "fijo"=>"SI"),
									   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"=>10, "titulo"=>"CLIS", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"LISTA", "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("tamano"=>50, "titulo"=>"SALDO", "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")
									   ),
						 "boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER EL DETALLE DE</b> LA VENTA"),
															  array("valor"=>"<b>Fecha Emisi&oacute;n : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Cliente : </b>"),
															  array("valor"=>8, "tipo"=>"INDEX")
												   			  ),
											  "click"=>array("funcion"=>"FormuDetalleJS",
															 "param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
															)
											  ),	
						 				array("cond"=>array(array(5,"<>","AN - ANULADO")),
											  "tipo"=>"img", "id"=>"banu", "name"=>"banu", "img"=>"images/b_table_delete.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ANULAR</b> LA VENTA<br><b>Fecha Emisi&oacute;n : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Cliente : </b>"),
															  array("valor"=>8, "tipo"=>"INDEX")
															  ),
											   "click"=>array("funcion"=>"xEliminarJS",
															  "param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			 array("valor"=>1, "tipo"=>"INDEX"),
																			 array("valor"=>2, "tipo"=>"INDEX"),
																			 array("valor"=>8, "tipo"=>"INDEX"),
																			 array("valor"=>"this", "tipo"=>"NUM") 
																			 )
															  )
											 
											),
										array("tipo"=>"img", "id"=>"bimp", "name"=>"bimp", "img"=>"images/b_printer.png", 
										   		 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>IMPRIMIR</b> LA VENTA<br><b>Fecha Emisi&oacute;n : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Documento : </b>"),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Cliente : </b>"),
																 array("valor"=>8, "tipo"=>"INDEX")
												   				),
												 "click"=>array("funcion"=>"ImprimirDoc",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>6, "tipo"=>"INDEX") 
																			   )
																)
											 )
										)						
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Venta_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);	
		return $fila[0];
		}
	}
	
?>