;** Et_Z016 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - EAN13    ** Moreira & Silva **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 04/03/2012 por Kamila Gomes  
;Ultima Alteracao: 05/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 "q600\n"         ;600 ;1cm=60Dots
Print File Arquivo "Q456,24\n"      ;480,024
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"           

If Not IsBlank(DITEM[1])
   Then Print File Arquivo "A540,377,2,1,1,2,N,\""+EMPRESA+"\"\n"
        Print File Arquivo "A596,336,2,1,1,1,N,\"Troca-se somente com esta\"\n"
        Print File Arquivo "A596,318,2,1,1,1,N,\"etiqueta devidamente afixada\"\n"
        Print File Arquivo "A596,290,2,1,1,1,N,\"ao fio de nylon.\"\n"
        Switch
          Case Search("EAN13",TPBARRA[1])>0 : Print File Arquivo "B577,274,2,E30,2,6,67,B,\""+CDBAR[1]+"\"\n"
          Case Search("EAN8",TPBARRA[1])>0  : Print File Arquivo "B577,274,2,E80,2,6,67,B,\""+CDBAR[1]+"\"\n"
          OtherWise                         : Print File Arquivo "B577,274,2,1,2,6,67,B,\""+CDBAR[1]+"\"\n" 
        EndSwitch          
        Print File Arquivo "A596,162,2,1,1,1,N,\""+DITEM[1]+"\"\n"
        Print File Arquivo "A596,143,2,1,1,1,N,\""+REFER[1]+"\"\n"
        Print File Arquivo "A596,124,2,1,1,1,N,\""+TMITE[1]+"\"\n"            
        Print File Arquivo "A596,76,2,2,1,1,N,\""+PR1[1]+"\"\n"                                   
        Print File Arquivo "A596,46,2,2,1,1,N,\""+PR2[1]+"\"\n"         
EndIf

If Not IsBlank(DITEM[2])           
   Then Print File Arquivo "A222,377,2,1,1,2,N,\""+EMPRESA+"\"\n"
        Print File Arquivo "A281,336,2,1,1,1,N,\"Troca-se somente com esta\"\n"
        Print File Arquivo "A281,318,2,1,1,1,N,\"etiqueta devidamente afixada\"\n"
        Print File Arquivo "A281,290,2,1,1,1,N,\"ao fio de nylon.\"\n"
        Switch
          Case Search("EAN13",TPBARRA[2])>0 : Print File Arquivo "B262,274,2,E30,2,6,67,B,\""+CDBAR[2]+"\"\n"
          Case Search("EAN8",TPBARRA[2])>0  : Print File Arquivo "B262,274,2,E80,2,6,67,B,\""+CDBAR[2]+"\"\n"
          OtherWise                         : Print File Arquivo "B262,274,2,1,2,6,67,B,\""+CDBAR[2]+"\"\n" 
        EndSwitch      
        Print File Arquivo "A281,162,2,1,1,1,N,\""+DITEM[2]+"\"\n"
        Print File Arquivo "A281,143,2,1,1,1,N,\""+REFER[2]+"\"\n"
        Print File Arquivo "A281,124,2,1,1,1,N,\""+TMITE[2]+"\"\n"   
        Print File Arquivo "A281,76,2,2,1,1,N,\""+PR1[2]+"\"\n" 
        Print File Arquivo "A281,46,2,2,1,1,N,\""+PR2[2]+"\"\n"    
EndIf

If DITEM[1]=DITEM[2]
   Then Print File Arquivo "P"+StrVal(CR)+"\n"
        ce=ce+((CR-1)*3)
   Else Print File Arquivo "P1\n"
EndIf

ne=2
EndProc

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

Array   DITEM[2]
Array   CITEM[2]
Array   CDBAR[2]
Array TPBARRA[2]
Array   REFER[2]
Array   TMITE[2]
Array   PR1[2]
Array   PR2[2]
      
Arquivo=PrivDir()+"et_Z014.ejf"
Deleta_Arquivo(Arquivo)

Switch
  Case SYS_CODIGO_CLIENTE="0171" : EMPRESA="  Venus Modas  "
  Case SYS_CODIGO_CLIENTE="0322" : EMPRESA = "Moreira & Silva"
  OtherWise                      : EMPRESA = ""
EndSwitch          

ne=2   
       

Coedit "Answer"
Scan
  te=[Quantidade]
  LPR1 =""
  LPR2 =""
  LPR3 =""

  CodItem=[Codigo do Item]
  CodItem=PegaCodigoRaiz(CodItem)

  LPR1="A Vista R$"
  LPR2="A Prazo R$"
  LPR3=""

  Moveto "Answer"

  If (te-(2-ne))>2
     Then CR=Int((te-(2-ne))/2)
     Else CR=1
  EndIf
  ce=0
  While True
    ce=ce+1
    ne=ne+1
    If ne=3
       Then For i From 1 To 2
              DITEM[i]=""
              CDBAR[i]=""
            TPBARRA[i]=""
              CITEM[i]=""
              REFER[i]=""
              TMITE[i]=""
              PR1[i]=""
              PR2[i]=""
            EndFor
            ne=1
    EndIf
    DITEM[ne]=SubStr([Descricao do Item],1,27)
    CITEM[ne]=[Codigo do Item   ]
    CDBAR[ne]=[Codigo de Barras ]
  TPBARRA[ne]=Upper([Tipo Codigo_Barras])
    REFER[ne]="Ref.: "+[Referencia]
    TMITE[ne]="Tam.: "+SubStr([Descricao do Item],29,2)
    PR1[ne]=LPR1
    PR2[ne]=LPR2
    If ne=2   Then Monta_Etiqueta() EndIf
    If ce>=te Then QuitLoop         EndIf
  EndWhile
EndScan
If ne<2 Then Monta_Etiqueta() EndIf
Do_It!
ClearAll
ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
