;** ET_Z408 ********************************************************************
;* Monta Etiqueta p/ Impressora Termica - CODE128                              *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 07/03/2018 por Bruno Carvalho
;Ultima Alteracao: 08/03/2018 por Bruno Carvalho 
;Motivo Alteracao: Ajustes p/ imprimir inverso na etiqueta -> De "ZT" para "ZB"  

;*******************************************************************************
Proc Monta_Etiqueta()
Moveto "Answer"

Print File Arquivo "O\n"
Print File Arquivo "N\n"
Print File Arquivo "q800\n"
Print File Arquivo "Q600\n"
Print File Arquivo "S2\n"
Print File Arquivo "D8\n"
Print File Arquivo "ZB\n"

If Not IsBlank(CITEM[1])
   Then
        Print File Arquivo "A20,056,0,3,1,2,N,\""+DITEA[1]+"\"\n"
        Print File Arquivo "A20,106,0,3,1,2,N,\""+DITEB[1]+"\"\n"
        Print File Arquivo "A20,156,0,3,1,2,N,\""+DCOMP1[1]+"\"\n"
        Print File Arquivo "A20,206,0,3,1,2,N,\""+DCOMP2[1]+"\"\n"
        Print File Arquivo "A20,246,0,3,1,2,N,\""+DCOMP3[1]+"\"\n"
        Print File Arquivo "A20,306,0,3,1,2,N,\""+DITEC[1]+"\"\n"
        Print File Arquivo "B50,366,0,1,3,2,75,B,\""+CITEM[1]+"\"\n"
        
        Imprime_Simbologia("ZEBRA","00","486","5")
        
EndIf

If Not IsBlank(CITEM[2])
   Then Print File Arquivo "A420,056,0,3,1,2,N,\""+DITEA[2]+"\"\n"
        Print File Arquivo "A420,106,0,3,1,2,N,\""+DITEB[2]+"\"\n"
        Print File Arquivo "A420,156,0,3,1,2,N,\""+DCOMP1[2]+"\"\n"
        Print File Arquivo "A420,206,0,3,1,2,N,\""+DCOMP2[2]+"\"\n"
        Print File Arquivo "A420,256,0,3,1,2,N,\""+DCOMP3[2]+"\"\n"
        Print File Arquivo "A420,306,0,3,1,2,N,\""+DITEC[2]+"\"\n"
        Print File Arquivo "B450,366,0,1,3,2,75,B,\""+CITEM[2]+"\"\n"
        
        Imprime_Simbologia("ZEBRA","400","486","5")
EndIf

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

EndProc

;*******************************************************************************
;* Monta Comandos p/ Impressora Termica                                        *
;*******************************************************************************
Proc Monta_Comandos()
If IsAssigned(DITEA)
   Then Release Vars DITEA, DITEB, DITEC, DCOMP1, DCOMP2, DCOMP3, CITEM
EndIf

NEMPR="Vlnus  Modas"

Array DITEA[2]
Array DITEB[2] 
Array DITEC[2] 
Array DCOMP1[2]
Array DCOMP2[2]
Array DCOMP3[2]
Array CITEM[2]

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

ne=2
Coedit "Answer"
Scan
  LARGURA    = ""
  RENDIMENTO = ""
  COMPOSICAO = ""
  SIMBOLOGIA = ""
  GetRecord "\\Sistemas\\Estoque\\Iten_Tec" [Codigo do Item] To REG_TECIDO
  If RetVal
     Then LARGURA    = REG_TECIDO["Largura"]                
          RENDIMENTO = REG_TECIDO["Rendimento"]
          COMPOSICAO = REG_TECIDO["Composicao"]
          SIMBOLOGIA = REG_TECIDO["Simbologia_Impressao"]
  EndIf
  
  DESCRICAO_COR = ""                          
  REFERENCIA    = ""
  GetRecord "\\Sistemas\\Estoque\\Itens" [Codigo do Item] To REG_ITEM
  If RetVal
     Then DESCRICAO_COR = REG_ITEM["Descricao da Cor_Tecido"]
          REFERENCIA    = REG_ITEM["Referencia"]                                                
  EndIf
  
  Release Vars CONT_SIMBOL,SIMBOL 
  CONT_SIMBOL=0
  DynArray SIMBOL[]
  If SIMBOLOGIA<>""
     Then PosI = Search("-",SIMBOLOGIA)
          If PosI>0
             Then While PosI>0
                    CONT_SIMBOL         = CONT_SIMBOL +1
                    SIMBOL[CONT_SIMBOL] = SubStr(SIMBOLOGIA,1,PosI-1)
                    SIMBOLOGIA = SubStr(SIMBOLOGIA,PosI+1,Len(SIMBOLOGIA))
                    PosI = Search("-",SIMBOLOGIA)
                    If PosI=0
                       Then CONT_SIMBOL         = CONT_SIMBOL +1
                            SIMBOL[CONT_SIMBOL] = SIMBOLOGIA
                            QuitLoop
                    EndIf   
                  EndWhile
             Else SIMBOL[1]=SIMBOLOGIA
          EndIf
     Else SIMBOL[1]=""
  EndIf  
  
  te=[Quantidade]
  If (te-(2-ne))>2
     Then CR=Int((te-(2-ne))/2)
     Else CR=1
  EndIf
  ce=0
  While True
    ce=ce+1
    ne=ne+1
    If ne=3
       Then For i From 1 To 2
              DITEA[i]=""
              DITEB[i]=""
              DITEC[i]=""
              DCOMP1[i]=""
              DCOMP2[i]=""
              DCOMP3[i]=""
              CITEM[i]=""
            EndFor
            ne=1
    EndIf
    
    DITEA[ne]  = " REF: "+REFERENCIA
    If DESCRICAO_COR<>""
       Then DITEA[ne] = DITEA[ne] + "/" + DESCRICAO_COR
    EndIf
    DITEB[ne]  = "LARG: "+Format("W8.2",LARGURA)
    DITEC[ne]  = "REND: "+Format("W8.2",RENDIMENTO)
    DCOMP1[ne] = SubStr(COMPOSICAO,01,25)
    DCOMP2[ne] = SubStr(COMPOSICAO,26,25)
    DCOMP3[ne] = SubStr(COMPOSICAO,51,25)
    CITEM[ne]  = [Codigo do Item]
    If ne=2   Then Monta_Etiqueta() EndIf
    If ce>=te Then QuitLoop         EndIf
  EndWhile
EndScan
If ne<2 Then Monta_Etiqueta() EndIf
Do_It!
ClearAll

ImpriArq(Arquivo)

Sleep 700
Deleta_Arquivo(Arquivo)
ClearAll
EndProc

Monta_Comandos()
Release Procs Monta_Etiqueta,Monta_Comandos
