;** Et_Z434 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra                               **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/03/2019 por Bruno Carvalho
;Ultima Alteracao: 05/04/2019 por Bruno Carvalho                   
;Motivo Alteracao: Ajustes na ImpressÆo   

;*******************************************************************************
Proc Monta_Etiqueta()
Moveto "Answer"

Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q856\n"  
Print File Arquivo "Q600,16\n"
Print File Arquivo "S2\n"
Print File Arquivo "D12\n"
Print File Arquivo "ZB\n"   

If Not IsBlank(DITEM[1])
   Then ;---- 1¦ Parte ---------------------------------------------------------
        Print File Arquivo "A550,587,2,2,2,2,N,\""+EMPRESA+"\"\n"
        Print File Arquivo "A770,545,2,1,1,1,N,\"TROCA SOMENTE COM ESSA ETIQUETA"+"\"\n"
        Print File Arquivo "A770,530,2,1,1,1,N,\"     PRESA NA PECA E COM       "+"\"\n"
        Print File Arquivo "A770,515,2,1,1,1,N,\"   A  APRESENTACAO DA NOTA     "+"\"\n"
        Print File Arquivo "B720,500,2,1,2,2,57,B,\""+CITEM2[1]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA2[1])>0 : Print File Arquivo "B720,410,2,E30,2,2,57,B,\""+CDBAR[1]+"\"\n"
          Case Search("EAN8",TPBARRA2[1])>0  : Print File Arquivo "B720,410,2,E80,2,2,57,B,\""+CDBAR[1]+"\"\n" 
          OtherWise                          : Print File Arquivo "B720,410,2,1,2,2,57,B,\""+CDBAR[1]+"\"\n" 
        EndSwitch                                                                                           
        
        Print File Arquivo "A690,320,2,1,1,1,N,\""+DITEM[1]+"\"\n"
        Print File Arquivo "A690,305,2,1,1,1,N,\""+DITEM2[1]+"\"\n"
        Print File Arquivo "A690,290,2,1,1,1,N,\""+"TAM:"+TMITE[1]+"    "+"COD:"+CITEM[1]+"\"\n"
        
        Print File Arquivo "A780,265,2,1,1,1,N,\"    TELEFONE (37) 3381 - 4317 "+"\"\n"
        
        ;---- 2¦ Parte ---------------------------------------------------------
        Switch
          Case Search("EAN13",TPBARRA2[1])>0 : Print File Arquivo "B810,190,2,E30,2,2,47,B,\""+CDBAR[1]+"\"\n"
          Case Search("EAN8",TPBARRA2[1])>0  : Print File Arquivo "B810,190,2,E80,2,2,47,B,\""+CDBAR[1]+"\"\n" 
          OtherWise                          : Print File Arquivo "B800,190,2,1,2,2,57,B,\""+CDBAR[1]+"\"\n" 
        EndSwitch                                                                                           
        
        Print File Arquivo "A610,200,2,1,1,1,N,\""+DITEMA[1]+"\"\n"
        Print File Arquivo "A610,180,2,1,1,1,N,\""+DITEMA2[1]+"\"\n"
        Print File Arquivo "A610,165,2,1,1,1,N,\""+"TAM:"+TMITE[1]+"\"\n" 
        Print File Arquivo "A610,145,2,1,1,1,N,\""+"COD:"+CITEM[1]+"\"\n"
        
        Print File Arquivo "A810,100,2,3,1,2,N,\""+PR1[1]+"\"\n"                                   
        Print File Arquivo "A810,055,2,3,1,2,N,\""+PR2[1]+"\"\n"
        
        Print File Arquivo "A540,030,2,2,2,1,N,\""+EMPRESA+"\"\n"          
EndIf

If Not IsBlank(DITEM[2])
   Then ;---- 1¦ Parte ---------------------------------------------------------
        Print File Arquivo "A135,587,2,2,2,2,N,\""+EMPRESA+"\"\n"
        Print File Arquivo "A355,545,2,1,1,1,N,\"TROCA SOMENTE COM ESSA ETIQUETA"+"\"\n"
        Print File Arquivo "A355,530,2,1,1,1,N,\"     PRESA NA PECA E COM       "+"\"\n"
        Print File Arquivo "A355,515,2,1,1,1,N,\"   A  APRESENTACAO DA NOTA     "+"\"\n"
        Print File Arquivo "B310,500,2,1,2,2,57,B,\""+CITEM2[2]+"\"\n"
        Switch
          Case Search("EAN13",TPBARRA2[2])>0 : Print File Arquivo "B310,410,2,E30,2,2,57,B,\""+CDBAR[2]+"\"\n"
          Case Search("EAN8",TPBARRA2[2])>0  : Print File Arquivo "B310,410,2,E80,2,2,57,B,\""+CDBAR[2]+"\"\n" 
          OtherWise                          : Print File Arquivo "B310,410,2,1,2,2,57,B,\""+CDBAR[2]+"\"\n" 
        EndSwitch                                                                                           
        
        Print File Arquivo "A280,320,2,1,1,1,N,\""+DITEM[2]+"\"\n"
        Print File Arquivo "A280,305,2,1,1,1,N,\""+DITEM2[2]+"\"\n"
        Print File Arquivo "A280,290,2,1,1,1,N,\""+"TAM:"+TMITE[2]+"    "+"COD:"+CITEM[2]+"\"\n"        
        
        Print File Arquivo "A380,265,2,1,1,1,N,\"    TELEFONE (37) 3381 - 4317 "+"\"\n"
        
        ;---- 2¦ Parte ---------------------------------------------------------
        Switch
          Case Search("EAN13",TPBARRA2[2])>0 : Print File Arquivo "B390,190,2,E30,2,2,47,B,\""+CDBAR[2]+"\"\n"
          Case Search("EAN8",TPBARRA2[2])>0  : Print File Arquivo "B390,190,2,E80,2,2,47,B,\""+CDBAR[2]+"\"\n" 
          OtherWise                          : Print File Arquivo "B390,190,2,1,2,2,57,B,\""+CDBAR[2]+"\"\n" 
        EndSwitch
                                                                                                            
        Print File Arquivo "A200,200,2,1,1,1,N,\""+DITEMA[2]+"\"\n"
        Print File Arquivo "A200,180,2,1,1,1,N,\""+DITEMA2[2]+"\"\n"
        Print File Arquivo "A200,165,2,1,1,1,N,\""+"TAM:"+TMITE[2]+"\"\n" 
        Print File Arquivo "A200,145,2,1,1,1,N,\""+"COD:"+CITEM[2]+"\"\n"
        
        Print File Arquivo "A390,100,2,3,1,2,N,\""+PR1[2]+"\"\n"                                   
        Print File Arquivo "A390,055,2,3,1,2,N,\""+PR2[2]+"\"\n"
        
        Print File Arquivo "A120,030,2,2,2,1,N,\""+EMPRESA+"\"\n"    
EndIf

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

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[2]
Array   DITEM2[2]
Array   DITEMA[2]
Array  DITEMA2[2]
Array    CITEM[2]
Array   CITEM2[2]                 
Array    CDBAR[2]
Array  TPBARRA[2]
Array   CDBAR2[2]
Array TPBARRA2[2]
Array    REFER[2]
Array    TMITE[2]
Array      PR1[2]
Array      PR2[2]
      
Arquivo=PrivDir()+"ET_Z434C.ejf"
Deleta_Arquivo(Arquivo)
       
If SYS_CODIGO_CLIENTE="0434"
   Then EMPRESA = "MAAF"
   Else EMPRESA = ""
EndIf          
       
ne=2   
       
View "\\Sistemas\\Vendas\\Tbprite"
View "\\Sistemas\\Vendas\\Tbprcpg"
View "\\Sistemas\\Vendas\\CondPgto"
Coedit "Answer"
Scan
  te=[Quantidade]
  If (te-(2-ne))>2
     Then CR=Int((te-(2-ne))/2)
     Else CR=1
  EndIf
  ce=0
  
  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
  
  ;PosI = Search(".",PRUNIT_VISTA)
  ;If PosI > 0
  ;   Then PRUNIT_VISTA = Substr(PRUNIT_VISTA,1,PosI-1) 
  ;EndIf
  ;
  ;For i from 1 to LEN(PRUNIT_VISTA)
  ;    PRUNITARIO_VISTA = Substr(PRUNIT_VISTA,i,1)+PRUNITARIO_VISTA
  ;EndFor
    
  ;---- 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
    
  ;PosI = Search(".",PRUNIT_PRAZO)
  ;If PosI > 0
  ;   Then PRUNIT_PRAZO = Substr(PRUNIT_PRAZO,1,PosI-1) 
  ;EndIf
  
  ;For i from 1 to LEN(PRUNIT_PRAZO)
  ;  PRUNITARIO_PRAZO = Substr(PRUNIT_PRAZO,i,1)+PRUNITARIO_PRAZO
  ;EndFor
  
  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"
  While True
    ce=ce+1
    ne=ne+1
    If ne=3
       Then For i From 1 To 2
              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
    DITEM[ne]="REF: "+SubStr([Descricao do Item],01,22)
   DITEM2[ne]="     "+Ltrim(SubStr([Descricao do Item],23,22))  
   DITEMA[ne]="REF:"+SubStr([Descricao do Item],01,14)
  DITEMA2[ne]="    "+Ltrim(SubStr([Descricao do Item],15,14))
    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=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
