<?php
//include "clase.conexion.php";
class clsVehiculo extends clsConexion{
	public $varTitulo 	= "MAESTRO DE VEHICULOS";
	public $varMyTabla  = "_sv_vehiculo";
	public $varMyID  	= "id_vehiculo";
	function FormuBusqueda() {
		$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"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "valor"=>$_POST["cod"], 
										 "alinear"=>"center", "ancho"=>"70")),								   
								   array("titulo"=>"Descripcion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$_POST["nam"], "ancho"=>"306")),
								   array("titulo"=>"Placa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"pla", "name"=>"pla", "valor"=>$_POST["pla"], "ancho"=>"100")),
								   ),
					  "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_Vehiculo('$varForm[cod]', '$varForm[nam]', '$varForm[pla]', $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"900", "sql_cab"=>utf8_decode($sql),	"pages"=>50,
						"conte"=>array(array("titulo"=>"CVEH",   	"ancho"=>"20" , "alinear"=>"center", "clase"=>"sortable-numeric", "tipo"=>"texto"),
									   array("titulo"=>"VEHICULO",	"ancho"=>"300", "clase"  =>"sortable", "fijo"=>"SI", "funcion"=>array("contar")),			   
									   array("titulo"=>"CMAR",     	"ancho"=>"20", "alinear"=>"center"), 									   
									   array("titulo"=>"MARCA",		"ancho"=>"100", "clase"  =>"sortable", "fijo"=>"SI"),
									   array("titulo"=>"PLACA", 	"ancho"=>"60" , "alinear"=>"center"),
									   array("titulo"=>"ANIO", 		"ancho"=>"60" , "alinear"=>"center"),
									   array("titulo"=>"TAR.PROP.", "ancho"=>"60"),
									   array("titulo"=>"COSTO", 	"ancho"=>"60" , "alinear"=>"right"),
									   array("titulo"=>"PESO.MAX.", "ancho"=>"60" , "alinear"=>"right", "OC"),
									   array("titulo"=>"LARGO", 	"ancho"=>"60" , "alinear"=>"right"),
									   array("titulo"=>"ANCHO", 	"ancho"=>"60" , "alinear"=>"right"),
									   array("titulo"=>"ALTO", 		"ancho"=>"60" , "alinear"=>"right"),
									   array("titulo"=>"ESTADO",   	"ancho"=>"20", "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;
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = $varCod";	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqlmar = "call spQuery_Combo_Marca_Vehiculo();";
		$sqlest	= array("A"=>"ACTIVO", "I"=>"INACTIVO");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "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"=>"90",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),								   
									   array("titulo"=>"Descripcion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["descripcion"], "ancho"=>"280")),
									   array("titulo"=>"Marca :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"mar", "name"=>"mar", "valor"=>$Fila["id_marca"],
															"combo"=>array("sql"=>$sqlmar, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"280"))),
									   array("titulo"=>"Tarjeta Prop. :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"tar", "name"=>"tar", "valor"=>$Fila["tarjeta_propiedad"], "ancho"=>"150")),
									   array("titulo"=>"Nro. Placa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pla", "name"=>"pla", "valor"=>$Fila["placa"],
																					 "ancho"=>"90",  "maxchar"=>15),
																			   array("tipo"=>"simple", "valor"=>"Anio Fab. : ", "clase_in"=>"FormCampo1", "ancho"=>"100"),
																			   array("tipo"=>"text", "id"=>"anio", "name"=>"anio", "valor"=>$Fila["anio"],
																					 "ancho"=>"90", "keypress"=>"return SoloEnteros(event)", "maxchar"=>4),
																			   )
														 	)
											 ),									   
									   array("titulo"=>"Largo (Mts) :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"lar", "name"=>"lar", "valor"=>$Fila["largo"],
																					 "ancho"=>"90", "keypress"=>"return SoloNumeros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Ancho (Mts) : ", "clase_in"=>"FormCampo1", "ancho"=>"150"),
																			   array("tipo"=>"text", "id"=>"anc", "name"=>"anc", "valor"=>$Fila["ancho"],
																					 "ancho"=>"90", "keypress"=>"return SoloNumeros(event)"),
																			   )
														 	)
											 ),
									   array("titulo"=>"Alto (Mts) :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"alt", "name"=>"alt", "valor"=>$Fila["alto"],
																					 "ancho"=>"90", "keypress"=>"return SoloNumeros(event)"),
																			   array("tipo"=>"simple", "valor"=>"Peso Max (Kg) : ", "clase_in"=>"FormCampo1", "ancho"=>"150"),
																			   array("tipo"=>"text", "id"=>"pes", "name"=>"pes", "valor"=>$Fila["peso_max"],
																					 "ancho"=>"90", "keypress"=>"return SoloNumeros(event)"),
																			   )
														 	)
											 ),
									   array("titulo"=>"Costo S/. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"cos", "name"=>"cos", "valor"=>$Fila["monto"],
																					 "ancho"=>"90", "keypress"=>"return SoloNumeros(event)", "alinear"=>"right"),
																			   array("tipo"=>"simple", "valor"=>"Costo Diario del Vehiculo en el Reparto")
																			   )
														 	)
											 ),
									   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]";
		$varDes = ($varForm["nam"]=="")? "NULL" : "'$varForm[nam]'";
		$varMar = ($varForm["mar"]=="Ninguno")? "0" : "$varForm[mar]";
		$varTar = ($varForm["tar"]=="")? "NULL" : "'$varForm[tar]'";	
		$varPla = ($varForm["pla"]=="")? "NULL" : "'$varForm[pla]'";
		$varAni = ($varForm["anio"]=="")? "NULL" : "'$varForm[anio]'";
		$varLar = ($varForm["lar"]=="")? "NULL" : $varForm[lar];
		$varAnc = ($varForm["anc"]=="")? "NULL" : $varForm[anc];
		$varAlt = ($varForm["alt"]=="")? "NULL" : $varForm[alt];
		$varPes = ($varForm["pes"]=="")? "NULL" : $varForm[pes];
		$varCos = ($varForm["cos"]=="")? "NULL" : $varForm[cos];
		$sql = "call spMante_Vehiculo('$varForm[opt]', $varCod, $varDes, $varMar, $varTar, $varPla, $varAni, $varLar, $varAnc, $varAlt, $varPes, $varCos, '$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();
		}
	}
	
?>