Foros del Web » Programando para Internet » ASP Clásico »

[SOLUCIONADO] Obtener facturas por mes seleccionado

Estas en el tema de Obtener facturas por mes seleccionado en el foro de ASP Clásico en Foros del Web. Buenos días, el problema que me esta ocurriendo es que quiero sacar las facturas del mes seleccionadas haciendo un filtro y no me aparecen resultados. ...
  #1 (permalink)  
Antiguo 17/11/2014, 04:36
 
Fecha de Ingreso: noviembre-2014
Mensajes: 8
Antigüedad: 9 años, 5 meses
Puntos: 0
Obtener facturas por mes seleccionado

Buenos días, el problema que me esta ocurriendo es que quiero sacar las facturas del mes seleccionadas haciendo un filtro y no me aparecen resultados. La consulta es la siguiente:

<%@LANGUAGE="VBSCRIPT"%>

<% Option Explicit
response.buffer %>
<HTML>
<HEAD>
<TITLE>CONTABILIDAD DE GASTOS</TITLE>
<style type="text/css" media="print">
#imprime {display:none}
</style>
<CENTER>
<FONT COLOR=BLUE SIZE=+5>
<B>INFORME DE GASTOS</B>
</FONT>
</CENTER>
</HEAD><HR><BR>
<CENTER>
<BODY BGCOLOR="#F3E2A3">
<TABLE BORDER=0>
<TR>
<TD>
<% Dim m,a,f,conex,rs,sqltext
m=Request.Form("mes")
a=Request.Form("ano")
f=Request.Form("n_factura")

set conex=Server.CreateObject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&Server.mappath("./bd/contabilidad.mdb") %>

<TABLE ALIGN=CENTER BORDER=0>
<TR>
<TD>
<FONT SIZE=+3><B>CONSULTA </B>
</FONT>
</TD>
</TR>
</TABLE><BR>

<% set rs=server.createobject("adodb.recordset")
sqltext="select ano, count(n_factura) as facturas, lugar.mes from meses inner join lugar on meses.mes = lugar.mes where ano='"&a&"' group by lugar.mes, ano, meses.numeromes order by meses.numeromes;"
set rs=conex.execute(sqltext)
if not rs.eof then %>

<TABLE ALIGN=CENTER BORDER=1>
<TR><%do While not rs.eof%>
<TH ALIGN=CENTER WIDTH="120" BGCOLOR="#00AAAA">
<FONT SIZE=+3>A&Ntilde;O
</FONT>
</TH>
<TD ALIGN=CENTER WIDTH="120">
<FONT SIZE=+3><%Response.Write rs("ano")%>
</FONT>
</TD>
</TR>
</TABLE><BR><BR>
<TABLE ALIGN=CENTER BORDER=1>
<TR>
<TH COLSPAN="2" BGCOLOR="#00AAAA">
<FONT SIZE=+2>MES
</FONT>
</TH>
</TR>
<TR><%do While not rs.eof%>
<TD WIDTH="120" ALIGN=CENTER>
<%Response.Write Ucase(rs("mes"))%>
</TD>

<TD ALIGN=CENTER>
<BUTTON TYPE="SUBMIT" STYLE="WIDTH:AUTO;HEIGHT:36PX;FONT-SIZE:10PT;BACKGROUND:#C0C0C0;BORDER-RADIUS:8PX;" ONCLICK="location.href='editar5.asp?action=editar5 &mes=<%= rs("facturas")%>'">
<IMG SRC='EDITAR3.PNG' ALIGN='ABSMIDDLE' HSPACE='4'/>CONSULTAR
</BUTTON>
</TD>
</TR><% rs.movenext
loop %>
</TABLE><BR>
<TABLE ALIGN=CENTER CELLSPACING="4" CELLPADDING="8" BORDER=0>
<TR>
<TD>
<BUTTON TYPE="SUBMIT" ID="IMPRIME" STYLE="WIDTH:auto;HEIGHT:36PX;FONT-SIZE:10PT;BACKGROUND:#C0C0C0;BORDER-RADIUS:8PX; "ONCLICK="location.href='MENSUAL.HTML'">
<IMG SRC="OK.PNG" ALIGN="ABSMIDDLE" HSPACE='4'/> ACEPTAR
</BUTTON>
</TD>
</TR>
</TABLE>
<% loop
end if
rs.close
conex.close
set rs=nothing
set conex=nothing %>

</TD>
</TR>
</TABLE>
</BODY>
</CENTER>
</HTML>
Y se me muestre en esta otra pagina:

<%@LANGUAGE="VBSCRIPT"%>

<% Option Explicit %>
<HTML>
<HEAD>
<TITLE>CONTABILIDAD HOGAR</TITLE>
<TABLE ALIGN=CENTER WIDTH=40% BGCOLOR=#F1F1F1 CELLPADDING="0" CELLSPACING="0" BORDER=3>
<TR ALIGN=CENTER>
<TD>
<FONT COLOR=BLACK SIZE=+5 FACE="VERDANA">
GASTOS SUANCES
</FONT>
</TD>
</TR>
</TABLE><P>
</HEAD><HR>
<BODY>
<TABLE ALIGN=CENTER BORDER=0>
<TR>
<TD>
<% Dim conex,sqltext,rs,m,a
a=Request.Form("ano")
m=Request.Form("mes")

set conex=Server.CreateObject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&Server.mappath ("./BD/contabilidad.mdb")%>

<TABLE ALIGN=CENTER CELLSPACING="6" CELLPADDING="2" BORDER=0>
<TR ALIGN=CENTER>
<TD ALIGN=LEFT><FONT COLOR=BLUE SIZE=+3 FACE="VERDANA"><U>DATOS OBTENIDOS</U></FONT>
</TD>
</TR>
</TABLE><BR>

<% set rs=Server.CreateObject("adodb.recordset")
sqltext="select * from lugar where mes='"&request("facturas")&"' ;"
set rs=conex.execute(sqltext)
if not rs.eof then %>

<TABLE ALIGN=CENTER BORDER=1>
<TR><%do While not rs.eof%>
<TH WIDTH="100" BGCOLOR="#00CCDDE">
<FONT SIZE=+2>AÑO
</FONT>
</TH>
<TD WIDTH="140" ALIGN=CENTER>
<FONT SIZE=+2><%Response.Write rs("ano")%>
</FONT>
</TD>
</TR>
<TR>
<TH BGCOLOR="#00CCDDE">
<FONT SIZE=+2>MES
</FONT>
</TH>
<TD ALIGN=CENTER>
<FONT SIZE=+2><%Response.Write UCase(rs("mes"))%>
</FONT>
</TD>
</TR>
</TABLE><BR>
<TABLE ALIGN=CENTER BORDER=1 >
<TR ALIGN=CENTER BGCOLOR="#00CCDD">
<TH WIDTH="150">Nº FACTURA
</TH>
<TH WIDTH="140">CONCEPTO
</TH>
<TH WIDTH="100">IMPORTE
</TH>
</TR>
<TR><% do While not rs.eof %>
<TD ALIGN=CENTER><%Response.Write rs("n_factura")%>
</TD>
<TD ALIGN=CENTER><%Response.Write UCase(rs("concepto"))%>
</TD>
<TD ALIGN=CENTER><%Response.Write formatnumber(rs("importe"),2)%> €
</TD>
</TR>
</TABLE><BR>
<TABLE ALIGN=RIGHT BORDER=1>
<% set conex=Server.CreateObject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&Server.mappath("./bd/contabilidad.mdb")

set rs=Server.CreateObject("adodb.recordset")
sqltext="select sum(importe) as total from lugar where mes='"&request("facturas")&"' ;"
rs.open sqltext,conex,1 %>
<TR>
<TD ALIGN=CENTER WIDTH="100" BGCOLOR="#FF2222">
<FONT SIZE=+2>TOTAL
</FONT>
</TD>
<TD ALIGN=CENTER WIDTH="100">
<FONT SIZE=+2><%Response.Write formatnumber(rs("total"),2)%> €
</FONT>
</TD>
</TR><% rs.movenext
loop %>

</TABLE><BR><BR><BR>
<FORM METHOD="GET" ACTION="MENSUAL.HTML" >

<TABLE ALIGN=CENTER CELLSPACING="6" CELLPADDING="2" BORDER=0>
<TR>
<TD>
<BUTTON TYPE="SUBMIT" STYLE="WIDTH:AUTO;HEIGHT:36PX;FONT-SIZE:10PT;BACKGROUND:#C0C0C0;BORDER-RADIUS:8PX; "ONCLICK="location.href='MENSUAL.HTML'">
<IMG SRC="OK.PNG" ALIGN="ABSMIDDLE" HSPACE='4'/> ACEPTAR
</BUTTON>
</TD>
</TR>
</TABLE><BR>
<% loop
end if
conex.close
set conex=nothing %>
</FORM>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

Muchas Gracias y un saludo.

Última edición por hugelig; 17/11/2014 a las 04:41
  #2 (permalink)  
Antiguo 01/12/2014, 14:33
 
Fecha de Ingreso: febrero-2011
Mensajes: 85
Antigüedad: 13 años, 2 meses
Puntos: 3
Respuesta: Obtener facturas por mes seleccionado

Buenas tardes

A ver si no digo una burrada, pero en la primera consulta, estas utilizando:

count(n_factura) as facturas

Por lo que solo te mostrara un registro con el numero de elementos que cumplan con el filtro, por lo que no veo sentido utilizar el group by yo mejor pondria esto:

SELECT Count(*) as facturas FROM meses inner join lugar on meses.mes = lugar.mes WHERE ano='"&a&"'

En facturas te dara el numero de facturas que cumplan con el criterio

El otro detalle es, donde no te muestra nada en la primera pagina o donde dices; "Y se me muestre en esta otra pagina: "

Saludos GRC
  #3 (permalink)  
Antiguo 01/12/2014, 16:06
 
Fecha de Ingreso: noviembre-2014
Mensajes: 8
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Obtener facturas por mes seleccionado

Buenas noches.

Lo que quiero es que me muestre los meses que tienen facturas (respuesta.asp) y los agrupo para que los meses que tengan mas de una factura (por ejemplo Enero si tiene 3 facturas no me aparezcan 3 Eneros) con lo cual al pinchar en ese mes me muestre en la otra pagina (editar.asp) todas las facturas de ese mes.

En la pagina respuesta.asp me agrupa los meses con el nº de facturas correspondiente a cada mes y esta todo correcto, el problema que tengo es que el resultado que me da en editar.asp no es el correcto, ya que si tengo 2 facturas en ese mes solo aparece una y el año o el mes no coinciden con lo consultado. No sé si esta bien hecho el filtro o tiene algo que ver con el resultado pero he hecho de todo y no consigo dar con ello, por eso necesito una ayuda de alguien que me pueda indicar como realizarlo y conseguirlo.

Un saludo y gracias.

Última edición por hugelig; 01/12/2014 a las 16:18
  #4 (permalink)  
Antiguo 01/12/2014, 18:17
 
Fecha de Ingreso: febrero-2011
Mensajes: 85
Antigüedad: 13 años, 2 meses
Puntos: 3
Respuesta: Obtener facturas por mes seleccionado

Buenas

Ya checaste con un response.write que:

a=Request.Form("ano")
m=Request.Form("mes")

Tengan valores, porque no veo como los envias a tu pagina "editar.asp"

Me gustaria separaras el codigo de cada pagina, asi seria mas facil de analizarlo.

Saludos GRC
  #5 (permalink)  
Antiguo 03/12/2014, 08:38
 
Fecha de Ingreso: noviembre-2014
Mensajes: 8
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Obtener facturas por mes seleccionado

En mi primera pagina (estado.asp) obtengo el año

<%@language="vbscript"%>
<% option explicit%>
<html>
<head>
<title>consultas</title>
<center>
<font color=blue size=+6 face="arial">
<b>comprobaciones
</b><hr>
</font>
</head>
<body bgcolor=#f3e2a3><p>
<table align=center cellspacing="6" cellpadding="2" border=0>
<tr>
<td>
<font color="red" size=+3 face="arial">datos
</font>
</td>
</tr>
</table><br>
<% dim conex,sqltext,rs,a
a=request.form("ano")
set conex=server.createobject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath ("./bd/contabilidad.mdb")%>
<form name="idano" method="post" action="respuesta.asp">
<table width=10% border=0>
<tr align=center>
<th>
<font size="+2" face="times new roman">a&ntilde;o
</font>
</th>
</tr>
<tr align=center>
<td>
<% sqltext= "select ano from lugar group by ano ;"
set rs=conex.execute(sqltext)%>
<select name="ano" style="font:16px verdana;border-radius:6px;">
<% do while not rs.eof%>
<option>
<% =rs("ano")%>
</option>
<% rs.movenext
loop %>
</select>
</td>
</tr>
</table><br>
<table width=22% border=0><br>
<tr align=center>
<td>
<button type="submit" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px; "onclick="location.href='respuesta.asp'">
<img src="ok.png" align="absmiddle" hspace='4'/> aceptar
</button>
</td>
<td>
<button type="reset" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px;"onclick="borrar();">
<img src="cancel2.png" align="absmiddle" hspace='4'/> deshacer
</button>
</td>
</tr>
</table><br>
<table align=center cellspacing="4" cellpadding="8" border=0>
<tr align=center>
<td>
<button type="reset" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px;"onclick="location.href='estado2.html'" >
<img src="atras.png" align="absmiddle" hspace='4'/> atras
</button>
</td>
</tr>
</table>
</form>
</body>
</html>





En la segunda respuesta.asp obtengo los meses que tienen facturas

<%@language="vbscript"%>
<% option explicit
response.buffer %>
<html>
<head>
<title>contabilidad de gastos</title>
<style type="text/css" media="print">
#imprime {display:none}
</style>
<center>
<font color=blue size=+5>
<b>informe de gastos</b>
</font>
</center>
</head><hr><br>
<center>
<body bgcolor="#f3e2a3">
<table border=0>
<tr>
<td>
<% dim m,a,f,conex,rs,sqltext
m=request.form("mes")
a=request.form("ano")
f=request.form("n_factura")
set conex=server.createobject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("./bd/contabilidad.mdb") %>

<table align=center border=0>
<tr>
<td>
<font size=+3><b>consulta </b>
</font>
</td>
</tr>
</table><br>

<% set rs=server.createobject("adodb.recordset")
sqltext="select ano, count(n_factura) as facturas, lugar.mes from meses inner join lugar on meses.mes = lugar.mes where ano='"&a&"' group by lugar.mes, ano, meses.numeromes order by meses.numeromes;"
set rs=conex.execute(sqltext)
if not rs.eof then %>

<table align=center border=1>
<tr><%do while not rs.eof%>
<th align=center width="120" bgcolor="#00aaaa">
<font size=+3>a&ntilde;o
</font>
</th>
<td align=center width="120">
<font size=+3><%response.write rs("ano")%>
</font>
</td>
</tr>
</table><br><br>
<table align=center border=1>
<tr>
<th colspan="2" bgcolor="#00aaaa">
<font size=+2>mes
</font>
</th>
</tr>
<tr><%do while not rs.eof%>
<td width="120" align=center>
<%response.write ucase(rs("mes"))%>
</td>
<td align=center>
<button type="submit" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px;" onclick="location.href='editar.asp?action=editar&n_factura= <%= rs("mes")%>'"<%= rs("facturas")%>>
<img src='editar3.png' align='absmiddle' hspace='4'/>consultar
</button>
</td>
</tr><% rs.movenext
loop %>
</table><br>
<table align=center cellspacing="4" cellpadding="8" border=0>
<tr>
<td>
<button type="submit" id="imprime" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px; "onclick="location.href='mensual.html'">
<img src="ok.png" align="absmiddle" hspace='4'/> aceptar
</button>
</td>
</tr>
</table>
<% loop
end if
rs.close
conex.close
set rs=nothing
set conex=nothing %>

</td>
</tr>
</table>
</body>
</center>
</html>




Y en la tercera editar.asp obtener las facturas del mes que desee con sus detalles (nº factura, concepto, importe e importe total de todas las facturas de ese mes)

<%@language="vbscript"%>
<% option explicit %>
<html>
<head>
<title>contabilidad</title>
<table align=center width=40% bgcolor=#f1f1f1 cellpadding="0" cellspacing="0" border=3>
<tr align=center>
<td>
<font color=black size=+5 face="verdana">
gastos
</font>
</td>
</tr>
</table><p>
</head><hr>
<body>
<table align=center border=0>
<tr>
<td>
<% dim conex,sqltext,rs,m,a
a=request.form("ano")
m=request.form("mes")
set conex=server.createobject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath ("./bd/contabilidad.mdb")%>
<table align=center cellspacing="6" cellpadding="2" border=0>
<tr align=center>
<td align=left><font color=blue size=+3 face="verdana"><u>datos obtenidos</u></font>
</td>
</tr>
</table><br>
<% set rs=server.createobject("adodb.recordset")
sqltext="select * from lugar where mes='"&request("n_factura")&"' ;"
set rs=conex.execute(sqltext) %>
<table align=center border=1>
<tr><%do while not rs.eof%>
<th width="100" bgcolor="#00ccdde">
<font size=+2>aÑo
</font>
</th>
<td width="140" align=center>
<font size=+2><%response.write rs("ano")%>
</font>
</td>
</tr>
<tr>
<th bgcolor="#00ccdde">
<font size=+2>mes
</font>
</th>
<td align=center>
<font size=+2><%response.write rs("mes")%>
</font>
</td>
</tr>
</table><br>
<table align=center border=1 >
<tr align=center bgcolor="#00ccdd">
<th width="150">nº factura
</th>
<th width="140">concepto
</th>
<th width="100">importe
</th>
</tr>
<tr><% do while not rs.eof %>
<td align=center><%response.write rs("n_factura")%>
</td>
<td align=center><%response.write ucase(rs("concepto"))%>
</td>
<td align=center><%response.write formatnumber(rs("importe"),2)%> €
</td>
</tr><%rs.movenext
loop%>
</table><br>
<table align=right border=1>
<% set conex=server.createobject("adodb.connection")
conex.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("./bd/contabilidad.mdb")
set rs=server.createobject("adodb.recordset")
sqltext="select sum(importe) as total from lugar where mes='"&request("n_factura")&"' ;"
set rs=conex.execute(sqltext) %>
<tr><%do While not rs.eof%>
<td align=center width="100" bgcolor="#ff2222">
<font size=+2>total
</font>
</td>
<td align=center width="100">
<font size=+2><%response.write formatnumber(rs("total"),2)%> €
</font>
</td>
</tr><% rs.movenext
loop %>
</table><br><br><br>
<form method="get" action="mensual.html" >
<table align=center cellspacing="6" cellpadding="2" border=0>
<tr>
<td>
<button type="submit" style="width:auto;height:36px;font-size:10pt;background:#c0c0c0;border-radius:8px; "onclick="location.href='mensual.html'">
<img src="ok.png" align="absmiddle" hspace='4'/> aceptar
</button>
</td>
</tr>
</table><br>
<% loop
conex.close
set conex=nothing %>
</form>
</td>
</tr>
</table>
</body>
</html>

No se si el problema puede estar en el filtro que hago en respuesta.asp o que la sentencia sql de editar.asp no es la correcta.

Un saludo y muchas gracias por la ayuda.

Etiquetas: facturas, seleccionado
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:36.