;** Ro_0339 ********************************************************************
;** Imprime a Digitacao do Romaneio               Deposito Pioneiro            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 24/06/2013 por Kamila Gomes
;Ultima Alteracao: 31/08/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes desconto item
;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 "FaturaC"

Print File ARQIMP CI_15CPP
Print File ARQIMP CI_8LPP

Print File ARQIMP "\n"

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

Print File ARQIMP Spaces(02)+"CLIENTE.: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W40,AL",[Razao Social])+"\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)+"\n"


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

DESCONTO=0

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W34,AL",[Descricao do Item])
   Print File ARQIMP Format("W03,AL",[Unidade Fiscal])
   Print File ARQIMP Format("W10.2,EIC",[Quantidade])+Spaces(01)
   Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Quantidade]*[Preco Unitario])+"\n"
                                                                     
   DESCONTO = DESCONTO+[Valor Desconto Item    ]          ;Total Desconto Item          

   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

Moveto "FaturaC"
TOTD=(([Valor Desconto]+DESCONTO)*100)/([Valor Mercadoria]+DESCONTO)

Print File ARQIMP Spaces(74)+"------"+"\n"
Print File ARQIMP Spaces(69)+Format("W11.2,EIC",[Valor Mercadoria]+DESCONTO)+"\n"
Print File ARQIMP Fill("-",80)+"\n"
Print File ARQIMP Spaces(02)+"VR.MERCADORIAS: "+Format("W11.2,EIC",[Valor Mercadoria]+DESCONTO)+     
                  Spaces(05)+"VR.DESCTO: "+Format("W10.2,EIC",[Valor Desconto]+DESCONTO)+
                  Spaces(05)+"VR.FRETE.: "+Format("W10.2,EIC",[Valor do Frete])+"\n"
Print File ARQIMP Spaces(02)+Format("W21,AL",[Descricao CondPagto])     
Print File ARQIMP Spaces(08)+"   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_15CPP
Print File ARQIMP Fill("-",80)+"\n\n\n"
Print File ARQIMP Spaces(17)+Fill("-",40)+"\n"
Print File ARQIMP Chr(27)+Chr(98)
Print File ARQIMP Spaces(17)+Format("W40,AC",CLIENTE)+"\n\n\n\n"

Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_15CPP
Print File ARQIMP Fill("=",79)+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
Print File ARQIMP CI_INEG

Switch                                                                                                          
  Case Search("DEVOL",[Descricao da Destinacao])>0           : Print File ARQIMP Spaces(07)+"DEVOLUCAO"
  Case Search("SIMPLES REMESSA",[Descricao da Destinacao])>0 : Print File ARQIMP Spaces(04)+"SIMPLES REMESSA"
  Case Search("VEND",[Descricao da Destinacao])>0            : Print File ARQIMP Spaces(07)+"OR€AMENTO" 
  OtherWise                                                  : Print File ARQIMP Format("W30,AL",[Descricao da Destinacao])
EndSwitch

Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_15CPP
Print File ARQIMP "\n"
Print File ARQIMP Spaces(17)+"DOCUMENTO NAO FISCAL - EXIJA O CUPOM FISCAL"+"\n"

Print File ARQIMP Fill("=",79)+"\n"
Print File ARQIMP Spaces(17)+"         AGRADECEMOS A PREFERENCIA"+"\n"
Print File ARQIMP Fill("-",80)+"\n"

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
EndProc ; (IMPRO)

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

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)

IMPRO()

;ImpressÆo de 2 Vias de Romaneio (Alterado em 12/09/2011)
;For j From 1 To 2
;  If j=2 
;     Then Print File ARQIMP "\n\n\n\n"
;  EndIf
;  IMPRO()
;EndFor
Print File ARQIMP "\n\n"

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

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

