Last active
December 16, 2015 10:28
-
-
Save valdiney/5420033 to your computer and use it in GitHub Desktop.
Script que realiza algumas de suas funções perfeitamente. Porem implementei uma função que grava o relatório de processamento no LocalStorage. Nos principais navegadores funciona perfeitamente. Porém no (IE) não está a funcionar! Eu também escrevi uma função que chama os dados contidos no LocalStorage assim que a página é carregada, e dentro uma…
This file contains 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
//////////////////////////////////////////////////////////////////// | |
// (JS) | |
// CLASS COMPUTA VALOR/CAPITAL, JUROS E MONTANTE | |
// AUTOR: VALDINEY FRANÇA | |
// | |
/////////////////////////////////////////////////////////////////// | |
window.onload = function(){ | |
////////////////////////////////////////////////////////////////// | |
// CHAMA E MOSTRA OS DADOS CONTIDOS NO STORAGE | |
//////////////////////////////////////////////////////////////// | |
function mostraDadosStorage(msg){ | |
var div_relatorioStorage = document.getElementById('div_relatorioStorage'); | |
var resgata_relatorio = localStorage.getItem('relatorio'); | |
if(resgata_relatorio == null){ | |
return div_relatorioStorage.innerHTML = " Não tem nenhum relátorio gravado ainda..."; | |
}else{ | |
return div_relatorioStorage.innerHTML = "<h3>"+msg+"</h3>"+"<br>"+resgata_relatorio; | |
} | |
} | |
mostraDadosStorage("Relatório anterior:"); | |
/////////////////////////////////////////////////////////////// | |
document.getElementById('computar_renda').onclick = function(){ | |
////////////////////////////////////////////////////////////////// | |
//RESGATA OS CAMPOS DE ENTRADA DE DADOS E O DE SAIDA VIA ID | |
var capital = Number(document.getElementById('capital').value); | |
var meses= Number(document.getElementById('meses').value); | |
var juros = Number(document.getElementById('juros').value); | |
var mostrar_resultado = document.getElementById('resultado_renda'); | |
var div_relatorio = document.getElementById('div_relatorio'); | |
///////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////////// | |
//CONSTRUÇÃO DA CLASS/FUNÇÃO CONSTRUTORA COM SEUS ATRIBUTOS E METODOS | |
function Renda(capital,meses,juros){ | |
this.capital = capital; | |
this.meses = meses; | |
this.juros = juros; | |
this.calculaPorcentagem = function(){ | |
oCalcular = this.capital * this.juros / 100; | |
return oCalcular.toFixed(2); | |
}; | |
this.calcularRendaAomes = function(){ | |
oCalcular = this.calculaPorcentagem() * this.meses; | |
return oCalcular.toFixed(2); | |
}; | |
this.calcularMontante = function(){ | |
oCalcular = this.capital + parseFloat(this.calcularRendaAomes()); | |
return oCalcular.toFixed(2); | |
}; | |
//////////////////////////////////////////////////////////// | |
//RELATÓRIO DE PROCESSAMENTO | |
this.relatorioDeProcessamento = function(){ | |
oMostrar = " <b>Capital</b> = "+this.capital+"| <b>meses =</b> "+this.meses+"| <b>juros =</b> "+this.juros; | |
oMostrar+= oProcesso_porcent = "<br><b>Calculando a porcentagem:</b> ( capital * juros / 100) = "+this.calculaPorcentagem(); | |
oMostrar+= oProcessoAoMes = " <br><b>Calculando juros ao mes:</b> ( "+this.calculaPorcentagem()+" * meses ) = "+this.calcularRendaAomes(); | |
oMostrar+= oMontante = " <br><b>Calculo do montante:</b> ( "+this.capital+" + "+this.calcularRendaAomes()+" ) = "+this.calcularMontante(); | |
return oMostrar; | |
} | |
}//END CLASS | |
//////////////////////////////////////////////////////////////// | |
/////////////////////////////////////////////////////////////// | |
//INSTANCIANDO O OBJETO CRIADO ATRAVEZ DA CLASS (RENDA) | |
primeiraRenda = new Renda(capital,meses,juros); | |
/////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////// | |
//FUNÇÃO VALIDA OS CAMPOS DE ENTRADA ATRAVEZ DE CONDICIONAIS | |
function validar(capital){ | |
if(capital==""){ | |
mostrar_resultado.innerHTML = "<p>Digite um valor para ser computado...</p>"; | |
}else if(isNaN(capital)){ | |
mostrar_resultado.innerHTML = "<p>Digite apenas valores numericos...</p>"; | |
}else{ | |
mostrar_resultado.innerHTML = "<b>Porcentagem de:</b> "+primeiraRenda.calculaPorcentagem()+"<br>"+"<b>Renda por Mês de:</b> "+primeiraRenda.calcularRendaAomes()+"<br>"+"<b>O seu montante é de:</b> "+primeiraRenda.calcularMontante(); | |
div_relatorio.innerHTML = primeiraRenda.relatorioDeProcessamento(); | |
/////////////////////////////////////////////// | |
// FUNÇÃO GRAVA NO LOCAL STORAGE O RELATÓRIO DE PROCESSAMENTO | |
////////////////////////////////////////////// | |
function gravaNoStorage(){ | |
localStorage.setItem('relatorio',div_relatorio.innerHTML); | |
} | |
gravaNoStorage(); | |
}//END ELSE | |
}//END FUNCTION | |
///////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
//CHAMANDO A FUNÇÃO (VALIDAR) | |
validar(capital); | |
}//END RENDA COMPUTAR | |
}//END WINDOW |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment