;** ET_Z159C *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - LOTE/DATA                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 29/05/2019 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 "q880\n"    
Print File Arquivo "Q168,24+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D12\n"
Print File Arquivo "ZT\n"   

If Not IsBlank(CITEM[1])
   Then Print File Arquivo "A000,010,0,4,1,1,N,\""+CITEM[1]+"\"\n"
        Print File Arquivo "A000,040,0,4,1,1,N,\""+TIT1[1]+"\"\n"
        Print File Arquivo "A000,070,0,4,1,1,N,\""+DITEA[1]+"\"\n"
        Print File Arquivo "A000,100,0,4,1,1,N,\""+TIT2[1]+"\"\n"
        Print File Arquivo "A000,130,0,4,1,1,N,\""+DITEB[1]+"\"\n"
EndIf
If Not IsBlank(CITEM[2])
   Then Print File Arquivo "A280,010,0,4,1,1,N,\""+CITEM[2]+"\"\n"
        Print File Arquivo "A280,040,0,4,1,1,N,\""+TIT1[2]+"\"\n"
        Print File Arquivo "A280,070,0,4,1,1,N,\""+DITEA[2]+"\"\n"
        Print File Arquivo "A280,100,0,4,1,1,N,\""+TIT2[2]+"\"\n"
        Print File Arquivo "A280,130,0,4,1,1,N,\""+DITEB[2]+"\"\n"
EndIf                                              
If Not IsBlank(CITEM[3])          
   Then Print File Arquivo "A575,010,0,4,1,1,N,\""+CITEM[3]+"\"\n"
        Print File Arquivo "A575,040,0,4,1,1,N,\""+TIT1[3]+"\"\n"
        Print File Arquivo "A575,070,0,4,1,1,N,\""+DITEA[3]+"\"\n"
        Print File Arquivo "A575,100,0,4,1,1,N,\""+TIT2[3]+"\"\n"
        Print File Arquivo "A575,130,0,4,1,1,N,\""+DITEB[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 CITEM, DITEA, DITEB, TIT1, TIT2
EndIf
Array CITEM[3]
Array DITEA[3]
Array DITEB[3]
Array TIT1[3]
Array TIT2[3]

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

ne=3
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
              CITEM[i]=""
              DITEA[i]=""
              DITEB[i]=""
               TIT1[i]=""
               TIT2[i]=""
            EndFor
            ne=1
    EndIf
    CITEM[ne]=Format("W16,AC",[Codigo do Item])
    ;DITEA[ne]="LOTE: "+[Lote]
    ;DITEB[ne]="DATA: "+Format("D10",[Data_Fabricacao])
     TIT1[ne]=Format("W16,AC","LOTE")
     TIT2[ne]=Format("W16,AC","DATA")
    DITEA[ne]=Format("W16,AC",[Lote])
    DITEB[ne]=Format("W16,AC",Format("D13",[Data_Fabricacao]))
    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
