;** RO_0340 ********************************************************************
;** Imprime a Digitacao do Romaneio                         ** Minas Oeste **  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 16/01/2013 por Bruno Carvalho
;Ultima Alteracao: 15/06/2016 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Pega_Endereco_Fatura() e ajustado dados do endere‡o
;Ultima Alteracao: 31/08/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes desconto item
;Ultima Alteracao: 19/10/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes celular        
;Ultima Alteracao: 30/04/2020 por Bruno Carvalho
;Motivo Alteracao: Sol. 54600 Imprimir em 2vias   

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT(PARAM)

;************************** IMPRESSAO DO CABECALHO *****************************
; 10 Itens no parametro
;*******************************************************************************

Moveto "FaturaC"
Pega_Endereco_Fatura([Numero da OF])

Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

Print File ARQIMP Format("W70,AL",StrVal(PARAM)+" VIA:"+" ORCAMENTO - MINAS OESTE - (37)3324-1497, (37)99942-1795")+"\n"
Print File ARQIMP                 "==========================================================================="+"\n"

Print File ARQIMP "\027E"
Print File ARQIMP " ENTREGA: "+Format("W34AL",VSD_E_Endereco)+"BAIRRO: " +Format("W15,AL",VSD_E_Bairro)+"\n" 
Print File ARQIMP "\027F"
Print File ARQIMP "\020"
Print File ARQIMP "   VENDA: "+Format("W12.3,AL",NOTAFISC)+Format("D10",Today())+"-"+Time()+ Spaces(02)+ "-" +Spaces(02)+"TEL: "+Format("W22,AL",[Telefone])+"\n"
Print File ARQIMP " CLIENTE: "+Format("W05,AL",[Codigo])+Format("W28,AL",[Razao Social])+" VENDEDOR: " +Format("W10,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP "ENDERECO: "+Format("W33,AL",[Endereco])+" BAIRRO: "+Format("W15,AL",[Bairro])+"\n"
Print File ARQIMP "  CIDADE: " +Format("W33,AL",[Cidade])+ " UF:" +Format("W03,AL",[UF])+ "\n"

Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "================================================================================================================================"+"\n"
Print File ARQIMP "Seq. Codigo     Descricao                                                       Un   Quantidade     Unitario         Total       "+"\n"
Print File ARQIMP "--------------------------------------------------------------------------------------------------------------------------------"+"\n"

CONTADOR = 0

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
  Print File ARQIMP Format("W03,AR",StrVal([Item da OF]))
  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 CI_INEG
  Print File ARQIMP Spaces(02)+Format("W02,Al",[Unidade Fiscal])
  Print File ARQIMP Spaces(01)+Format("W12.2,EIC",[Quantidade])
  Print File ARQIMP CI_FNEG

  Print File ARQIMP Spaces(01)+Format("W12.2,EIC",[Preco Unitario])
  Print File ARQIMP Spaces(01)+Format("W13.2,EIC",[Preco Total])+"\n"

  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 9
    Print File ARQIMP "\n"
EndFor
Print File ARQIMP "--------------------------------------------------------------------------------------------------------------------------------"+"\n"

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "FaturaC"

Print File ARQIMP "OBS.: "
Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,100))
Print File ARQIMP "\N"
Print File ARQIMP "Total.............."+Format("W11.2,EIC",[Valor Mercadoria])
Print File ARQIMP Spaces(02)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])
Print File ARQIMP Spaces(02)+"Frete............."+Format("W12.2,EIC",[Valor do Frete])
Print File ARQIMP Spaces(02)+"Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido]+[Valor do Frete])+"\n"
Print File ARQIMP "--------------------------------------------------------------------------------------------------------------------------------"+"\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 "\020"
Print File ARQIMP "\027E"
Print File ARQIMP "Vencimentos: "

Array DATA[12]
Array VALOR[12]
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=11
     Then VENC()
          K=0
          QuitLoop
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()  
EndIf

Print File ARQIMP "\027F"

;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP Spaces(22)+"   /   /     -                                   " + "\n"
Print File ARQIMP Spaces(01)+"Data e Assinatura: "
Print File ARQIMP "-----------------------------------------------------"

Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"
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(01)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(01)
EndFor
Print File ARQIMP "\n\n"

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0055.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
For oi From 1 To 2
  IMPRIMINDO_PARCELAS=FALSE
  NParc=[FaturaC->Numero de Parcelas]
  If NParc<1 Then NParc=1 EndIf

  For NP From 1 to NParc
    If [FaturaC->Forma de Pagamento]="NP"
       Then IMPRIMINDO_PARCELAS=TRUE
    EndIf
    IMPFAT(oi)
    If IMPRIMINDO_PARCELAS=False Then QuitLoop EndIf
  EndFor
EndFor
ImpriArq(ARQIMP)

Release Vars VALOR,DATA
Release Procs IMPFAT,VENC
LIMPAGUARDE()

