codice:
<!-- #include file="fpdf.asp" -->
<!-- #include file="adovbs.inc" -->
<!-- #include file="Connessioni.asp" -->
<%
for i=1 to Request.QueryString("NumeroOrdine").Count
NumeroOrdine = Request.QueryString("NumeroOrdine")(i)
next
' stampa su carta bianca
' la prima cosa da fare: leggere i dati dell'ordine
Dim situazione, msg, riga, PC, indirizzosel, TotaleImponibile, TotaleImporto, i, tipodoc, tdoc
Dim RAGSOC, indirizzo, cap, citta, partitaIva, codicefiscale, provincia, codicecliente, ncivico
Dim indirizzo1, cap1, citta1, provincia1, npagine, ctr, Righe, descrizionepagamento, Riferimento, ritiratoda
Dim txt1, txt2, txt3, txt4, txt5, txt6, txt7, txt8, tbIVA(100,2), filestampa, DataFattura
Dim Scontrino, datascontrino
'
' dati principali ordine
'
SQL="select * From Ordini where NumeroOrdine = " & NumeroOrdine
RS.Open SQL, connB
' in linea la scheda ordine
codicecliente=RS("CodiceAnagrafico")
codiceindirizzo=RS("CodiceIndirizzo")
dataordine=fmtDate(RS("DataOrdine"))
tipopagamento=RS("TipoPagamento")
trasportatore=RS("Trasportatore")
ncolli=RS("NColli")
peso=RS("PesoKg")
aspetto=RS("Aspetto")
causale=LeggiCausale(RS("Causale")&"")
datainiziotras=RS("DataInizioTras")
orainiziotras=RS("OraInizioTras")
TotaleImporto=RS("TotaleImporto")
TotaleImponibile=RS("TotaleImponibile")
ExtraSconto=RS("ExtraSconto")
Riferimento=RS("Riferimenti")
ritiratoda=RS("ritiratoda")
'
ctr=0 ' prima pagina
if RS("NumeroFattura")=0 then
numfat=right(RS("NumeroOrdine"),6)
annofat=left(RS("NumeroOrdine"),4)
tipodoc="ORDINE"
nf = RS("NumeroOrdine")
tdoc="ORD"
else
tipodoc="FATTURA"
tdoc="FAT"
nf = RS("NumeroFattura")
numfat=right(RS("NumeroFattura"),6)
annofat=left(RS("NumeroFattura"),4)
DataFattura=LeggiDataFattura(nf)
end if
LeggiAnagrafica(codicecliente)
LeggiTipoPagamento(tipopagamento)
RS.Close
'
' legge scontrino
SQL="select * From Scontrini where NumeroOrdine = " & NumeroOrdine
RS.Open SQL, connB
if not RS.EOF then
scontrino=RS("Scontrino")
DataScontrino=fmtDate(RS("DataScontrino"))
end if
RS.Close
filewrite=server.mappath("public/" & tdoc & trim(nf) & ".pdf")
filefattura=tdoc & trim(nf) & ".pdf"
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF()
pdf.SetPath("fpdf/")
pdf.SetMargins 15, 10, 4
pdf.SetFont "Courier","",8
pdf.Open()
ContaPagineFattura
' prepara modulo dati anagrafici e totali
StampaTestata
' n di righe ordine diviso 35 righe per pagina ---> n. di pagine
' da caricare n. di pagine
SQL="select * from ItemOrdini where NumeroOrdine=" & NumeroOrdine & " ORDER BY ItemOrdine ASC"
RS.Open SQL, connB
i=0
' step 1
' Calcolo dei totali pie di pagina
for k=1 to 100
tbIVA(i,1)=0
tbIVA(i,2)=0
next
if tipodoc="FATTURA" then
RiferimentoOrdine NumeroOrdine, DataOrdine
end if
do until RS.EOF
importor1=((RS.Fields("Quantita") * RS.Fields("PrezzoUnitario")) / 100) * (100 - RS.Fields("Sconto"))
importor2=(importor1 / 100) * (100 - RS.Fields("ScontoB"))
importor3=(importor2 / 100) * (100 - ExtraSconto)
importor4=(importor3 * (100 + RS.Fields("PercentualeIva"))) / 100
' importo3 netto senza iva sulla riga ordine
'
' caricamento tabella iva
'
'importo senza IVA netto
tbIVA(RS.Fields("PercentualeIva"),1)=tbIVA(RS.Fields("PercentualeIva"),1) + importor3
'importo con iva lordo
tbIVA(RS.Fields("PercentualeIva"),2)=tbIVA(RS.Fields("PercentualeIva"),2) + importor4
RS.MoveNext
loop
RS.Close
' step2
' stamparighe articoli
RS.Open SQL, connB
do until RS.EOF
itm=formatNumber(RS.fields("ItemOrdine"),0,-1)
txt1=RS.Fields("CodiceArticolo")
txt2=left(RS.Fields("Descrizione"),48)
if txt1="RIF" then
StampaRiferimento txt2
else
txt3=formatNumber(RS.Fields("Quantita"),0,-1)
txt4=formatNumber(RS.Fields("PrezzoUnitario"),5,-1)
txt5=formatNumber(RS.Fields("Sconto"),0,-1)
txt6=formatNumber(RS.Fields("ScontoB"),0,-1)
txt8=FormatNumber(RS.Fields("PercentualeIva"),0)
importor1=((RS.Fields("Quantita") * RS.Fields("PrezzoUnitario")) / 100) * (100 - RS.Fields("Sconto"))
importor2=(importor1 / 100) * (100 - RS.Fields("ScontoB"))
importor3=(importor2 / 100) * (100 - ExtraSconto)
importor4=(importor3 * (100 + RS.Fields("PercentualeIva"))) / 100
txt7=FormatNumber(importor3,5,-1)
'txt7=FormatNumber(importor4,2,-1)
txt3=right(space(5)&txt3,5)
txt4=right(space(13)&txt4,13)
txt5=right(space(5)&txt5,5)
txt7=right(space(13)&txt7,13)
txt8=right("0"&txt8,2)
'codart
i=i+1
pdf.SetXY 9, 98 + i * 4
'pdf.Write 8, itm & "-" & txt1
pdf.Write 8, txt1
'descrizione
pdf.SetXY 39, 98 + i * 4
pdf.Write 8, txt2
'qta
pdf.SetXY 126, 98 + i * 4
pdf.Write 8, txt3
'prezzo
pdf.SetXY 132, 98 + i * 4
pdf.Write 8, txt4
'sconto
pdf.SetXY 161, 98 + i * 4
if ExtraSconto = 0 then
if trim(txt6)="0" then
pdf.SetXY 158, 98 + i * 4
pdf.Write 8, txt5
else
pdf.SetXY 152, 98 + i * 4
pdf.Write 8, txt5 & "+" & txt6
end if
else
if trim(txt6)="0" then
pdf.SetXY 158, 98 + i * 4
pdf.Write 8, txt5 & "+" & FormatNumber(ExtraSconto,0)
else
pdf.SetXY 152, 98 + i * 4
pdf.Write 8, txt5 & "+" & txt6 & "+" & FormatNumber(ExtraSconto,0)
end if
end if
'importo riga
pdf.SetXY 172, 98 + i * 4
pdf.Write 8, txt7
' perc. IVA
pdf.SetXY 196, 98 + i * 4
pdf.Write 8,txt8 &" "
' aggiunge una pagina dopo 35 righe....
if i>=35 then
PiePagina
StampaTestata
i=0
end if
end if ' end RIF
ResetTxt
RS.Movenext
loop
RS.Close
if i>0 then
PiePagina
end if
pdf.Output(filewrite)
pdf.Close()
'Session("LASTMSG")="PDF format eseguito..."
'filestampa=server.mappath("public/FAT" & trim(nf) & ".pdf")
%>
<!-- #include file="Disconnessioni.asp" -->
<%
response.redirect "VisualizzaFattura.asp?filefattura="&filefattura&"&NumeroOrdine="&NumeroOrdine
sub resetTxt()
txt1=""
txt2=""
txt3=""
txt4=""
txt5=""
txt6=""
txt7=""
txt8=""
end sub
' ------------------------------ fine fattura -- inizio rutines
%>
<%
sub StampaRiferimento(txt2)
'ordine collegato al master
dim NumOrd,dtOrd
Numord=trim(mid(txt2,9,11))
SQL2="select * from Ordini where NumeroOrdine=" & NumOrd
RS2.Open SQL2, connB
if not RS2.EOF then
dtOrd=fmtDate(RS2("DataOrdine"))
Riferimento=RS2("Riferimenti")
RiferimentoOrdine NumOrd, dtOrd
end if
RS2.Close
end sub
sub LeggiAnagrafica(codicecliente)
SQL1="select * From Clienti where codiceanagrafico= " & codicecliente
RS1.Open SQL1, connB
if not RS1.EOF then
codicefiscale=RS1("CodiceFiscale")
partitaIva=RS1("PartitaIVA")
RAGSOC=RS1("RagioneSociale")
cap=RS1("cap")
citta=ucase(RS1("Citta"))
provincia=ucase(RS1("Provincia"))
indirizzo=ucase(RS1("Indirizzo"))
ncivico=RS1("NumeroCivico")
if codiceindirizzo >0 then
LeggiDestinazione codicecliente, codiceindirizzo
end if
end if
RS1.close
end sub
'
' Destinazione diversa dalla default
'
sub LeggiDestinazione(codicecliente, codiceindirizzo)
SQL2="select * From IndirizziCliente where codiceanagrafico= " & codicecliente & " and CodiceDestinazione=" & codiceindirizzo
RS2.Open SQL2, connB
if not RS2.EOF then
indirizzo1=ucase(RS2("Indirizzo"))
cap1=RS2("Cap")
citta1=ucase(RS2("Citta"))
provincia1=ucase(RS2("Provincia"))
end if
RS2.Close
end sub
sub ContaPagineFattura
' contarigheordine
SQL2="select count(*) as Nrighe From ItemOrdini where NumeroOrdine = " & NumeroOrdine
RS2.Open SQL2, connB
if not RS2.EOF then
npagine = int(RS2("Nrighe") / 35) + 1
end if
RS2.close
'
end sub
sub LeggiTipoPagamento(tipopagamento)
SQL2="select * from TipoPagamento where codice=" & tipopagamento
RS2.Open SQL2, connB
if not RS2.EOF then
descrizionepagamento=RS2("Descrizione")
end if
RS2.Close
end sub
sub stampaTestata
' dati della testata della fattura PDF ogni pagina ha la testata
pdf.AddPage()
'pdf.Image "images/SfondoOrdine.jpg",0,0,212
pdf.Image "images/SfondoDocBase.jpg",0,0,212
' pdf.Image "images/FondoFattura1024.jpg",0,0,211
ctr=ctr+1
'pdf.SetXY 8, 50
'pdf.Write 8, "SPETT.LE"
pdf.SetXY 10, 55
pdf.Write 8, RAGSOC
pdf.SetXY 10, 59
pdf.Write 8, trim(indirizzo)&", " & ncivico
pdf.SetXY 10, 63
pdf.Write 8, cap & " " & citta & " " & provincia
if codiceindirizzo > 0 then
pdf.SetXY 120, 59
pdf.Write 8, indirizzo1
pdf.SetXY 120, 63
pdf.Write 8, cap1 & " " & citta1 & " " & provincia1
else
pdf.SetXY 110, 59
pdf.Write 8, "SEDE"
end if
' n. ordine
pdf.SetXY 20, 83
pdf.Write 8, right("00000000" & trim(codicecliente), 8)
pdf.SetXY 58, 83
pdf.Write 8, tipodoc
pdf.SetXY 82, 83
pdf.Write 8, annofat & "/" & numfat
pdf.SetXY 108, 83
pdf.Write 8, DataFattura
'pdf.Write 8, dataordine
pdf.SetXY 130, 83
pdf.Write 8, partitaiva & " " & codicefiscale
pdf.SetXY 192, 83
pdf.Write 8, FormatNumber(ctr,0) & "/" & FormatNumber(npagine,0)
pdf.SetXY 10, 90
pdf.Write 8, descrizionepagamento
end sub
'
' totali e tb IVA
'
sub PiePagina()
if ctr < npagine then
exit sub
end if
n=0
imposte=0
lordo=0
netto=0
pdf.SetFont "Courier","",8
linea=242 ' al posto di 252
for k=0 to 100
if tbIVA(k,1) > 0 then
n=n+1
'riga1 IVA
pdf.SetXY 10, linea + n * 3
pdf.Write 8, n
pdf.SetXY 32, linea + n * 3
pdf.Write 8, right(" " & FormatNumber(tbIVA(k,1),2),10)
pdf.SetXY 63, linea + n * 3
pdf.Write 8,right("00"&trim(k),2)
pdf.SetXY 83, linea + n * 3
pdf.Write 8, right(" " & FormatNumber(tbIVA(k,2)-tbIVA(k,1),2),10)
imposte=imposte+(tbIVA(k,2)-tbIVA(k,1))
lordo=lordo+tbIVA(k,2)
netto=netto+tbIVA(k,1)
end if
next
' stampa sconto cassa
if Extrasconto > 0 then
n=n+2
pdf.SetXY 20, linea + n * 3
pdf.Write 8, "sconto cassa " & Extrasconto & "%"
end if
'trasportatore
pdf.SetXY 107, linea + 3
pdf.Write 8, trasportatore
'peso
pdf.SetXY 146, linea + 3
pdf.Write 8, peso
' totale netto
pdf.SetXY 172, linea + 3
pdf.Write 8, " " & right(space(10) & FormatNumber(round(netto,2),2),10) & " "
'causale
pdf.SetXY 9, linea + 18
pdf.Write 8, causale
'aspetto
pdf.SetXY 60, linea +18
pdf.Write 8, aspetto
'inizio trasporto
pdf.SetXY 112, linea + 18
pdf.Write 8, datainiziotras & " " & orainiziotras
'imposte
pdf.SetXY 172, linea + 12
pdf.Write 8, " " & right(space(10) & FormatNumber(round(imposte,2),2),10) & " "
'lordo
pdf.SetXY 172, linea + 21
pdf.Write 8, " " & right(space(10) & FormatNumber(round(lordo,2),2), 10) & " "
'riferimento
pdf.SetXY 9, linea + 30
pdf.Write 8 , Riferimento
' scontrino
pdf.SetXY 60, linea + 30
pdf.Write 8 , scontrino & " - " & DataScontrino
'ncolli
pdf.SetXY 107, linea + 30
pdf.Write 8 , ncolli
'ritiratoda
pdf.SetXY 160, linea + 30
pdf.Write 8 , ucase(ritiratoda)
'pdf.SetY 280
'pdf.SetX 92
'pdf.Cell 100,8,"COLLI n."&ncolli,0
end sub
sub Footer()
pdf.SetX 15
pdf.SetY -20
end sub
function LeggiCausale(cod)
if cod="" then
LeggiCausale=""
exit function
end if
SQL2="Select * from CausaliTrasporto where Codice = " & Cod
RS2.Open SQL2, connB, 3, 3
if not RS2.EOF then
LeggiCausale=left(RS2.Fields("descrizione"),25)
end if
RS2.Close
end function
function LeggiDataFattura(nf)
SQL2="Select * from Fatture where NumeroFattura=" & nf
RS2.Open SQL2, connB, 3, 3
if not RS2.EOF then
LeggiDataFattura=fmtdate(RS2("DataFattura"))
else
LeggiDataFattura=""
end if
RS2.Close
end function
function fmtdate(dt)
if isDate(dt) then
fmtDate=right("00" & day(dt),2)&"/"&right("00" & month(dt),2)&"/"&right("0000" & year(dt),4)
else
fmtDate="-"
end if
end function
sub RiferimentoOrdine(NumeroOrdine, dataOrdine)
i=i+1
pdf.SetXY 39, 98 + i * 4
pdf.Write 8, "vs ordine " & left(NumeroOrdine,4)&"/"&right(NumeroOrdine,6) & " del " & DataOrdine& ", rif." & trim(ucase(Riferimento))
end sub
%>