;** EV_0382  *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/10/2018 por Bruno Carvalho
;Ultima Alteracao: 04/10/2018 por Bruno Carvalho                   
;Motivo Alteracao: Ajustes na impressÆo 

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

Print File Arquivo "q880\n"    
Print File Arquivo "Q560,032\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,\""+NOTAFISC+"\"\n"    
Print File Arquivo "A40,080,0,4,1,2,N,\""+CLIENTE+"\"\n" 
Print File Arquivo "A40,140,0,4,1,2,N,\""+CIDADE+"\"\n"    
Print File Arquivo "A40,200,0,4,1,2,N,\""+VOLUME+"\"\n"       ;4,2,2
Print File Arquivo "A40,260,0,4,1,2,N,\""+ETQ+"\"\n"          ;4,2,2
Print File Arquivo "A40,320,0,4,1,2,N,\""+EMPRESA+"\"\n"   
If PARAM_TRANSP=27                                                              ;Imprime Transportador menor
   Then Print File Arquivo "A50,410,0,3,2,3,N,\""+RAZTRA1+"\"\n"  
        Print File Arquivo "A50,460,0,3,2,3,N,\""+RAZTRA2+"\"\n"   
   Else Print File Arquivo "A50,410,0,4,1,2,N,\""+RAZTRA1+"\"\n"  
        Print File Arquivo "A50,460,0,4,1,2,N,\""+RAZTRA2+"\"\n"     
EndIf        
        
Print File Arquivo "P1\n"         

EndProc                                         

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

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

Arquivo="EV_0382.EJF"
Deleta_Arquivo(Arquivo)

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

  RAZTRA1      = ""

  VOLUME      = ""
  TPDOCTO     = ""
  
  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"]
  EndIf
   
  NUMNOT = [Numero do Documento]
  NCOP   = [NCopias]    
  
  ;---- Formata‡Æo da Etiqueta -------------------------------------------------
  EMPRESA = ""
  If SYS_CODIGO_CLIENTE="0419"  
     Then EMPRESA = "REMETENTE: TECIDOS JANON - 41.854.274/0001-25"
     Else GetRecord "\\Sistemas\\Cadastro\\Empresas" "0001" To REG_EMP
          If RetVal
             Then EMPRESA = Format("W39,AC",REG_EMP["Nome Fantasia Empresa"]+" - "+REG_EMP["CGC Empresa"])
          EndIf
  EndIf 
  
  CLIENTE  = Format("W49","  CLIENTE: "+RAZAOSOCIAL)
  CIDADE   = Format("W49",Format("W32","   CIDADE: "+Rtrim(CIDADE))+"  UF: "+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("W28",Format("W28","  VOLUMES: "+VOLUME))
  If RAZTRA1<>""
     Then RAZTRA2=""
          If Len(RAZTRA1)>PARAM_TRANSP-15
             Then RAZTRA2 = SubStr(RAZTRA1,PARAM_TRANSP-15+1,PARAM_TRANSP-15)
                  RAZTRA1 = SubStr(RAZTRA1,01,PARAM_TRANSP-15)  
          EndIf
          RAZTRA1 = Format("W"+StrVal(PARAM_TRANSP),Format("W"+StrVal(PARAM_TRANSP),"TRANSPORTADOR: "+RAZTRA1))
          If RAZTRA2<>""
             Then RAZTRA2 = Format("W"+StrVal(PARAM_TRANSP),Format("W"+StrVal(PARAM_TRANSP),"               "+RAZTRA2))
          EndIf        
  EndIF   
  For wi From 1 To TM 
   INI = ALINHM(StrVal(wi),3)
   ETQ   = " ETIQUETA: "+INI+"/"+FIM
   If SYS_CODIGO_CLIENTE="0318"
      Then If Rtrim(TPDOCTO)<>""
              Then NOTAFISC = Format("W21,AC",TPDOCTO+": "+NUMNOT)
              Else NOTAFISC = Format("W21,AC",NUMNOT)    
            EndIf
      Else If Rtrim(TPDOCTO)<>""
              Then NOTAFISC = Format("W49","     "+TPDOCTO+": "+NUMNOT)
              Else NOTAFISC = Format("W49",NUMNOT)    
            EndIf
   EndIf            
   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
