;** OR_0278 ********************************************************************
;** Imprime o Orcamento                                                        *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 10/02/2020 por Bruno Carvalho
;Ultima Alteracao:

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

Moveto "Orcac"
;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "Orcac"

Print File ARQIMP CI_15CPP
Print File ARQIMP Fill("=",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n"

Print File ARQIMP CI_INEG
Print File ARQIMP "** OR€AMENTO **"
Print File ARQIMP Spaces(10)+ "NUMERO:  "+Format("W06.3,AL",[Numero do Orcamento])
Print File ARQIMP CI_FNEG+"\n\n"

Print File ARQIMP "EMISSAO: "+Format("D13",Today())+"-"+Time()+"  "+
                       "VEND: "+Format("W21,AL",[Nome Fantasia Represent])+"\n"

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

Print File ARQIMP "CLIENTE.: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W35,AL",[Razao Social])+"\n"

Print File ARQIMP "ENDERE€O: "+ Format("W40,AL",[Endereco])+"\n"

Print File ARQIMP "BAIRRO..: "+ Format("W20,AL",[Bairro])+
                       "FONE: " + Format("W20,AL",[Telefone])+"\n"

Print File ARQIMP "CIDADE..: "+Format("W20,AL",[Cidade])+Spaces(2)+"\n"             

If Not Isblank(SubStr([Observacao do Orcamento],001,36))
   Then Print File ARQIMP Spaces(01)+"OB......: "
        Moveto "FaturaC"
        Print File ARQIMP Format("W36,AL",SubStr([Observacao do Orcamento],001,36))+"\n"
        If Not IsBlank (SubStr([Observacao do Orcamento],037,47))
           Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao do Orcamento],037,47))+"\n"
                If Not IsBlank(SubStr([Observacao do Orcamento],84,47))
                   Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao do Orcamento],84,47))+"\n"
                        If Not IsBlank(SubStr([Observacao do Orcamento],131,47))
                           Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao do Orcamento],131,47))+"\n"
                        EndIf 
                EndIf
        EndIf
EndIf

;*************************** IMPRESSAO DOS ITENS *******************************
Moveto "Orcai"

Print File ARQIMP Fill("=",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n"
Print File ARQIMP "   CODIGO     DESCRICAO"+"\n"
Print File ARQIMP "              MARCA    "+"\n"
Print File ARQIMP "       QTD  UF      Vr.Uni     Vr.Total"+"\n"
Print File ARQIMP Fill("=",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n"                 
QUANT=0
TOT=0
Scan
  getrecord "\\sistemas\\estoque\\itens" [Codigo do Item] to regitens
  if retval
     then marca=regitens["Descricao da Marca"]
     else marca=""
  endif

  Print File ARQIMP Spaces(03)+Format("W11,AL",[Codigo do Item])+
                    Format("W30,AL",[Descricao do Item])+"\n"
  Print File ARQIMP Spaces(14)+Format("W30,AL",marca)+"\n"
  Print File ARQIMP Format("W11.3,EIC",[Quantidade])+" "+
                    Format("W03,AL",[Unidade Fiscal])+"x "+
                    Format("W09.2,EIC",[Preco Unitario])+" = "+
                    Format("W10.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   
   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
EndScan

Moveto "Orcac"
Print File ARQIMP Spaces(05)+"------"
Print File ARQIMP Spaces(22)+"------"+"\n"
Print File ARQIMP Spaces(02)+Format("W09.3,EIC",QUANT)
Print File ARQIMP Spaces(17)+Format("W11.2,EIC",[Valor Mercadoria])+"\n"
Print File ARQIMP Fill("-",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n"

Print File ARQIMP "VR.MERCADORIAS: "+Format("W11.2,EIC",[Valor Mercadoria])+
                  Spaces(02)+"VR.DESCTO: "+Format("W8.2,EIC",[Valor do Desconto])+"\n"
Print File ARQIMP "VR.SERVICO....: "+Format("W11.2,EIC",[Valor Servico])+
                  Spaces(02)+"VR.FRETE.: "+Format("W8.2,EIC",[Valor do Frete])+"\n"
Print File ARQIMP "VR LIQUIDO....: "+Format("W11.2,EIC",[Valor Mercadoria]-[Valor do Desconto])+"\n\n"

Moveto"OrcaCPG"
Print File ARQIMP "CONDICOES  DE  PAGAMENTOS  "+"\n"
Scan
  Print File ARQIMP Format("W20,AL",[Descricao CondPagto])
  Print File ARQIMP " Vr Total: "+Format("W11.2,EIC",[Orcac->Valor Nota Fiscal]+(([Orcac->Valor Nota Fiscal]*[Taxa Financeira])/100))+"\n"
EndScan

Moveto "Orcac"
Print File ARQIMP "\n"
Print File ARQIMP Fill("-",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n\n\n"
Print File ARQIMP Format("W"+StrVal(TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+",AC",Fill("-",Len([Orcac->Razao Social])+6))+"\n"
Print File ARQIMP Format("W"+StrVal(TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+",AC",[Orcac->Razao Social])+"\n\n\n"
Print File ARQIMP Format("W"+StrVal(TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+",AC","AGRADECEMOS A PREFERENCIA")+"\n\n\n"
Print File ARQIMP Fill("-",TAMANHO_COLUNA_IMPRESSORA_CI_15CPP)+"\n\n\n"                                                                           
Print File ARQIMP EPSON_GUILHOTINA

EndProc

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

If Not IsAssigned(BIBSHOW_IMPRESSORA_SETADA)                                    ;Daruma 
   Then CI_15CPP = CI_10CPP
        TAMANHO_COLUNA_IMPRESSORA_CI_15CPP = 48 
EndIf

If Isassigned(BIBSHOW_IMPRESSORA_SETADA) And (BIBSHOW_IMPRESSORA_SETADA = "EPSON" Or BIBSHOW_IMPRESSORA_SETADA="BEMATECH")
   Then Print File ARQIMP EPSON_INICIALIZA_IMPRESSAO 
        Print File ARQIMP CI_8LPP
        Print File ARQIMP CI_15CPP 
   Else Print File ARQIMP CI_15CPP      
EnDIf  

IMPORC()
ImpriArq(ARQIMP)

Release Vars VALOR,DATA,CLIENTE
Release Procs IMPORC
LIMPAGUARDE()