;** ET_Z412 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - EAN13                        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 08/05/2018 por Bruno Carvalho
;Ultima Alteracao: 09/05/2018 por Bruno Carvalho
;Motivo Alteracao: Imprimir apenas 1 linha para descri‡Æo do item, independente se estiver truncando

;*******************************************************************************
Proc Monta_Etiqueta()

Moveto "Answer"
Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q776\n"
Print File Arquivo "Q136,24+\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 "A45,10,0,2,1,1,N,\""+DITEA[1]+"\"\n"
        ;Print File Arquivo "A45,28,0,2,1,1,N,\""+Ltrim(DITEB[1])+"\"\n"
        
        Print File Arquivo "A45,02,0,2,1,1,N,\""+DITEA[1]+"\"\n"
        If Search("128",TIPOCB[1])>0
           Then Print File Arquivo "B65,25,0,1,2,2,45,B,\""+CDBAR[1]+"\"\n" 
           Else Print File Arquivo "B45,30,0,E30,2,2,45,B,\""+CDBAR[1]+"\"\n"
        EndIf                      
EndIf
If Not IsBlank(CITEM[2])
   Then ;Print File Arquivo "A285,10,0,2,1,1,N,\""+DITEA[2]+"\"\n"
        ;Print File Arquivo "A285,28,0,2,1,1,N,\""+Ltrim(DITEB[2])+"\"\n"
        
        Print File Arquivo "A285,02,0,2,1,1,N,\""+DITEA[2]+"\"\n"
        If Search("128",TIPOCB[2])>0
           Then Print File Arquivo "B305,25,0,1,2,2,45,B,\""+CDBAR[2]+"\"\n" 
           Else Print File Arquivo "B285,30,0,E30,2,2,45,B,\""+CDBAR[2]+"\"\n"
        EndIf
EndIf
If Not IsBlank(CITEM[3])
   Then ;Print File Arquivo "A528,10,0,2,1,1,N,\""+DITEA[3]+"\"\n"
        ;Print File Arquivo "A528,28,0,2,1,1,N,\""+Ltrim(DITEB[3])+"\"\n"
        
        Print File Arquivo "A528,02,0,2,1,1,N,\""+DITEA[3]+"\"\n"
        If Search("128",TIPOCB[3])>0
           Then Print File Arquivo "B546,25,0,1,2,2,45,B,\""+CDBAR[3]+"\"\n" 
           Else Print File Arquivo "B526,30,0,E30,2,2,45,B,\""+CDBAR[3]+"\"\n"
        EndIf     
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, NEMPR
EndIf
Array DITEA[3]
Array DITEB[3]
Array CDBAR[3]
Array CITEM[3]
Array TIPOCB[3]

Arquivo="et_Z001B.ejf"
Deleta_Arquivo(Arquivo)

ne=3
Coedit "Answer"
Scan
  COD_BARRA = ""
  GetRecord "\\Sistemas\\Estoque\\Itens" [Codigo do Item] To REG_ITENS 
  If RetVal
     Then COD_BARRA = REG_ITENS["Tipo Codigo_Barras"]
  EndIf
  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
              DITEA[i]=""
              DITEB[i]=""
              CDBAR[i]=""
              CITEM[i]=""
              TIPOCB[i]=""
            EndFor
            ne=1
    EndIf
    CITEM[ne] =[Codigo do Item]
    DITEA[ne] =SubStr([Descricao do Item],01,17)
    DITEB[ne] =SubStr([Descricao do Item],18,17) 
    CDBAR[ne] =[Codigo de Barras]
    TIPOCB[ne]=COD_BARRA
    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
