-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
49 lines (44 loc) · 2.06 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const taxaImpostoPadrao = 0.6
const taxaImposto0 = 0
let taxaImposto
const taxaICMS = 0.17
let valor_sem_impostos
let valor_com_impostos
fetch('https://api.bcb.gov.br/dados/serie/bcdata.sgs.10813/dados?formato=json').then(response => response.json()).then(data => {
const dolar = data[data.length - 1].valor
document.getElementById('dolar-hoje').textContent = parseFloat(dolar).toFixed(2)
}).catch(error => console.error(error))
const calcula_valor_com_impostos = () => {
const dolar = document.getElementById('dolar-hoje').textContent
valor_sem_impostos = document.getElementById("valor_sem_impostos").value
if(valor_sem_impostos <= 50 * dolar){
taxaImposto = taxaImposto0
} else {
taxaImposto = taxaImpostoPadrao
}
valor_com_impostos = valor_sem_impostos * (1 + taxaImposto) / (1 - taxaICMS)
document.getElementById("valor_com_impostos").value = valor_com_impostos.toFixed(2)
document.getElementById("imposto").value = (valor_sem_impostos * taxaImposto).toFixed(2)
document.getElementById("icms").value = (valor_com_impostos * taxaICMS).toFixed(2)
if(valor_sem_impostos == ""){
document.getElementById("valor_com_impostos").value = ""
}
}
const calcula_valor_sem_impostos = () => {
const dolar = document.getElementById('dolar-hoje').textContent
valor_com_impostos = document.getElementById("valor_com_impostos").value
let icms = valor_com_impostos * taxaICMS
valor_sem_impostos = valor_com_impostos * (1 - taxaICMS)
if(valor_sem_impostos > 50 * dolar * (1 + taxaImposto)){
taxaImposto = taxaImpostoPadrao
} else {
taxaImposto = taxaImposto0
}
valor_sem_impostos /= 1 + taxaImposto
document.getElementById("valor_sem_impostos").value = valor_sem_impostos.toFixed(2)
document.getElementById("imposto").value = (valor_sem_impostos * taxaImposto).toFixed(2)
document.getElementById("icms").value = icms.toFixed(2)
if(valor_com_impostos == ""){
document.getElementById("valor_sem_impostos").value = ""
}
}