-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
108 lines (84 loc) · 6.23 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var selling_price=45;
function totalProduction()
{
var shedA = parseInt(document.getElementById('shedA').value);
var values = {}
values["shedA"] = parseInt(document.getElementById('shedA').value);
values["shedB"] = parseInt(document.getElementById('shedB').value);
values["shedC"] = parseInt(document.getElementById('shedC').value);
values["shedD"] = parseInt(document.getElementById('shedD').value);
var total = values.shedA+values.shedB + values.shedC +values.shedD;
document.getElementById("produce-header").innerHTML += '<div class="alert text-white bg-dark h4">Production</div>';
document.getElementById("produce-body").innerHTML += "<tr><td>Your production in Shed A</td><td>"+ values.shedA +" litres per day </td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your production in Shed B</td><td>"+ values.shedB +" litres per day </td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your production in Shed C</td><td>"+ values.shedC +" litres per day </td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your production in Shed D</td><td>"+ values.shedD +" litres per day </td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>The total production is</td><td>" + total + " litres per day</td></tr>";
resetForm();
var daily = incomeOverTime(selling_price, 1);
var weekly = incomeOverTime(selling_price, 7);
var yearly = incomeOverTime(selling_price, 365);
document.getElementById("produce-body").innerHTML += "<tr><td></td><td></td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your Daily income will be</td><td>Ksh " + (daily*total) + "</td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your Monthly income will be</td><td>Ksh " + (weekly*total) + "</td></tr>";
document.getElementById("produce-body").innerHTML += "<tr><td>Your Yearly income will be</td><td>Ksh " + (yearly*total) + "</td></tr>";
var leapyear = [
{ month : "January",income : (31 * total * selling_price)},
{ month : "February",income : (29 * total * selling_price) },
{ month : "March",income : (31 * total * selling_price) },
{ month : "April",income : (30 * total * selling_price) },
{ month : "May",income : (31 * total * selling_price) },
{ month : "June",income : (30 * total * selling_price) },
{ month : "July",income : (31 * total * selling_price) },
{ month : "August",income : (31 * total * selling_price) },
{ month : "September",income : (30 * total * selling_price) },
{ month : "October",income : (31 * total * selling_price) },
{ month : "November",income : (30 * total * selling_price) },
{ month : "December",income : (31 * total * selling_price) }
];
document.getElementById("leapYear-div").innerHTML += '<div class="alert text-white bg-dark h4">Leap Year Income Per Month </div>';
for(var x=0;x<12;x++)
{
document.getElementById("leapYear").innerHTML += "<tr><td>Your income for "+ leapyear[x].month + " is </td><td>Ksh. " + leapyear[x].income + "</td></tr></div>";
}
comparison(total)
}
function incomeOverTime(selling_price, time)
{
return (selling_price*time)
}
function comparison(total)
{
updated_price = 49.60;
var normalYear = [
{ month : "January",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "February",income : Math.round(28 * total * updated_price).toFixed(2), difference : Math.round((29 * total * updated_price)-(28 * total * selling_price)).toFixed(2) },
{ month : "March",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "April",income : Math.round(30 * total * updated_price).toFixed(2), difference : Math.round((30 * total * updated_price)-(30 * total * selling_price)).toFixed(2) },
{ month : "May",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "June",income : Math.round(30 * total * updated_price).toFixed(2), difference : Math.round((30 * total * updated_price)-(30 * total * selling_price)).toFixed(2) },
{ month : "July",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "August",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "September",income : Math.round(30 * total * updated_price).toFixed(2), difference : Math.round((30 * total * updated_price)-(30 * total * selling_price)).toFixed(2) },
{ month : "October",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) },
{ month : "November",income : Math.round(30 * total * updated_price).toFixed(2), difference : Math.round((30 * total * updated_price)-(30 * total * selling_price)).toFixed(2) },
{ month : "December",income : Math.round(31 * total * updated_price).toFixed(2), difference : Math.round((31 * total * updated_price)-(31 * total * selling_price)).toFixed(2) }
];
document.getElementById("caption-div").innerHTML += '<div class="alert text-white bg-dark h4">Earnings after price increase and difference</div> ';
document.getElementById("comparison-headers").innerHTML += "<tr><td>Month</td><td>Earnings(Ksh) @49/-</td><td>difference from 45/-(Ksh)</td></tr>";
for(var x=0;x<12;x++)
{
document.getElementById("comparison").innerHTML += "<tr><td>"+ normalYear[x].month + "</td><td>" + normalYear[x].income + "</td><td>" + normalYear[x].difference + "</td></tr>";
}
}
function resetForm()
{
document.getElementById('shedA').value = " ";
document.getElementById('shedB').value = " ";
document.getElementById('shedC').value = " ";
document.getElementById('shedD').value = " ";
}
function reloadPage()
{
location.reload();
}