;** EV_0444  *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 21/07/2020 por Bruno Carvalho
;Ultima Alteracao:   /  /     por Bruno Carvalho                   
;Motivo Alteracao: 

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

Print File Arquivo "q864\n"    
Print File Arquivo "Q600,040\n" 
Print File Arquivo "rN\n"
Print File Arquivo "S3\n"
Print File Arquivo "D12\n"
Print File Arquivo "ZT\n"
Print File Arquivo "JF\n"
Print File Arquivo "O\n"
Print File Arquivo "N\n"

Print File Arquivo "A40,015,0,4,2,2,N,\""+EMPRESA+"\"\n"    
Print File Arquivo "A20,080,0,5,1,2,N,\""+CLIENTE1+"\"\n"
Print File Arquivo "A20,190,0,5,1,2,N,\""+CLIENTE2+"\"\n" 
Print File Arquivo "A40,300,0,4,2,2,N,\""+CIDADE+"\"\n"
Print File Arquivo "A40,360,0,5,1,2,N,\""+NOTAFISC+"\"\n"    
Print File Arquivo "A40,470,0,3,2,2,N,\""+ETQ+"\"\n"       ;4,2,2
Print File Arquivo "A40,520,0,3,2,2,N,\""+RAZTRA1+"\"\n"
;Print File Arquivo "A40,515,0,3,2,2,N,\""+OBS+"\"\n" 

Print File Arquivo "P1\n"         

EndProc                                         

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()

PARAM_TRANSP = 45        ;Menor => 27
Verifica     = False
RAZTRA1      = ""

Arquivo=PrivDir()+"EV_0382.EJF"
Deleta_Arquivo(Arquivo)

Fim=False
CoEdit "Answer"
Moveto [Sequencia]
Scan                       
  RAZAOSOCIAL = [Razao Social]
  CIDADE      = [Cidade      ]
  ESTADO      = [UF          ]

  RAZTRA1      = ""

  VOLUME      = ""
  TPDOCTO     = ""
  OBS         = "   OBS: "
  
  GetRecord "\\Sistemas\\Vendas\\FaturaC" [Numero da OF] To REG_FATURAC
  If RetVal
    Then RAZTRA1 = REG_FATURAC["Razao Social Transport"]
         VOLUME  = StrVal(REG_FATURAC["Numero de Volumes"])
         TPDOCTO = REG_FATURAC["Docto Nota Gerada"]
         OBS     = Format("W26",OBS + REG_FATURAC["Observacao na Nota Fiscal"])
  EndIf
   
  NUMNOT = [Numero do Documento]
  NCOP   = [NCopias]    
  
  ;---- Formata‡Æo da Etiqueta -------------------------------------------------
  EMPRESA = ""
  GetRecord "\\Sistemas\\Cadastro\\Empresas" "0001" To REG_EMP
  If RetVal
     Then EMPRESA = Format("W24"," ORIG: "+REG_EMP["Nome Fantasia Empresa"])   
  EndIf                
                           
  CLIENTE1  = Format("W22"," DEST: "+SubStr(RAZAOSOCIAL,01,15))
  CLIENTE2  = Format("W22","       "+Ltrim(SubStr(RAZAOSOCIAL,16,15)))
  CIDADE    = Format("W24",Rtrim(CIDADE)+" - "+ESTADO)
  
  TM = NumVal(VOLUME)
  If IsBlank(TM) Or TM<=0 Or Type(TM)<>"N"
     Then TM = 1
  EndIf
  FIM     = ALINHM(StrVal(TM),3)     
  VOLUME  = Format("W24","   VOL: "+VOLUME)
  RAZTRA1 = Format("W24","TRANSP: "+SubStr(RAZTRA1,01,16))
  RAZTRA2 = Format("W24","TRANSP: "+SubStr(RAZTRA1,17,16))

  For wi From 1 To TM 
   INI = ALINHM(StrVal(wi),3)
   ETQ   = "QTDE VOLUME: "+INI+"/"+FIM
   ;If Rtrim(TPDOCTO)<>""    
   ;   Then NOTAFISC = Format("W24","NOTA FISCAL: "+TPDOCTO+"/"+NUMNOT)
   ;   Else NOTAFISC = Format("W24","NOTA FISCAL: "+NUMNOT)
   ;EndIf            
   NOTAFISC = Format("W24","NOTA FISCAL: "+NUMNOT)
   Monta_Etiqueta()    
  EndFor  
EndScan
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 1000
Deleta_Arquivo(Arquivo)

EndProc

Monta_Comandos()
Release Vars INICIO        
Release Procs Monta_Etiqueta,Monta_Comandos
