-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (70 loc) · 2.98 KB
/
Copy pathscript.js
File metadata and controls
85 lines (70 loc) · 2.98 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
const tbody = document.querySelector("#invoiceTable tbody");
function generateMonth() {
const monthInput = document.getElementById("invoiceMonth").value;
const period = document.getElementById("periodType").value;
if (!monthInput) {
alert("Please select a month");
return;
}
const tbody = document.querySelector("#invoiceTable tbody");
tbody.innerHTML = "";
const [year, month] = monthInput.split("-");
const daysInMonth = new Date(year, month, 0).getDate();
let startDay = 1;
let endDay = daysInMonth;
if (period === "first") {
endDay = 15;
} else if (period === "second") {
startDay = 16;
}
for (let day = startDay; day <= endDay; day++) {
const date = new Date(year, month - 1, day);
const dayName = date.toLocaleDateString("en-US", { weekday: "long" });
const isWeekend = date.getDay() === 0 || date.getDay() === 6;
const row = document.createElement("tr");
row.innerHTML = `
<td><input type="date" value="${year}-${month}-${String(day).padStart(2, "0")}"></td>
<td>${dayName}</td>
<td><input type="number" min="0" value="${isWeekend ? 0 : 8}" onchange="calculate()"></td>
<td><input type="number" min="0" value="0" onchange="calculate()"></td>
<td class="rowTotal">0.00</td>
<td>
<button onclick="this.closest('tr').remove(); calculate();">Remove</button>
</td>
`;
tbody.appendChild(row);
}
calculate();
}
function addRow(dateValue = "", isWeekend = false) {
const row = document.createElement("tr");
row.innerHTML = `
<td><input type="date" value="${dateValue}"></td>
<td>${dateValue ? new Date(dateValue).toLocaleDateString('en-US', { weekday: 'long' }) : ""}</td>
<td><input type="number" min="0" value="${isWeekend ? 0 : 8}" onchange="calculate()"></td>
<td><input type="number" min="0" value="0" onchange="calculate()"></td>
<td class="rowTotal">0.00</td>
<td><button onclick="this.closest('tr').remove(); calculate();">Remove</button></td>
`;
tbody.appendChild(row);
calculate();
}
function calculate() {
let grandTotal = 0;
document.querySelectorAll("#invoiceTable tbody tr").forEach(row => {
const hours = parseFloat(row.cells[2].querySelector("input").value) || 0;
const rate = parseFloat(row.cells[3].querySelector("input").value) || 0;
const total = hours * rate;
row.querySelector(".rowTotal").textContent = total.toFixed(2);
grandTotal += total;
});
document.getElementById("grandTotal").textContent = grandTotal.toFixed(2);
}
function saveInvoice() {
localStorage.setItem("htna_invoice", document.querySelector(".container").innerHTML);
alert("Invoice Saved Locally");
}
window.onload = function() {
const saved = localStorage.getItem("htna_invoice");
if (saved) document.querySelector(".container").innerHTML = saved;
}