;** RO2v0022   *****************************************************************
;** Imprime a Digitacao do Romaneio 2a Via       ** Divinąpolis Botoes **      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 20/09/2017 por Kamila Gomes
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()
Linha = 1
;************************* IMPRESSAO DO CABECALHO *****************************

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP "\n"
Print File ARQIMP Format("W40,AL",NOMEMPRESA)+Spaces(04)+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"
;**********************
Linha = Linha + 2

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(17)+"2a Via "+[Tipo do Documento]+" N§ "+Format("W06.3,AL",[Numero do Documento])+"\n"
Print File ARQIMP "(0xx37) 3431-1200 "+"\n"
Print File ARQIMP "\020"
;**********************
Linha = Linha + 1

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

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

Print File ARQIMP Spaces(10)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+"\n"

Print File ARQIMP Spaces(10)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])+"\n"

Print File ARQIMP Spaces(10)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])+"\n\n"

;**********************
Linha = Linha + 1

Print File ARQIMP "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP ""+[Codigo da Destinacao]+" "+[Descricao da Destinacao]+"\n"
Print  File ARQIMP "Emissao..: "+Format("D13",[Data de Emissao    ])+"\n"
Print File ARQIMP Chr(27)+Chr(72)

;**********************
Linha = Linha + 2

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP "\015"

;**********************
Linha = Linha + 2

;********************* IMPRESSAO DOS ITENS ********************************

Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"Item                                                                           Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------"+"\n"
;**********************
Linha = Linha + 2

Moveto "NotaI"
Moveto [Codigo da Empresa]
Locate [Answer->Codigo da Empresa  ],
       [Answer->Numero do Documento],
       [Answer->Serie do Documento ]
       
QUANT    = 0
TOT      = 0
CONTADOR = 0
       
While [Codigo da Empresa  ]=[Answer->Codigo da Empresa  ] And
      [Numero do Documento]=[Answer->Numero do Documento] And
      [Serie do Documento ]=[Answer->Serie do Documento ]

  Print File ARQIMP Spaces(02)+Format("W03,AR",StrVal([Item do Documento]))
  Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W62,AL",[Descricao do Item])
  Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])
  Print File ARQIMP Spaces(02)+Format("W09.3,EIC",[Quantidade])
  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 12
    Print File ARQIMP "\n"
EndFor

Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"
;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "Answer"
Print File ARQIMP "\n"

Linha = Linha + 1

Print File ARQIMP Spaces(87)+"Total.............."+Format("W11.2,EIC",TOT)+"\n"

Print File ARQIMP Spaces(87)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP "          *** FAVOR MANTER O ENDERECO E O TELEFONE ATUALIZADOS ***"
Print File ARQIMP Spaces(21)+"Total Liquido......"+Format("W11.2,EIC",[Valor Nota Fiscal])+"\n\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"\n"

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP "\018"
Print File ARQIMP "\027E"
Print File ARQIMP "Vencimentos: "

Array DATA[9]
Array VALOR[9]
K=0
KV=0
Moveto "NotaV"
Moveto [Codigo da Empresa]
Locate [Answer->Codigo da Empresa  ],
       [Answer->Numero do Documento],
       [Answer->Serie do Documento ]

While [Codigo da Empresa  ]=[Answer->Codigo da Empresa  ] And
      [Numero do Documento]=[Answer->Numero do Documento] And
      [Serie do Documento ]=[Answer->Serie do Documento ]
  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
Print File ARQIMP "\n"
Print File ARQIMP "\027F"

;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP Spaces(12)+"   /   /     -                                   " + "\n"
Print File ARQIMP Spaces(12)+"-------------------------------------------------" + "\n"
Print File ARQIMP Spaces(12)+"              Data e Assinatura"+"\n"
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"
;**********************
Linha = Linha + 3

If Numero_Pagina = 1
   Then For ContLinha From Linha To 40
           Print File ARQIMP  "\n"
        EndFor
   Else Print File ARQIMP "\f"
EndIf
Print File ARQIMP Chr(27)+Chr(50)
Print File ARQIMP Chr(27)+Chr(18)

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                                                            *
;*******************************************************************************
CONTINUA_IMPRESSAO=True
Numero_Pagina=0
N_COPIAS=1
ArqImp=PrivDir()+"RO2aVia.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
AGUARDE("Imprimindo 2a Via Romaneio -> "+[Answer->Numero do Documento])
            Print File ARQIMP Chr(27)+Chr(48)
            Print File ARQIMP Chr(27)+Chr(18)
            IMPFAT()
;---- Imprime Arquivo Impressao ------------------------------------------------
          ImpriArq(ARQIMP)

          LIMPAGUARDE()

