;** Or_0334 ********************************************************************
;** Imprime a Digitacao do Orcamento                        ** CASA FONSECA ** *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 19/08/1997 por Ricardo Augusto Silva
;Alterado em     : 19/02/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Alterado em     : 26/02/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes sem impostos
;Alterado em     : 19/09/2014 por Andrey Fillipe
;Motivo Alteracao: Ajustes para sair impressao em meia folha
;Alterado em     : 15/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes mensagem e negritos

;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(Nl)
private nl,tabela

tabela=table()

If (CONTADOR+nl)>31
   Then While CONTADOR < 31
          Print File ARQIMP "\n"
          CONTADOR=CONTADOR+1
        EndWhile
        Print File ARQIMP "\n"
        Print File ARQIMP Format("W117,AC","   * * * *  CONTINUA NO PROXIMO FORMULARIO * * * *    ")+"\f"

        Cabecalho()     
        Moveto tabela
   Else CONTADOR=CONTADOR+nl
EndIf

EndProc ;Checa_Linha()

;*******************************************************************************
;* Rotina para Impressao do cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()

Moveto "OrcaC"
CoEditKey

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

Print File ARQIMP ASP1+CI_15CPP
Print File ARQIMP ASP2+"\n"
Print File ARQIMP ASP1+"  ------------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+Format("W40,AL",NOMEMPRESA)+Spaces(15)+"Orcamento"+Spaces(38)+"Impressao: "+Format("D13",Today())+"-"+Time()+ASP2+"\n"
Print File ARQIMP ASP1+ "  ------------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Cliente: "
Print File ARQIMP CI_INEG+Format("W05,AL",[Codigo])
Print File ARQIMP Format("W70,AL",[Razao Social])
Print File ARQIMP CI_IEXP+"N§ do Orcamento: " +Format("W06.3,AL",[Numero do Orcamento])+CI_FEXP+CI_FNEG+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(16)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao : "
Print File ARQIMP Format("D13",[Data de Emissao])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(16)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])
Print File ARQIMP "Validade: "+Format("D13",[Data de Validade])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(16)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP "Empresa : "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+ASP2+"\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])
Print File ARQIMP "TabPreco: "+Format("W06,AL",[Codigo da Tabela])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(02)+"Transportador: "+Format("W05,AL",[Codigo da Transportadora])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Transport])
Print File ARQIMP Spaces(29)+"Frete por Conta: "+Format("W15,AL",[Frete por Conta])+ASP2+"\n\n"

CONTADOR=15

EndProc

;*******************************************************************************
;* Rotina para Impressao dos itens                                             *
;*******************************************************************************            
Proc Itens()

Moveto "OrcaI"
Print File ARQIMP ASP1+Spaces(02)+"Sq Item                                                          Quantidade  Un PrUnitario    PrTotal "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"-- ------------------------------------------------------------- ----------- -- ---------- ---------- "+ASP2+"\n"
Scan
  Checa_Linha(1)
  Moveto [Codigo do Item]
  If Busca_Lookup("Codigo do Item",[OrcaI->Codigo do Item],"")
     Then DescrItem=Reg_Busca_Lookup["Descricao Complementar"]
     Else DescrItem=[Descricao do Item]
  EndIf
  UnLockRecord
   If CONTADOR = 15
      Then Print File ARQIMP ASP1+Spaces(02)+"Sq Item                                                          Quantidade  Un PrUnitario    PrTotal "+ASP2+"\n"
           Print File ARQIMP ASP1+Spaces(02)+"-- ------------------------------------------------------------- ----------- -- ---------- ---------- "+ASP2+"\n"
           CONTADOR = CONTADOR + 1
   EndIf
   Print File ARQIMP ASP1+Spaces(01)+Format("W03,AL",[Item do Orcamento])
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W51,AL",DescrItem)
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+ASP2+"\n"
EndScan
                      
Release Vars DescrItem

EndProc

;*******************************************************************************
;* Rotina para Impressao do rodape                                             *
;*******************************************************************************            
Proc Rodape()

Checa_Linha(10)

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "OrcaC"
Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+"  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces         Total"+ASP2+"\n"
;;9.999.999,99888.88%777.777,776.666.666,6644.444,44111.111,112.222.222,223.333.333,334.444.444,441.111.111,11

Print File ARQIMP ASP1+Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W09.2,EIC",[Valor do Frete])
Print File ARQIMP Format("W10.2,EIC",[Valor do Seguro])
Print File ARQIMP Format("W012.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Format("W014.2,EIC",[Valor Nota Fiscal])+ASP2+"\n\n"

Moveto"Orcacpg"
Aux=true
Scan
If Aux
   Then Print File ARQIMP ASP1+CI_INEG+Spaces(02)+"Cond. Pagamento.: "
        Aux=false
   Else Print File ARQIMP ASP1+CI_INEG+Spaces(20)
endif
Print File ARQIMP Format("W20,AL",[Descricao CondPagto])
Print File ARQIMP "   Vr Total: "+Format("W012.2,EIC",[Orcac->Valor Nota Fiscal]+(([Orcac->Valor Nota Fiscal]*[Taxa Financeira])/100))+CI_FNEG+ASP2+"\n"

EndScan

;************************* IMPRESSAO DO RODAPE ********************************
Moveto "OrcaC"
Print File ARQIMP ASP1+Spaces(02)+"Observacao......: "+Format("W110,AL",SubStr([Observacao do Orcamento],001,110))+ASP2+"\n"
If Substr([Observacao do Orcamento],111,110)<>""
   Then Print File ARQIMP ASP1+Spaces(20)+Format("W110,AL",SubStr([Observacao do Orcamento],111,110))+ASP2+"\n"
EndIf

Print File ARQIMP ASP1+CI_INEG+Format("W77,AC","*** Parcele sua compra em ate 24x com Cartao GMinas ***")+CI_FNEG+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(80)+"_______________________________________________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(90)+"Data/Assinatura Responsavel"+ASP2+"\n\n"
Print File ARQIMP ASP1+ "  ------------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
Print File ARQIMP "\f"+ASP2

EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

Seta_FilePrint("OR_0334")
Cabecalho()
Itens()
Rodape()
Do_It!
Imprime_FilePrint("Imprimindo Orcamento -> "+ORCA,"1")

Release Vars VALOR,DATA, CONTADOR, DescrItem, K, KV, ArqImp
Release Procs Checa_Linha, Cabecalho, Itens, Rodape