;** Et_Z010b *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - Interno Bali - So um lado       *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    :  09/09/2009 por Nikolas
;Ultima Alteracao: 07/11/2018 por Bruno Carvalho
;Motivo Alteracao: Ajustes padrĈo p/ codigo de barras EAN8, EAN13 ou COD128 

;*******************************************************************************

Proc Monta_Etiqueta()

Arquivo=PrivDir()+"BALI.ext"
Deleta_Arquivo(Arquivo)

Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q560\n"
Print File Arquivo "Q104,24\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

Switch
  Case Search("EAN13",TPBARRA)>0 : Print File Arquivo "B004,20,0,E30,2,2,50,B,\""+CDBAR+"\"\n" 
  Case Search("EAN8",TPBARRA)>0  : Print File Arquivo "B004,20,0,E80,2,2,50,B,\""+CDBAR+"\"\n"
  OtherWise                      : Print File Arquivo "B004,20,0,1,2,2,50,B,\""+CDBAR+"\"\n"
EndSwitch
Print File Arquivo "A040,10,0,1,1,1,N,\""+CITEM+"\"\n"
Print File Arquivo "A180,10,0,1,1,1,N,\""+DITEM+"\"\n"
;Print File Arquivo "A255,10,0,1,1,1,N,\""+CMAR+"\"\n"
;Print File Arquivo "A180,30,0,1,1,1,N,\""+DGRUP+"\"\n"
;Print File Arquivo "A205,30,0,1,1,1,N,\""+CDFOR+"\"\n"
;Print File Arquivo "A185,55,0,2,1,1,N,\""+LPR1+"\"\n"
;Print File Arquivo "A185,75,0,2,1,1,N,\""+LPR2+"\"\n"
;Print File Arquivo "P"+StrVal(te)+"\n"

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
Sleep 700

EndProc

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()
If IsAssigned(DITEA)
   Then Release Vars DITEA, DGRUP, CITEM, NEMPR, CMAR, TPBARRA
EndIf

View "\\Sistemas\\Vendas\\Tbprite"
View "\\Sistemas\\Vendas\\Tbprcpg"
View "\\Sistemas\\Vendas\\CondPgto"
Coedit "Answer"
Scan
  te=[Quantidade]

  CMAR=[Codigo da Marca           ]
  DITEM=SubStr([Descricao do Item ],1,3)
  DGRUP=SubStr([Descricao do Grupo],1,1)
TPBARRA=Upper([Tipo Codigo_Barras])  
  CDBAR=[Codigo de Barras         ]
  CITEM=[Codigo do Item           ]
  CDFOR=RTrim(SubStr([Codigo Fornecedor],1,10))
  CDFOR=Fill(" ",10-Len(CDFOR))+CDFOR

  LPR1 =""
  LPR2 =""

  Moveto "\\Sistemas\\Vendas\\Tbprite"
  Moveto [Codigo da Tabela]
  Locate VSDGTABELA,CITEM
  If RetVal
     Then PRECO=[Preco Unitario]

          Moveto "\\Sistemas\\Vendas\\Tbprcpg"
          Moveto [Codigo da Tabela]
          Locate VSDGTABELA
          If RetVal
             Then np=0
                  While [Codigo da Tabela]=VSDGTABELA
                    TXFIN=[Taxa Financeira]
                    CONDP=[Condicao de Pagamento]
                    Moveto "\\Sistemas\\Vendas\\CondPgto"
                    Moveto [Condicao de Pagamento]
                    Locate CONDP
                    If RetVal
                       Then np=np+1
                            Switch
															Case np=1 : NP1=[Numero de Parcelas]
																					PRECO1=(PRECO+((PRECO*TXFIN)/100))/NP1
                                          LPR1=StrVal(NP1)+"xR$ "+LTrim(Format("W9.2,EIC",PRECO1))
															Case np=2 : NP2=[Numero de Parcelas]
																					PRECO2=(PRECO+((PRECO*TXFIN)/100))/NP2
                                          LPR2=StrVal(NP2)+"xR$ "+LTrim(Format("W9.2,EIC",PRECO2))
                                          QuitLoop
                            EndSwitch
                    EndIf
                    Moveto "\\Sistemas\\Vendas\\Tbprcpg"
                    Skip
                    If EOT() Then QuitLoop Endif
                  EndWhile
          EndIf
  EndIf

  Moveto "Answer"
  Monta_Etiqueta()
EndScan
Do_It!
ClearAll

EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
