<?php
//include "clase.conexion.php";
class clsVendedor extends clsConexion{
	public $varTitulo 	= "MAESTRO DE VENDEDORES";
	public $varMyTabla  = "_sv_vendedor";
	public $varMyID  	= "id_vendedor";
	function FormuBusqueda() {
		$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"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "valor"=>$_POST["cod"], 
										 "alinear"=>"center", "ancho"=>"70")),								   
								   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$_POST["nam"], "ancho"=>"306")),
								   array("titulo"=>"Direccion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"dire", "name"=>"dire", "valor"=>$_POST["dire"], "ancho"=>"306")),
								   array("titulo"=>"Tipo Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"varios",
														"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod", "valor"=>$_POST["tcod"], 
																				 "ancho"=>"50", "alinear"=>"center", 
																				 "blur"=>"xajax_seleccionar_tipo_vendedor(this.value)", 
																				 "dclick"=>"fn_cargar_listado_tipo_vendedor('tcod', 'tnom')"),
																		   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "valor"=>$_POST["tnom"], 
																			   	 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																		   )
														)
										 )
								   ),
					  "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
					   )  {
						  
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$sql = "call spQuery_Vendedor('$varForm[cod]', '$varForm[nam]', '$varForm[dir]', '$varForm[tcod]', $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"CVEN",      "ancho"=>"40" , "alinear"=>"center", "tipo"=>"texto"), 
									   array("titulo"=>"VENDEDOR",  "ancho"=>"300", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CTIP",      "ancho"=>"40" , "alinear"=>"center", "oculto"=>"SI"), 
									   array("titulo"=>"TIPO",  	"ancho"=>"100"),
									   array("titulo"=>"DNI",       "ancho"=>"60"),
									   array("titulo"=>"DIRECCION", "ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"SUELDO",    "ancho"=>"60",  "alinear"=>"right"),
									   array("titulo"=>"%_COM.","ancho"=>"60",  "alinear"=>"right", "tipodat"=>"PORC"),
									   array("titulo"=>"TELEFONO",  "ancho"=>"60", "alinear"=>"center"),
									   array("titulo"=>"CELULAR",   "ancho"=>"60", "alinear"=>"center"),
									   array("titulo"=>"RPM", 		"ancho"=>"60", "oculto"=>"SI"),
									   array("titulo"=>"RPC", 		"ancho"=>"60", "oculto"=>"SI"),
									   array("titulo"=>"NEXTEL", 	"ancho"=>"60", "oculto"=>"SI"),
									   array("titulo"=>"ESTADO", 	"ancho"=>"60", "alinear"=>"center"),
									   array("titulo"=>"FCREADO",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  	"ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  	"ancho"=>"100", "oculto"=>"SI")
									   ), 
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table_edit.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br><b>"),
																	 array("valor"=>0, "tipo"=>"INDEX"),
																	 array("valor"=>" - "),
																	 array("valor"=>1, "tipo"=>"INDEX"),
																	 array("valor"=>"</b>")
																	),
												 "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/b_table_delete.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br><b>"),
																	 array("valor"=>0, "tipo"=>"INDEX"),
																	 array("valor"=>" - "),
																	 array("valor"=>1, "tipo"=>"INDEX"),
																	 array("valor"=>"</b>")
																	),
												 "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";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;
			$Fila["CDEP"] = "14";
			$Fila["CPRO"] = "1401";
			$Fila["CDIS"] = "140101";
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			
			$sql = "select V.*, T.nombre as tipo from ".$this->varMyTabla." V 
					inner join _sv_tipo_vendedor T on V.id_tipo_vendedor = T.id_tipo_vendedor
					where V.".$this->varMyID." = $varCod";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqltipov = "select id_tipo_vendedor, nombre from _sv_tipo_vendedor where _estado='A' and id_tipo_vendedor <> 0;";
		$sqlest	= array("A"=>"ACTIVO", "I"=>"INACTIVO");
		$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"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], "ancho"=>"306")),
								   array("titulo"=>"Nro. DNI :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"dni", "name"=>"dni", "valor"=>$Fila["dni"], "ancho"=>"100",
										 				 "maxchar"=>8, "keypress"=>"return SoloEnteros(event)"
										 				)
										),								   
								   array("titulo"=>"Direccion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"dir", "name"=>"dir", "valor"=>$Fila["direccion"], "ancho"=>"306")),
								   array("titulo"=>"Tipo Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"select", "id"=>"tipo", "name"=>"tipo", "valor"=>$Fila["id_tipo_vendedor"],
														"combo"=>array("sql"=>$sqltipov, "ancho"=>"250", "sincod"=>"SI"))),
								   array("titulo"=>"Sueldo Base :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"base", "name"=>"base", "valor"=>$Fila["sueldo"], "ancho"=>"100",
										 				 "maxchar"=>11, "keypress"=>"return SoloNumeros(event)"
										 				)
										),
								   array("titulo"=>"% Comision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"comi", "name"=>"comi", "valor"=>$Fila["comision"], "ancho"=>"100",
										 				 "maxchar"=>11, "keypress"=>"return SoloNumeros(event)"
										 				)
										),
								   array("titulo"=>"# Telefono :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"tele", "name"=>"tele", "valor"=>$Fila["telefono"], "ancho"=>"100")),
								   array("titulo"=>"# Celular :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"celu", "name"=>"celu", "valor"=>$Fila["celular"], "ancho"=>"100")),
								   array("titulo"=>"# RPC :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"rpm", "name"=>"rpm", "valor"=>$Fila["rpm"], "ancho"=>"100")),
								   array("titulo"=>"# RPM :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"rpc", "name"=>"rpc", "valor"=>$Fila["rpc"], "ancho"=>"100")),
								   array("titulo"=>"# Nextel :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nextel", "name"=>"nextel", "valor"=>$Fila["nextel"], "ancho"=>"100")),
								   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										     "campo"=>array("tipo"=>"select_simple", "id"=>"est", "name"=>"est", "valor"=>$Fila["estado"],
														    "combo"=>array("sql"=>$sqlest, "ancho"=>"100"))),
								   ),
						"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"];
		$varBas = ($varForm["base"]=="")? "NULL" : $varForm["base"];
		$varCom = ($varForm["comi"]=="")? "NULL" : $varForm["comi"];
		$varTip = ($varForm["tipo"]=="")? "0"    : $varForm["tipo"];
		
		$sql = "call spMante_vendedor('$varForm[opt]', $varCod, $varTip, '$varForm[nam]', '$varForm[dni]', '$varForm[dir]', 
				$varBas, $varCom, '$varForm[tele]', '$varForm[celu]', '$varForm[rpm]', '$varForm[rpc]', '$varForm[nextel]', '$varForm[est]', $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($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();
		}
	}
	
?>