;** ER_Z001G *******************************************************************
;* Monta Etiqueta p/ Impressora Termica c/ Pre‡o - Zebra - EAN13 - Marrom Caf‚ *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 25/07/2014 por Bruno Carvalho 
;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 "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q768\n"
Print File Arquivo "Q169,17+\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,10,0,2,1,1,N,\""+CLASS[1]+"\"\n"
        Print File Arquivo "A00,28,0,2,1,1,N,\""+DITEA[1]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[1])>0 : Print File Arquivo "B10,57,0,E30,2,2,60,B,\""+CDBAR[1]+"\"\n"
          Case Search("EAN8",TPBARRA[1])>0  : Print File Arquivo "B10,57,0,E80,2,2,60,B,\""+CDBAR[1]+"\"\n"
          OtherWise                         : Print File Arquivo "B10,57,0,1,2,2,60,B,\""+CDBAR[1]+"\"\n"  
        EndSwitch
        Print File Arquivo "A00,140,0,2,1,1,N,\""+LIVRE[1]+"\"\n"
EndIf
If Not IsBlank(CITEM[2])
   Then
        Print File Arquivo "A275,10,0,2,1,1,N,\""+CLASS[2]+"\"\n"
        Print File Arquivo "A275,28,0,2,1,1,N,\""+DITEA[2]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[2])>0 : Print File Arquivo "B280,57,0,E30,2,2,60,B,\""+CDBAR[2]+"\"\n" 
          Case Search("EAN8",TPBARRA[2])>0  : Print File Arquivo "B280,57,0,E80,2,2,60,B,\""+CDBAR[2]+"\"\n"
          OtherWise                         : Print File Arquivo "B280,57,0,1,2,2,60,B,\""+CDBAR[2]+"\"\n"
        EndSwitch
        Print File Arquivo "A275,140,0,2,1,1,N,\""+LIVRE[2]+"\"\n"
EndIf
If Not IsBlank(CITEM[3])
   Then
        Print File Arquivo "A553,10,0,2,1,1,N,\""+CLASS[3]+"\"\n"
        Print File Arquivo "A553,28,0,2,1,1,N,\""+DITEA[3]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA[3])>0 : Print File Arquivo "B556,57,0,E30,2,2,60,B,\""+CDBAR[3]+"\"\n"
          Case Search("EAN8",TPBARRA[3])>0  : Print File Arquivo "B556,57,0,E80,2,2,60,B,\""+CDBAR[3]+"\"\n"
          OtherWise                         : Print File Arquivo "B556,57,0,1,2,2,60,B,\""+CDBAR[3]+"\"\n"  
        EndSwitch
        Print File Arquivo "A553,140,0,2,1,1,N,\""+LIVRE[3]+"\"\n"
EndIf

If CITEM[1]=CITEM[2] And CITEM[1]=CITEM[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(DITEA)
   Then Release Vars DITEA, DITEB, CITEM, TPBARRA
EndIf

Array   CLASS[3]
Array   DITEA[3]
Array   CDBAR[3]
Array TPBARRA[3]
Array   CITEM[3]
Array   REFER[3]
Array   LIVRE[3]
Array   PRECO[3]

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

If Not IsAssigned(VSDGMESANO)
  Then VSDGMESANO=Alinhm(StrVal(Month(Today())),2)+"."+StrVal(Year(Today()))
EndIf

ne=3

View "\\Sistemas\\Vendas\\Tbprite"
Coedit "Answer"
Scan
  te=[Quantidade]
  If (te-(3-ne))>3
     Then CR=Int((te-(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
              CLASS[i]=""
              DITEA[i]=""
              CDBAR[i]=""
              CITEM[i]=""
            TPBARRA[i]=""
              REFER[i]=""
              LIVRE[i]=""
              PRECO[i]=""
            EndFor
            ne=1
    EndIf

    Moveto "\\Sistemas\\Vendas\\Tbprite"
    Moveto [Codigo da Tabela]
    Locate VSDGTABELA,[Answer->Codigo do Item]
    If RetVal
       Then PRECO[ne]=StrVal([Preco Unitario])
            
            Inicio = Search(".",PRECO[ne])
            If Inicio>0
               Then PRECO[ne] = SubStr(PRECO[ne],1,Inicio-1)
            EndIf   
       
    EndIf
    Moveto "Answer"

    CLASS[ne]=[Descricao da Familia]
    
    If SYS_CODIGO_CLIENTE="0304" Or
       SYS_CODIGO_CLIENTE="0306" Or
       SYS_CODIGO_CLIENTE="0307" 
       Then DITEA[ne]=SubStr([Descricao do Item],01,18)                       
       Else DITEA[ne]=SubStr([Descricao do Item],01,16)+"/"+PRECO[ne]
    EndIf
    
    CITEM[ne]=[Codigo do Item  ]
    CDBAR[ne]=[Codigo de Barras]
  TPBARRA[ne]=Upper([Tipo Codigo_Barras])  
    REFER[ne]="REF "+[Referencia]
    LIVRE[ne]=Tira_CharNum(StrVal(Format("W10.2,EIC",[Preco Unitario])))+
              SubStr(VSDGMESANO,1,2)+SubStr(VSDGMESANO,4,4)+ "/"+[Referencia]

    If ne=3   Then Monta_Etiqueta() EndIf
    If ce>=te Then QuitLoop         EndIf
  EndWhile
EndScan
If ne<3 Then Monta_Etiqueta() EndIf
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
