;** RO_0232F *******************************************************************
;** Imprime a Digitacao do Romaneio                   ** ZUGGY-ZI ***
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 03/03/2015 por Andrey Fillipe
;Ultima Alteracao: 05/07/2017 por Rafael Matos
;Motivo Alteracao: Retirado "Fatura TG", alterado para tabela tempor ria        
;Ultima Alteracao: 13/04/2018 por Bruno Carvalho
;Motivo Alteracao: Alterado [ValordoDesconto] p/ [Valor Desconto] 
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico
;Ultima Alteracao: 04/04/2019 por Kamila Gomes                          
;Motivo Alteracao: Ajustes Moveto [FaturaI->Numero da OF]
;Ultima Alteracao: 04/04/2019 por Kamila Gomes                          
;Motivo Alteracao: Adicionado no Total Liquido o campo [Valor Despesas Acessorias] e [Valor do Frete] 
;Ultima Alteracao: 23/03/2021 por Bruno Carvalho                          
;Motivo Alteracao: Adicionado Despesas Adicionais e Frete no Total do Romaneiro 
;Ultima Alteracao: 07/04/2021 por Bruno Carvalho                          
;Motivo Alteracao: Adicionado [Numero da OF] no Cabe‡alho
;Ultima Alteracao: 03/05/2021 por Bruno Carvalho
;Motivo Alteracao: Ajustes no controle de linha de impressÆo -> NLINHA = 57 

;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()
Print File ARQIMP CI_10CPP+CI_6LPP+"\n"
NPAG=NPAG+1

Moveto "FaturaC"
Print File ARQIMP  "--------------------------------------------------------------------------------" + "\n"
Print File ARQIMP Spaces(28)+"Emissao: "+Format("D13",Today())+"-"+Time()+"              Pagina: "+StrVAl(NPAG)+"\n"
Print File ARQIMP  "--------------------------------------------------------------------------------" + "\n\n"
Print File ARQIMP Spaces(02)+"Operacao: "+Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP Spaces(08)+"Romaneio No "+Format("W06,AL",NOTAFISC)+Spaces(5)+"OF No "+Format("W06,AL",[Numero da OF])+"\n"
Print File ARQIMP Spaces(61)+"Pedido No "+Format("W06,AL",[Numero do Pedido])+"\n"

Print File ARQIMP Spaces(02)+"Cliente.......: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(02)+"Local Fatura..: "
Print File ARQIMP Format("W33,AL",[Endereco])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Bairro])+"\n"
Print File ARQIMP Spaces(18)+Format("W10,AL",[CEP])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Cidade])+" -"
Print File ARQIMP Spaces(01)+Format("W04,AL",[UF])+"\n"
Print File ARQIMP Spaces(18)+Format("W18,AL",[CGC])
Print File ARQIMP Spaces(02)+Format("W25,AL",[IE])+"\n"

Print File ARQIMP Spaces(02)+"Dt Emissao Dt Saida Volumes Representante            NoCarreg"+ "\n"
Print File ARQIMP Spaces(02)+"---------- -------- ------- ------------------------ --------"+"\n"

Print File ARQIMP Spaces(02)+Format("D13",[Data de Emissao])
Print File ARQIMP Spaces(01)+Format("D13",[Data de Saida])
Print File ARQIMP Spaces(01)+Format("W07,AR",[Numero de Volumes])
Print File ARQIMP Spaces(01)+Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP Format("W6,AL",[Numero_Carregamento])+CI_15CPP+"\n\n"

NLINHA=15
Cabecalho_Item()

;********************* IMPRESSAO DOS ITENS ********************************
;Print File ARQIMP "+-------------------------------------------------------------------"+
;                       "--------------------------------------------------------------------+"+"\n"
;
;Print File ARQIMP "|   |      |                                  | PP |  P |  M |  G | GG "+
;                       "|    |    |    |    |    |    |    |      |  |        |          |  "+"\n"
;
;Print File ARQIMP "|Seq|Ref   |Descricao                         |    |    |    |    |     "+
;                       "| 04 | 06 | 08 | 10 | 12 | 14 | 16 | Total|UN|Vr.Unit.| Vr.Total |"+"\n"
;
;Print File ARQIMP "+---+------+----------------------------------+----+----+----+----+----+----"+
;                  "+----+----+----+----+----+----+------+--+--------+----------|"+"\n"
;
;

EndProc  

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Private wc,linha,nlin

          linha="-----------------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP linha+"\n"
nlin = 0

For wc From 1 to DynArraySize(Array_Grade)
  If wc=DynArraySize(Array_Grade)
     Then linha=" Seq|Ref   |Descricao                       |"+Array_Grade[wc]+" Total|UN|                   "
     Else linha="    |      |                                |"+Array_Grade[wc]+"      |  |                   "
  EndIf
  Print File ARQIMP linha+"\n"
  nlin=nlin+1
EndFor

          linha="+---+------+--------------------------------+-+----+----+----+----+----+----+----+----+----+----+----+----+------+--+-------------------+"
Print File ARQIMP linha+"\n"

NLINHA=NLINHA+nlin

EndProc

;*******************************************************************************
;* Rotina para Impressao do Rodape                                             *
;*******************************************************************************
Proc Rodape()
Print File ARQIMP Spaces(110)+"** Continua =>"+"\n"
Print File ARQIMP
"----------------------------------------------------------------------"+
"-----------------------------------------------------------------"+"\n\f"
EndProc

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()
;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
NPAG=0                     
Cabecalho()

Moveto TABELA_TEMP
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT  =0
QUANT1 =0
QUANT2 =0
QUANT3 =0
QUANT4 =0
QUANT5 =0
QUANT6 =0
QUANT7 =0
QUANT8 =0
QUANT9 =0
QUANT10=0
QUANT11=0
QUANT12=0
TOT=0
SeqItPed=0
While [Numero da OF]=[FaturaC->Numero da OF]
   If NLINHA>57
      Then Rodape()
           Cabecalho()
           Moveto TABELA_TEMP
   EndIf

   SeqItPed=SeqItPed+1
   Print File ARQIMP "|"+Format("W03,AR",StrVal(SeqItPed))+"|"
   Print File ARQIMP ""+Format("W06,AL",[Codigo do Item])+"|"
   Print File ARQIMP Spaces(01)+Format("W30,AL",[Descricao do Item])+"   |"
   Print File ARQIMP Format("W04,EIC",[Qtd1    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd2    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd3    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd4    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd5    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd6    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd7    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd8    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd9    ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd10   ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd11   ])+"|"
   Print File ARQIMP Format("W04,EIC",[Qtd12   ])+"|"
   Print File ARQIMP Format("W06,EIC",[Qtd1   ]+[Qtd2   ]+[Qtd3   ]+[Qtd4    ]+
                                      [Qtd5   ]+[Qtd6   ]+[Qtd7   ]+[Qtd8    ]+
                                      [Qtd9   ]+[Qtd10  ]+[Qtd11  ]+[Qtd12   ])+"|"
   Print File ARQIMP ""+Format("W02,AL",[Unidade Fiscal])+"|"
   Print File ARQIMP Format("W08.2,EIC",[Preco Unitario])+"|"
   Print File ARQIMP Format("W10.2,EIC",[Preco Total])+"|"+"\n"
   NLINHA=NLINHA+1

   QUANT  =QUANT  +[Qtd1    ]+[Qtd2    ]+[Qtd3    ]+[Qtd4    ]+
                   [Qtd5    ]+[Qtd6    ]+[Qtd7    ]+[Qtd8    ]+
                   [Qtd9    ]+[Qtd10   ]+[Qtd11   ]+[Qtd12   ]
   QUANT1   =QUANT1   +[Qtd1    ]
   QUANT2   =QUANT2   +[Qtd2    ]
   QUANT3   =QUANT3   +[Qtd3    ]
   QUANT4   =QUANT4   +[Qtd4    ]
   QUANT5   =QUANT5   +[Qtd5    ]
   QUANT6   =QUANT6   +[Qtd6    ]
   QUANT7   =QUANT7   +[Qtd7    ]
   QUANT8   =QUANT8   +[Qtd8    ]
   QUANT9   =QUANT9   +[Qtd9    ]
   QUANT10  =QUANT10  +[Qtd10   ]
   QUANT11  =QUANT11  +[Qtd11   ]
   QUANT12  =QUANT12  +[Qtd12   ]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

Moveto "FaturaC"
Moveto [Forma de Pagamento]
If Busca_Lookup("Tipo do Pagamento",[FaturaC->Forma de Pagamento],"SM")
   Then NFP=REG_BUSCA_LOOKUP["Descricao Tipo Pagamento"]
   Else NFP=""
EndIf
UnLockRecord

Print File ARQIMP          "                                               ---- ---- ---- ---- ----"+
" ---- ---- ---- ---- ---- ---- ---- ------             ----------"+"\n"

Print File ARQIMP Spaces(46)
Print File ARQIMP Format("W05,EIC",QUANT1   )
Print File ARQIMP Format("W05,EIC",QUANT2   )
Print File ARQIMP Format("W05,EIC",QUANT3   )
Print File ARQIMP Format("W05,EIC",QUANT4   )
Print File ARQIMP Format("W05,EIC",QUANT5   )
Print File ARQIMP Format("W05,EIC",QUANT6   )
Print File ARQIMP Format("W05,EIC",QUANT7   )
Print File ARQIMP Format("W05,EIC",QUANT8   )
Print File ARQIMP Format("W05,EIC",QUANT9   )
Print File ARQIMP Format("W05,EIC",QUANT10  )
Print File ARQIMP Format("W05,EIC",QUANT11  )
Print File ARQIMP Format("W05,EIC",QUANT12  )
Print File ARQIMP Format("W07,EIC",QUANT)
Print File ARQIMP Format("W23.2,EIC",TOT)+"\n"
Print File ARQIMP CI_10CPP+CI_6LPP+"\n"

If [Faturac->Frete Incluso na Nota]="S" Or
   [Faturac->Frete Incluso na Nota]="+"
   Then vrfrete=[Faturac->Valor do Frete]
   Else vrfrete=BlankNum()
EndIf  

Print File ARQIMP Spaces(48)+"Desconto "+Format("W6.2",[Taxa de Desconto])+"%....." + Format("W12.2,EIC",[Valor Desconto])+"\n"
Print File ARQIMP Spaces(48)+"Frete................"+Format("W12.2,EIC",vrfrete)+"\n"
Print File ARQIMP Spaces(48)+"Despesas Adicionais.."+Format("W12.2,EIC",[Valor Despesas Acessorias])+"\n"
Print File ARQIMP Spaces(48)+"Total Liquido......"+Format("W12.2,EIC",[Valor Mercadoria Liquido]+[Valor Despesas Acessorias]+vrfrete)+"\n\n"

If NLINHA>57
   Then Rodape()
        Cabecalho()
EndIf

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP Spaces(00)+"Condicao Pagto: "+[Descricao CondPagto]+"  Forma Pagto: "+[Forma de Pagamento]+" "+NFP+"\n"

Print File ARQIMP Spaces(00)+"Vencimentos   : "+CI_INEG

Array DATA[9]
Array VALOR[9]
K=0
KV=0
Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
  K=K+1
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W11.2,AL,EIC",[Valor])
  If K=4
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()
EndIf

Moveto"Faturac"
Print File ARQIMP CI_FNEG
Print File ARQIMP "Transportadora: "+[Razao Social Transport]+"\n"
Print File ARQIMP "Observacoes   : "
Print File ARQIMP CI_INEG
If Substr([Observacao na Nota Fiscal],01,64)<>""
   Then Print File ARQIMP Spaces(00)+Format("W64,AL",SubStr([Observacao na Nota Fiscal],001,64))+"\n"
   Else Print File ARQIMP "\n"
EndIf
If Substr([Observacao na Nota Fiscal],65,64)<>""
   Then Print File ARQIMP Spaces(16)+Format("W64,AL",SubStr([Observacao na Nota Fiscal],65,64))+"\n"
EndIf
If Substr([Observacao na Nota Fiscal],129,64)<>""
   Then Print File ARQIMP Spaces(16)+Format("W64,AL",SubStr([Observacao na Nota Fiscal],129,64))+"\n"
EndIf
;Print File ARQIMP "NA OPORTUNIDADE PEDIMOS QUE NOS ENVIE OS CHEQUES REFERENTE A ESTE PEDIDO,\n"
;Print File ARQIMP "CONFORME A RELACAO ACIMA AO NOSSO ENDERECO, VIA SEDEX OU CARTA COM A.R.\n"
Print File ARQIMP CI_FNEG

;************************* IMPRESSAO DO RODAPE ********************************

Print File ARQIMP CI_10CPP+CI_6LPP+"\f"

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If KV>0
   Then Print File ARQIMP Spaces(16)
EndIf
For I From 1 to K
  Print File ARQIMP  DATA[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(16)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"

KV=KV+1
EndProc


;*******************************************************************************
;* Rotina Monta Aray Grade                                                     *
;*******************************************************************************
Proc Verifica_Array_Grade()
Private i,wsite,CODANTERIOR

WSREF =[Codigo do Item]
COLUNA=0
                
Moveto [Codigo do Item]
If Not BUSCA_LOOKUP("Codigo do Item",[Codigo do Item],"Item n„o Cadastrado !")
   Then Return
EndIf

WSREF=REG_BUSCA_LOOKUP["Referencia"]

Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
Locate REG_BUSCA_LOOKUP["Codigo da Grade"]
If Not RetVal
   Then Mensagem("Item "+[FaturaI->Codigo do Item]+" sem grade definida !")
        Return
   Else CopyToArray REG_BUSCA_LOOKUP
EndIf

Moveto "FaturaI"
Array_TM[1] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item1"]))
Array_TM[2] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item2"]))
Array_TM[3] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item3"]))
Array_TM[4] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item4"]))
Array_TM[5] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item5"]))
Array_TM[6] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item6"]))
Array_TM[7] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item7"]))
Array_TM[8] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item8"]))
Array_TM[9] =LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item9"]))
Array_TM[10]=LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item10"]))
Array_TM[11]=LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item11"]))
Array_TM[12]=LTrim(RTrim(REG_BUSCA_LOOKUP["Codigo Item12"]))

For i from 1 to 12
  If Not IsBlank(WSREF)
     Then QuitLoop
  EndIf
  If LTrim(RTrim(SubStr(Array_TM[i],1,2)))<>""
     Then If Len(Array_TM[i])=1
             Then CODANTERIOR=SubStr([Codigo do Item],1,7)+"00"+Array_TM[i]
             Else CODANTERIOR=SubStr([Codigo do Item],1,6)+"00"+Array_TM[i]
          EndIf
          If BUSCA_LOOKUP("Codigo do Item",CODANTERIOR,"SM")
             Then WSREF=REG_BUSCA_LOOKUP["Referencia"]
          EndIf
  EndIf
EndFor       

For i from 1 to 12
  If Len(RTrim(SubStr(Array_TM[i],1,2)))=1
     Then If SubStr([Codigo do Item],10,1)=SubStr(Array_TM[i],1,1)
             Then Coluna=i
                  QuitLoop
          EndIf
     Else If SubStr([Codigo do Item],9,2)=SubStr(Array_TM[i],1,2)
             Then Coluna=i
                  QuitLoop
          EndIf
  EndIf
EndFor

EndProc

;*******************************************************************************
;* Verifica as Grades no Pedido                                                *
;*******************************************************************************
Proc Verifica_Grades()
Private wc,gok

DynArray Array_Grade[]

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
  gok=False 
  
  Moveto [Codigo do Item]
  Ativa_Lookup()
  Moveto [Codigo do Item]
  Locate [FaturaI->Codigo do Item]
  If RetVal
     Then COD_GRADE=[Codigo da Grade]
  EndIf
  KeyPress "ESC"

  For wc From 1 to DynArraySize(Array_Grade)
    If Array_Grade[wc]=COD_GRADE
       Then gok =True
    EndIf
  EndFor
  If Not gok
     Then Array_Grade[DynArraySize(Array_Grade)+1]=Completa(COD_GRADE,1," ")
  EndIf

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Array array_tittm[12]
Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
For wc From 1 to DynArraySize(Array_Grade)
  Locate SubStr(Array_Grade[wc],1,1)         
  If RetVal
     Then array_tittm[1] =[Titulo Grade1 ]
          array_tittm[2] =[Titulo Grade2 ]
          array_tittm[3] =[Titulo Grade3 ]
          array_tittm[4] =[Titulo Grade4 ]
          array_tittm[5] =[Titulo Grade5 ]
          array_tittm[6] =[Titulo Grade6 ]
          array_tittm[7] =[Titulo Grade7 ]
          array_tittm[8] =[Titulo Grade8 ]
          array_tittm[9] =[Titulo Grade9 ]
          array_tittm[10]=[Titulo Grade10]
          array_tittm[11]=[Titulo Grade11]
          array_tittm[12]=[Titulo Grade12]
     Else For i From 1 to 12
            array_tittm[i]=""
          EndFor
  EndIf

  Array_Grade[wc]=Array_Grade[wc]+"|"+
                  Format("W4,AR",array_tittm[01])+"|"+
                  Format("W4,AR",array_tittm[02])+"|"+
                  Format("W4,AR",array_tittm[03])+"|"+
                  Format("W4,AR",array_tittm[04])+"|"+
                  Format("W4,AR",array_tittm[05])+"|"+
                  Format("W4,AR",array_tittm[06])+"|"+
                  Format("W4,AR",array_tittm[07])+"|"+
                  Format("W4,AR",array_tittm[08])+"|"+
                  Format("W4,AR",array_tittm[09])+"|"+
                  Format("W4,AR",array_tittm[10])+"|"+
                  Format("W4,AR",array_tittm[11])+"|"+
                  Format("W4,AR",array_tittm[12])+"|"
EndFor

Release Vars wc,wi,gok,array_tittm
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"RO_0232f.Txt"
If IsFile(ArqImp)
   Then Run NoRefresh "Del "+ArqImp
EndIf

Array Array_TM[12]

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)

Do_It!

TABELA_TEMP=Cria_Tabela("","Numero da OF(A6*),Sequencia(S*),Referencia(A20*),Codigo do Item(A10),Codigo da Cor_Tecido(A4),"+
"Preco Unitario($),Descricao do Item(A100),Descricao da Cor_Tecido(A20),Qtd1(S),Qtd2(S),Qtd3(S),Qtd4(S),Qtd5(S),Qtd6(S),Qtd7(S),Qtd8(S),Qtd9(S),"+
"Qtd10(S),Qtd11(S),Qtd12(S),Quantidade(N),Unidade Fiscal(A4),Preco Total($),Aliquota de IPI(N),Aliquota de ICMS(N),Peso Liquido(N),Peso Embalagem(N),Volumes(N)")

Adiciona_Indice_Secundario(TABELA_TEMP,"Indftgrd","Codigo do Item,Codigo da Cor_Tecido,Preco Unitario,Numero da OF,Sequencia")


CoEditKey

{TableAdd} TypeIn TABELA_TEMP Enter
{TableAdd} "\\Sistemas\\Estoque\\TpGrade" Enter

SEQG=1
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]

  Verifica_Array_Grade()
  Moveto "FaturaI"

  WSCOR =[Codigo da Cor_Tecido]
  WSPRU =[Preco Unitario      ]

  Moveto TABELA_TEMP
  Moveto [Codigo do Item]
  Locate IndexOrder by "Indftgrd" WSREF
  If Not RetVal
     Then End
          Down
          [Numero da OF           ]=[FaturaI->Numero da OF           ]
          [Sequencia              ]=BlankNum()
          [Referencia             ]=WSREF
          [Codigo do Item         ]=WSREF
          [Codigo da Cor_Tecido   ]=[FaturaI->Codigo da Cor_Tecido   ]
          [Preco Unitario         ]=[FaturaI->Preco Unitario         ]
          [Descricao do Item      ]=[FaturaI->Descricao do Item      ]

          [Descricao do Item]=Substr([FaturaI->Descricao do Item],1,23)

          [Descricao da Cor_Tecido]=[FaturaI->Descricao da Cor_Tecido]
          [Unidade Fiscal         ]=[FaturaI->Unidade Fiscal         ]
          SEQG=SEQG+1
  EndIf

  Switch
    Case Coluna=0 : [Qtd1  ]=[Qtd1  ]+[FaturaI->Quantidade]
    Case Coluna=1 : [Qtd1  ]=[Qtd1  ]+[FaturaI->Quantidade]
    Case Coluna=2 : [Qtd2  ]=[Qtd2  ]+[FaturaI->Quantidade]
    Case Coluna=3 : [Qtd3  ]=[Qtd3  ]+[FaturaI->Quantidade]
    Case Coluna=4 : [Qtd4  ]=[Qtd4  ]+[FaturaI->Quantidade]
    Case Coluna=5 : [Qtd5  ]=[Qtd5  ]+[FaturaI->Quantidade]
    Case Coluna=6 : [Qtd6  ]=[Qtd6  ]+[FaturaI->Quantidade]
    Case Coluna=7 : [Qtd7  ]=[Qtd7  ]+[FaturaI->Quantidade]
    Case Coluna=8 : [Qtd8  ]=[Qtd8  ]+[FaturaI->Quantidade]
    Case Coluna=9 : [Qtd9  ]=[Qtd9  ]+[FaturaI->Quantidade]
    Case Coluna=10: [Qtd10 ]=[Qtd10 ]+[FaturaI->Quantidade]
    Case Coluna=11: [Qtd11 ]=[Qtd11 ]+[FaturaI->Quantidade]
    Case Coluna=12: [Qtd12 ]=[Qtd12 ]+[FaturaI->Quantidade]
  EndSwitch
  [Preco Total]=[Preco Unitario]*([Qtd1]+[Qtd2]+[Qtd3]+[Qtd4]+[Qtd5]+[Qtd6]+
                                  [Qtd7]+[Qtd8]+[Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])
  UnLockRecord

  Moveto "FaturaI"
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

Verifica_Grades()
IMPFAT()

;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

Do_It!
Moveto TABELA_TEMP
ClearImage
Delete TABELA_TEMP
Moveto "\\Sistemas\\Estoque\\TpGrade"
ClearImage

Moveto "FaturaC"
CoEditKey
Release Vars VALOR,DATA,ARRAY_TM,WSREF,COLUNA, NPAG, NLINHA, NFP
Release Procs IMPFAT,VENC,Verifica_Array_Grade, Cabecalho, Rodadpe
LIMPAGUARDE()
