;** ET_Z051C *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 27/10/2020 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                   
;Motivo Alteracao:  

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

Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q620\n"
Print File Arquivo "Q250,28+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D12\n"
Print File Arquivo "ZB\n"               

Print File Arquivo "A00,20,0,1,2,2,N,\""+DESCRICAO+"\"\n"
Print File Arquivo "A00,50,0,1,2,2,N,\""+CITEM+"\"\n"
Print File Arquivo "A00,80,0,1,2,2,N,\""+UNIDADE+"\"\n"
If Not IsBlank(CDBAR)
   Then Switch
          Case Search("EAN13",TPBARRA)>0 : Print File Arquivo "B140,120,0,E30,3,2,80,B,\""+CDBAR+"\"\n" 
          Case Search("EAN8",TPBARRA)>0  : Print File Arquivo "B140,120,0,E80,3,2,80,B,\""+CDBAR+"\"\n"
          OtherWise                      : Print File Arquivo "B160,120,0,1,3,2,80,B,\""+CDBAR+"\"\n"
        EndSwitch 
EndIf     
Print File Arquivo "P1\n"
              
EndProc

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()
If IsAssigned(DESCRICAO) 
   Then Release Vars DESCRICAO,CITEM,CDBAR
EndIf

UNID_INT = ""
UNID_EMB = ""
COD_ITEM = "****"
Arquivo="ET_Z051C.ext"
Deleta_Arquivo(Arquivo)

Coedit "Answer"
Scan
  te=[Quantidade]
  ce=0
  While True
    ce=ce+1
    TPBARRA   = Upper([Tipo Codigo_Barras])  
    CDBAR     = Ltrim([Codigo de Barras ])
    CITEM     = [Codigo do Item]
    DESCRICAO = Ltrim([Descricao do Item])
    
    If COD_ITEM<>[Codigo do Item]
       Then COD_ITEM = [Codigo do Item]
            GetRecord "\\Sistemas\\Estoque\\Itens" COD_ITEM To REG_ITEM
            If RetVal
               Then UNID_INT = Ltrim(REG_ITEM["Unidade Interna"])
                    UNID_EMB = Ltrim(REG_ITEM["Unidade Embalagem"])
                    FAT_EMB  = Ltrim(REG_ITEM["Fator Conversao Embalagem"])
                    If UNID_EMB<>"" 
                       Then UNID_EMB = "EMB " + UNID_EMB + "/" + FAT_EMB
                    EndIf     
               Else UNID_INT = ""
                    UNID_EMB = "" 
            EndIf   
    EndIF 
    UNIDADE = Format("W15,AL",UNID_INT)+Format("W15,AR",UNID_EMB)
    
    Monta_Etiqueta()
    If ce>=te 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
