;** ET_Z434B *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - EAN13                        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 11/04/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 "q856\n"
Print File Arquivo "Q168,16+\n"
Print File Arquivo "S8\n"
Print File Arquivo "D12\n"
Print File Arquivo "ZT\n"

If Not IsBlank(CITEM[1])
   Then Switch
         Case Search("EAN13",TPBARRA2[1])>0 : Print File Arquivo "B790,140,2,E30,2,2,57,B,\""+CDBAR[2]+"\"\n"
          Case Search("EAN8",TPBARRA2[1])>0  : Print File Arquivo "B780,140,2,E80,2,2,57,B,\""+CDBAR[1]+"\"\n" 
          OtherWise                          : Print File Arquivo "B770,150,2,1,2,2,57,B,\""+CDBAR[1]+"\"\n" 
        EndSwitch
                                                                                                            
        ;Print File Arquivo "A720,150,2,1,1,1,N,\""+DITEMA[1]+"\"\n"
        ;Print File Arquivo "A720,130,2,1,1,1,N,\""+DITEMA2[1]+"\"\n"
        ;Print File Arquivo "A720,110,2,1,1,1,N,\""+"TAM:"+TMITE[1]+"\"\n" 
        ;Print File Arquivo "A720,090,2,1,1,1,N,\""+"COD:"+CITEM[1]+"\"\n"
        
        Print File Arquivo "A800,060,2,1,1,2,N,\""+PR1[1]+"\"\n"                                   
        Print File Arquivo "A800,030,2,1,1,2,N,\""+PR2[1]+"\"\n"
        
        Print File Arquivo "A610,030,2,1,1,2,N,\""+EMPRESA+"\"\n"            
EndIf
If Not IsBlank(CITEM[2])
   Then Switch
          Case Search("EAN13",TPBARRA2[2])>0 : Print File Arquivo "B510,140,2,E30,2,2,57,B,\""+CDBAR[2]+"\"\n"
          Case Search("EAN8",TPBARRA2[2])>0  : Print File Arquivo "B500,140,2,E80,2,2,57,B,\""+CDBAR[2]+"\"\n" 
          OtherWise                          : Print File Arquivo "B490,150,2,1,2,2,57,B,\""+CDBAR[2]+"\"\n" 
        EndSwitch
        
        Print File Arquivo "A520,060,2,1,1,2,N,\""+PR1[2]+"\"\n"                                   
        Print File Arquivo "A520,030,2,1,1,2,N,\""+PR2[2]+"\"\n"
        
        Print File Arquivo "A330,030,2,1,1,2,N,\""+EMPRESA+"\"\n"     
EndIf

If Not IsBlank(CITEM[3])
   Then Switch
          Case Search("EAN13",TPBARRA2[3])>0 : Print File Arquivo "B230,140,2,E30,2,2,57,B,\""+CDBAR[3]+"\"\n"
          Case Search("EAN8",TPBARRA2[3])>0  : Print File Arquivo "B220,140,2,E80,2,2,57,B,\""+CDBAR[3]+"\"\n" 
          OtherWise                          : Print File Arquivo "B210,150,2,1,2,2,57,B,\""+CDBAR[3]+"\"\n" 
        EndSwitch
                                                                                    
        Print File Arquivo "A240,060,2,1,1,2,N,\""+PR1[3]+"\"\n"                                   
        Print File Arquivo "A240,030,2,1,1,2,N,\""+PR2[1]+"\"\n"
        
        Print File Arquivo "A50,030,2,1,1,2,N,\""+EMPRESA+"\"\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(DITEA1)
   Then Release Vars DITEA1,DITEA2,CDBAR,TPBARRA,CDBAR2,TPBARRA2,DITEM2,DITEMA,DITEMA2,CITEM2
EndIf  

DATA = chr(196)+chr(196)+chr(96)+chr(96)+chr(92)+chr(96)+chr(196)+chr(96)+chr(96)+chr(92)+chr(96)+chr(96)+chr(96)+chr(196)

Array    DITEM[3]
Array   DITEM2[3]
Array   DITEMA[3]
Array  DITEMA2[3]
Array    CITEM[3]
Array   CITEM2[3]                 
Array    CDBAR[3]
Array  TPBARRA[3]
Array   CDBAR2[3]
Array TPBARRA2[3]
Array    REFER[3]
Array    TMITE[3]
Array      PR1[3]
Array      PR2[3]

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

If SYS_CODIGO_CLIENTE="0434"
   Then EMPRESA = "MAAF"
   Else EMPRESA = ""
EndIf  

ne=3
Coedit "Answer"
Scan
  te=[Quantidade]
  
  CodItem          = [Codigo do Item]
  CodItemRaiz      = PegaCodigoRaiz(CodItem)
  LPR_VISTA        = ""
  LPR_PRAZO        = ""
  
  PRUNIT_VISTA     = ""
  PRUNIT_PRAZO     = ""  
  PRUNITARIO_VISTA = ""
  PRUNITARIO_PRAZO = ""
  
  ;---- Pre‡o A VISTA ----------------------------------------------------------
  If Not IsBlank(VSDGTABELA2)
     Then GetRecord "\\Sistemas\\Vendas\\Tbprite" VSDGTABELA2,CodItem To TABELADEPRECO1
         If RetVal
             Then PRUNIT_VISTA = StrVal(TABELADEPRECO1["Preco Unitario"]) 
             Else PRUNIT_VISTA = ""
         EndIf
     Else PRUNIT_VISTA = ""    
  EndIf
  
  ;---- Pre‡o A PRAZO ----------------------------------------------------------
  If Not IsBlank(VSDGTABELA3)
     Then GetRecord "\\Sistemas\\Vendas\\Tbprite" VSDGTABELA3,CodItem To TABELADEPRECO2
         If RetVal
             Then PRUNIT_PRAZO = StrVal(TABELADEPRECO2["Preco Unitario"]) 
             Else PRUNIT_PRAZO = ""
         EndIf
     Else PRUNIT_PRAZO = ""    
  EndIf
  
  LPR_VISTA="A Vista R$ "+LTrim(Format("W9.2,EIC",PRUNIT_VISTA))
  LPR_PRAZO="A Prazo R$ "+LTrim(Format("W9.2,EIC",PRUNIT_PRAZO))

  Moveto "Answer"

  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
              DITEM[i]=""
             DITEM2[i]=""
             DITEMA[i]=""
            DITEMA2[i]="" 
              CDBAR[i]=""
            TPBARRA[i]=""
             CDBAR2[i]=""
           TPBARRA2[i]=""
              CITEM[i]="" 
             CITEM2[i]=""
              REFER[i]=""
              TMITE[i]=""
              PR1[i]=""
              PR2[i]=""
            EndFor
            ne=1
    EndIf  
   DITEMA[ne]=SubStr([Descricao do Item],01,15)
  DITEMA2[ne]=Ltrim(SubStr([Descricao do Item],16,15))
    CITEM[ne]=[Codigo do Item   ]
   CITEM2[ne]=CodItemRaiz
    CDBAR[ne]=[Codigo de Barras ]
  TPBARRA[ne]=Upper([Tipo Codigo_Barras])
   CDBAR2[ne]=[Codigo de Barras ]
 TPBARRA2[ne]=Upper([Tipo Codigo_Barras])
   ;REFER[ne]="Ref.: "+[Referencia]
    TMITE[ne]=SubStr([Descricao do Item],29,2)
      PR1[ne]=LPR_VISTA
      PR2[ne]=LPR_PRAZO
    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