*RECHERCHE DAA       NUMERO
*RECHERCHE DAA       NUMERO
SET TALK OFF
pol1=CHR(27)+"&l0O"+chr(27)+"(s12U"+chr(27)+"(s0P"+chr(27)+"(s12H"+chr(27)+"(s10V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s3T"
pol2=CHR(27)+"&l0O"+chr(27)+"(s12U"+chr(27)+"(s0P"+chr(27)+"(s19H"+chr(27)+"(s12V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s3T"
pol3=CHR(27)+"&l0O"+chr(27)+"(s12U"+chr(27)+"(s1P"+chr(27)+"(s5H"+chr(27)+"(s24V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s6T"
pol4=CHR(27)+"&l0O"+chr(27)+"(s12U"+chr(27)+"(s0P"+chr(27)+"(s10H"+chr(27)+"(s12V"+chr(27)+"(s0S"+chr(27)+"(s0B"+chr(27)+"(s3T"
TITRE="EDITION DE DEMANDE DE DAA"
SELECT 1
USE &cldb INDEX &clndx1,&clndx2  ALIAS CL
SELE 2
USE SDFACTUR INDEX SDFACTUR,FACTURN ALIAS FC
SELE 3
USE SDARTI INDEX SDARTI ALIAS AR
sele 5
use daa index daanum
SELE 4
USE SDLIGNES INDEX SDLIGNES,SDLIGNE2 ALIAS LG
DO WHILE .T.
DO TITRE
NUMDEB=0
NUMFIN=99
@ 12,2 SAY"NUMERO facture" GET NUMDEB
READ
IF NUMDEB=0
EXIT                                 
ENDI                                 
SET ESCA ON                                 
NLFAC=40
NLPG=66
NLET=5
*ET ESCAP OFF
TITRE = "DEMANDE DE DAA"
rep="N"            
SELE FC
SET ORDER TO 2           
SEEK NUMDEB
IF .NOT.EOF()
RECFIC=RECNO()
VNUMTMP=NUMERO
rep="N"
@ 16,2 say" VOULEZ VOUS COMPLETER LES DONNEES O/N" get rep picture "!"
read
if rep = "O"
do bgdebfac
endi
sele 5
seek fc->DAA
if not found()
append blank
replace numdaa with fc->daa
endi
sele 4
********
@ 7,0 clear
if daa->v7l1 =""
replace daa->v7l1 with fc->idtvacli
endi
if daa->v7l2=""
replace daa->v7l2 with fc->entete+" "+trim(fc->nomcli)+" "+trim(fc->prenomcli)
replace daa->v7l2 with ltrim(DAA->v7l2)
replace daa->v7l2 with v7l2+space(55-len(daa->v7l2))
endi
if daa->v7l3=""
replace daa->v7l3 with trim(FC->ad1cli)
if daa->v7l3=""
replace daa->v7l3 with space(55)
else
replace daa->v7l3 with trim(daa->v7l3)
replace daa->v7l3 with daa->v7l3+space(55-len(daa->v7l3))
endi
endi
if daa->v7l4=""
replace daa->v7l4 with trim(fc->ad2cli)
if daa->v7l4=""
replace daa->v7l4 with space(55)
else
replace daa->v7l4 with trim(daa->v7l4)
replace daa->v7l4 with daa->v7l4+space(55-len(daa->v7l4))
endi
endi
if daa->v7al1=""
replace daa->v7al1 with trim(fc->cpcli)+" "+fc->villecli
replace daa->v7al1 with daa->v7al1+space(55-len(daa->v7al1))
endi
if daa->v7al2=""
replace daa->v7al2 with space(55)
endi
if daa->v7al3=""
replace daa->v7al3 with space(55)
endi
if daa->v8l1=""
replace daa->v8l1 with "Recette locale des Douanes 13 rue Thiers 21200 BEAUNE"
endi
if daa->v8l2=""
replace daa->v8l2 with""
endi
if daa->v13=""
replace daa->v13 with space(20)
endi
if daa->v9l1=""
replace daa->v9l1 with space(25)
endi
if daa->v9l2=""
replace daa->v9l2 with space(25)
if daa->v10=""
endi
replace daa->v10 with "CA Beaune Nø 21/5222"
endi
if daa->v11 =""
replace daa->v11 with space(30)
endi
if daa->v12=""
replace daa->v12 with "FR"
endi
if fc->type="C"
 if daa->v13=""
 replace daa->v13 with fc->payscli+space(20-len(fc->payscli))
 endi
 else
 if daa-> v26=""
 replace daa->v26 with fc->payscli+space(20-len(fc->payscli))
 endi
endi
if daa->v15=""
replace daa->v15 with "BEAUNE"
endi
*v14=""
vh1=val(substr(time(),1,2))
vheure=str(vh1+2,2,0)+" h"
if daa->v16=""
replace daa->v16 with dtoc(date())+" "+vheure+"   "
endi
if daa->v17=""
replace daa->v17 with "QUATRE JOURS           "
endi
if daa->v24l1 =""
replace daa->v24l1 with societe
endif
if daa->v24l2=""
replace daa->v24l2 with vtelsoc
endi
if daa->v24l3=""
replace daa->v24l3 with "A. F. GROS"
endi
if daa->v24l4=""
replace daa->v24l4 with "BEAUNE"+" le, "+dtoc(date())
endi
*v18al1=space(25)
* extraction des valeurs possibles
vtotlit=0000
vtotbt=0000
vnbcb=0000
vnbbtb=12
vnbcr=0000
vnbbtr=12
sele fc
*v19a ="2204     21     13"
v20a=vnbcb*vnbbtb*0.75
v21a=2*v20a
v22a=v20a
v19b ="2204     21     43"
v20b=vnbcr*vnbbtr*.75
v21b=2*v20b
v22b=v20b
v18al2="E 13% ou MOINS "
vcase18bl1=space(25)
v18bl2="VIN ROUGE DE BOURGOGNE DE 13% ou MOINS "
*saisie
@ 8,2 say "case 7 destinataire 1" get daa->v7l1 picture "@!"
@ 9,2 say "case 7 destinataire 2" get daa->v7l2 picture "@!"
@ 10,2 say "case 7 destinataire 3" get daa->v7l3 picture "@!"
@ 11,2 say "case 7 destinataire 4" get daa->v7l4 picture "@!"
@ 12,2 say "case 7a   livraison 1" get daa->v7al1 picture "@!"
@ 13,2 say "case 7a   livraison 2" get daa->v7al2 picture "@!"
@ 14,2 say "case 7a   livraison 3" get daa->v7al3 picture "@!"
@ 15,2 say "case 9l 1 TRANSPORTEUR" get daa->v9l1 picture "@!"
@ 16,2 say "case 9 MATRICUL CAMION" get daa->v9l2 picture "@!"
@ 17,2 say "case 11 PRECISIONS ex (sortie le havre) " get daa->v11 picture "@!"
@ 18,2 say "case 13 PAYS CEE " get daa->v13 picture "@!"
@ 19,2 say "case 16 DATE EXPEDITION + heure " get daa->v16 picture "@!"
@ 20,2 say "case 17 DUREE TRANSPORT " get daa->v17 picture "@!"
@ 21,2 say "case 24 SIGNATAIRE      " get daa->v24l3 picture "@!"
@ 22,2 say "case 24 LIEU DATE       " get daa->v24l4 picture "@!"
@ 23,2 say "case 26 pays FINAL      "get daa->v26 picture "@!"
read
*impression
vnbpage=1
page=0
@ 7,0 clear
@ 12,2 say"nombre de pages " get vnbpage
read

@ 12,2 say"placez les IMPRIMES"
@ 15,2 say"choix OKI ou HP O/H" get rep
read
if upper(rep)="O"
do bgdaaoki
else
 do while page<vnbpage
 vlit=0
 vcar=0
 vpoids=0
 set print on
 ??chr(27)+"&l26A"+chr(27)+"&l0L"+chr(27)+"&a400V"+pol2
 set margin to 18
 ? chr(27)+"&a18C"+dtoc(fc->datefact)+CHR(27)+"&a69C"+str(vnumtmp,5,0)+chr(27)+"&a120C"+FC->daa
 ?
 ?"                  ID TVA : "+vidtva+chr(27)+"&a75C"+"1"+chr(27)+"&a90C"+vaccise
 ?
 ? societe
 ? "16 rue, Pierre Joigneaux "
 ? "21200 BEAUNE"+chr(27)+"&a90C"+daa->v10
 ?
 ?
 ? daa->v15
 ?
 ? daa->v8l1+chr(27)+"&a90C"+daa->v14
 ? daa->v8l2
 ? chr(27)+"&a50C"+daa->v7l1
 ? daa->v7l2+chr(27)+"&a90C"+daa->v9l1
 ? daa->v7l3+chr(27)+"&a90C"+daa->v9l2
 ? daa->v7l4
 ?
 ? fc->acciscli+chr(27)+"&a55C"+daa->v13+chr(27)+"&a90C"+daa->v11
 ?
 ? daa->v7al1+chr(27)
 ? daa->v7al2
 ? daa->v7al3+chr(27)+"&a55C"+daa->v26+chr(27)+"&a90C"+daa->v16+chr(27)+"&a125C"+daa->v17
 set margin to 5
 ?
 ?
 ?
 sele lg
 set relation to codearti into AR
 go top
 seek vnumtmp
 vcd7=0
  do while lg->numfact = vnumtmp
   if lg->quantite<>0 .and. lg->colisage<>0
    vtotlit=int(lg->quantite*lg->colisage)
     if lg->cartonage>0
      vnbbtb=lg->cartonage
      else    
      do case    
	   case lg->colisage=0.375
       vnbbtb=24
       case lg->colisage=0.75
       vnbbtb=12
       case lg->colisage=1.5
       vnbbtb=6
      endcase
     endi
    vnbcb=int(quantite/vnbbtb)
    vtotbt=quantite
    vlign=0
    vnlign=int(quantite/vnbbtb)
    vcar=vcar+vnbcb
    vlit=vlit+vtotlit
    vpoids=vpoids+val(str(vtotlit*2,4,0))
    ? str(vnlign,5,0)+" x "+str(vnbbtb,3,0)+"     "+str(lg->colisage,5,3)+chr(27)+"&a28C"+ar->degre
    ??chr(27)+"&a50C"+substr(ar->designart,1,37)+chr(27)+"&a88C"+str(vtotlit,4,0)+"     "+substr(ar->cddaa,1,11)
    ?? chr(27)+"&a114C"+substr(ar->cddaa,13,1)
    ??chr(27)+"&a125C"+str(vtotlit,4,0)+chr(27)+"&a153C"+str(vtotlit*2,4,0)
   endi
   if .not.eof()
    skip
    else
    exit
   endi
  enddo
  do while prow() <46 
   ?
  enddo
  ? str(vcar,4,0)+chr(27)+"&a125C"+str(vlit,5,0)+chr(27)+"&a153C"+str(vpoids,5,0)
  ?
  ?
  ?chr(27)+"&a68C"+"Le pr‚sent document vaut attestation d'appellation d'origine"
  ?chr(27)+"&a68C"+"pour les VQPRD y figurant."
  ?
  ?
  ?
  ?
  ?
  ? chr(27)+"&a96C"+daa->v24l1
  ?
  ? chr(27)+"&a96C"+daa->v24l2
  ?
  ? chr(27)+"&a96C"+daa->v24l3
  ?
  ? chr(27)+"&a96C"+daa->v24l4
  eject
  page=page+1
 enddo
 ? chr(27)+"E"
endif
endif
 enddo
 set margin to 0
 set print off
 sET ESCA OFF
 sele 1    
 use          
 close DATA
 RETU
