<?php
//include "clase.conexion.php";
class clsTipoDocVenta extends clsConexion{
	public $varTitulo 	= "SERIES X PUNTO DE VENTA";
	public $varMyTabla  = "_sv_serie_punto_venta";
	public $varMyID  	= "id_serie";
	function FormuBusqueda() {
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		$sqltip = "call spQuery_Lista_Tipo_Doc_Venta_Full(NULL,NULL);";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"430", "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"=>"select", "id"=>"emp", "name"=>"emp", 
															"sql"=>$sqlemp, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--")),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPun",
										     "campo"=>array("tipo"=>"select", "id"=>"tip", "name"=>"tip",
														    "sql"=>$sqltip, "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300"))				   
								   ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"100", "texto"=>"Nuevo", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('', 'NEW')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = (isset($varForm["emp"]) && $varForm["emp"]<>"Ninguno")?$varForm["emp"]:"NULL";
		$varTip = (isset($varForm["tip"]) && $varForm["tip"]<>"Ninguno")?$varForm["tip"]:"NULL";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$sql = "call spQuery_Serie_Punto_Venta($varEmp, $varTip, $_SESSION[_CUSE], $varFie, $varOrd);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"850", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"IDE",     	"ancho"=>"40" , "alinear"=>"center"),
									   array("titulo"=>"CEMP",     	"ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"EMPRESA", 	"ancho"=>"300", "fijo"=>"SI"),
									   array("titulo"=>"CPVT",     	"ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"PUNTO VENTA","ancho"=>"300", "fijo"=>"SI"),
									   array("titulo"=>"CTIP",     	"ancho"=>"40" , "alinear"=>"center"), 
									   array("titulo"=>"TIPO DOC.", "ancho"=>"300", "fijo"=>"SI"),
									   array("titulo"=>"SERIE",     "ancho"=>"60" , "alinear"=>"center"), 
									   array("titulo"=>"SECUENCIA", "ancho"=>"60", "alinear"=>"center"),
									   array("titulo"=>"FCREADO",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  	"ancho"=>"50", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  	"ancho"=>"50", "oculto"=>"SI"),
									   ), 
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO"),
																 array("valor"=>"<br><b>Empresa : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Punto Venta : </b>"),
																 array("valor"=>3, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>4, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Tipo Doc. : </b>"),
																 array("valor"=>5, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>6, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Serie : </b>"),
																 array("valor"=>7, "tipo"=>"INDEX"),
																),
												 "click"=>array("funcion"=>"FormuRegistroJS",
																"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																			   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																			  )
																)
												 
												),
										   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"../images/16x16/table_delete.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO"),
																 array("valor"=>"<br><b>Empresa : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Punto Venta : </b>"),
																 array("valor"=>3, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>4, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Tipo Doc. : </b>"),
																 array("valor"=>5, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>6, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Serie : </b>"),
																 array("valor"=>7, "tipo"=>"INDEX"),
																	),
												 "click"=>array("funcion"=>"xEliminarJS",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>1, "tipo"=>"INDEX"),
																			   array("valor"=>"this", "tipo"=>"NUM"),
																			   )
																)
												 )
										)
							);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit   = $this->varTitulo." - NUEVO";
			$varLock  = "NO";
			$varStyle = "inputNormal";
			$Fila[id_empresa] = 0;
			}
		else {
			$SubTit   =  $this->varTitulo." - EDITAR";
			$varLock  = "SI";
			$varStyle = "inputDisable";
			$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = $varCod";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		$sqlpun = "call spQuery_Lista_Punto_Venta($Fila[id_empresa], NULL, NULL, $_SESSION[_CUSE]);";	
		$sqltip = "call spQuery_Lista_Tipo_Doc_Venta_Full(NULL,NULL);";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$SubTit,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$varOpt)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 				 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "valor"=>$Fila["id_empresa"],
															"sql"=>$sqlemp, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--", "locked"=>$varLock,
															"reload"=>"xajax_ComboListaPuntoVenta(this.value, $_SESSION[_CUSE])")),
									   array("titulo"=>"Punto Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPun",
										     "campo"=>array("tipo"=>"select", "id"=>"pun", "name"=>"pun", "valor"=>$Fila["id_punto_venta"],
														    "sql"=>$sqlpun, "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock)),	
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"tip", "name"=>"tip", "valor"=>$Fila["id_tipo_doc"],
															"sql"=>$sqltip, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--", "locked"=>$varLock)),
									   array("titulo"=>"Serie :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"ser", "name"=>"ser", "valor"=>$Fila["nro_serie"], 
											 				 "ancho"=>"100", "maxchar"=>"3", "bloqueado"=>$varLock, "keypress"=>"return SoloEnteros(event)")),
									   array("titulo"=>"Secuencia :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"sec", "name"=>"sec", "valor"=>$Fila["nro_secuencia"], 
											 				 "ancho"=>"100","maxchar"=>"7", "keypress"=>"return SoloEnteros(event)")),
								   	  ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_guardar", "texto"=>"Grabar", "click"=>"javascrip:xGrabarJS()"),			  
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		return $this->setTablaForm($varTabla);	
		}
		
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="") ? "NULL" : $varForm["cod"];	
		$varEmp = ($varForm["emp"]=="" || $varForm["emp"]=="Ninguno") ? "NULL" : $varForm["emp"];
		$varPun = ($varForm["pun"]=="" || $varForm["pun"]=="Ninguno") ? "NULL" : $varForm["pun"];
		$varTip = ($varForm["tip"]=="" || $varForm["tip"]=="Ninguno") ? "NULL" : $varForm["tip"];
		$varSer = ($varForm["ser"]=="") ? "NULL" : $varForm["ser"];
		$varSec = ($varForm["sec"]=="") ? "NULL" : $varForm["sec"];
		$sql = "call spMante_Serie_Punto_Venta('$varForm[opt]', $varCod, $varEmp, $varPun, $varTip, $varSer, $varSec, $varUsr)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr where ".$this->varMyID."= '".$varCod."';";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>