﻿/// <reference path="Funcoes.js" />

Parcela = function (numeroVezes, valorParcela, avista, comJuros, porcDesconto) {
    this.numeroVezes = parseInt( numeroVezes );
    this.valorParcela = parseFloat(valorParcela.toString().replace(",", "."));
    this.avista = new Boolean(avista);
    this.comJuros = new Boolean(comJuros);
    this.porcDesconto = parseFloat(porcDesconto.toString().replace(",", "."));
}

Parcela.prototype = {
    numeroVezes: this.numeroVezes,
    valorParcela: this.valorParcela,
    avista: this.avista,
    comJuros: this.comJuros,
    porcDesconto: this.porcDesconto,
    GetParcelaFormatada: function (emAte) {
        var retorno = new String();
        var valorParc = this.valorParcela;

        if (this.porcDesconto > 0)
            valorParc = valorParc - (valorParc * (this.porcDesconto / 100));

        if ((new Boolean(emAte)) == true) {
            if (this.numeroVezes > 1)
                retorno = retorno.concat("Em até ");
        }

        if (this.numeroVezes == 1 && this.avista == true) {
            retorno = retorno.concat("A Vista");
        } else {
            retorno = retorno.concat(this.numeroVezes + " x " +
                                      new Funcoes().FomatoMoeda(valorParc.toString()) +
                                      ((this.comJuros == false) ? " sem juros" : " mais juros"));
        }
        return retorno;
    }
}
