Created
May 19, 2012 20:28
-
-
Save hvitorino/2732288 to your computer and use it in GitHub Desktop.
Mode com knockout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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