-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (65 loc) · 3.13 KB
/
script.js
File metadata and controls
78 lines (65 loc) · 3.13 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//helper function for getting
function getValue(id) {
const value = document.getElementById(id).value;
if (value === "" || isNaN(value)) {
return 0;
} else {
return parseFloat(value);
}
}
function calculate() {
// The price of about 3oz of gold
const nisab_amount = 7497.03;
// Assets
const cash_amount = getValue("cash_amount");
const value_of_gold = getValue("value_of_gold");
const value_of_silver = getValue("value_of_silver");
const other_savings = getValue("other_savings");
const RRSP_RESP_savings = getValue("RRSP_RESP_savings");
const money_owed_to_you = getValue("money_owed_to_you");
const stock_share_values = getValue("stock_share_values");
// Liabilities
const money_you_owe = getValue("money_you_owe");
const personal_expenses = getValue("personal_expenses");
const business_expenses = getValue("business_expenses");
const other_outgoing_dues = getValue("other_outgoing_dues");
// The sum of all of your different assets that you've had for the last
// lunar year
const total_gross_assets = cash_amount + value_of_gold + value_of_silver + other_savings + money_owed_to_you + RRSP_RESP_savings + stock_share_values;
// The sum of all of your different liabilities
const total_net_liabilities = money_you_owe + personal_expenses + business_expenses + other_outgoing_dues;
// Gross assets minus the liabilities you have. Again these are typically
// immediate liabilities. Not the totality of a large loan like a mortgage
const total_net_assets = total_gross_assets - total_net_liabilities
let eligable_amount = 0;
// If this net amount is bigger than the nisab, then it's eligible
// to have Zakat assessed against it
if (total_net_assets > nisab_amount) {
eligable_amount = Math.ceil(total_net_assets);
}
// Zakat is 2.5% of ones eligible wealth if it above Nisab
const zakat_amount = Math.ceil(eligable_amount * .025);
const formatter = new Intl.NumberFormat('en-CA', {
style: 'currency',
currency: 'CAD',
});
// Write the total values back for the user
document.getElementById("main-zakat-net-assets-number").innerText = formatter.format(total_net_assets);
document.getElementById("main-zakat-nisab-threshold-amount").innerText = formatter.format(nisab_amount);
document.getElementById("main-zakat-total-amount-number").innerText = formatter.format(zakat_amount);
}
function handleReset() {
// Reset All Values
document.getElementById("cash_amount").value = ""
document.getElementById("value_of_gold").value = ""
document.getElementById("value_of_silver").value = ""
document.getElementById("other_savings").value = ""
document.getElementById("RRSP_RESP_savings").value = ""
document.getElementById("money_owed_to_you").value = ""
document.getElementById("stock_share_values").value = ""
document.getElementById("money_you_owe").value = ""
document.getElementById("personal_expenses").value = ""
document.getElementById("business_expenses").value = ""
document.getElementById("other_outgoing_dues").value = ""
calculate()
}