;** Or_0339 ********************************************************************
;** Imprime a Digitacao do Orcamento               ** DEPOSITO PIONEIRO **     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 11/02/2014 por Andrey Fillipe
;Alterado em     :   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina para Impressao do Relatorio - Cabecalho                              *
;*******************************************************************************
Proc Cabecalho()

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

Moveto "OrcaC"
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_15CPP
Print File ARQIMP CI_8LPP
Print File ARQIMP "\n"

GetRecord "\\Sistemas\\Cadastro\\Empresas" [OrcaC->Codigo da Empresa] To DynArray EMP
If RetVal
   Then TEL = EMP["Telefone Empresa"]
   Else TEL = ""
EndIf  

Print File ARQIMP CI_INEG
Print File ARQIMP Spaces(02)+"EMISSAO.: "+Format("D13",Today())+"-"+Time()+"  "
Print File ARQIMP RTrim(Format("W21,AL",[Nome Fantasia Empresa]))

If TEL<>""
   Then Print File ARQIMP " - "+TEL+"   " 
   Else Print File ARQIMP "   "                    
EndIf
Print File ARQIMP Spaces(02)+Format("W06.3,AL",[Numero do Orcamento])+"\n"
Print File ARQIMP CI_FNEG

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)+"ENDERECO: "+ Format("W40,AL",[Endereco])+"\n"
Print File ARQIMP Spaces(02)+"BAIRRO..: "+ Format("W20,AL",[Bairro])+
"FONE: " + Format("W20,AL",[Telefone])+
"CIDADE..: "+Rtrim(Format("W20,AL",[Cidade]))+ " - "+Format("W2,AL",[UF])+"\n"

Print File ARQIMP CI_INEG
Print File ARQIMP Spaces(02)+"OPERACAO: "+Format("W05,AL",[Codigo da Destinacao])+
                                               Format("W20,AL",[Descricao da Destinacao])+"\n"
Print File ARQIMP CI_FNEG

Print File ARQIMP Fill("=",90)+"\n" 
Print File ARQIMP Spaces(01)+"PRODUTO                                     UN       QUANT        Vr.Unit        Vr.Total "+"\n"

EndProc ;Cabecalho()

;*******************************************************************************
;* Rotina para Impressao do Relatorio . Itens                                  *
;*******************************************************************************
Proc Itens()

Moveto "OrcaI"
DESCONTO=0
VR_SDESC=0
QUANT   =0
CONTADOR=0
TOT     =0  

While [Numero do Orcamento]=[OrcaC->Numero do Orcamento]
   Checa_Linha(1)
   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])+Spaces(01)
   Print File ARQIMP Format("W10.2,EIC",[Quantidade])+Spaces(05)
   Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])+Spaces(05)
   Print File ARQIMP Format("W11.2,EIC",[Quantidade]*[Preco Unitario])+"\n"
   
   DESCONTO = DESCONTO+[Valor Desconto Unitario]          ;Total Desconto Unit rio
   QUANT    = QUANT+[Quantidade]                          ;Quantidade
   VR_SDESC = VR_SDESC+([Quantidade]*[Preco Unitario])    ;Pre‡o Total Bruto
   TOT      = TOT+[Preco Total]                           ;Total Liquido
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

For ITEM From CONTADOR To 10
    Print File ARQIMP "\n"
EndFor
EndProc ;Itens()

;*******************************************************************************
;* Rotina para Impressao do Relatorio . Totais                                  *
;*******************************************************************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

Moveto "OrcaC"
TOTD=([Valor Desconto]*100)/[Valor Mercadoria]

Print File ARQIMP Fill("-",90)+"\n"
Print File ARQIMP Spaces(02)+"VR.MERCADORIAS: "+Format("W11.2,EIC",VR_SDESC)+
                  Spaces(09)+"VR.DESCTO: "+Format("W10.2,EIC",DESCONTO)+
                  Spaces(07)+"VR.FRETE.: "+Format("W10.2,EIC",[Valor do Frete])+"\n"
Print File ARQIMP Spaces(02)+Format("W21,AL",[Descricao CondPagto]) 
Print File ARQIMP Spaces(12)+"   VR A PAGAR.: "
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
If QUEBRAFORM 
   Then Print File ARQIMP "*********"+"\n"
   Else Print File ARQIMP LTrim(Format("W11.2,EIC",[Valor Nota Fiscal]))+"\n"
EndIf
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_15CPP
Print File ARQIMP Fill("-",90)+"\n\n"

If QUEBRAFORM 
   Then Print File ARQIMP Spaces(20)+"* * * *  CONTINUA NO PROXIMO FORMULARIO * * * *    "+"\n\n"
   Else Print File ARQIMP Spaces(22)+Fill("-",40)+"\n"
        Print File ARQIMP Chr(27)+Chr(98)
        Print File ARQIMP Spaces(22)+Format("W40,AC",CLIENTE)+"\n\n"
EndIf                  

Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_15CPP
Print File ARQIMP Fill("=",90)+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
Print File ARQIMP CI_INEG
Print File ARQIMP Spaces(05)+"SOMENTE OR€AMENTO"+"\n"
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_15CPP
Print File ARQIMP Spaces(22)+"DOCUMENTO NAO FISCAL - EXIJA O CUPOM FISCAL"+"\n"
Print File ARQIMP Fill("=",90)+"\n"
Print File ARQIMP Spaces(22)+"         AGRADECEMOS A PREFERENCIA"+"\n"
Print File ARQIMP Fill("-",90)+"\n\n"

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

EndProc ;(Rodape)

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

If (CONTADOR+nl)>10
   Then RodaPe(True)
        Cabecalho()
        CONTADOR=nl
        Moveto "OrcaI"
   Else CONTADOR=CONTADOR+nl
EndIf
EndProc

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

AGUARDE("Imprimindo Orcamento -> "+[Numero do Orcamento])

Cabecalho()
Itens()
Rodape(False) 

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

Release Vars CLIENTE,END_ENT,BAI_ENT,CID_ENT,CEP_ENT
Release Procs Cabecalho, Itens, Rodape
LIMPAGUARDE()