-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
264 lines (236 loc) · 6.86 KB
/
index.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TNB bill calculator</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
table th, td {
text-align:center;
}
.spacer {
padding-top: 1.5em;
}
</style>
</head>
<body ng-app="tnb" ng-cloak>
<main class="text-center">
<section ng-controller="billCtrl">
<header>
<h1>TNB Calculator 2016 (Household)</h1>
<p>Calculate your electricity bill here!</p>
</header>
<section class="col-md-12">
<table class="table table-striped">
<thead>
<tr>
<th>No</th>
<th>Tariff Block (kWh)</th>
<th>Rate (cents)</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="rate in ::rates">
<td>{{$index + 1}}</td>
<td>{{rate.limit}}</td>
<td>{{rate.charge}}</td>
</tr>
</tbody>
</table>
</section>
<section class="col-md-12">
<form ng-submit="calculate()">
<div class="input-group">
<span class="input-group-addon" id="consumption">Consumption (kWh)</span>
<input type="number" class="form-control" placeholder="kWh" aria-describedby="consumption" ng-model="kwh" autofocus>
</div>
</form>
</section>
<section class="col-md-12 spacer">
<form ng-submit="refinance(finance)">
<div class="input-group">
<span class="input-group-addon" id="prediction">Predict consumable kWh (RM)</span>
<input type="number" class="form-control" placeholder="currency in MYR" aria-describedby="prediction" ng-model="finance">
</div>
</form>
</section>
<section class="col-md-12 spacer" ng-if="consumable > 0">
<div class="panel panel-default">
<div class="panel-heading">
Consumable kWh (Experimental)
</div>
<table class="table table-striped">
<tbody>
<tr>
<td width="50%">Predicted Consumable kWh</td>
<td>{{consumable}} kWh</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="col-md-12 spacer" ng-if="total > 0">
<div class="panel panel-default">
<div class="panel-heading">
Billing Summary
</div>
<table class="table table-striped">
<tbody>
<tr>
<td width="50%">Total (Before GST)</td>
<td>RM{{total}}</td>
</tr>
<tr>
<td>GST</td>
<td>RM{{gst}}</td>
</tr>
<tr>
<td>ICPT Rebate (Valid till June 2016)</td>
<td>RM{{icpt}}</td>
</tr>
<tr>
<td>Total (After GST)</td>
<td>RM{{gstTotal}}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="col-md-12 spacer">
<div class="panel panel-default">
<div class="panel-heading">Notes</div>
<div class="panel-body">
<p class="text-info">Minimum bill amount of Domestic Tariff is RM3.00</p>
<p class="text-info">ICPT Rebate only available for consumption <a href="https://www.tnb.com.my/faq/tariff" target="_blank">exceed 300 kWh</a></p>
<p class="text-info">ICPT abbr. of <strong><a href="https://www.tnb.com.my/faq/tariff#what-is-imbalance-cost-pass-through-icpt" target="_blank">Imbalance Cost Pass-Through</a></strong></p>
</div>
</div>
</section>
</section>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.1.3/ui-bootstrap.min.js"></script>
<script>
var tnb = angular.module('tnb', []);
tnb.controller('billCtrl', ['$scope', function ($scope) {
$scope.kwh = null;
$scope.gst = 0;
$scope.rates = [
{
level: 1,
charge: 21.8,
limit: 200
},
{
level: 2,
charge: 33.4,
limit: 100
},
{
level: 3,
charge: 51.6,
limit: 300
},
{
level: 4,
charge: 54.6,
limit: 300
}
];
$scope.calculate = function() {
$scope.consumable = undefined;
$scope.finance = undefined;
var total = 0,
kwh = $scope.kwh,
icptRebate = {
nongst: (kwh >= 300) ? (300 * 1.52 / 100) : 0,
gst: (kwh > 300) ? ((kwh - 300) * 1.52 / 100) : 0
}, // rebate > 300 tariff
cent = 0,
gstRate = 0.06;
var prices = {
nongst: 0,
gst: 0,
};
angular.forEach($scope.rates, function(rate) {
cent = (rate.charge/100);
if (rate.level === 4) {
prices['gst'] += (kwh * cent);
total += (kwh * cent);
kwh = 0;
} else if (kwh > rate.limit) {
total += (rate.limit * cent);
kwh -= rate.limit;
if (rate.level < 3) {
prices['nongst'] += (rate.limit * cent);
} else {
prices['gst'] += (rate.limit * cent);
}
} else if (kwh !== 0) {
total += (kwh * cent);
if (rate.level < 3) {
prices['nongst'] += (kwh * cent);
} else {
prices['gst'] += (kwh * cent);
}
kwh = 0;
}
});
total = prices['nongst'] - icptRebate['nongst'];
var gstChargeable = prices['gst'] - icptRebate['gst'];
$scope.total = getDecimal(total + gstChargeable);
$scope.gst = getDecimal(gstChargeable * gstRate);
$scope.icpt = getDecimal(icptRebate['gst'] + icptRebate['nongst']);
$scope.gstTotal = getDecimal(total + gstChargeable + (gstChargeable * gstRate));
};
// experimental
$scope.refinance = function(amount) {
$scope.total = undefined;
$scope.kwh = undefined;
var consumable = 0;
var stages = {};
angular.forEach($scope.rates, function(rate) {
stages[rate.level] = {
max: (rate.charge / 100 * rate.limit),
limit: rate.limit,
charge: (rate.charge / 100)
};
});
if (amount >= stages[1].max) {
consumable += stages[1].limit;
amount -= stages[1].max;
} else {
consumable = amount / stages[1].charge;
amount = 0;
}
if (amount >= stages[2].max) {
consumable += stages[2].limit;
amount -= stages[2].max;
} else {
consumable += amount / stages[2].charge;
amount = 0;
}
if (amount > 0) {
amount -= (amount * 0.06);
if (amount >= stages[3].max) {
consumable += stages[3].limit;
amount -= stages[3].max;
} else {
consumable += amount / stages[3].charge;
amount = 0;
}
if (amount > 0) {
consumable += amount / stages[4].charge;
}
}
$scope.consumable = (consumable).toFixed(0);
};
function getDecimal(num) {
return parseFloat(num).toFixed(2);
}
}]);
</script>
</body>
</html>