<?php
//include "clase.conexion.php";
class clsAnulacionVentas extends clsConexion{
	public $varTitulo = "ANULACION 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"=>NULL, 
																					 "ancho"=>"70", "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"=>"70", "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"=>"70", "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"=>"70", "alinear"=>"center",
																					 "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"=>"70", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_tipo_doc_venta(this.value)", 
																					 "dclick"=>"fn_cargar_listado_tipo_doc_venta('tcod', 'tnom')"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   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"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = (isset($varForm["ecod"]) && $varForm["ecod"]<>'')? $varForm["ecod"]:"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";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$sql = "call spQuery_Registro_Ventas($varEmp, $varCli, $varVen, $varRut, $varTip, $varIni, $varFin, $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"=>10, "titulo"=>"CEMP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>150,"titulo"=>"EMPRESA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"EMISION", "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"=>"CONDICION", "alinear"=>"center"),
									   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", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CLIS", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"LISTA", "fijo"=>"SI"),
									   array("tamano"=>40, "titulo"=>"PEDIDO","alinear"=>"center", "oculto"=>"SI"),
									   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"=>"70",  "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"70",  "oculto"=>"SI")
									   ),
						 "boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER EL DETALLE DE</b> LA VENTA"),
											  				  array("valor"=>"<br><b>Empresa : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>" - "),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>F. Emision : </b>"),
															  array("valor"=>3, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>4, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Cliente : </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("cond"=>array(array(7,"<>","AN")),
											  "tipo"=>"img", "id"=>"banu", "name"=>"banu", "img"=>"../images/16x16/table_delete.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ANULAR</b> LA VENTA"),
															  array("valor"=>"<br><b>Empresa : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>" - "),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>F. Emision : </b>"),
															  array("valor"=>3, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>4, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Cliente : </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"=>1, "tipo"=>"INDEX"),
																			 array("valor"=>2, "tipo"=>"INDEX"),
																			 array("valor"=>3, "tipo"=>"INDEX"),
																			 array("valor"=>4, "tipo"=>"INDEX"),
																			 array("valor"=>9, "tipo"=>"INDEX"),
																			 array("valor"=>10,"tipo"=>"INDEX"),
																			 array("valor"=>"this", "tipo"=>"NUM") 
																			 )
															  )
											 
											),
										array("tipo"=>"img", "id"=>"bimp", "name"=>"bimp", "img"=>"../images/16x16/printer.png", 
											  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>IMPRIMIR</b> LA VENTA"),
															  array("valor"=>"<br><b>Empresa : </b>"),
															  array("valor"=>1, "tipo"=>"INDEX"),
															  array("valor"=>" - "),
															  array("valor"=>2, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>F. Emision : </b>"),
															  array("valor"=>3, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Documento : </b>"),
															  array("valor"=>4, "tipo"=>"INDEX"),
															  array("valor"=>"<br><b>Cliente : </b>"),
															  array("valor"=>9, "tipo"=>"INDEX"),
															  array("valor"=>" - "),
															  array("valor"=>10, "tipo"=>"INDEX"),
												   			  ),
												 "click"=>array("funcion"=>"xajax_xImprimirDoc",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>1, "tipo"=>"INDEX"),
																			   array("valor"=>8, "tipo"=>"INDEX") 
																			   )
																)
											 )
										)						
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	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];
		}
	}
	
?>