;** Np_0236 ********************************************************************
;*  Emissao de Duplicatas                     Matex Textil . Super Martins    **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 23/08/2012 por Bruno Carvalho
;Alterado em     :   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Calculo da Data Media                                                       *
;*******************************************************************************
;ImpressÆo informando a DATA MEDIA, com a data referente do dia que esta sendo processada.

Proc CALC_MEDIA()

VSDGDTREF  =Today()        ;Data Base
M_VALORM   =0
VALOR_TOTAL=0

Do_It!
FormKey

Moveto "FaturaV"
Scan
  MDIA=[Data]-VSDGDTREF
  If MDIA=0
     Then M_VALORM   =M_VALORM   + [Valor]
     Else M_VALORM   =M_VALORM   +([Valor]*MDIA)
  EndIf
  VALOR_TOTAL=VALOR_TOTAL+[Valor]
EndScan 
    
M_DIAREF     = Round( ( M_VALORM / VALOR_TOTAL ), 3 )
M_DIAREFI    = Int( M_DIAREF )
M_DIAREFD    = M_DIAREF - M_DIAREFI

If M_DIAREFD > 0.51
   Then M_DIAREFI = M_DIAREFI + 1
EndIf

DTMEDIA=VSDGDTREF+M_DIAREFI
NDIAS  =M_DIAREFI

CoeditKey

EndProc  ; (Calcula)

;*******************************************************************************
;* Rotina de Impressao de Duplicatas                                           *
;*******************************************************************************
ArqImp=PrivDir()+"NP_236.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

Moveto "FaturaC"
Moveto [Codigo da Empresa]
Ativa_Lookup()
Locate [FaturaC->Codigo da Empresa]
If RetVal
   Then EMPRESA=[Razao Social Empresa]
        CNPJEMP=[CGC Empresa         ]
        CIDEMP =[Cidade Empresa      ]
   Else EMPRESA=""
        CNPJEMP=""
        CIDEMP =""
EndIf
KeyPress "ESC"

CALC_MEDIA()

Moveto "FaturaC"
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

Print File ARQIMP "+------------------------------------------------------------------------------+"+"\n"
Print File ARQIMP "|                   N O T A    P R O M I S S O R I A                           |"+"\n"
Print File ARQIMP "|                   ================================                           |"+"\n"
Print File ARQIMP "|                    Republica Federativa do Brasil                            |"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"

Print File ARQIMP "| Numero: "+ Format("W6,AC",[Numero Nota Gerada])+Spaces(15)

Print File ARQIMP COMPLETA("Vencimento: "+StrVal(Day(DTMEDIA))+" de "+
                           RTrim(MesExt(Month(DTMEDIA)))+" de "+
                           Strval(Year(DTMEDIA)),48," ")+"|"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"

Print File ARQIMP "|"+Spaces(30)+"Valor.....: "+LTrim(Format("W13.2,EIC,AR",[Valor Mercadoria Liquido]))+Spaces(21)
Print File ARQIMP Fill(" ",15-Len(LTrim(Format("W13.2,EIC,AR",[Valor Mercadoria Liquido]))))+"|"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"

Print File ARQIMP "| No dia "+
                 COMPLETA(StrVal(Day(DTMEDIA))+" de "+
                 RTrim(MesExt(Month(DTMEDIA)))+" de "+
                 Strval(Year(DTMEDIA))+
                 ", pagarei pela presente NOTA PROMISSORIA   ",70," ")+"|"+"\n"
;Print File ARQIMP "| "+Spaces(77)+"|"+"\n"
Print File ARQIMP "| ou … sua ordem a quantia de: "+Spaces(48)+"|"+"\n"

ESCEXT([Valor Mercadoria Liquido])
Print File ARQIMP "|                                                                              |"+"\n"

Print File ARQIMP "|"+Spaces(04) + SubStr(EXTENSO,001,60) +Spaces(14)+"|" +"\n"
Print File ARQIMP "|"+Spaces(04) + SubStr(EXTENSO,061,60) +Spaces(14)+"|" +"\n"
Print File ARQIMP "|"+Spaces(04) + SubStr(EXTENSO,122,60) +Spaces(14)+"|" +"\n"

Print File ARQIMP "| em moeda corrente deste pais, pag vel na pra‡a de Divin¢polis-MG.            |"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"

Print File ARQIMP "| Emitente: "+[Codigo]+" - "+ Format("W40,AL",[Nome Fantasia EmitDest])+Spaces(20)+"|"+"\n"
Print File ARQIMP "| CNPJ/CPF: "+Format("W18,AL",[CGC])+Spaces(48)+" |"+"\n"
Print File ARQIMP "| Endereco: "+Format("W38,AL",[Endereco])
Print File ARQIMP "Bairro: "+Format("W20,AL",[Bairro])+" |"+"\n"
Print File ARQIMP "| Cidade..: "+[CEP]+" - "+Format("W20,AL",[Cidade])+Spaces(5)
Print File ARQIMP "    Uf: "+[UF]+Spaces(28) + " |"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"
Print File ARQIMP "| "+COMPLETA(CIDEMP+", "+StrVal(Day([Data de Emissao]))+" de "+
                      RTrim(MesExt(Month([Data de Emissao])))+" de "+
                      Strval(Year([Data de Emissao])),34," ")
Print File ARQIMP "   Assinatura: ___________________________"+Spaces(01)+"|"+"\n"
Print File ARQIMP "|                                                                              |"+"\n"
Print File ARQIMP "+------------------------------------------------------------------------------+"+"\n"

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP+"\f"

Print File ARQIMP chr(27)+chr(67)+chr(66) ;Imprime 66 Linhas por pagina

;---- Imprime Arquivo Impressao ------------------------------------------------
NUMCOPIA=1
ImpriArq(ARQIMP)

Moveto "FaturaC"


