;** Or_0270   ******************************************************************
;** Imprime a Digitacao do Or‡amento                       ** Comercial JB **  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 16/08/2010 por Bruno Carvalho
;Alterado em     :   /  /     por 
;Motivo Alteracao: 

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

If (NLINHA+nl)>67
   Then Print File ARQIMP "\f"
        Cabecalho()
EndIf
NLINHA=NLINHA+nl
EndProc

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

Moveto "OrcaC"
Print File ARQIMP CI_12CPP
                                   
Print File ARQIMP "\n"
Print File ARQIMP  "---------------------------------------------------------------------------------------------" + "\n"
Print File ARQIMP  "Comercial JB Equipamentos Eletroeletronicos LTDA"+Spaces(17)+"Emissao: "+Format("D13",Today())+"-"+Time()+ "\n"
Print File ARQIMP  "---------------------------------------------------------------------------------------------" + "\n\n"

Print File ARQIMP "Operacao: "+Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP Spaces(35)+"N§ do Orcamento: " +Format("W06.3,AL",[Numero do Orcamento])+"\n\n"

Print File ARQIMP "Cliente.: "+Format("W50,AL",[Razao Social])
If [Telefone] <> "" 
   Then Print File ARQIMP Spaces(01)+"Fone: "+Format("W20,AL",[Telefone])+"\n" 
   Else Print File ARQIMP "\n"   
EndIf 

NLINHA=8
                                                  
If Not IsBlank (EMAIL) 
   Then Print File ARQIMP "email ..: "+Format("W70,AL",EMAIL)+"\n"
        NLINHA=NLINHA+1
EndIf   

Print File ARQIMP "Endere‡o: "
Print File ARQIMP RTrim(Format("W33,AL",[Endereco]))+" - "
Print File ARQIMP RTrim(Format("W20,AL",[Bairro]))+"\n"
Print File ARQIMP Spaces(10)+RTrim(Format("W10,AL",[CEP])) 
Print File ARQIMP Spaces(02)+RTrim(Format("W20,AL",[Cidade]))+" / "+RTrim(Format("W03,AL",[UF]))+"\n"       
Print File ARQIMP Spaces(10)+Format("W18,AL",[CGC])
Print File ARQIMP Spaces(02)+Format("W25,AL",[IE])+"\n\n"
                                                      
Print File ARQIMP "Representante : "+Format("W25,AL",[Nome Fantasia Represent])+"\n\n"

If NAO_IMPRIME=False
   Then Print File ARQIMP "Item                                                Un Quantidade Unitario             Total"+"\n"
        Print File ARQIMP "--------------------------------------------------- -- ---------- -------- -----------------"+"\n"
        NLINHA=NLINHA+8
   Else Print File ARQIMP "--------------------------------------------------------------------------------------------"+"\n"   
        NLINHA=NLINHA+7  
EndIf

Moveto "OrcaI"

EndProc ; Cabecalho()

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

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

Moveto "OrcaC"
Moveto [Codigo]
If BUSCA_LOOKUP("Codigo",[Codigo],"SM")
   Then EMAIL=REG_BUSCA_LOOKUP["Endereco_Eletronico"]
EndIf

NAO_IMPRIME=False

Cabecalho()

Moveto "OrcaI"
QUANT=0
TOT=0
Scan
   Checa_Linha(1)
   Print File ARQIMP Format("W03,AR",StrVal([Item do Orcamento]))
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Spaces(01)+Format("W34,AL",[Descricao do Item])
   Print File ARQIMP Spaces(01)+Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
   Print File ARQIMP Spaces(07)+Format("W11.2,EIC",[Preco Total])+"\n"
   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
EndScan

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "OrcaC"

Checa_Linha(4)
Print File ARQIMP Spaces(55)+"----------                -----------"+"\n"
Print File ARQIMP Spaces(54)+Format("W11.3,EIC",QUANT)
Print File ARQIMP Spaces(16)+Format("W11.2,EIC",TOT)+"\n\n"

Print File ARQIMP  "---------------------------------------------------------------------------------------------" + "\n"

NAO_IMPRIME=True

Checa_Linha(3)
Moveto "OrcaC"
Print File ARQIMP "\n"
                  "---------------------------------------------------------------------------------------------"
Print File ARQIMP "  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces       Total"+"\n"
                  ;9.999.999,99888.88%777.777,776.666.666,6644.444,44111.111,112.222.222,224.444.444,44

Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor do 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("W012.2,EIC",[Valor Nota Fiscal])+"\n\n"


If Substr([Observacao do Orcamento],001,090)<>""
    Then If Substr([Observacao do Orcamento],091,090)<>""
            Then Checa_Linha(4)
                 Print File ARQIMP "- "+Format("W90,AL",SubStr([Observacao do Orcamento],001,090))+"\n"
                 Print File ARQIMP Spaces(02)+Format("W90,AL",SubStr([Observacao do Orcamento],091,090))+"\n\n\n"
            Else Checa_Linha(2)
                 Print File ARQIMP "- "+Format("W90,AL",SubStr([Observacao do Orcamento],001,090))+"\n\n"
         EndIf   
EndIf    

Checa_Linha(4)
Print File ARQIMP "\027E"
Print File ARQIMP "OBS.:"+"\n"
Print File ARQIMP "1) ENTREGA E INSTALA€ÇO: "
Print File ARQIMP "\027F"
Print File ARQIMP "Imediata"+"\n"
Print File ARQIMP "\027E"
Print File ARQIMP "2) CONDI€åES DE PAGAMENTO: "
Print File ARQIMP "\027F"
Print File ARQIMP "· Vista com 5% de desconto"+"\n"
Print File ARQIMP Spaces(27)+"ou entrada +30/60 dias no cheque ou cartÆo Master"+"\n"

Checa_Linha(9)
Print File ARQIMP "\027E"
Print File ARQIMP "3) GARANTIA: "
Print File ARQIMP "\027F"
Print File ARQIMP "12 (doze) meses contra defeito de f brica"+"\n"
Print File ARQIMP "\027E"
Print File ARQIMP "- O DESCONTO · VISTA NÇO SE APLICA A MÇO DE OBRA"+"\n"
Print File ARQIMP "- OS ITENS COM QUANTIDADE ZERADA SERÇO CALCULADOS APàS A FINALIZA€ÇO DO"+"\n"
Print File ARQIMP "  SERVI€O, SE FOREM UTILIZADOS."+"\n"
Print File ARQIMP "\027F"

Print File ARQIMP "\n\n"
;************************* IMPRESSAO DO RODAPE ********************************

Print File ARQIMP Spaces(22)+"_______________________________________________"+"\n"
Print File ARQIMP Spaces(32)+"Data/Assinatura Responsavel"+"\n\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
Print File ARQIMP "\f"
EndProc

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

AGUARDE("Imprimindo Or‡amento -> "+ORCA)
Moveto "OrcaC"
CoeditKey
IMPFAT()
Do_It!
;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

Release Vars nl, NLINHA, NAO_IMPRIME, NOMEMPRESA, EMAIL, QUANT , TOT, ArqImp
Release Procs Checa_Linha, Cabecalho, IMPFAT
LIMPAGUARDE()