;** ROE_322 ********************************************************************
;** Imprime a Digitacao do Romaneio em impressora T‚rmica EPSON                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 05/12/2019 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                 
;Motivo Alteracao:

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

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

Pega_Endereco_Fatura([FaturaC->Numero da OF])                

Moveto "FaturaC"
Print File ARQIMP EPSON_INICIALIZA_IMPRESSAO
Print File ARQIMP Fill("=",48)+"\n"
Print File ARQIMP "EMISSAO: "+Format("D13",Today())+"-"+Time()+"  "+"   NUMERO:  "+Format("W06.3,AL",NOTAFISC)+"\n\n"
Print File ARQIMP EPSON_NEG_ON
Switch
  Case Search("DEV",[Descricao da Destinacao])>0            : Print File ARQIMP Format("W48,AC","DEVOLU€ˇO       ** DOCUMENTO SEM VALOR FISCAL ** ")
  Case Search("SIMPLES REMESSA",[Descricao da Destinacao])>0: Print File ARQIMP Format("W48,AC","SIMPLES REMESS  ** DOCUMENTO SEM VALOR FISCAL **")
  Case [Codigo da Destinacao]<>""                           : Print File ARQIMP Format("W48,AC","PEDIDO          ** DOCUMENTO SEM VALOR FISCAL **")
  OtherWise                                                 : Print File ARQIMP Format("W48,AC","PEDIDO          ** DOCUMENTO SEM VALOR FISCAL **") 
EndSwitch
Print File ARQIMP EPSON_NEG_OFF
Print File ARQIMP "\n"

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

CLIENTE=[Razao Social]
Print File ARQIMP Spaces(01)+"CLIENTE.: "
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W31,AL",[Razao Social])+"\n"
Print File ARQIMP Spaces(11)+Format("W22,AL",[CGC])+Format("W15,AL",[Telefone])+"\n"
Print File ARQIMP Spaces(01)+"ENDERECO: "+ Format("W36,AL",[Endereco])+"\n"
Print File ARQIMP Spaces(11)             + [Bairro]+ ","+[Cidade]+","+[UF]+"\n"

;********** PARCELAS/VENCIMENTOS ********************
Print File ARQIMP Fill("-",48)+"\n"
Print File ARQIMP Spaces(01)+"PARCELA"+Spaces(05)+"ND"+Spaces(05)+"VENCIMENTO"+Spaces(07)+"VALOR"+Spaces(02)+"FP"+"\n"

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
   Then While ([Numero da OF]=[FaturaC->Numero da OF])
          Print File ARQIMP Spaces(4)+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
EndIf

;******************************** IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Fill("-",48)+"\n"
Print File ARQIMP " CODIGO     DESCRICAO                      UF"+"\n"                
;                 " 1234567890 123456789012345678901234567890 12"
Print File ARQIMP "  Quantidade   VrUnitario      VrTotal      "+"\n"
;                 " 12345678901 123456789012 123456789012 "
Print File ARQIMP Fill(chr(196),48)+"\n"

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
CONTA = 0
QUANT = 0
TOT   = 0
While [Numero da OF]=[FaturaC->Numero da OF]
  Print File ARQIMP Spaces(01)+Format("W10",[Codigo do Item])+""+Format("W30",[Descricao do Item])+"  "+[Unidade Fiscal]+"\n"
  Print File ARQIMP Spaces(01)+Format("W11.3,EIC",[Quantidade])+" "+Format("W12.2,EIC",[Preco Unitario])+" "+Format("W12.2,EIC",[Preco Total])+"\n"
  If Not IsBlank([Informacoes_Adicionais])
     Then Print File ARQIMP Spaces(01)+Format("W46,AL","Inf. Item: "+SubStr([Informacoes_Adicionais],1,35))+"\n"
          If Not IsBlank(SubStr([Informacoes_Adicionais],36,46))
             Then Print File ARQIMP Spaces(01)+Format("W46,AL",SubStr([Informacoes_Adicionais],36,46))+"\n"
          EndIf   
  EndIf
  CONTA = CONTA + 1
  QUANT = QUANT+[Quantidade]
  TOT   = TOT+[Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Moveto "FaturaC"
Print File ARQIMP " ÄÄÄÄÄÄÄÄÄÄÄ              ÄÄÄÄÄÄÄÄÄÄÄÄ      "+"\n"
Print File ARQIMP Spaces(01)+Format("W11,EIC",CONTA)
If QUANT>1
   Then Print File ARQIMP " No itens"
   Else Print File ARQIMP " No item "  
EndIf
Print File ARQIMP Spaces(5)+Format("W12.2,EIC",TOT)+"\n"
Print File ARQIMP Fill("-",48)+"\n"

Print File ARQIMP "MERCADORIAS: "+Format("W11.2,EIC",[Valor Mercadoria])+Spaces(01)+"DESCTO: "+Format("W9.2,EIC",[Valor Desconto])+"\n"
Print File ARQIMP "SERVICO....: "+Format("W11.2,EIC",[Valor Servico])   +Spaces(01)+"DESCTO: "+Format("W9.2,EIC",[Valor Desconto Servico])+"\n"
Print File ARQIMP "FRETE......: "+Format("W11.2,EIC",[Valor do Frete])+"\n\n"
Print File ARQIMP "A PAGAR....: "
Print File ARQIMP CI_IEXP
Print File ARQIMP Format("W11.2,EIC",[Valor Nota Fiscal])+"\n\n"
Print File ARQIMP CI_FEXP

If IsAssigned(VSD_VrTroco)
   Then Print File ARQIMP Spaces(01)+"RECEBIDO..: "+Format("W11.2,EIC",VSD_VrTroco)+"\n"
        Print File ARQIMP Spaces(01)+"TROCO.....: "+Format("W11.2,EIC",VrTroco)+"\n"
EndIf

If Not Isblank(SubStr([Observacao na Nota Fiscal],001,36))
   Then Print File ARQIMP "OBS: "
        Moveto "FaturaC"
        Print File ARQIMP Format("W36,AL",SubStr([Observacao na Nota Fiscal],001,36))+"\n"
        If Not IsBlank (SubStr([Observacao na Nota Fiscal],037,47))
           Then Print File ARQIMP Format("W47,AL",SubStr([Observacao na Nota Fiscal],037,47))+"\n"
                If Not IsBlank(SubStr([Observacao na Nota Fiscal],84,47))
                   Then Print File ARQIMP Format("W47,AL",SubStr([Observacao na Nota Fiscal],84,47))+"\n"
                        If Not IsBlank(SubStr([Observacao na Nota Fiscal],131,47))
                           Then Print File ARQIMP Format("W47,AL",SubStr([Observacao na Nota Fiscal],131,47))+"\n"
                        EndIf 
                EndIf
        EndIf
EndIf

Print File ARQIMP "\n\n"
Print File ARQIMP Spaces(04)+Fill("-",40)+"\n"
Print File ARQIMP Spaces(04)+Format("W40,AC",CLIENTE)+"\n"
Print File ARQIMP "\n\n\n\n\n\n"
Print File ARQIMP EPSON_GUILHOTINA

EndProc ; (IMPRO)

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

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

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

Release Procs TESTE