;** Et_Z004 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - Interno 3                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 22/04/2004 por Davi Pereira Carrano
;Ultima Alteracao: 23/09/2004 por Davi Pereira Carrano
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 29/03/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes contador ce
;Ultima Alteracao: 15/08/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Run
;Ultima Alteracao: 29/02/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes DispositivoI
;Ultima Alteracao: 07/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 "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q2000\n"
Print File Arquivo "Q2250+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

If Not IsBlank(CITEM[1])
   Then Print File Arquivo "A00,360,0,3,2,2,N,\"     "+"R$ "+PRUNI[1]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[1])>0 : Print File Arquivo "B170,150,0,E30,2,2,60,B,\""+CITEM[1]+"\"\n" 
          Case Search("EAN8",TPBARRA[1])>0  : Print File Arquivo "B170,150,0,E80,2,2,60,B,\""+CITEM[1]+"\"\n"
          OtherWise                         : Print File Arquivo "B170,150,0,1,2,2,60,B,\""+CITEM[1]+"\"\n"
        EndSwitch 
        Print File Arquivo "A00,120,0,2,2,1,N,\"     "+MARCA[1]+"\"\n"
        Print File Arquivo "A00,50,0,4,1,1,N,\"       "+DITEA[1]+"\"\n"
        Print File Arquivo "A00,80,0,4,1,1,N,\"       "+DITEB[1]+"\"\n"
        Print File Arquivo "A00,260,0,3,1,1,N,\"           "+"So trocamos com"+"\"\n"
        Print File Arquivo "A00,280,0,3,1,1,N,\"           "+" esta etiqueta"+"\"\n"


EndIf

If Not IsBlank(CITEM[2])
   Then Print File Arquivo "A450,360,0,3,2,2,N,\""+"R$ "+PRUNI[2]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[2])>0 : Print File Arquivo "B490,150,0,E30,2,2,60,B,\""+CITEM[2]+"\"\n"
          Case Search("EAN8",TPBARRA[2])>0  : Print File Arquivo "B490,150,0,E80,2,2,60,B,\""+CITEM[2]+"\"\n"
          OtherWise                         : Print File Arquivo "B490,150,0,1,2,2,60,B,\""+CITEM[2]+"\"\n"
        EndSwitch 
        Print File Arquivo "A445,120,0,2,2,1,N,\""+MARCA[2]+"\"\n"
        Print File Arquivo "A440,50,0,4,1,1,N,\""+DITEA[2]+"\"\n"
        Print File Arquivo "A440,80,0,4,1,1,N,\""+DITEB[2]+"\"\n"
        Print File Arquivo "A460,260,0,3,1,1,N,\""+"So trocamos com"+"\"\n"
        Print File Arquivo "A460,280,0,3,1,1,N,\""+" esta etiqueta"+"\"\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, DITEB, CITEM, MARCA, PRUNI, TPBARRA
EndIf
Array   DITEA[2]
Array   DITEB[2]
Array   CITEM[2]
Array TPBARRA[2]
Array   MARCA[2]
Array   PRUNI[2]

Arquivo=PrivDir()+"CR.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
              DITEA[i]=""
              DITEB[i]=""
              CITEM[i]=""
            TPBARRA[i]=""  
              MARCA[i]=""
              PRUNI[i]=""
            EndFor
            ne=1
    EndIf
    DITEA[ne]=SubStr([Descricao do Item],01,18)
    DITEB[ne]=SubStr([Descricao do Item],19,18)
    MARCA[ne]=[Descricao da Marca]
    CITEM[ne]=[Codigo do Item]
  TPBARRA[ne]=Upper([Tipo Codigo_Barras])  
    If Search("EAN13",TPBARRA[ne])>0 Or Search("EAN8",TPBARRA[ne])>0
       Then CITEM[ne]=[Codigo de Barras]
    EndIf
    PRUNI[ne]=Strval([Preco Unitario])

    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
