;** RE_M004 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - Zebra - Mostru rio                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 29/09/2018 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                  
;Motivo Alteracao: 

;ETIQUETA DE MOSTRUµRIO -> RE_0010E

;*******************************************************************************
;Monta Etiqueta Retrato                                                        *
;*******************************************************************************
Proc Monta_Etiqueta_Paisagem()
Private TAM1,TAM2

Moveto "Answer"
Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q760\n"
Print File Arquivo "Q208,24+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

TAM1 = "5" TAM2 = "5" TAM3 = 0
If Not IsBlank(DITEA[1])
   Then Switch
          Case Len(Rtrim(DITEA[1])) = 2 : TM = "40"
          Case Len(Rtrim(DITEA[1])) = 3 : TM = "10"
          Case Len(Rtrim(DITEA[1])) = 4 : TM = "05" TAM1="4" TAM2="4" TAM3=7
          OtherWise                     : TM = "65"
       EndSwitch
       Print File Arquivo "A"+StrVal((130)-TAM3)+","+TM+",1,2,"+TAM1+","+TAM2+",N,\""+DITEA[1]+"\"\n"                      
EndIf
TAM1 = "5" TAM2 = "5" TAM3 = 0
If Not IsBlank(DITEA[2])
   Then Switch
          Case Len(Rtrim(DITEA[2])) = 2 : TM = "40"
          Case Len(Rtrim(DITEA[2])) = 3 : TM = "10"
          Case Len(Rtrim(DITEA[2])) = 4 : TM = "05" TAM1="4" TAM2="4" TAM3=6
          OtherWise                     : TM = "65"
       EndSwitch
       Print File Arquivo "A"+StrVal((275)-TAM3)+","+TM+",1,2,"+TAM1+","+TAM2+",N,\""+DITEA[2]+"\"\n"
EndIf
TAM1 = "5" TAM2 = "5" TAM3 = 0
If Not IsBlank(DITEA[3])
   Then Switch
          Case Len(Rtrim(DITEA[3])) = 2 : TM = "40" 
          Case Len(Rtrim(DITEA[3])) = 3 : TM = "10"
          Case Len(Rtrim(DITEA[3])) = 4 : TM = "05" TAM1="4" TAM2="4" TAM3=6
          OtherWise                     : TM = "65"
       EndSwitch
       Print File Arquivo "A"+StrVal((418)-TAM3)+","+TM+",1,2,"+TAM1+","+TAM2+",N,\""+DITEA[3]+"\"\n"  
EndIf 
TAM1 = "5" TAM2 = "5" TAM3 = 0
If Not IsBlank(DITEA[4])
   Then Switch
          Case Len(Rtrim(DITEA[4])) = 2 : TM = "40" 
          Case Len(Rtrim(DITEA[4])) = 3 : TM = "10"
          Case Len(Rtrim(DITEA[4])) = 4 : TM = "00" TAM1="4" TAM2="4" TAM3=5
          OtherWise                     : TM = "65"
       EndSwitch
       Print File Arquivo "A"+StrVal((560)-TAM3)+","+TM+",1,2,"+TAM1+","+TAM2+",N,\""+DITEA[4]+"\"\n"  
EndIf

TAM1 = "5" TAM2 = "5" TAM3 = 0
If Not IsBlank(DITEA[5])
   Then Switch
          Case Len(Rtrim(DITEA[5])) = 2 : TM = "30" 
          Case Len(Rtrim(DITEA[5])) = 3 : TM = "05"
          Case Len(Rtrim(DITEA[5])) = 4 : TM = "00" TAM1="4" TAM2="4" TAM3=5
          OtherWise                     : TM = "65" 
       EndSwitch
       Print File Arquivo "A"+StrVal((705)-TAM3)+","+TM+",1,2,"+TAM1+","+TAM2+",N,\""+DITEA[5]+"\"\n"  
EndIf


If DITEA[1]=DITEA[2] And DITEA[1]=DITEA[3] And DITEA[1]=DITEA[4] And DITEA[1]=DITEA[5]    
   Then Print File Arquivo "P"+StrVal(CR)+"\n"
        ce=ce+((CR-1)*5)
   Else Print File Arquivo "P1\n"
EndIf
ne=5

EndProc ;Monta_Etiqueta_Paisagem()

;*******************************************************************************
;Monta Etiqueta Retrato                                                        *
;*******************************************************************************
Proc Monta_Etiqueta_Retrato()

Moveto "Answer"
Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q656\n"
Print File Arquivo "Q208,24+\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZT\n"

If Not IsBlank(DITEA[1])
   Then Switch
          Case Len(Rtrim(DITEA[1])) = 2 : TM = "050"
          Case Len(Rtrim(DITEA[1])) = 3 : TM = "020"
          OtherWise                     : TM = "090"
       EndSwitch
       Print File Arquivo "A"+TM+",60,0,2,5,5,N,\""+DITEA[1]+"\"\n"                      
EndIf
If Not IsBlank(DITEA[2])
   Then Switch
          Case Len(Rtrim(DITEA[2])) = 2 : TM = "200"
          Case Len(Rtrim(DITEA[2])) = 3 : TM = "140"
          OtherWise                     : TM = "230"
       EndSwitch
       Print File Arquivo "A"+TM+",60,0,2,5,5,N,\""+DITEA[2]+"\"\n"
EndIf
If Not IsBlank(DITEA[3])
   Then Switch
          Case Len(Rtrim(DITEA[3])) = 2 : TM = "350" 
          Case Len(Rtrim(DITEA[3])) = 3 : TM = "290"
          OtherWise                     : TM = "380"
       EndSwitch
        Print File Arquivo "A"+TM+",60,0,2,5,5,N,\""+DITEA[3]+"\"\n"  
EndIf
If Not IsBlank(DITEA[4])
   Then Switch
          Case Len(Rtrim(DITEA[4])) = 2 : TM = "490" 
          Case Len(Rtrim(DITEA[4])) = 3 : TM = "430"
          OtherWise                     : TM = "520"
       EndSwitch
        Print File Arquivo "A"+TM+",60,0,2,5,5,N,\""+DITEA[4]+"\"\n"  
EndIf
If Not IsBlank(DITEA[5])
   Then Switch
          Case Len(Rtrim(DITEA[5])) = 2 : TM = "490" 
          Case Len(Rtrim(DITEA[5])) = 3 : TM = "430"
          OtherWise                     : TM = "520"
       EndSwitch
        Print File Arquivo "A"+TM+",60,0,2,5,5,N,\""+DITEA[5]+"\"\n"  
EndIf


If DITEA[1]=DITEA[2] And DITEA[1]=DITEA[3] And DITEA[1]=DITEA[4] And DITEA[1]=DITEA[5]    
   Then Print File Arquivo "P"+StrVal(CR)+"\n"
        ce=ce+((CR-1)*5)
   Else Print File Arquivo "P1\n"
EndIf
ne=5

EndProc

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()
If IsAssigned(DITEA)
   Then Release Vars DITEA
EndIf
Array DITEA[5]

Arquivo=PrivDir()+"RE_M004.ejf"
Deleta_Arquivo(Arquivo)
  
ne=5
Coedit "Answer"
Scan
  numero = [Numero]
  te     = [Quantidade]
  If (te-(5-ne))>5
     Then CR=Int((te-(5-ne))/5)
     Else CR=1
  EndIf
  ;If (te-(4-ne))>4
  ;   Then CR=Int((te-(4-ne))/4)
  ;   Else CR=1
  ;EndIf  
  ce=0
  While True
    ce=ce+1
    ne=ne+1        
    If ne=6
       Then For i From 1 To 5
              DITEA[i]=""
            EndFor
            ne=1
    EndIf
    DITEA[ne]=numero
    If ne=5   Then Monta_Etiqueta_Paisagem() EndIf
    If ce>=te Then QuitLoop                  EndIf
  EndWhile
EndScan
If ne<4 Then Monta_Etiqueta_Paisagem() EndIf
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta_Retrato,Monta_Etiqueta_Paisagem,Monta_Comandos
