;** Et_Z0286 *******************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra                    * Modelo 87 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 12/06/2013 por Bruno Carvalho
;Ultima Alteracao: 20/06/2013 por Bruno Carvalho 
;Motivo Alteracao: Ajustes 

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

Moveto "Answer"
Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q768\n"
Print File Arquivo "Q167,17+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

If Not IsBlank(CITEM[1])
   Then Print File Arquivo "A00,010,0,1,2,1,N,\""+CITEM[1]+"\"\n"        
        Print File Arquivo "A00,032,0,2,1,2,N,\""+DITEA[1]+"\"\n"
        Print File Arquivo "A00,065,0,2,1,2,N,\""+DITEB[1]+"\"\n"
        Print File Arquivo "A00,100,0,2,1,1,N,\""+PRVIS[1]+"\"\n"
        Print File Arquivo "A00,118,0,2,1,1,N,\""+PRPRZ[1]+"\"\n"
EndIf
If Not IsBlank(CITEM[2])
   Then Print File Arquivo "A270,010,0,1,2,1,N,\""+CITEM[2]+"\"\n"
        Print File Arquivo "A270,032,0,2,1,2,N,\""+DITEA[2]+"\"\n"
        Print File Arquivo "A270,065,0,2,1,2,N,\""+DITEB[2]+"\"\n"
        Print File Arquivo "A270,100,0,2,1,1,N,\""+PRVIS[2]+"\"\n"
        Print File Arquivo "A270,118,0,2,1,1,N,\""+PRPRZ[2]+"\"\n"
EndIf
If Not IsBlank(CITEM[3])
   Then
        Print File Arquivo "A548,010,0,1,2,1,N,\""+CITEM[3]+"\"\n"
        Print File Arquivo "A548,032,0,2,1,2,N,\""+DITEA[3]+"\"\n"
        Print File Arquivo "A548,065,0,2,1,2,N,\""+DITEB[3]+"\"\n"
        Print File Arquivo "A548,100,0,2,1,1,N,\""+PRVIS[3]+"\"\n"
        Print File Arquivo "A548,118,0,2,1,1,N,\""+PRPRZ[3]+"\"\n"
EndIf

;*** Antes da Altera‡Æo ****
;If Not IsBlank(CITEM[1])
;   Then Print File Arquivo "A00,10,0,1,2,1,N,\""+CITEM[1]+"\"\n"        
;        Print File Arquivo "A00,28,0,2,1,1,N,\""+DITEA[1]+"\"\n"
;        Print File Arquivo "A00,46,0,2,1,1,N,\""+DITEB[1]+"\"\n"
;        Print File Arquivo "A00,70,0,1,2,1,N,\""+PRVIS[1]+"\"\n"
;        Print File Arquivo "A00,88,0,1,2,1,N,\""+PRPRZ[1]+"\"\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(DITEA)
   Then Release Vars CITEM, DITEA, DITEB, PRVIS, PRPRZ
EndIf

Array CITEM[3]
Array DITEA[3]
Array DITEB[3]
Array PRVIS[3]
Array PRPRZ[3]

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

ne=3

View "\\Sistemas\\Vendas\\Tbprite"
Coedit "Answer"
Scan
  te=[Quantidade]
  CodItem=[Codigo do Item]
  
  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
              CITEM[i]=""
              DITEA[i]=""
              DITEB[i]=""
              PRVIS[i]=""
              PRPRZ[i]=""
            EndFor
            ne=1
    EndIf   
    
    PRECO1 = BlankNum()
    PRECO2 = BlankNum()
    Moveto "\\Sistemas\\Vendas\\Tbprite"
    Moveto [Codigo da Tabela]
    Locate VSDGTABELA,CodItem
    If RetVal
       Then PRECO1=[Preco Unitario]
    Endif
    Moveto "Answer"
    
    PRECO2 = PRECO1 + (PRECO1 * (TAXA_VISTA/100))                               ;Rotina realizada no Re_0010 - Modelo 87
    CITEM[ne]=[Codigo do Item]
    DITEA[ne]=SubStr([Descricao do Item],01,18)
    DITEB[ne]=Format("W16",SubStr([Descricao do Item],19,16)) 
    PRVIS[ne]="A Vista: R$ "+Format("W8.2,EIC",StrVal(PRECO2))
    PRPRZ[ne]="A Prazo: R$ "+Format("W8.2,EIC",StrVal(PRECO1))
    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
