Skip to content

Instantly share code, notes, and snippets.

@hvitorino
Created May 19, 2012 20:28
Show Gist options
  • Select an option

  • Save hvitorino/2732288 to your computer and use it in GitHub Desktop.

Select an option

Save hvitorino/2732288 to your computer and use it in GitHub Desktop.
Mode com knockout
(function () {
nlib.Models.BaixaVencimentoViewModel = nlib.Models.BaixaVencimentoViewModel.extend({
init: function (data) {
this._super(data);
var calcula = new Calculadora();
this.Desconto = ko.observable().extend({ valorMonetario: {} });
this.ValorDaMulta = ko.computed(function () {
return this.DataDaBaixa() > this.DataDoVencimento()
? calcula.valorPercentual(this.ValorNominalDaBaixa(), this.Multa())
: 0;
}, this);
this.ValorDosJuros = ko.computed(function () {
if (this.DataDaBaixa() > this.DataDoVencimento())
return calcula.valorDosJuros(this.ValorNominalDaBaixa(), this.Juros(), this.DataDaBaixa().diffdays(this.DataDoVencimento()));
else
return 0;
}, this);
this.ValorDoDesconto = ko.computed(function () {
return this.Desconto()
? calcula.valorPercentual(this.ValorNominalDaBaixa(), this.Desconto())
: 0;
}, this);
}
});
function Calculadora() {
this.jurosProporcional = function (percentualDeJuros, quantidadeDeDias) {
return (percentualDeJuros / 30) * quantidadeDeDias;
};
this.valorDosJuros = (function (valorTotal, percentualDeJuros, quantidadeDeDias) {
var jurosProporcional = this.jurosProporcional(percentualDeJuros, quantidadeDeDias) / 100;
return valorTotal * jurosProporcional;
}).bind(this);
this.valorPercentual = function(valorTotal, percentual) {
return valorTotal * (percentual / 100);
};
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment