;** Et_Z011C *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Eltron  EAN13 III - Siri             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 16/06/2015 por Andrey Fillipe
;Ultima Alteracao: 20/05/2016 por Bruno Carvalho
;Motivo Alteracao: Ajustes "Iten_Com" -> [Codigo Concentrador]
;Ultima Alteracao: 03/11/2016 por Bruno Carvalho
;Motivo Alteracao: Ajustado Medidas "q880" -> "q816" e "Q168" ->"Q168,16
;Ultima Alteracao: 07/11/2018 por Bruno Carvalho
;Motivo Alteracao: Adicionado Array CITEM[] p/ um melhor controle de impressÆo ao montar -> "P"+StrVal(CR)

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

Moveto "Answer"
Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q816\n"
Print File Arquivo "Q168,16\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,\""+DITEM[1]+"\"\n"
        Print File Arquivo "A00,28,0,2,1,1,N,\""+DITEM2[1]+"\"\n"
        Print File Arquivo "A00,46,0,3,1,1,N,\""+REFER[1]+"\"\n"
        Print File Arquivo "B10,75,0,E30,2,2,60,B,\""+CDBAR[1]+"\"\n"
EndIf                        
If Not IsBlank(CITEM[2])
   Then Print File Arquivo "A280,10,0,2,1,1,N,\""+DITEM[2]+"\"\n"
        Print File Arquivo "A280,28,0,2,1,1,N,\""+DITEM2[2]+"\"\n"
        Print File Arquivo "A280,46,0,3,1,1,N,\""+REFER[2]+"\"\n"
        Print File Arquivo "B290,75,0,E30,2,2,60,B,\""+CDBAR[2]+"\"\n"
EndIf
If Not IsBlank(CITEM[3])
   Then
        Print File Arquivo "A560,10,0,2,1,1,N,\""+DITEM[3]+"\"\n"
        Print File Arquivo "A560,28,0,2,1,1,N,\""+DITEM2[3]+"\"\n"
        Print File Arquivo "A560,46,0,3,1,1,N,\""+REFER[3]+"\"\n"
        Print File Arquivo "B570,75,0,E30,2,2,60,B,\""+CDBAR[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(CITEM)
   Then Release Vars CITEM, DITEM, DITEM2, REFER, CDBAR
EndIf
Array CITEM[3]
Array DITEM[3]
Array DITEM2[3]
Array REFER[3]
Array CDBAR[3]

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

ne=3
Coedit "Answer"
Scan
  te=[Quantidade]
  
  CodItem=[Codigo do Item]
  
  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] = ""
              DITEM[i] = ""
             DITEM2[i] = ""
              REFER[i] = ""
              CDBAR[i] = ""
            EndFor
            ne=1
    EndIf    
    GetRecord "\\Sistemas\\Estoque\\Iten_Com" CodItem To CODCONC  
    If RetVal
       Then CODCONC=SubStr(CODCONC["Codigo Concentrador"],1,6)
       Else CODCONC=""
    EndIf
    CITEM[ne]=[Codigo do Item]                                       
    DITEM[ne]=Rtrim(Format("W20",Rtrim(CODCONC)+" "+SubStr([Descricao Complementar],1,12)))
   DITEM2[ne]=Rtrim(Format("W20",SubStr([Descricao Complementar],13,19)))
    REFER[ne]=Rtrim(Format("W20","REF.: "+SubStr([Referencia],1,6)))
    CDBAR[ne]=[Codigo Fornecedor]
    
    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

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
