<%@page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,m05bBD.m05bGastosTarjeta,m05bClasses.*" %>
<%@include file="/mantenimientosJSP/includes/m05b.inc"%>
	
	
<%
	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if ((session.getAttribute("objetoSeguridad")) == null)  { 
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%> <%
	}
		String matricula=request.getParameter("Matricula");
		if (matricula==null || matricula.equals("NULL")){
		          matricula="";
		}
%>
<%@ include file="/m05bIdioma.inc"%>
	
<HTML>
	
<head>
		<title><%= resTit.getString("titVehGastos")%></title>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
		<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Funciones.js"></script>
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/formateador.js"></script>
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Horas.js"></script>
</head>
			
<BODY style="cursor: wait"  onkeydown="cancelaEnter();" onload="document.body.style.cursor='default'; InitMenu();" onunload="document.body.style.cursor='wait';">
	
	<%String codigo = request.getParameter("Codigo");%>

	 <SCRIPT language=JavaScript>
		var urlIdioma;		//URL recarga en funcion del idioma
        urlIdioma = "<%=m05bConstantesPaginas.VEH_DET_GESTION_TARJGASTOS%>?Matricula=<%=matricula%>&Codigo=<%=codigo%>";
        var urlCambioVentana;
	    urlCambioVentana = "<%=m05bConstantesPaginas.VEH_DET_GESTION_TARJGASTOS%>";		 
		//var rutaCabecera;	//Camino de migas
		//rutaCabecera = "<a style='text-decoration:none; font-size:8pt; color:yellow; font-family:verdana' href='/m05bParqueMovilWar/m05bGastosJsp.jsp'>\\Gastos</a>";
	 </SCRIPT>

		<%@include file="m05bVehiculosFijo.inc"%>
		<FORM NAME="formGastosTarjeta" METHOD="POST">
				<%
				String sql = "", accion;
				//m05bComun comun= new m05bComun();
				m05bCombo miCombo2= new m05bCombo();
				m05bGastosTarjeta gastostarjeta = null;
				
				String sHora="", sFecha="";
				if ( (codigo==null) || (codigo.equals("")) || (codigo.equals("NUEVO")) ) {
					codigo= "";
					accion=m05bConstantes.ACC_INSERTAR;
					session.removeAttribute("m05bGastosTarjeta");
				}
				else   {
					accion=m05bConstantes.ACC_ACTUALIZAR;
					gastostarjeta = (m05bGastosTarjeta)session.getAttribute("m05bGastosTarjeta");
				    sFecha=gastostarjeta.getGastar_fecha();
				    if (sFecha==null)
				        sFecha="";
				    else {  	
					    sFecha=sFecha.trim();
					    sHora=comun.Hora(sFecha);
				        sHora=comun.formatearHora(sHora);
				        sFecha=comun.Mes(sFecha,campoTexto3);
				    }
				}

				if (gastostarjeta == null){
					gastostarjeta = new m05bGastosTarjeta();
					session.setAttribute("m05bGastosTarjeta",gastostarjeta);
				}
				String cargabon = gastostarjeta.getGastar_cargo()==null?"":gastostarjeta.getGastar_cargo();
				String sCIF = gastostarjeta.getGastar_estcif()==null?"":gastostarjeta.getGastar_estcif();
				String sUEconomica = gastostarjeta.getGastar_ueconomic()==null?"":gastostarjeta.getGastar_ueconomic();
				String sKM = gastostarjeta.getGastar_km()==null?"":gastostarjeta.getGastar_km();
				String litrosgast=gastostarjeta.getGastar_litros()==null?"":gastostarjeta.getGastar_litros();
				if (accion.equals(m05bConstantes.ACC_INSERTAR)) {
					%>
						  <!--   	BOTONERA   -->
						  <TABLE class="buscar">
						    <tr>
							      <td align="right">
							      	<input type="button" class="boton" name="<%= res.getString("etBOT_GRABAR")%>" value="<%= res.getString("etBOT_GRABAR")%>" ONCLICK="JavaScript:fncGrabar(Codigo.value, '<%=accion%>');return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSGRABAR")%>'; return false" onMouseOut="top.status=''; return false" />
							      </td>
							</tr>
						  </TABLE>
				<% }  %>
				  <TABLE class="buscar">
						<tr>
							<td align="right">
			    				<input type="button" class="boton" name="<%= res.getString("etBOT_RETORNAR")%>" value="<%= res.getString("etBOT_RETORNAR")%>" ONCLICK="JavaScript:history.back();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSRETORNAR")%>'; return false" onMouseOut="top.status=''; return false" />
			    			</td>
						</tr>
				  </TABLE>
				  <TABLE class="buscar">
				    <tr>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etCodigo")%></td>
					      <td align="left" class="inputFieldTitle" colspan="2"><%= res.getString("etTarjeta")%></td>
					      <td align="left" class="inputFieldTitle" colspan="3"><%= res.getString("etFecha")%></td>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etVerificado")%></td>
				    </tr>
				    <tr>
				      <% if (accion.equals(m05bConstantes.ACC_INSERTAR)) {
					      	  m05bGenerarClave miCodigo = new m05bGenerarClave();
					      	  int cod = miCodigo.getNextId(m05bConstantes.TAB_OPEBANCOS ,m05bConstantes.COL_18_CONTROL);
					  %>
						      <td align="left" width="25%"><INPUT class="inputField" TYPE="TEXT" NAME="Codigo"  disabled VALUE="<%=cod%>" size="20" maxlength="15"/></td>
				      <% } else { %>
						      <td align="left" width="25%"><INPUT class="inputField" TYPE="TEXT" NAME="Codigo" disabled VALUE="<%=codigo%>" size="20" maxlength="15"/></td>
				      <% } %>
					      <td align="left" colspan="2" width="25%"><INPUT class="inputField" TYPE="TEXT" NAME="Tarjeta" readonly="readonly" VALUE="<%=gastostarjeta.getGastar_tarjeta()%>" size="30" maxlength="30"/></td>
					      <td align="left" width="10%"><INPUT class="inputField" TYPE="TEXT" NAME="Fecha" VALUE="<%=sFecha%>" size="10" maxlength="10" readonly="readonly" ></td>
					      <td align="left" width="5%"></td>
					      <td align="left" width="10%"><INPUT class="inputField" TYPE="TEXT" NAME="Hora" VALUE="<%=sHora%>" size="5" maxlength="5" readonly="readonly"/> </td>
					      <td align="left" width="25%"><INPUT class="inputField" TYPE="CHECKBOX" NAME="Verifica" VALUE="S" <%if (gastostarjeta.getGastar_verifi()!=null && gastostarjeta.getGastar_verifi().equals("S")){%> checked <%}%> size="20" maxlength="20" disabled="disabled"/></td>
				    </tr>
				    <tr>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etCentro")%></td>
					      <td align="left" class="inputFieldTitle" colspan="5"><%= res.getString("etDepartamento")%></td>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etServicio")%></td>
				    </tr>
				    <tr>
					      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Centro" VALUE="<%=gastostarjeta.getGastar_centro()%>" size="20" maxlength="20" readonly="readonly"/></td>
						  <td align="left" colspan="5">
								<select class=inputField disabled="disabled" NAME="Dpto" onchange="Javascript: fncCambiaDpto();fncModificarDatos(this.name,this.value);fncModificarDatos(DescDpto.name,DescDpto.value);return false;">
								     <option value=""> </option>
								     <%=miCombo2.popCombo(m05bConstantes.COL_06_CODDPTO,m05bConstantes.COL_06_DESCDPTO, m05bConstantes.TAB_DEPARTAMENTOS, "", "",gastostarjeta.getGastar_dpto())%>
								</select>
						  </td>
					      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Servicio" VALUE="<%=gastostarjeta.getGastar_servicio()%>" size="20" maxlength="20" readonly="readonly"/></td>
				    </tr>
				    <tr>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etTipo")%></td>
					      <td align="left" class="inputFieldTitle" colspan="5"><%= res.getString("etConcepto")%></td>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etCargoAbono")%></td>
				    </tr>
				    <tr>
					     <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Tipo" VALUE="<%=gastostarjeta.getGastar_tipo()%>" size="8" maxlength="10" readonly="readonly"/></td>
					     <td align="left" colspan="5"><INPUT class="inputField" TYPE="TEXT" NAME="Concepto" VALUE="<%=gastostarjeta.getGastar_concepto()%>" size="71" maxlength="10" readonly="readonly"/></td>
					     <td align="left">
					        	<select name="Cargo" disabled="disabled" class="inputField">
					                    <option value="" <% if (cargabon.equals("")) { %> selected <% } %>/> </option>
					                    <option value="C" <% if (cargabon.equals("C")) { %> selected <% } %>/><%= res.getString("etCargo")%></option>
					                    <option value="A" <% if (cargabon.equals("A")) { %> selected <% } %>/><%= res.getString("etAbono")%></option>
						        </select>
					      </td>

				    </tr>
				    <tr>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etCifEstablecimiento")%></td>
					      <td align="left" class="inputFieldTitle" colspan="6"><%= res.getString("etComercio")%></td>
				    </tr>
				    <tr>
			 		     <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="CIF" VALUE="<%=sCIF%>" size="20" maxlength="20" readonly="readonly"/></td>
					     <td align="left" colspan="6"><INPUT class="inputField" TYPE="TEXT" NAME="Nombre" VALUE="<%=gastostarjeta.getGastar_estdesc()%>" size="80" maxlength="20" readonly="readonly"/></td>
				    </tr>
				    <tr>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etUnidadEconomica")%></td>
					      <td align="left" class="inputFieldTitle" colspan="2"><%= res.getString("etLitros")%></td>
					      <td align="left" class="inputFieldTitle" colspan="3"><%= res.getString("etKm")%></td>
					      <td align="left" class="inputFieldTitle"><%= res.getString("etImporte")%></td>
				    </tr>
				    <tr>
					     <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Uecono" VALUE="<%=sUEconomica%>" size="8" maxlength="2" readonly="readonly"/></td>
					     <td align="left" colspan="2"><INPUT class="inputField" TYPE="TEXT" NAME="Litros" VALUE="<%=litrosgast%>" size="15" maxlength="20" readonly="readonly"/></td>
					     <td align="left" colspan="3"><INPUT class="inputField" TYPE="TEXT" NAME="Km" VALUE="<%=sKM%>" size="15" maxlength="6" readonly="readonly"/></td>
					     <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Importe" VALUE="<%=gastostarjeta.getGastar_importe()%>" size="20" maxlength="8" readonly="readonly"/></td>
					     <script>
                             formatNumeroDecimalConSigno(document.formGastosTarjeta.Importe,10,2);
                             formatNumeroDecimalConSigno(document.formGastosTarjeta.Litros,10,2);
                             formatNumero(document.formGastosTarjeta.Km);
                         </script>	
				    </tr>
				    </TABLE>
				<input type="hidden" name="Matricula" value="<%=matricula%>">
				<input type="hidden" name="KmAct">
				<input type="hidden" name="FKAct">
		</FORM>
		</td>
	</tr>
	<tr>
			<td colspan="3"><%@ include file="/mantenimientosJSP/includes/m05Pie_c.jsp"%></td>
	</tr>
</table>
<SCRIPT language='javascript'>
			function fncGrabar(codigo,accion) {
				var docu = document.formGastosTarjeta;
				var kGasto = parseInt(docu.Km.value,10);
				var kActual = parseInt(document.formVehiculos.KmAct.value,10);
			    if (!(comparaFechas(document.formVehiculos.FKmAct.value, docu.Fecha.value )) ) {
			            var msge1= dameAlerta(idioma, 224);
			            msge1=msge1.replace("replace1", docu.Fecha.value);
			            msge1=msge1.replace("replace2", document.formVehiculos.FKmAct.value);
			            alert(msge1);
						return false;
			    }
				if (kGasto < kActual ){ 			            
			            alert(dameAlerta(idioma, 225));
						return false;
				}
			    if ((kGasto-kActual)>20000){
			    		var msge2= dameAlerta(idioma, 226);
			            msge2=msge2.replace("replace1", kActual);
			            msge2=msge2.replace("replace2", kGasto);
						if (!confirm(msg2)){
								return false;
				        }
			    }
			    docu.action="m05bGrabarGastosTarjetaServlet?Codigo=" + codigo + "&Accion=" + accion;
			    docu.submit();
			}  // Fin funcion fncGrabar
							  
    setTimeout('initSlide();', 1);
    
   	var tabGastos=document.getElementById("tabGastos");
   	tabGastos.style.backgroundColor="#000078";
</SCRIPT>
</BODY>
</HTML>