*edition du journal tabul‚
*EDITION DES REGIES
*TITRE =" JOURNAL DE douanes standard sur une page de 14"
dimension tab[29,4]
tab[1,1]=10
tab[2,1]=22
tab[3,1]=34
tab[4,1]=46
tab[5,1]=58
tab[6,1]=70
tab[7,1]=82
tab[8,1]=94
tab[9,1]=106
tab[10,1]=118
tab[11,1]=130
tab[12,1]=142
tab[13,1]=154
tab[14,1]=166
tab[15,1]=10
tab[16,1]=22
tab[17,1]=34
tab[18,1]=46
tab[19,1]=58
tab[20,1]=70
tab[21,1]=82
tab[22,1]=94
tab[23,1]=106
tab[24,1]=118
tab[25,1]=130
tab[26,1]=142
tab[27,1]=154
tab[28,1]=166
pg=0
ppg=0
vtotcum=0
for c=1 to 28
tab [c,2]=0.00
tab [c,3]=0.00
tab[c,4]=" "
vtotfac=0
next c
do titre
wait
sele 1
use sdarti index sdarti
set filter to group<>" "
go top
do while .not. eof()
tab[tab,4]=trim(group)
skip
enddo
close data
sele 1
use bgmv index temp alias mv
set filter to group<>" ".and.&vfiltre
*set order to 2
Blanc="               "
go bott
date2=mv->date
go top
date1=mv->date
mois1=cmonth(date1)
mois2=cmonth(date2)
mois=mois1
************
pol1=CHR(27)+"&l1O"+chr(27)+"(s12U"+chr(27)+"(s0P"+chr(27)+"(s12H"+chr(27)+"(s12V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s3T"
pol2=CHR(27)+"&l1O"+chr(27)+"&l8D"+chr(27)+"(s12U"+chr(27)+"(s0P"+chr(27)+"(s16H"+chr(27)+"(s10V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s3T"
pol3=CHR(27)+"&l1O"+chr(27)+"(s12U"+chr(27)+"(s1P"+chr(27)+"(s5H"+chr(27)+"(s24V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s6T"
totfac=0000.00
vtotmois=0
vcummois=0
*************
* recherche de la tabulation maxi
vtab=0
go top
do while .not. eof()
if mv->tabul >vtab
vtab=mv->tabul
endi
skip
enddo
vtabmax=vtab
if vtabmax >13
ppg=int(vtabmax/13)+1
endi
? "tab max = ",vtab,"page :",ppg
wait
**********************
go top
vimp=0
sele 2
use bgregd index bgregd alias lig
zap
sele mv
replace all type with "N" for type ="H"
set esca on
go top
do while .not. eof()
vcode=right(dtoc(mv->date),2)+substr(dtoc(mv->date),4,2)+left(dtoc(mv->date),2)+mv->type+mv->group+caps
sele lig
append blank
replace code with vcode,date with mv->date,type with mv->type,groupe with mv->group, caps with mv->caps
replace tabul with mv->tabul,numfact with mv->numfact
flush
sele mv
do while .t.
replace lig->total with lig->total+mv->q2
? "fiche : "+vcode,lig->total ,recno()
if .not. eof()
skip
else
exit
endif
if vcode = trim(right(dtoc(mv->date),2)+substr(dtoc(mv->date),4,2)+left(dtoc(mv->date),2)+mv->type+mv->group+caps)
*wait
loop
else
exit
endi
enddo
enddo
sele lig
index on groupe to bgregg
*pr‚paration des cumuls 
go top
do while .not. eof()
vgroup=lig->groupe
do while lig->groupe = vgroup
tab[lig->tabul,3]=tab[lig->tabul,3]+lig->total
skip
enddo
enddo
set index to bgregd,bgregg
*‚quilibrage des lignes
*pour chaque jour v‚rifier qu'il y a une tabul <14 et une >15 sinon en cr‚er une
go top
do while .not. eof()
ex=0
vdaa=lig->daa
tabmax=14
tabmin=18
vcode =lig->code
vdate=lig->date                                                                           
vtype=lig->type
vcaps=lig->caps
vfact=lig->numfact
do while date=vdate
if tabul>tabmax
tabmax=tabul
endi
if tabul<tabmin
tabmin=tabul
endi
skip
enddo
rec=recno()
if tabmax =12
append blank
replace code with vcode,date with vdate,type with vtype, caps with vcaps,groupe with " "
replace tabul with 26,daa with vdaa,numfact with vfact
ex=1
endi
if tabmin =13
append blank
replace code with vcode,date with vdate,type with vtype,groupe with " ", caps with vcaps
replace tabul with 12,daa with vdaa,numfact with vfact
ex=1
endi
if ex=1
go top
endi
enddo
go top
* boucle des pages
do while ppg>0
set print on
? chr(27)+"&l1O"+chr(27)+"&l26A"
? pol2
eject
set margin to 0
set print off
go top
do wHIle .not. eof()
mois=cmonth(lig->date)
set print on
if mois=mois2 .and.lig->tabul> pg*13 .and. lig->tabul <=14+(pg*13)
vimp=1
vtitlig="       "
set margin to 0
else
vimp=0
skip
loop
endi
vcode=left(lig->code,7)
if vimp=1
*****************************titre****************
if prow()<2
? pol3+titre+" mois de "+mois+"  "+str(year(lig->date),4)+"  "+societe+" page "+str(pg+1,2,0)
?
? pol2 +"   jour   "
for c=(13*pg)+1 to 13+(13*pg)
??"  "+tab[c,4]+left(blanc,10-len(tab[c,4]))
next c
?
?
endi
****************************fin titre***************
?? left(dtoc(lig->date),5)
vt=ltrim(str(tab[1,1]))
*do case
*case lig->type ="E"
*vtitlig="Export"
*case lig->type ="C"
*vtitlig="C.E.E."
*case lig->type ="S"
*vtitlig="Sus. Tax."
*case lig->caps ="O"
*vtitlig="C.R.D."
*endcase
??chr(27)+"&a"+vt+"C"+" "
*********creation d'une ligne
endi
do while left(lig->code,7) =vcode
vi=lig->tabul
if vi> pg*13 .and. vi <14+(pg*13)
vt=ltrim(str(tab[vi+(1*pg),1]-1))
if vimp=1
??chr(27)+"&a"+vt+"C"+str(lig->total,10,2)
tab[vi,2]=tab[vi,2]+lig->total
vtotmois=vtotmois+lig->total
tab[28,2]=tab[28,2]+lig->total
endi
*tab[vi,3]=tab[vi,3]+lig->total
tab[28,3]=tab[28,3]+lig->total
vcummois=vcummois+lig->total
vtotcum=vtotcum+lig->total
endi    
*********
skip
enddo
for vtb=(14*pg)+1 to 14+(14*pg)
vt=ltrim(str(tab[vtb,1]-3))
?? chr(27)+"&a"+vt+"C³"
next vtb
vt=ltrim(str(tab[28,1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[28,2],10,2)
?"-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
?
tab[28,2]=0
mois=cmonth(lig->date)
if prow()>53
*impression des totaux colonne
tab[28,2]=vtotmois
?? "total page "
for c=(13*pg)+1 to 13+(13*pg)
vt=ltrim(str(tab[c+(1*pg),1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[c,2],10,2)
tab[c,2]=0
next C
vt=ltrim(str(tab[28,1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[28,2],10,2)
vtotmois=0
for c=(14*pg)+2 to 14+(14*pg)
vt=ltrim(str(tab[c,1]-3))
?? chr(27)+"&a"+vt+"C³"
next C
? " "
? "cumul‚"
for c=(13*pg)+1 to 13 +(13*pg)
vt=ltrim(str(tab[c+(1*pg),1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[c,3],10,2)
tab[27,3]=tab[27,3]+tab[c,3]
next C
vt=ltrim(str(tab[28,1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[27,3],10,2)
? "g‚n‚ral: ",vtotcum
?"                          ."
set print off
wait "attente impression"
set print on
? chr(27)+"&l1O"+chr(27)+"&l26A"
? pol2
eject
set print off
mois1=mois
if .not.eof()
loop
else
exit
endi
endi
enddo
*impression des totaux colonne
tab[28,2]=vtotmois
?? "total page "
for c=(13*pg)+1 to 13 +(13*pg)
vt=ltrim(str(tab[c+(1*pg),1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[c,2],10,2)
tab[c,2]=0
next C
vt=ltrim(str(tab[28,1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[28,2],10,2)
vtotmois=0
for c=(14*pg)+2 to 14+(14*pg)
vt=ltrim(str(tab[c,1]-3))
?? chr(27)+"&a"+vt+"C³"
next C
?
? "cumul‚"
for c=(13*pg)+1 to 13 +(13*pg)
vt=ltrim(str(tab[c+(1*pg),1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[c,3],10,2)
tab[27,3]=tab[27,3]+tab[c,3]
next C
vt=ltrim(str(tab[28,1]-1))
??chr(27)+"&a"+vt+"C"+str(tab[27,3],10,2)
? "g‚n‚ral: ",vtotcum,"soit ",vtotcum/.75,"bt"
?"                          ."
set print off
wait
pg=pg+1
ppg=ppg-1
enddo
set print on
? chr(27)+"&l1O"+chr(27)+"&l26A"
? pol2
*eject
close data
do pol
set print off
retu
