;** Ro_0152********************************************************************
;** Imprime a Digitacao do Romaneio               CINDERELA                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 26/12/2002 por Karen Lauar Nery
;Alterado em     : 21/02/2006 por Nikolas M. Mateus
;Motivo Alteracao: Ajustes
;Alterado em     : 20/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

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

Moveto "Answer"


Print File ARQIMP CI_8LPP
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_20CPP
Print File ARQIMP "\n"
Print File ARQIMP Fill("=",61)+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
Print File ARQIMP CI_INEG

Switch
  Case Search("DEV",[Descricao da Destinacao])>0            : Print File ARQIMP "DEVOLU€ŽO"
  Case Search("SIMPLES REMESSA",[Descricao da Destinacao])>0: Print File ARQIMP "SIMPLES REMESSA"
  Case [Codigo da Destinacao]="005"                         : Print File ARQIMP Format("W30,AL",[Descricao da Destinacao])
  Case Search("VEND",[Descricao da Destinacao])>0           : Print File ARQIMP "2¦ VIA CUPOM"
  OtherWise                                                 : Print File ARQIMP Format("W30,AL",[Descricao da Destinacao])
EndSwitch
Print File ARQIMP CI_20CPP

Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
;Print File ARQIMP Spaces(10)+Username()
Print File ARQIMP "\n"

Print File ARQIMP Spaces(01)+"EMISSAO: "+Format("D13",Today())+"-"+Time()+" "+
                  "VEND: "+Format("W11,AL",[Nome Fantasia Represent])+
                  " NUMERO: "+Format("W06.3,AL",NOTAFISC)+"\n"

Print File ARQIMP Fill("-",61)+"\n"

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

Print File ARQIMP Spaces(02)+"AUTORIZ.: "+Format("W42,AL",[Nome do Autorizado])+Format("W20,AL",[CPF do Autorizado])+"\n"
CLIENTE=[Razao Social]
Print File ARQIMP Spaces(02)+"ENDERE€O: "+ Format("W40,AL",[Endereco])+"\n"
Print File ARQIMP Spaces(02)+"BAIRRO..: "+ Format("W20,AL",[Bairro])+
"FONE: " + Format("W20,AL",[Telefone])+"\n"
Print File ARQIMP Spaces(02)+"CIDADE..: "+Format("W20,AL",[Cidade])+Spaces(30)
Print File ARQIMP "\n\n"

;END_ENT=[Endereco de Entrega]
;BAI_ENT=[Bairro de Entrega  ]
;CID_ENT=[Cidade de Entrega  ]
;CEP_ENT=[CEP de Entrega     ]

;If IsBlank(END_ENT) Then END_ENT=[Endereco] EndIf
;If IsBlank(BAI_ENT) Then BAI_ENT=[Bairro  ] EndIf
;If IsBlank(CID_ENT) Then CID_ENT=[Cidade  ] EndIf
;If IsBlank(CEP_ENT) Then CEP_ENT=[Cep     ] EndIf

;Print File ARQIMP Spaces(02)+"ENTREGA.: "+Format("W33,AL",END_ENT)+Spaces(02)+"BAIRRO: "+Format("W20,AL",BAI_ENT)+"\n"
;Print File ARQIMP Spaces(02)+"CIDADE DE ENTREGA: "+Format("W20,AL",CID_ENT)+Spaces(09)+"CEP: "+Format("W10,AL",CEP_ENT)+"\n\n"

Print File ARQIMP Spaces(02)+"OBS...:"
Moveto "Answer"
If SubStr([Observacao na Nota Fiscal],001,73)<>""
   Then Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,73))+"\n"
EndIf
If SubStr([Observacao na Nota Fiscal],074,73)<>""
   Then Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],074,73))+"\n"
EndIf
If SubStr([Observacao na Nota Fiscal],147,73)<>""
   Then Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],147,73))+"\n"
EndIf
If SubStr([Observacao na Nota Fiscal],220,73)<>""
   Then Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],220,73))+"\n"
EndIf

;********** PARCELAS/VENCIMENTOS ********************

Print File ARQIMP Fill("-",50)+"\n"
Print File ARQIMP Spaces(09)+"PARCELA"+Spaces(05)+"ND"+Spaces(05)+"VENCIMENTO"+Spaces(07)+"VALOR"+Spaces(02)+"FP"+"\n"

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])
  Print File ARQIMP Spaces(12)+AlinhM([Sequencia],2)+Spaces(05)+Format("W4",[Numero de Dias])+
                    Spaces(05)+ Format("D13",[Data])+Spaces(01)+Format("W11.2,EIC",[Valor])+Spaces(02)+Format("W2",[Forma de Pagamento])+"\n"
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

;******************************** IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Fill("=",61)+"\n"
 Print File ARQIMP " PRODUTO                       UF    QUANT  Vr.Unit  Vr.Total"+"\n"

QUANT=0
TOT  =0

Moveto "Notai"
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])

   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W20,AL",[Descricao do Item])
   Print File ARQIMP Format("W03,AL",[Unidade Fiscal])
   Print File ARQIMP Format("W08.2,EIC",[Quantidade])+Spaces(01)
   Print File ARQIMP Format("W08.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W10.2,EIC",[Preco Total])+"\n"

   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

Moveto "Answer"
Print File ARQIMP Spaces(55)+"------"+"\n"
Print File ARQIMP Spaces(50)+Format("W11.2,EIC",[Valor Mercadoria]+[Valor Servico])+"\n"
Print File ARQIMP Fill("-",61)+"\n"

Print File ARQIMP Spaces(02)+"VR.MERCADORIAS: "+Format("W11.2,EIC",[Valor Mercadoria])+
                  Spaces(05)+"VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP Spaces(02)+"VR.SERVICO....: "+Format("W11.2,EIC",[Valor Servico])+
                  Spaces(05)+"VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto Servico])+"\n"

Print File ARQIMP Spaces(02)+"VR.FRETE......: "+Format("W11.2,EIC",[Valor do Frete])+"\n\n"

Print File ARQIMP Spaces(02)+"   VR A PAGAR.: "
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
Print File ARQIMP LTrim(Format("W11.2,EIC",[Valor Nota Fiscal]))+"\n\n"
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_20CPP
Print File ARQIMP Fill("-",61)+"\n\n\n"
Print File ARQIMP Spaces(10)+Fill("-",40)+"\n"
Print File ARQIMP Chr(27)+Chr(98)
Print File ARQIMP Spaces(10)+Format("W40,AC",CLIENTE)+"\n"
Print File ARQIMP Fill("-",61)+"\n"
Print File ARQIMP Spaces(05)+"NAO VALE COMO N.F PROCURE O CUPOM NO CAIXA"+"\n"
Print File ARQIMP Spaces(05)+"         AGRADECEMOS A PREFERENCIA"+"\n"
Print File ARQIMP Spaces(05)+"         ''NAO TEMOS COBRADOR''     "+"\n"
Print File ARQIMP Spaces(05)+ "     HAVERA AUMENTO APOS O VENCIMENTO "+"\n"

Print File ARQIMP Fill("-",61)+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

Print File ARQIMP CI_IEXP
Print File ARQIMP Spaces(05)+ "2¦ VIA"
Print File ARQIMP Fill("\n",03)
Print File ARQIMP CI_INEG

;Print File ARQIMP "\n\n\n\n\n\n\n\n\n\n"
EndProc ; (IMPRO)

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

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPRO()

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

Release Vars CLIENTE,END_ENT,BAI_ENT,CID_ENT,CEP_ENT
Release Procs IMPRO
LIMPAGUARDE()


