;** Et_Z226 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - EAN13 com Pre‡o              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 31/10/2013 por Andrey Fillipe
;Ultima Alteracao: 31/10/2013 por Bruno Carvalho
;Motivo Alteracao: Ajustes  
;Ultima Alteracao: 06/11/2013 por Bruno Carvalho
;Motivo Alteracao: Ajustes Tipo Codigo de Barras
;Ultima Alteracao: 30/11/2013 por Bruno Carvalho
;Motivo Alteracao: Novos Ajustes com ZebraDesign 
;Ultima Alteracao: 06/11/2018 por Bruno Carvalho
;Motivo Alteracao: Ajustes padrÆo p/ codigo de barras EAN8, EAN13 ou COD128 

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

Print File Arquivo "I8,A,001\n"
Print File Arquivo "Q192,024\n"
Print File Arquivo "q831\n"
Print File Arquivo "rN\n"
Print File Arquivo "S3\n"
Print File Arquivo "D7\n"
Print File Arquivo "ZT\n"
Print File Arquivo "JF\n"
Print File Arquivo "O\n"
Print File Arquivo "R76,0\n"
Print File Arquivo "f100\n"
Print File Arquivo "N\n"            
                 
If Not IsBlank(CITEM[1])
   Then
        Print File Arquivo "A320,156,2,2,1,1,N,\""+DITEA[1]+"\"\n"
        Print File Arquivo "A320,131,2,2,1,1,N,\""+DITEB[1]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[1])>0 : Print File Arquivo "B284,111,2,E30,2,4,55,B,\""+CDBAR[1]+"\"\n" 
          Case Search("EAN8",TPBARRA[1])>0  : Print File Arquivo "B284,111,2,E80,2,4,55,B,\""+CDBAR[1]+"\"\n"
          OtherWise                         : Print File Arquivo "B284,111,2,1,2,4,55,B,\""+CDBAR[1]+"\"\n" 
        EndSwitch  
                              
        ;Print File Arquivo "B269,106,2,1,2,6,40,B,\""+CDBAR[1]+"\"\n"
        
        ;If TIPOB[1]="EAN13" 
        ;   Then Print File Arquivo "B269,106,0,E30,2,2,60,B,\""+CDBAR[1]+"\"\n" 
        ;   Else Print File Arquivo "B269,106,0,1,2,2,60,B,\""+CDBAR[1]+"\"\n" 
        ;EndIf
        
        Print File Arquivo "A320,20,2,3,1,1,N,\""+PRECO1[1]+"\"\n"
        EndIf
If Not IsBlank(CITEM[2])
   Then
        Print File Arquivo "A656,156,2,2,1,1,N,\""+DITEA[2]+"\"\n"
        Print File Arquivo "A656,131,2,2,1,1,N,\""+DITEB[2]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[2])>0 : Print File Arquivo "B630,111,2,E30,2,4,55,B,\""+CDBAR[2]+"\"\n" 
          Case Search("EAN8",TPBARRA[2])>0  : Print File Arquivo "B630,111,2,E80,2,4,55,B,\""+CDBAR[2]+"\"\n"
          OtherWise                         : Print File Arquivo "B630,111,2,1,2,4,55,B,\""+CDBAR[2]+"\"\n" 
        EndSwitch  
        
        ;Print File Arquivo "B605,106,2,1,2,6,40,B,\""+CDBAR[2]+"\"\n"
        
        ;If TIPOB[2]="EAN13" 
        ;   Then Print File Arquivo "B605,106,0,E30,2,2,60,B,\""+CDBAR[2]+"\"\n" 
        ;   Else Print File Arquivo "B605,106,0,1,2,2,60,B,\""+CDBAR[2]+"\"\n" 
        ;EndIf
        
        Print File Arquivo "A656,20,2,3,1,1,N,\""+PRECO1[2]+"\"\n"
EndIf

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

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()
If IsAssigned(DITEA)
   Then Release Vars DITEA, CITEM, PRECO, TPBARRA
EndIf
Array   DITEA[2]
Array   DITEB[2]
Array   CITEM[2]
Array   TIPOB[2]
Array   CDBAR[2] 
Array TPBARRA[2]
Array  PRECO1[2]

Arquivo=PrivDir()+"et_Z001B.ejf"
Deleta_Arquivo(Arquivo)

ne=2

Coedit "Answer"
Scan
  te=[Quantidade]
  If (te-(2-ne))>2
     Then CR=Int((te-(2-ne))/2)
     Else CR=1
  EndIf
  ce=0
  While True
    ce=ce+1
    ne=ne+1
    If ne=3
       Then For i From 1 To 2
              CITEM[i]=""
              DITEA[i]=""
              DITEB[i]=""
              TIPOB[i]=""
              CDBAR[i]=""
            TPBARRA[i]=""  
             PRECO1[i]=""
            EndFor
            ne=1
    EndIf
    UN = [Unidade Fiscal]
    If UN<>""
       Then UN=" / "+UN
    EndIf   
    
    CITEM[ne]  = [Codigo do Item]
    DITEA[ne]  = SubStr([Descricao do Item],01,23)
    DITEB[ne]  = Format("W7,AL",SubStr([Descricao do Item],24,7))+Format("W16,AR",[Codigo do Item])
    TIPOB[ne]  = SubStr([Codigo Concentrador],3,10)
    CDBAR[ne]  = [Codigo de Barras]
  TPBARRA[ne]=Upper([Tipo Codigo_Barras])  
    If [Preco Unitario]<>"" 
       Then PRECO1[ne] = "R$ "+Rtrim(Ltrim(Format("W12.2",[Preco Unitario])))+UN
    EndIf
    If ne=2   Then Monta_Etiqueta() EndIf
    If ce>=te Then QuitLoop         EndIf
  EndWhile
EndScan
If ne<2 Then Monta_Etiqueta() EndIf
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
