-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproportioning.html
More file actions
187 lines (171 loc) · 8.07 KB
/
proportioning.html
File metadata and controls
187 lines (171 loc) · 8.07 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Price Calculation Table</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css" rel="stylesheet">
<style>
.input-field {
width: 100px;
}
.total-input {
width: 150px;
text-align: right;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">ProcTool</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="https://vatcalculator.vercel.app/" active>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://vatcalculator.vercel.app/proportioning.html">Proportioner</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<h1 class="mb-4">Price Calculation Table</h1>
<div class="mb-3">
<label for="discount" class="form-label">Discount:</label>
<input type="number" class="form-control" id="discount" placeholder="Enter discount">
</div>
<div class="mb-3">
<label for="vat" class="form-label">VAT (%):</label>
<input type="number" class="form-control" id="vat" placeholder="Enter VAT percentage">
</div>
<button id="addRow" class="btn btn-primary mb-3">Add Row</button>
<table id="priceTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Quantity</th>
<th>Old Unit Price</th>
<th>Subtotal (Old)</th>
<th>VAT (Old)</th>
<th>Total Cost Before Discount</th>
<th>Proportional Discount</th>
<th>New Total Cost</th>
<th>New Unit Price</th>
<th>Subtotal (New)</th>
<th>VAT (New)</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Rows will be added dynamically -->
</tbody>
</table>
<div class="row mt-3">
<div class="col-md-6">
<label for="totalOldPrice" class="form-label">Total Old Price:</label>
<input type="number" class="form-control total-input" id="totalOldPrice" readonly>
</div>
<div class="col-md-6">
<label for="totalNewPrice" class="form-label">Total New Price:</label>
<input type="number" class="form-control total-input" id="totalNewPrice" readonly>
</div>
<div class="col-md-6 mt-3">
<label for="totalOldVAT" class="form-label">Total Old VAT:</label>
<input type="number" class="form-control total-input" id="totalOldVAT" readonly>
</div>
<div class="col-md-6 mt-3">
<label for="totalNewVAT" class="form-label">Total New VAT:</label>
<input type="number" class="form-control total-input" id="totalNewVAT" readonly>
</div>
</div>
<hr>
<p>Created by Carl Angelo Nievarez</p>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
$(document).ready(function() {
let table = $('#priceTable').DataTable({
paging: false,
searching: false,
info: false
});
function updateTotals() {
let totalCostBeforeDiscount = 0;
let totalNewCost = 0;
let discount = parseFloat($('#discount').val()) || 0;
let vat = parseFloat($('#vat').val()) || 0;
let totalProportionalDiscount = 0;
let totalOldVAT = 0;
let totalNewVAT = 0;
table.rows().every(function() {
let row = $(this.node());
let quantity = parseFloat(row.find('.quantity').val()) || 0;
let oldPrice = parseFloat(row.find('.old-price').val()) || 0;
let totalCost = quantity * oldPrice;
let oldVAT = (totalCost * vat) / 100;
totalOldVAT += oldVAT;
totalCostBeforeDiscount += totalCost;
row.find('.total-cost').text(totalCost.toFixed(2));
row.find('.subtotal-old').text(totalCost.toFixed(2));
row.find('.vat-old').text(oldVAT.toFixed(2));
});
table.rows().every(function() {
let row = $(this.node());
let totalCost = parseFloat(row.find('.total-cost').text()) || 0;
let proportionalDiscount = (totalCost / totalCostBeforeDiscount) * discount;
totalProportionalDiscount += proportionalDiscount;
let newTotalCost = totalCost - proportionalDiscount;
let quantity = parseFloat(row.find('.quantity').val()) || 0;
let newUnitPrice = newTotalCost / quantity;
let subtotalNew = quantity * newUnitPrice;
let newVAT = (subtotalNew * vat) / 100;
totalNewVAT += newVAT;
totalNewCost += subtotalNew;
row.find('.proportional-discount').text(proportionalDiscount.toFixed(2));
row.find('.new-total-cost').text(newTotalCost.toFixed(2));
row.find('.new-unit-price').text(newUnitPrice.toFixed(2));
row.find('.subtotal-new').text(subtotalNew.toFixed(2));
row.find('.vat-new').text(newVAT.toFixed(2));
});
$('#totalOldPrice').val(totalCostBeforeDiscount.toFixed(2));
$('#totalNewPrice').val(totalNewCost.toFixed(2));
$('#totalOldVAT').val(totalOldVAT.toFixed(2));
$('#totalNewVAT').val(totalNewVAT.toFixed(2));
}
$('#addRow').on('click', function() {
table.row.add([
'<input type="number" class="form-control quantity input-field" placeholder="Quantity">',
'<input type="number" class="form-control old-price input-field" placeholder="Old Unit Price">',
'<span class="subtotal-old">0.00</span>',
'<span class="vat-old">0.00</span>',
'<span class="total-cost">0.00</span>',
'<span class="proportional-discount">0.00</span>',
'<span class="new-total-cost">0.00</span>',
'<span class="new-unit-price">0.00</span>',
'<span class="subtotal-new">0.00</span>',
'<span class="vat-new">0.00</span>',
'<button class="btn btn-danger btn-sm delete-row">Delete</button>'
]).draw(false);
});
$('#priceTable tbody').on('input', '.quantity, .old-price', function() {
updateTotals();
});
$('#priceTable tbody').on('click', '.delete-row', function() {
table.row($(this).parents('tr')).remove().draw();
updateTotals();
});
$('#discount, #vat').on('input', function() {
updateTotals();
});
});
</script>
</body>
</html>