;** Et_Z004 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - Tecidos Brazao               *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 23/04/2015 por Andrey Fillipe
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
Proc Monta_Etiqueta()
Moveto "Answer"

Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q880\n"
Print File Arquivo "Q520\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

If Not IsBlank(NOME1[1])
   Then Print File Arquivo "A830,3,1,2,2,2,N,\""+NOME1[1]+"\"\n"
        Print File Arquivo "A790,3,1,2,2,2,N,\""+NOME2[1]+"\"\n"
        Print File Arquivo "A740,3,1,2,2,1,N,\""+CONT[1]+"\"\n"
        Print File Arquivo "A690,3,1,2,1,1,N,\""+ENDE[1]+"\"\n"
        Print File Arquivo "A650,3,1,2,1,1,N,\""+CEP[1]+"  "+BAI[1]+"\"\n"
        Print File Arquivo "A610,3,1,2,1,1,N,\""+CID[1]+" - "+UF[1]+"\"\n"
EndIf
If Not IsBlank(NOME1[2])
   Then Print File Arquivo "A550,3,1,2,2,2,N,\""+NOME1[2]+"\"\n"
        Print File Arquivo "A510,3,1,2,2,2,N,\""+NOME2[2]+"\"\n"
        Print File Arquivo "A460,3,1,2,2,1,N,\""+CONT[2]+"\"\n"
        Print File Arquivo "A410,3,1,2,1,1,N,\""+ENDE[2]+"\"\n"
        Print File Arquivo "A370,3,1,2,1,1,N,\""+CEP[2]+"  "+BAI[2]+"\"\n"
        Print File Arquivo "A330,3,1,2,1,1,N,\""+CID[2]+" - "+UF[2]+"\"\n"
EndIf
If Not IsBlank(NOME1[3])
   Then Print File Arquivo "A270,3,1,2,2,2,N,\""+NOME1[3]+"\"\n"
        Print File Arquivo "A230,3,1,2,2,2,N,\""+NOME2[3]+"\"\n"
        Print File Arquivo "A180,3,1,2,2,1,N,\""+CONT[3]+"\"\n"
        Print File Arquivo "A130,3,1,2,1,1,N,\""+ENDE[3]+"\"\n"
        Print File Arquivo "A090,3,1,2,1,1,N,\""+CEP[3]+"  "+BAI[3]+"\"\n"
        Print File Arquivo "A050,3,1,2,1,1,N,\""+CID[3]+" - "+UF[3]+"\"\n"
EndIf

If NOME1[1]=NOME1[2] And NOME1[1]=NOME1[3]
   Then Print File Arquivo "P"+StrVal(CR)+"\n"
        ce=ce+((CR-1)*3)
   Else Print File Arquivo "P1\n"
EndIf
ne=3

EndProc

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()

If IsAssigned(NOME1)
   Then Release Vars NOME1, NOME2, CONT, ENDE, CEP, BAI, CID, UF
EndIf
Array NOME1[3]
Array NOME2[3]
Array CONT [3]
Array ENDE[3]
Array CEP  [3]
Array BAI  [3]
Array CID  [3]
Array UF   [3]


Arquivo="ETIQ.ejf"
Deleta_Arquivo(Arquivo)

ne=3
Coedit "Answer"
Scan
  qtde=[Quantidade]
  If (qtde-(3-ne))>3
     Then CR=Int((qtde-(3-ne))/3)
     Else CR=1
  EndIf
  ce=0
  While True
    ce=ce+1
    ne=ne+1
    If ne=4
       Then For i From 1 To 3
              NOME1[i]=""
              NOME2[i]=""
              CONT [i]=""
              ENDE[i]=""
              BAI  [i]=""
              CEP  [i]=""
              CID  [i]=""
              UF   [i]=""
            EndFor
            ne=1
    EndIf
    NOME1[ne]=SubStr([Razao Social],01,20)
    NOME2[ne]=SubStr([Razao Social],21,20) 
    CONT [ne]="AT.: "+[Contato     ]
    ENDE [ne]=[Endereco]
    BAI  [ne]=[Bairro  ]
    CEP  [ne]=[CEP     ]
    CID  [ne]=[Cidade  ]
    UF   [ne]=[UF      ]
    
    If ne=3   Then Monta_Etiqueta() EndIf
    If ce>=qtde Then QuitLoop         EndIf
  EndWhile  
EndScan
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc
;*******************************************************************************

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
