;** Ro_0037b ********************************************************************
;** Imprime a Digitacao do Orcamento                        ** UNITEC **       *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 02/07/98 por Anivel Augusto Rodrigues
;Ultima Alteracao: 15/08/2006 por Nikolas M. Mateus
;Motivo Alteracao: Somar o valor dos servicos no total e ajustes
;Ultima Alteracao: 12/05/2008 por Nikolas
;Motivo Alteracao: inclusao forma de pagamento
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPORC()

Moveto "FaturaC"
;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP ASP1+CI_10CPP+ASP2
Print File ARQIMP ASP1+CI_IEXP
Print File ARQIMP  "UNITEC Telefonia e Inform tica Ltda."+ASP2+"\n"
Print File ARQIMP ASP1+CI_FEXP
Print File ARQIMP CI_15CPP
Print File ARQIMP Spaces(01)+ "  Av. Vinte e Um de Abril, 368 - CEP 35500-010  Centro Divinopolis. Pabx (37) 3222-6755"+ASP2+"\n\n"
Print File ARQIMP ASP1+CI_10CPP
Print File ARQIMP  " ORCAMENTO n§ "+ Format("W06.3,AL",NOTAFISC)
Print File ARQIMP "  Emissao: "+Format("D13",[Data de Emissao])+Spaces(05)
Print File ARQIMP Format("W21,AL",[Nome Fantasia Represent]) +ASP2+"\n\n"


Print File ARQIMP ASP1+" Cliente "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W35,AL",[Razao Social])
Print File ARQIMP Format("W20,AL",[Nome do Autorizado])+ASP2+"\n"

Print File ARQIMP ASP1+" End     "
Print File ARQIMP Format("W40,AL",[Endereco])
Print File ARQIMP Format("W20,AL",[Bairro])+Spaces(2)+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(09)+Format("W20,AL",[Cidade])+"-"
Print File ARQIMP Format("W2,AL",[UF])+Spaces(1)
Print File ARQIMP "CEP "+Format("W10,AL",[CEP])+Spaces(2)
Print File ARQIMP "Fone "+Format("W14,AL",[Telefone])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(09)+Format("W20,AL",[CGC])+Spaces(2)
Print File ARQIMP Format("W15,AL",[IE])+ASP2+"\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP ASP1+"--------------------------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+" Qtde   Un Codigo     Descricao                            Vlr Unit     Total   "+ASP2+"\n"
Print File ARQIMP ASP1+"------- -- ----------------------------------------------- ---------- ----------"+ASP2+"\n"
LINHA=0

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
   Print File ARQIMP ASP1+Format("W07.2,EIC",[Quantidade])+Spaces(01)
   Print File ARQIMP Format("W03,AL",[Unidade Fiscal])
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W36,AL",[Descricao do Item])
   Print File ARQIMP Format("W11.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+ASP2+"\n"
   LINHA=LINHA+1
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile
While LINHA<6
   Print File ARQIMP ASP1+ASP2+"\n"
   LINHA=LINHA+1
EndWhile

Print File ARQIMP ASP1+Spaces(62)+"Total.."+Format("W11.2,EIC",[FaturaC->Valor Mercadoria])+ASP2+"\n"
Print File ARQIMP ASP1+ "-------------------------------------------------------------------------------"+ASP2+"\n"

Moveto"FaturaC"
Print File ARQIMP ASP1+" Condi‡”es de pagamentos     "
Print File ARQIMP Format("W20,AL",[Descricao CondPagto])
Print File ARQIMP "  FP: "+[Forma de Pagamento]
Print File ARQIMP "  Desconto"+Format("W06.2,EIC",[Taxa de Desconto])+"%.."+Spaces(01)
Print File ARQIMP Format("W10.2,EIC",[Valor Desconto])+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(62)+"Total.."+Format("W11.2,EIC",[Valor Nota Fiscal])+ASP2+"\n"

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP " Vencimentos: "

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("W10.2,AR,EIC",[Valor])
  If K=9
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()
EndIf

Moveto"FaturaC"
Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+" Obs: "
Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,75))+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(02)+"                     -   /   /   "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"---------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"   Assinatura/Data do Cliente"+ASP2+"\n"

Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+CI_10CPP
Print File ARQIMP CI_6LPP+ASP2

EndProc

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

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*****************+*************************************************************
ArqImp=PrivDir()+"RO_0037B.Txt"
ASP1=""
ASP2=""
Switch
  Case OK="A":
       ARQIMP = DIREPORT+ARQUIVO+".TXT"
  Case OK="V": ASP1="\""
               ASP2="\""
EndSwitch
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
;IMPORC()
If OK="V"
  Then Tabela=Cria_Temp(PrivDir())
       {Tools} {Copy} {Table} {\\Base\\Sistemas\\Compras\\Rm_tx250} TypeIn Tabela Enter
       {Tools} {ExportImport} {Import} {ASCII} {AppendDelimited} TypeIn ARQIMP Enter
       TypeIn Tabela Enter ClearImage
       IMPRIREL(Tabela,"R")
       Deleta_Arquivo(ARQIMP)
       Delete Tabela
       View "FaturaI"
       CoEdit "FaturaC"
   Else If OK="I"
           Then AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
           IMPORC()

;---- Imprime Arquivo Impressao ------------------------------------------------
      ImpriArq(ARQIMP)
      Mensagem ("Impress„o Concluida!")
      EndIF
      EndIF
      Release Vars VALOR,DATA,CLIENTE
      Release Procs IMPORC
      LIMPAGUARDE()
