;** RC_0000 ********************************************************************
;** Imprime pre‡o de venda/pre‡o de custo/custo medio/total custo medio        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 30/04/2018 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                   
;Motivo Alteracao:

;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()
Print File ARQIMP CI_15CPP+CI_6LPP+"\n"

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

Moveto "FaturaC"
Print File ARQIMP Fill("-",132)+"\n"
Print File ARQIMP Format("W20",NOMEMPRESA)+Spaces(83)+"Emissao: "+Format("D13",Today())+"-"+Time()+"\n"
Print File ARQIMP Fill("-",132)+"\n\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(40)+"       OF N§ "+Format("W06.3,AL",[FaturaC->Numero da OF])+"\n"
If Rtrim(NOTAFISC)<>""
   Then Print File ARQIMP Spaces(40)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+"\n"
EndIf   
Print File ARQIMP "\027F"
Print File ARQIMP "\020"

Print File ARQIMP Spaces(02)+"Cliente.......: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(02)+"Local Fatura..: "
Print File ARQIMP Format("W33,AL",[Endereco])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Bairro])+"\n"
Print File ARQIMP Spaces(18)+Format("W10,AL",[CEP])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Cidade])+" -"
Print File ARQIMP Spaces(01)+Format("W04,AL",[UF])+"\n"
Print File ARQIMP Spaces(18)+Format("W18,AL",[CGC])+"\n"

NLINHA=10
Cabecalho_Item()

EndProc  

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Private wc,linha,nlin

Print File ARQIMP "                                                                   Venda       Ultimo ______ Custo Medio ______" + "\n"                                                                                                        
Print File ARQIMP "Seq Item                                      Un Quantidade        Pre‡o  Custo Pre‡o        Pre‡o        Total" + "\n"
Print File ARQIMP "--- ----------------------------------------- -- ---------- ------------ ------------ ------------ ------------" + "\n"

NLINHA = NLINHA + 3

EndProc

;*******************************************************************************
;* Rotina para Impressao do Rodape                                             *
;*******************************************************************************
Proc Rodape()
Print File ARQIMP Spaces(110)+"** Continua =>"+"\n"
Print File ARQIMP Fill("-",132)+"\n\f"

EndProc

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()
;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
NPAG=0                     
Cabecalho()

TOT_QUANTIDADE          =BlankNum()  
TOT_PR_TOTAL_CUSTO_MEDIO=BlankNum()

ANO = StrVal(Year([Data de Emissao]))
MES = AlinhM(StrVal(Month([Data de Emissao])),2)

Moveto "FaturaI"
Scan
 If NLINHA>60
    Then Rodape()
         Cabecalho()
         Moveto "FaturaI"
 EndIf


 PR_VENDA             = [Preco Unitario]
 PR_CUSTO             = BlankNum()
 PR_CUSTO_MEDIO       = BlankNum()
 PR_TOTAL_CUSTO_MEDIO = BlankNum()
 GetRecord "\\Sistemas\\Estoque\\SdEstq" [FaturaC->Codigo da Empresa],[Codigo do Item],ANO,MES To Reg_SdEstq
 If ReTval
    Then PR_CUSTO       = Reg_SdEstq["Preco de Custo"]
         PR_CUSTO_MEDIO = Reg_SdEstq["Ultimo Custo Atual"]
 EndIf
 PR_TOTAL_CUSTO_MEDIO = Round([Quantidade]*PR_CUSTO_MEDIO,2)

 Print File ARQIMP Format("W03,AR",StrVal([Item da OF]))+" "
 Print File ARQIMP Format("W10,AL",[Codigo do Item])+" "
 Print File ARQIMP Format("W30,AL",[Descricao do Item])+" "
 Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+" "
 Print File ARQIMP Format("W10,EIC",[Quantidade])+" "
 Print File ARQIMP Format("W12.2,EIC",PR_VENDA)+" "
 Print File ARQIMP Format("W12.2,EIC",PR_CUSTO)+" "
 Print File ARQIMP Format("W12.2,EIC",PR_CUSTO_MEDIO)+" "
 Print File ARQIMP Format("W12.2,EIC",PR_TOTAL_CUSTO_MEDIO)+"\n"
 NLINHA=NLINHA+1
 
 TOT_QUANTIDADE = TOT_QUANTIDADE + [Quantidade]
 TOT_PR_TOTAL_CUSTO_MEDIO = TOT_PR_TOTAL_CUSTO_MEDIO + PR_TOTAL_CUSTO_MEDIO
EndScan
Moveto "FaturaI"

Print File ARQIMP "                                                 ----------                                        ------------" + "\n"
Print File ARQIMP Format("W49,AR","Total... ")+Format("W10,EIC",TOT_QUANTIDADE)+Spaces(40)
Print File ARQIMP Format("W12.2,EIC",TOT_PR_TOTAL_CUSTO_MEDIO)+"\n"

EndProc ;IMPFAT()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ARQIMP=PrivDir()+"RC_0000.Txt"
;If IsFile(ARQIMP)
;   Then Delete ARQIMP
;EndIf

NOTAFISC =[FaturaC->Numero Nota Gerada]

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPFAT()

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

Release Procs IMPFAT,Cabecalho, Rodadpe
LIMPAGUARDE()
