Spaces:
Running
Running
Deploy hoursprig to the hub
Browse files- .gitattributes +1 -0
- hoursprig/app.js +526 -0
- hoursprig/icon-192.png +0 -0
- hoursprig/icon-512.png +0 -0
- hoursprig/icon.svg +9 -0
- hoursprig/index.html +259 -0
- hoursprig/lib/calc.js +362 -0
- hoursprig/lib/pdf.js +327 -0
- hoursprig/manifest.webmanifest +17 -0
- hoursprig/og.png +3 -0
- hoursprig/pro.js +139 -0
- hoursprig/robots.txt +3 -0
- hoursprig/sitemap.xml +2 -0
- hoursprig/style.css +301 -0
- hoursprig/sw.js +33 -0
.gitattributes
CHANGED
|
@@ -647,3 +647,4 @@ brand/hoursprig/cover.png filter=lfs diff=lfs merge=lfs -text
|
|
| 647 |
brand/hoursprig/image-1-shot.png filter=lfs diff=lfs merge=lfs -text
|
| 648 |
brand/hoursprig/image-2-output.png filter=lfs diff=lfs merge=lfs -text
|
| 649 |
brand/hoursprig/image-3-inside.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 647 |
brand/hoursprig/image-1-shot.png filter=lfs diff=lfs merge=lfs -text
|
| 648 |
brand/hoursprig/image-2-output.png filter=lfs diff=lfs merge=lfs -text
|
| 649 |
brand/hoursprig/image-3-inside.png filter=lfs diff=lfs merge=lfs -text
|
| 650 |
+
hoursprig/og.png filter=lfs diff=lfs merge=lfs -text
|
hoursprig/app.js
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Hoursprig app: time card editor, live totals, timesheet preview, PDF/print/CSV, Pro features. Everything stays in this browser.
|
| 2 |
+
* © 2026 CyberMax. All rights reserved. */
|
| 3 |
+
(function () {
|
| 4 |
+
"use strict";
|
| 5 |
+
var C = window.HourCalc, P = window.HourPDF, X = window.CMXPro;
|
| 6 |
+
var KEY = "hoursprig:v1";
|
| 7 |
+
var HUB = "https://cybermax-tools-cybermax.static.hf.space/hoursprig/index.html?utm_source=pdf-credit";
|
| 8 |
+
var MAX_PAIRS = 4;
|
| 9 |
+
var $ = function (id) { return document.getElementById(id); };
|
| 10 |
+
var form = $("editor");
|
| 11 |
+
|
| 12 |
+
function pro() { return X.isPro(); }
|
| 13 |
+
function toast(m) { X.toast(m); }
|
| 14 |
+
function upsell(msg, from) { X.upsell(msg || "That is a Hoursprig Pro feature.", from); }
|
| 15 |
+
function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); }
|
| 16 |
+
function clone(o) { return JSON.parse(JSON.stringify(o)); }
|
| 17 |
+
function uid() { return Date.now().toString(36) + Math.random().toString(36).slice(2, 7); }
|
| 18 |
+
function todayISO() { var d = new Date(); return d.getFullYear() + "-" + ("0" + (d.getMonth() + 1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2); }
|
| 19 |
+
|
| 20 |
+
/* ---------- state ---------- */
|
| 21 |
+
function entriesOf(period) {
|
| 22 |
+
var e = {};
|
| 23 |
+
(period.days || []).forEach(function (d) { e[d.date] = { pairs: d.pairs, brk: d.brk, note: d.note }; });
|
| 24 |
+
return e;
|
| 25 |
+
}
|
| 26 |
+
function tidy(entries, h24) {
|
| 27 |
+
Object.keys(entries).forEach(function (d) { entries[d].pairs.forEach(function (q) { var n = C.normalizePair(q.in, q.out, h24); q.in = n.in; q.out = n.out; }); });
|
| 28 |
+
return entries;
|
| 29 |
+
}
|
| 30 |
+
function fromExample(k) {
|
| 31 |
+
var ex = C.example(k), id = uid();
|
| 32 |
+
var settings = Object.assign(C.defaults(), ex.settings, { paper: "" });
|
| 33 |
+
var rate = settings.rate; delete settings.rate;
|
| 34 |
+
return {
|
| 35 |
+
settings: settings, company: ex.company, notes: "",
|
| 36 |
+
employee: { id: id, name: ex.employee.name, ref: ex.employee.ref, rate: rate },
|
| 37 |
+
period: { kind: ex.period.kind, start: ex.period.start, entries: tidy(entriesOf(ex.period), settings.h24) },
|
| 38 |
+
};
|
| 39 |
+
}
|
| 40 |
+
function fresh() {
|
| 41 |
+
var ex = fromExample("weekly");
|
| 42 |
+
var o = { v: 1, settings: ex.settings, company: ex.company, notes: "", employees: [ex.employee], active: ex.employee.id, periods: {}, history: [], logo: null, results: 0 };
|
| 43 |
+
o.periods[ex.employee.id] = ex.period;
|
| 44 |
+
return o;
|
| 45 |
+
}
|
| 46 |
+
function valid(s) { return s && typeof s === "object" && Array.isArray(s.employees) && s.employees.length && s.periods && s.settings; }
|
| 47 |
+
function load() {
|
| 48 |
+
var s = null;
|
| 49 |
+
try { s = JSON.parse(localStorage.getItem(KEY) || "null"); } catch (e) { s = null; }
|
| 50 |
+
if (!valid(s)) return fresh();
|
| 51 |
+
var f = fresh();
|
| 52 |
+
Object.keys(f).forEach(function (k) { if (s[k] == null) s[k] = f[k]; });
|
| 53 |
+
return s;
|
| 54 |
+
}
|
| 55 |
+
var S = load();
|
| 56 |
+
var saveT = null;
|
| 57 |
+
function save() {
|
| 58 |
+
clearTimeout(saveT);
|
| 59 |
+
saveT = setTimeout(saveNow, 150);
|
| 60 |
+
}
|
| 61 |
+
function saveNow() { clearTimeout(saveT); try { localStorage.setItem(KEY, JSON.stringify(S)); } catch (e) { toast("Could not save in this browser (storage full or private mode)."); } }
|
| 62 |
+
|
| 63 |
+
function emp() {
|
| 64 |
+
if (!pro()) return S.employees[0];
|
| 65 |
+
return S.employees.filter(function (e) { return e.id === S.active; })[0] || S.employees[0];
|
| 66 |
+
}
|
| 67 |
+
function period() {
|
| 68 |
+
var e = emp(), p = S.periods[e.id];
|
| 69 |
+
if (!p) { p = S.periods[e.id] = { kind: S.settings.kind || "week", start: defaultStart(S.settings.kind || "week"), entries: {} }; }
|
| 70 |
+
return p;
|
| 71 |
+
}
|
| 72 |
+
function defaultStart(kind) {
|
| 73 |
+
var t = todayISO();
|
| 74 |
+
if (kind === "semimonth") return C.periodStart(kind, t);
|
| 75 |
+
return C.addDays(t, -C.dow(t)); // most recent Sunday
|
| 76 |
+
}
|
| 77 |
+
function blankEntry() { return { pairs: [{ in: "", out: "" }], brk: "", note: "" }; }
|
| 78 |
+
function entry(date) { var p = period(); if (!p.entries[date]) p.entries[date] = blankEntry(); return p.entries[date]; }
|
| 79 |
+
function periodObj(p) {
|
| 80 |
+
p = p || period();
|
| 81 |
+
return { kind: p.kind, start: p.start, days: C.periodDates(p.kind, p.start).map(function (d) { return Object.assign({ date: d }, p.entries[d] || blankEntry()); }) };
|
| 82 |
+
}
|
| 83 |
+
function proRulesOn(s) { return !!(s.dailyOn || s.dtOn || s.seventhOn); }
|
| 84 |
+
function effSettings(settings, e, kind) {
|
| 85 |
+
var s = Object.assign({}, settings, { rate: e.rate, kind: kind });
|
| 86 |
+
return pro() ? s : C.freeRules(s);
|
| 87 |
+
}
|
| 88 |
+
function result() { var p = period(); return C.compute(periodObj(p), effSettings(S.settings, emp(), p.kind)); }
|
| 89 |
+
function sheet() { return { company: S.company, employee: { name: emp().name, ref: emp().ref }, result: result(), notes: S.notes }; }
|
| 90 |
+
function hasTimes(p) {
|
| 91 |
+
return Object.keys(p.entries || {}).some(function (d) { var x = p.entries[d]; return (x.pairs || []).some(function (q) { return String(q.in || "").trim() || String(q.out || "").trim(); }); });
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/* ---------- employee + period form ---------- */
|
| 95 |
+
function fillSelects() {
|
| 96 |
+
$("r-currency").innerHTML = C.CURRENCIES.map(function (c) { return '<option value="' + c.code + '">' + c.code + "</option>"; }).join("");
|
| 97 |
+
$("r-weekStart").innerHTML = C.DOW_LONG.map(function (d, i) { return '<option value="' + i + '">' + d + "</option>"; }).join("");
|
| 98 |
+
}
|
| 99 |
+
function renderEmployees() {
|
| 100 |
+
var list = pro() ? S.employees : [S.employees[0]];
|
| 101 |
+
$("f-emp").innerHTML = list.map(function (e, i) { return '<option value="' + esc(e.id) + '">' + esc(e.name || "Employee " + (i + 1)) + "</option>"; }).join("");
|
| 102 |
+
$("f-emp").value = emp().id;
|
| 103 |
+
$("f-emp").disabled = list.length < 2;
|
| 104 |
+
$("btn-del-emp").hidden = !(pro() && S.employees.length > 1);
|
| 105 |
+
$("plan-chip").textContent = pro() ? S.employees.length + (S.employees.length === 1 ? " employee" : " employees") : "Free: 1 employee";
|
| 106 |
+
}
|
| 107 |
+
function toForm() {
|
| 108 |
+
var e = emp(), p = period();
|
| 109 |
+
$("f-name").value = e.name || ""; $("f-ref").value = e.ref || ""; $("f-rate").value = e.rate || "";
|
| 110 |
+
$("f-company").value = S.company || ""; $("f-notes").value = S.notes || "";
|
| 111 |
+
$("f-start").value = p.start;
|
| 112 |
+
Array.prototype.forEach.call(document.querySelectorAll(".seg button"), function (b) { b.setAttribute("aria-checked", String(b.dataset.kind === p.kind)); });
|
| 113 |
+
document.body.classList.toggle("semi", p.kind === "semimonth");
|
| 114 |
+
Array.prototype.forEach.call(form.querySelectorAll("[data-set]"), function (el) {
|
| 115 |
+
var v = S.settings[el.dataset.set];
|
| 116 |
+
if (el.type === "checkbox") el.checked = !!v;
|
| 117 |
+
else if (el.dataset.set === "h24") el.value = v ? "1" : "";
|
| 118 |
+
else el.value = v == null ? "" : String(v);
|
| 119 |
+
});
|
| 120 |
+
renderEmployees();
|
| 121 |
+
renderDays();
|
| 122 |
+
hints();
|
| 123 |
+
}
|
| 124 |
+
form.addEventListener("submit", function (e) { e.preventDefault(); });
|
| 125 |
+
form.addEventListener("input", function (e) {
|
| 126 |
+
var el = e.target;
|
| 127 |
+
if (el.dataset.emp) { emp()[el.dataset.emp] = el.value; if (el.dataset.emp === "name") renderEmployees(); changed(); }
|
| 128 |
+
else if (el.dataset.top) { S[el.dataset.top] = el.value; changed(); }
|
| 129 |
+
else if (el.dataset.set && el.type !== "checkbox" && el.tagName === "INPUT") { S.settings[el.dataset.set] = el.value; changed(); }
|
| 130 |
+
});
|
| 131 |
+
form.addEventListener("change", function (e) {
|
| 132 |
+
var el = e.target, k = el.dataset.set;
|
| 133 |
+
if (!k) return;
|
| 134 |
+
if (el.type === "checkbox") {
|
| 135 |
+
if (el.checked && el.dataset.pro && !pro()) {
|
| 136 |
+
el.checked = false;
|
| 137 |
+
return upsell("Daily overtime, double time and the 7th-day rule are part of Pro.", "ot-rules");
|
| 138 |
+
}
|
| 139 |
+
S.settings[k] = el.checked;
|
| 140 |
+
} else if (k === "h24") { S.settings.h24 = !!el.value; tidy(period().entries, S.settings.h24); renderDays(); }
|
| 141 |
+
else if (k === "rounding" || k === "weekStart") S.settings[k] = +el.value;
|
| 142 |
+
else if (el.tagName === "SELECT") S.settings[k] = el.value;
|
| 143 |
+
hints(); changed();
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
Array.prototype.forEach.call(document.querySelectorAll(".seg button"), function (b) {
|
| 147 |
+
b.addEventListener("click", function () { setPeriod(b.dataset.kind, null); });
|
| 148 |
+
});
|
| 149 |
+
$("f-start").addEventListener("change", function () { if (C.validISO(this.value)) setPeriod(null, this.value); else this.value = period().start; });
|
| 150 |
+
$("btn-prev").addEventListener("click", function () { var p = period(); setPeriod(null, C.shiftPeriod(p.kind, p.start, -1)); });
|
| 151 |
+
$("btn-next").addEventListener("click", function () { var p = period(); setPeriod(null, C.shiftPeriod(p.kind, p.start, 1)); });
|
| 152 |
+
|
| 153 |
+
/** Change period kind and/or start. Free keeps one period: moving to a different one clears times (after a confirm); Pro saves the old one to history. */
|
| 154 |
+
function setPeriod(kind, start) {
|
| 155 |
+
var p = period();
|
| 156 |
+
kind = kind || p.kind;
|
| 157 |
+
start = C.periodStart(kind, start || p.start);
|
| 158 |
+
if (kind === p.kind && start === p.start) return toForm();
|
| 159 |
+
var oldDates = C.periodDates(p.kind, p.start), newDates = C.periodDates(kind, start);
|
| 160 |
+
var moving = start !== p.start && newDates.indexOf(oldDates[0]) < 0;
|
| 161 |
+
if (moving && hasTimes(p)) {
|
| 162 |
+
if (pro()) { recordHistory(p, true); toast("Saved " + C.fmtRange(oldDates[0], oldDates[oldDates.length - 1]) + " to your pay periods."); }
|
| 163 |
+
else if (!confirm("The free plan keeps one pay period. Start a new period and clear the current times?\n\nHoursprig Pro saves every period to history.")) { $("f-start").value = p.start; return; }
|
| 164 |
+
}
|
| 165 |
+
var keep = {};
|
| 166 |
+
newDates.forEach(function (d) { if (p.entries[d] && !moving) keep[d] = p.entries[d]; });
|
| 167 |
+
p.kind = kind; p.start = start; p.entries = keep;
|
| 168 |
+
S.settings.kind = kind;
|
| 169 |
+
toForm(); changed();
|
| 170 |
+
}
|
| 171 |
+
function hints() {
|
| 172 |
+
var p = period(), dates = C.periodDates(p.kind, p.start), s = S.settings;
|
| 173 |
+
var txt = C.fmtRange(dates[0], dates[dates.length - 1]) + " · " + dates.length + " days. ";
|
| 174 |
+
if (p.kind === "semimonth") txt += "Weekly overtime uses workweeks starting " + C.DOW_LONG[s.weekStart] + "; a workweek that crosses into the next period only counts the days in this one.";
|
| 175 |
+
else txt += "Weekly overtime counts each 7 days from the start date as one workweek" + (p.kind === "biweek" ? " (2 workweeks)." : ".");
|
| 176 |
+
$("period-hint").textContent = txt;
|
| 177 |
+
var r = +s.rounding;
|
| 178 |
+
$("round-hint").textContent = !r ? "Exact minutes are used. Rounding, if your workplace uses it, moves each in and out time to the nearest step." :
|
| 179 |
+
r === 15 ? "Each in and out time moves to the nearest quarter hour: 8:07 becomes 8:00, 8:08 becomes 8:15." :
|
| 180 |
+
r === 6 ? "Each in and out time moves to the nearest 6 minutes (0.1 h): 8:02 becomes 8:00, 8:03 becomes 8:06." :
|
| 181 |
+
"Each in and out time moves to the nearest 5 minutes: 8:02 becomes 8:00, 8:03 becomes 8:05.";
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/* ---------- employees (Pro) ---------- */
|
| 185 |
+
$("btn-add-emp").addEventListener("click", function () {
|
| 186 |
+
if (!pro()) return upsell("The free plan covers 1 employee. Hoursprig Pro keeps every employee's timesheet in one place.", "employees");
|
| 187 |
+
var p = period(), e = { id: uid(), name: "", ref: "", rate: emp().rate || "" };
|
| 188 |
+
S.employees.push(e); S.active = e.id;
|
| 189 |
+
S.periods[e.id] = { kind: p.kind, start: p.start, entries: {} };
|
| 190 |
+
toForm(); changed(); $("f-name").focus();
|
| 191 |
+
toast("New employee added. Type their name and times.");
|
| 192 |
+
});
|
| 193 |
+
$("f-emp").addEventListener("change", function () { S.active = this.value; toForm(); changed(); });
|
| 194 |
+
$("btn-del-emp").addEventListener("click", function () {
|
| 195 |
+
if (S.employees.length < 2) return;
|
| 196 |
+
var e = emp();
|
| 197 |
+
if (!confirm("Remove " + (e.name || "this employee") + " and their current times? Saved pay periods stay in history.")) return;
|
| 198 |
+
S.employees = S.employees.filter(function (x) { return x.id !== e.id; });
|
| 199 |
+
delete S.periods[e.id]; S.active = S.employees[0].id;
|
| 200 |
+
toForm(); changed();
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
/* ---------- the time card ---------- */
|
| 204 |
+
function renderDays() {
|
| 205 |
+
var p = period(), h24 = !!S.settings.h24;
|
| 206 |
+
$("days").innerHTML = C.periodDates(p.kind, p.start).map(function (date) {
|
| 207 |
+
var x = p.entries[date] || blankEntry(), dw = C.DOW[C.dow(date)], lab = dw + " " + C.fmtDate(date);
|
| 208 |
+
var list = x.pairs && x.pairs.length ? x.pairs : [{ in: "", out: "" }], n = list.length;
|
| 209 |
+
var pairs = list.map(function (q, i) {
|
| 210 |
+
return '<div class="pair" data-p="' + i + '"><input class="t" data-k="in" value="' + esc(q.in) + '" placeholder="In" aria-label="' + lab + " in" + (i ? ", shift " + (i + 1) : "") + '" inputmode="text" enterkeyhint="next">' +
|
| 211 |
+
'<span class="dash" aria-hidden="true">–</span><input class="t" data-k="out" value="' + esc(q.out) + '" placeholder="Out" aria-label="' + lab + " out" + (i ? ", shift " + (i + 1) : "") + '" inputmode="text" enterkeyhint="next">' +
|
| 212 |
+
(i ? '<button type="button" class="icon-btn sm" data-act="delpair" aria-label="Remove shift ' + (i + 1) + " on " + lab + '" title="Remove this shift">×</button>' :
|
| 213 |
+
'<button type="button" class="icon-btn sm add" data-act="addpair" aria-label="Add a split shift on ' + lab + '" title="Add a split shift"' + (n >= MAX_PAIRS ? " disabled" : "") + ">+</button>") + "</div>";
|
| 214 |
+
}).join("");
|
| 215 |
+
return '<div class="day" data-date="' + date + '"><div class="dl"><b>' + dw + "</b><span>" + C.fmtDate(date) + "</span></div>" +
|
| 216 |
+
'<div class="pairs">' + pairs + "</div>" +
|
| 217 |
+
'<div class="brk"><input data-k="brk" value="' + esc(x.brk) + '" inputmode="numeric" placeholder="0" aria-label="' + lab + ' unpaid break in minutes"><span>min</span></div>' +
|
| 218 |
+
'<div class="dt" aria-live="polite"></div>' +
|
| 219 |
+
'<input class="note" data-k="note" value="' + esc(x.note) + '" placeholder="Note" aria-label="' + lab + ' note"></div>';
|
| 220 |
+
}).join("");
|
| 221 |
+
dayTotals();
|
| 222 |
+
}
|
| 223 |
+
function dayTotals(r) {
|
| 224 |
+
r = r || result();
|
| 225 |
+
var map = {};
|
| 226 |
+
r.days.forEach(function (d) { map[d.date] = d; });
|
| 227 |
+
Array.prototype.forEach.call($("days").querySelectorAll(".day"), function (row) {
|
| 228 |
+
var d = map[row.dataset.date]; if (!d) return;
|
| 229 |
+
var on = d.worked > 0;
|
| 230 |
+
row.classList.toggle("off", !on);
|
| 231 |
+
var over = d.shifts.some(function (s) { return s.end > C.DAY; });
|
| 232 |
+
row.querySelector(".dt").innerHTML = on ? "<b>" + C.hm(d.worked) + "</b><small>" + C.dec(d.worked) + " h" + (d.ot || d.dt ? "<br>OT " + C.hm(d.ot + d.dt) : "") + (over ? "<br>+1 day" : "") + "</small>" : '<b class="z">0:00</b>';
|
| 233 |
+
Array.prototype.forEach.call(row.querySelectorAll(".pair"), function (pr) {
|
| 234 |
+
var i = +pr.dataset.p, bad = d.errors.indexOf(i) > -1;
|
| 235 |
+
var ins = pr.querySelectorAll("input.t");
|
| 236 |
+
Array.prototype.forEach.call(ins, function (inp) {
|
| 237 |
+
var v = inp.value.trim(), b = bad && (!v || !C.parseTime(v));
|
| 238 |
+
inp.classList.toggle("bad", b);
|
| 239 |
+
if (b) { inp.setAttribute("aria-invalid", "true"); inp.title = v ? "Could not read this time. Try 9, 9a, 9:30pm or 21:30." : "Add the " + inp.dataset.k + " time."; }
|
| 240 |
+
else { inp.removeAttribute("aria-invalid"); inp.removeAttribute("title"); }
|
| 241 |
+
});
|
| 242 |
+
});
|
| 243 |
+
});
|
| 244 |
+
}
|
| 245 |
+
$("days").addEventListener("input", function (e) {
|
| 246 |
+
var el = e.target, row = el.closest(".day"); if (!row || !el.dataset.k) return;
|
| 247 |
+
var x = entry(row.dataset.date);
|
| 248 |
+
if (el.dataset.k === "in" || el.dataset.k === "out") {
|
| 249 |
+
var i = +el.closest(".pair").dataset.p;
|
| 250 |
+
if (!x.pairs[i]) x.pairs[i] = { in: "", out: "" };
|
| 251 |
+
x.pairs[i][el.dataset.k] = el.value;
|
| 252 |
+
} else x[el.dataset.k] = el.value;
|
| 253 |
+
changed(true);
|
| 254 |
+
});
|
| 255 |
+
$("days").addEventListener("focusout", function (e) {
|
| 256 |
+
var el = e.target;
|
| 257 |
+
if (!el.classList || !el.classList.contains("t")) return;
|
| 258 |
+
var pr = el.closest(".pair"), ins = pr.querySelectorAll("input.t"), inEl = ins[0], outEl = ins[1];
|
| 259 |
+
if (!el.value.trim()) return;
|
| 260 |
+
if (el === outEl && !inEl.value.trim()) return;
|
| 261 |
+
var n = C.normalizePair(inEl.value, outEl.value, !!S.settings.h24);
|
| 262 |
+
if (el === inEl && !C.span(inEl.value, outEl.value)) n.out = outEl.value;
|
| 263 |
+
var x = entry(el.closest(".day").dataset.date), q = x.pairs[+pr.dataset.p];
|
| 264 |
+
if (!q) return;
|
| 265 |
+
if (n.in !== inEl.value) inEl.value = n.in;
|
| 266 |
+
if (n.out !== outEl.value) outEl.value = n.out;
|
| 267 |
+
q.in = n.in; q.out = n.out; save();
|
| 268 |
+
});
|
| 269 |
+
$("days").addEventListener("click", function (e) {
|
| 270 |
+
var b = e.target.closest("[data-act]"); if (!b) return;
|
| 271 |
+
var row = b.closest(".day"), x = entry(row.dataset.date);
|
| 272 |
+
if (b.dataset.act === "addpair" && x.pairs.length < MAX_PAIRS) x.pairs.push({ in: "", out: "" });
|
| 273 |
+
if (b.dataset.act === "delpair") x.pairs.splice(+b.closest(".pair").dataset.p, 1);
|
| 274 |
+
renderDays(); changed(true);
|
| 275 |
+
if (b.dataset.act === "addpair") { var ins = $("days").querySelectorAll('.day[data-date="' + row.dataset.date + '"] .pair input.t'); if (ins.length) ins[ins.length - 2].focus(); }
|
| 276 |
+
});
|
| 277 |
+
$("btn-copy").addEventListener("click", function () {
|
| 278 |
+
var p = period(), dates = C.periodDates(p.kind, p.start);
|
| 279 |
+
var src = null;
|
| 280 |
+
dates.some(function (d) { var x = p.entries[d]; if (x && x.pairs.some(function (q) { return String(q.in).trim() && String(q.out).trim(); })) { src = x; return true; } return false; });
|
| 281 |
+
if (!src) return toast("Type the first day's times, then copy them.");
|
| 282 |
+
var n = 0;
|
| 283 |
+
dates.forEach(function (d) { var w = C.dow(d); if (w >= 1 && w <= 5 && p.entries[d] !== src) { p.entries[d] = { pairs: clone(src.pairs), brk: src.brk, note: "" }; n++; } });
|
| 284 |
+
renderDays(); changed(true); toast("Copied to " + n + " weekdays.");
|
| 285 |
+
});
|
| 286 |
+
$("btn-clear").addEventListener("click", function () {
|
| 287 |
+
if (!confirm("Clear every time on this card?")) return;
|
| 288 |
+
period().entries = {}; renderDays(); changed(true);
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
/* ---------- totals + preview ---------- */
|
| 292 |
+
function renderSummary(r) {
|
| 293 |
+
var T = r.totals, s = r.settings, m = function (v) { return esc(C.money(v, s.currency)); };
|
| 294 |
+
var showDT = s.dtOn || s.seventhOn || T.dt > 0;
|
| 295 |
+
var rows = '<tr><th scope="row">Regular</th><td>' + C.hm(T.reg) + "</td><td>" + C.dec(T.reg) + "</td><td>" + (T.rate ? m(T.regPay) : "") + "</td></tr>" +
|
| 296 |
+
'<tr><th scope="row">Overtime ×' + esc(s.otMult) + "</th><td>" + C.hm(T.ot) + "</td><td>" + C.dec(T.ot) + "</td><td>" + (T.rate ? m(T.otPay) : "") + "</td></tr>" +
|
| 297 |
+
(showDT ? '<tr><th scope="row">Double time ×' + esc(s.dtMult) + "</th><td>" + C.hm(T.dt) + "</td><td>" + C.dec(T.dt) + "</td><td>" + (T.rate ? m(T.dtPay) : "") + "</td></tr>" : "");
|
| 298 |
+
var locked = !pro() && proRulesOn(S.settings);
|
| 299 |
+
$("sum").innerHTML =
|
| 300 |
+
'<div class="sum-top"><div><div class="k">Total hours</div><div class="big" id="total-hm">' + C.hm(T.worked) + '</div><div class="sub">' + C.dec(T.worked) + " h decimal · " + T.daysWorked + (T.daysWorked === 1 ? " day" : " days") + "</div></div>" +
|
| 301 |
+
'<div class="pay"><div class="k">' + (T.rate ? "Gross pay" : "Add an hourly rate for pay") + '</div><div class="big" id="total-pay">' + (T.rate ? m(T.gross) : "—") + "</div>" + (T.rate ? '<div class="sub">at ' + m(T.rate) + "/h</div>" : "") + "</div></div>" +
|
| 302 |
+
'<table class="sum-t"><thead><tr><th></th><th>h:mm</th><th>Decimal</th><th>Pay</th></tr></thead><tbody>' + rows + "</tbody></table>" +
|
| 303 |
+
'<p class="rules-line">' + esc(C.ruleLines(s)) + "</p>" +
|
| 304 |
+
(locked ? '<p class="locked-note">Daily overtime, double time and the 7th-day rule are switched on but only apply with Pro, so this shows weekly overtime only. <button type="button" class="linkish" id="btn-rules-pro">Unlock all rules</button></p>' : "");
|
| 305 |
+
var lb = $("btn-rules-pro"); if (lb) lb.onclick = function () { upsell(null, "ot-rules"); };
|
| 306 |
+
$("warn").textContent = T.errors ? T.errors + (T.errors === 1 ? " shift has" : " shifts have") + " a time that could not be read or is missing (marked in red)." : "";
|
| 307 |
+
}
|
| 308 |
+
function previewHTML(sh, opts) {
|
| 309 |
+
var r = sh.result, s = r.settings, T = r.totals, h24 = !!s.h24, emp = sh.employee || {};
|
| 310 |
+
var m = function (v) { return esc(C.money(v, s.currency)); };
|
| 311 |
+
var showDT = s.dtOn || s.seventhOn || T.dt > 0, multi = r.weeks.length > 1;
|
| 312 |
+
var rows = r.weeks.map(function (wk, wi) {
|
| 313 |
+
return wk.days.map(function (d) {
|
| 314 |
+
var on = d.worked > 0;
|
| 315 |
+
return '<tr class="' + (on ? "" : "off") + '"><td>' + esc(C.fmtDate(d.date, true)) + "</td><td>" + (on ? d.shifts.map(function (x) { return esc(C.fmtClock(x.start, h24) + " – " + C.fmtClock(x.end, h24)) + (x.end > C.DAY ? " <i>(+1 day)</i>" : ""); }).join("<br>") : "—") +
|
| 316 |
+
'</td><td class="n">' + (on && d.brk ? d.brk + " min" : "") + '</td><td class="n b">' + (on ? C.hm(d.worked) : "—") + '</td><td class="n">' + (on ? C.hm(d.reg) : "") + '</td><td class="n">' + (d.ot ? C.hm(d.ot) : "") + "</td>" +
|
| 317 |
+
(showDT ? '<td class="n">' + (d.dt ? C.hm(d.dt) : "") + "</td>" : "") + '<td class="nt">' + esc((d.seventh ? "7th day. " : "") + d.note) + "</td></tr>";
|
| 318 |
+
}).join("") + (multi ? '<tr class="wk"><td>Week ' + (wi + 1) + "</td><td>" + esc(C.fmtDate(wk.start) + " – " + C.fmtDate(wk.end)) + '</td><td></td><td class="n">' + C.hm(wk.worked) + '</td><td class="n">' + C.hm(wk.reg) + '</td><td class="n">' + C.hm(wk.ot) + "</td>" + (showDT ? '<td class="n">' + C.hm(wk.dt) + "</td>" : "") + "<td></td></tr>" : "");
|
| 319 |
+
}).join("");
|
| 320 |
+
var pay = [["Regular", T.reg, T.regPay]];
|
| 321 |
+
if (s.weeklyOn || s.dailyOn || s.seventhOn || T.ot) pay.push(["Overtime ×" + s.otMult, T.ot, T.otPay]);
|
| 322 |
+
if (showDT) pay.push(["Double time ×" + s.dtMult, T.dt, T.dtPay]);
|
| 323 |
+
return '<header class="p-head">' + (opts.logo ? '<img class="p-logo" src="' + opts.logo + '" alt="">' : "") + '<div class="p-co"><div class="p-name">' + esc(sh.company) + '</div><div class="p-kind">' + esc(C.KIND_LABEL[r.kind]) + ' timesheet</div></div><div class="p-title"><div>TIMESHEET</div><span>' + esc(C.fmtRange(r.start, r.end)) + "</span></div></header>" +
|
| 324 |
+
'<div class="p-band"><div><small>EMPLOYEE</small><b>' + esc(emp.name || "—") + "</b></div><div><small>EMPLOYEE ID</small><b>" + esc(emp.ref || "—") + "</b></div><div><small>PAY PERIOD</small><b>" + esc(C.fmtDate(r.start, "y") + " to " + C.fmtDate(r.end, "y")) + "</b></div><div><small>HOURLY RATE</small><b>" + (T.rate ? m(T.rate) : "—") + "</b></div></div>" +
|
| 325 |
+
'<table class="p-t"><thead><tr><th>Date</th><th>In – Out</th><th class="n">Break</th><th class="n">Hours</th><th class="n">Regular</th><th class="n">Overtime</th>' + (showDT ? '<th class="n">Double</th>' : "") + "<th>Note</th></tr></thead><tbody>" + rows +
|
| 326 |
+
'<tr class="tot"><td>Total</td><td>' + T.daysWorked + (T.daysWorked === 1 ? " day" : " days") + ' worked</td><td class="n">' + (T.brk ? T.brk + " min" : "") + '</td><td class="n">' + C.hm(T.worked) + '</td><td class="n">' + C.hm(T.reg) + '</td><td class="n">' + C.hm(T.ot) + "</td>" + (showDT ? '<td class="n">' + C.hm(T.dt) + "</td>" : "") + '<td class="nt">' + C.dec(T.worked) + " h decimal</td></tr></tbody></table>" +
|
| 327 |
+
'<section class="p-bottom"><div class="p-rules"><small>HOW THIS WAS CALCULATED</small><p>' + esc(C.ruleLines(s)) + "</p>" + (sh.notes ? "<small>NOTES</small><p>" + esc(sh.notes) + "</p>" : "") + "</div>" +
|
| 328 |
+
'<table class="p-pay">' + pay.map(function (x) { return "<tr><td>" + esc(x[0]) + "</td><td>" + C.hm(x[1]) + " (" + C.dec(x[1]) + " h)</td><td>" + (T.rate ? m(x[2]) : "") + "</td></tr>"; }).join("") +
|
| 329 |
+
'<tr class="g"><td colspan="2">' + (T.rate ? "Gross pay" : "Total hours") + "</td><td>" + (T.rate ? m(T.gross) : C.hm(T.worked)) + "</td></tr></table></section>" +
|
| 330 |
+
'<p class="p-confirm">I confirm the hours above are a true record of the time worked.</p>' +
|
| 331 |
+
'<div class="p-sig"><div><span></span><small>EMPLOYEE SIGNATURE</small><em>' + esc(emp.name) + '</em></div><div class="d"><span></span><small>DATE</small></div><div><span></span><small>SUPERVISOR / EMPLOYER SIGNATURE</small><em>' + esc(sh.company) + '</em></div><div class="d"><span></span><small>DATE</small></div></div>' +
|
| 332 |
+
'<footer class="p-foot"><span class="p-disc">Calculated from the entered times and settings; not legal or payroll advice.</span>' + (opts.credit ? '<span class="p-credit">Calculated with Hoursprig by CyberMax · free time card calculator</span>' : "") + "</footer>";
|
| 333 |
+
}
|
| 334 |
+
function renderPreview(r) {
|
| 335 |
+
var sh = sheet(); if (r) sh.result = r;
|
| 336 |
+
var el = $("doc");
|
| 337 |
+
el.className = "paper" + (P.pageSize(S.settings.paper, S.settings.currency)[0] === 612 ? " letter" : "");
|
| 338 |
+
el.innerHTML = previewHTML(sh, { credit: !pro(), logo: pro() && S.logo && S.logo.data ? S.logo.data : "" });
|
| 339 |
+
fit();
|
| 340 |
+
}
|
| 341 |
+
function fit() {
|
| 342 |
+
var wrap = $("paper-wrap"), el = $("doc");
|
| 343 |
+
var s = Math.min(1, wrap.clientWidth / el.offsetWidth);
|
| 344 |
+
el.style.transform = "scale(" + s + ")";
|
| 345 |
+
wrap.style.height = Math.ceil(el.offsetHeight * s) + "px";
|
| 346 |
+
}
|
| 347 |
+
window.addEventListener("resize", fit);
|
| 348 |
+
|
| 349 |
+
function limitsLine() {
|
| 350 |
+
$("limits").innerHTML = pro() ? "<b>Pro:</b> every employee, saved pay periods, CSV for payroll, all overtime rules, no footer line." :
|
| 351 |
+
'<b>Free plan:</b> 1 employee · current pay period only · print and PDF carry a small Hoursprig line. <a href="#cmx-pro" id="lim-pro">Pro is $15 once</a>';
|
| 352 |
+
var a = $("lim-pro"); if (a) a.onclick = function (e) { e.preventDefault(); upsell(null, "limits"); };
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
var changeT = null;
|
| 356 |
+
function changed(daysOnly) {
|
| 357 |
+
save();
|
| 358 |
+
clearTimeout(changeT);
|
| 359 |
+
changeT = setTimeout(function () {
|
| 360 |
+
var r = result();
|
| 361 |
+
dayTotals(r); renderSummary(r); renderPreview(r);
|
| 362 |
+
}, daysOnly ? 40 : 60);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/* ---------- PDF, print, CSV ---------- */
|
| 366 |
+
function b64ToBytes(dataUrl) {
|
| 367 |
+
var b = atob(dataUrl.split(",")[1] || ""), u = new Uint8Array(b.length);
|
| 368 |
+
for (var i = 0; i < b.length; i++) u[i] = b.charCodeAt(i);
|
| 369 |
+
return u;
|
| 370 |
+
}
|
| 371 |
+
function pdfFor(sh) {
|
| 372 |
+
var logo = pro() && S.logo && S.logo.data ? { bytes: b64ToBytes(S.logo.data), w: S.logo.w, h: S.logo.h } : null;
|
| 373 |
+
return P.build(sh, { credit: !pro(), creditUrl: HUB, logo: logo, paper: S.settings.paper });
|
| 374 |
+
}
|
| 375 |
+
$("btn-pdf").addEventListener("click", function () {
|
| 376 |
+
var sh = sheet(), bytes;
|
| 377 |
+
if (!sh.result.totals.worked) return toast("Add some in and out times first.");
|
| 378 |
+
try { bytes = pdfFor(sh); } catch (e) { return toast("Sorry, the PDF could not be made: " + e.message); }
|
| 379 |
+
X.download(P.fileName(sh), new Blob([bytes], { type: "application/pdf" }));
|
| 380 |
+
done("Timesheet PDF downloaded.");
|
| 381 |
+
});
|
| 382 |
+
$("m-pdf").addEventListener("click", function () { $("btn-pdf").click(); });
|
| 383 |
+
$("btn-print").addEventListener("click", function () { renderPreview(); done(null); setTimeout(function () { window.print(); }, 30); });
|
| 384 |
+
$("btn-csv").addEventListener("click", function () {
|
| 385 |
+
if (!pro()) return upsell("CSV export for payroll is part of Hoursprig Pro.", "csv");
|
| 386 |
+
var sh = sheet();
|
| 387 |
+
X.download(P.fileName(sh, "csv"), C.csvDays([sh]) + "\r\n" + C.csvSummary([sh]), "text/csv;charset=utf-8");
|
| 388 |
+
done("CSV downloaded.");
|
| 389 |
+
});
|
| 390 |
+
function done(msg) {
|
| 391 |
+
S.results = (S.results || 0) + 1; saveNow();
|
| 392 |
+
if (!pro()) $("pro-cta").hidden = false;
|
| 393 |
+
if (msg) toast(msg);
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
/* ---------- Pro: saved periods ---------- */
|
| 397 |
+
function recordHistory(p, quiet) {
|
| 398 |
+
var e = emp();
|
| 399 |
+
var id = e.id + ":" + p.start + ":" + p.kind;
|
| 400 |
+
var item = { id: id, saved: new Date().toISOString(), employee: { id: e.id, name: e.name, ref: e.ref, rate: e.rate }, company: S.company, notes: S.notes, settings: clone(S.settings), period: clone(p) };
|
| 401 |
+
S.history = [item].concat(S.history.filter(function (h) { return h.id !== id; })).slice(0, 1000);
|
| 402 |
+
renderHistory();
|
| 403 |
+
if (!quiet) save();
|
| 404 |
+
}
|
| 405 |
+
function histResult(h) { return C.compute(periodObj(h.period), Object.assign({}, h.settings, { rate: h.employee.rate, kind: h.period.kind })); }
|
| 406 |
+
function histSheet(h) { return { company: h.company, employee: { name: h.employee.name, ref: h.employee.ref }, result: histResult(h), notes: h.notes }; }
|
| 407 |
+
function renderHistory() {
|
| 408 |
+
var body = $("hist-body");
|
| 409 |
+
$("hist-btns").hidden = !pro();
|
| 410 |
+
if (!pro()) {
|
| 411 |
+
body.innerHTML = '<div class="locked"><p>The free plan keeps the current pay period. Pro saves every period for every employee, reopens any of them, and exports one CSV for your payroll or accountant.</p><button type="button" class="btn" id="btn-hist-pro">Unlock saved periods</button></div>';
|
| 412 |
+
$("btn-hist-pro").onclick = function () { upsell(null, "history"); };
|
| 413 |
+
return;
|
| 414 |
+
}
|
| 415 |
+
if (!S.history.length) { body.innerHTML = '<p class="hint">Press “Save this period” (or move to the next period) and it appears here.</p>'; return; }
|
| 416 |
+
body.innerHTML = '<div class="table-wrap"><table class="ht"><thead><tr><th>Employee</th><th>Period</th><th class="num">Hours</th><th class="num">Overtime</th><th class="num">Gross pay</th><th>Actions</th></tr></thead><tbody>' +
|
| 417 |
+
S.history.map(function (h) {
|
| 418 |
+
var r = histResult(h), T = r.totals;
|
| 419 |
+
return '<tr data-id="' + esc(h.id) + '"><td>' + esc(h.employee.name || "—") + "</td><td>" + esc(C.fmtRange(r.start, r.end)) + '</td><td class="num">' + C.hm(T.worked) + '</td><td class="num">' + C.hm(T.ot + T.dt) + '</td><td class="num">' + (T.rate ? esc(C.money(T.gross, r.settings.currency)) : "—") +
|
| 420 |
+
'</td><td><button type="button" class="btn ghost sm" data-h="open">Open</button> <button type="button" class="btn ghost sm" data-h="pdf">PDF</button> <button type="button" class="icon-btn" data-h="del" aria-label="Delete this saved period">×</button></td></tr>';
|
| 421 |
+
}).join("") + "</tbody></table></div>";
|
| 422 |
+
}
|
| 423 |
+
$("hist-body").addEventListener("click", function (e) {
|
| 424 |
+
var b = e.target.closest("[data-h]"); if (!b) return;
|
| 425 |
+
var id = b.closest("tr").dataset.id, h = S.history.filter(function (x) { return x.id === id; })[0]; if (!h) return;
|
| 426 |
+
var act = b.dataset.h;
|
| 427 |
+
if (act === "pdf") { var sh = histSheet(h); X.download(P.fileName(sh), new Blob([pdfFor(sh)], { type: "application/pdf" })); return; }
|
| 428 |
+
if (act === "open") {
|
| 429 |
+
var e2 = S.employees.filter(function (x) { return x.id === h.employee.id; })[0];
|
| 430 |
+
if (!e2) { e2 = { id: h.employee.id, name: h.employee.name, ref: h.employee.ref, rate: h.employee.rate }; S.employees.push(e2); }
|
| 431 |
+
S.active = e2.id; S.periods[e2.id] = clone(h.period); S.settings = Object.assign(S.settings, clone(h.settings));
|
| 432 |
+
toForm(); changed(); $("app").scrollIntoView({ behavior: "smooth" }); toast("Opened " + (h.employee.name || "the timesheet") + ".");
|
| 433 |
+
return;
|
| 434 |
+
}
|
| 435 |
+
if (act === "del") { if (!confirm("Delete this saved pay period?")) return; S.history = S.history.filter(function (x) { return x.id !== id; }); save(); renderHistory(); }
|
| 436 |
+
});
|
| 437 |
+
$("btn-save-hist").addEventListener("click", function () {
|
| 438 |
+
if (!pro()) return upsell("Saved pay periods are part of Hoursprig Pro.", "history");
|
| 439 |
+
recordHistory(period()); toast("Saved this pay period.");
|
| 440 |
+
});
|
| 441 |
+
$("btn-csv-all").addEventListener("click", function () {
|
| 442 |
+
if (!pro()) return upsell("CSV export for payroll is part of Hoursprig Pro.", "csv");
|
| 443 |
+
var list = S.history.map(histSheet);
|
| 444 |
+
if (!list.length) return toast("Save a pay period first.");
|
| 445 |
+
X.download("hoursprig-payroll-" + todayISO() + ".csv", C.csvSummary(list) + "\r\n" + C.csvDays(list), "text/csv;charset=utf-8");
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
/* ---------- logo (Pro) ---------- */
|
| 449 |
+
$("f-logo").addEventListener("click", function (e) { if (!pro()) { e.preventDefault(); upsell("Your company logo on timesheets is part of Pro.", "logo"); } });
|
| 450 |
+
$("f-logo").addEventListener("change", function () {
|
| 451 |
+
var f = this.files && this.files[0]; this.value = "";
|
| 452 |
+
if (!f) return;
|
| 453 |
+
if (f.size > 5e6) return toast("That image is over 5 MB. Try a smaller logo.");
|
| 454 |
+
var url = URL.createObjectURL(f), img = new Image();
|
| 455 |
+
img.onload = function () {
|
| 456 |
+
var s = Math.min(1, 600 / img.naturalWidth, 240 / img.naturalHeight) || 1;
|
| 457 |
+
var w = Math.max(1, Math.round((img.naturalWidth || 300) * s)), h = Math.max(1, Math.round((img.naturalHeight || 120) * s));
|
| 458 |
+
var c = document.createElement("canvas"); c.width = w; c.height = h;
|
| 459 |
+
var g = c.getContext("2d"); g.fillStyle = "#fff"; g.fillRect(0, 0, w, h); g.drawImage(img, 0, 0, w, h);
|
| 460 |
+
S.logo = { data: c.toDataURL("image/jpeg", 0.9), w: w, h: h };
|
| 461 |
+
URL.revokeObjectURL(url); save(); logoUi(); renderPreview(); toast("Logo added.");
|
| 462 |
+
};
|
| 463 |
+
img.onerror = function () { URL.revokeObjectURL(url); toast("That file could not be read as an image."); };
|
| 464 |
+
img.src = url;
|
| 465 |
+
});
|
| 466 |
+
$("btn-logo-clear").addEventListener("click", function () { S.logo = null; save(); logoUi(); renderPreview(); });
|
| 467 |
+
function logoUi() {
|
| 468 |
+
var has = pro() && S.logo && S.logo.data;
|
| 469 |
+
$("logo-prev").innerHTML = has ? '<img src="' + S.logo.data + '" alt="Your logo">' : "No logo";
|
| 470 |
+
$("btn-logo-clear").hidden = !has;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
/* ---------- example, backup ---------- */
|
| 474 |
+
$("btn-example").addEventListener("click", function () {
|
| 475 |
+
var ex = fromExample($("example-kind").value);
|
| 476 |
+
S.settings = ex.settings; S.company = ex.company; S.notes = "";
|
| 477 |
+
var e = emp();
|
| 478 |
+
e.name = ex.employee.name; e.ref = ex.employee.ref; e.rate = ex.employee.rate;
|
| 479 |
+
S.periods[e.id] = ex.period;
|
| 480 |
+
toForm(); changed();
|
| 481 |
+
if (!pro() && proRulesOn(S.settings)) toast("Example loaded. Its daily and 7th-day rules apply with Pro; free shows weekly overtime.");
|
| 482 |
+
if (window.innerWidth < 980) setTimeout(function () { $("preview").scrollIntoView({ behavior: "smooth", block: "start" }); }, 80);
|
| 483 |
+
});
|
| 484 |
+
$("btn-backup").addEventListener("click", function () {
|
| 485 |
+
if (!pro()) return upsell("JSON backup is part of Hoursprig Pro.", "backup");
|
| 486 |
+
saveNow();
|
| 487 |
+
X.download("hoursprig-backup-" + todayISO() + ".json", JSON.stringify({ app: "hoursprig", version: 1, saved: new Date().toISOString(), data: S }, null, 1), "application/json");
|
| 488 |
+
});
|
| 489 |
+
$("f-restore").addEventListener("change", function () {
|
| 490 |
+
var f = this.files && this.files[0]; this.value = "";
|
| 491 |
+
if (!f) return;
|
| 492 |
+
f.text().then(function (t) {
|
| 493 |
+
var j = JSON.parse(t), d = j && j.app === "hoursprig" ? j.data : null;
|
| 494 |
+
if (!valid(d)) throw new Error("not a Hoursprig backup");
|
| 495 |
+
var f0 = fresh(); Object.keys(f0).forEach(function (k) { if (d[k] == null) d[k] = f0[k]; });
|
| 496 |
+
S = d; saveNow(); toForm(); renderHistory(); logoUi(); changed();
|
| 497 |
+
toast("Backup restored.");
|
| 498 |
+
}).catch(function (e) { toast("Could not restore: " + e.message + "."); });
|
| 499 |
+
});
|
| 500 |
+
$("btn-cta").addEventListener("click", function () { upsell(null, "mid-cta"); });
|
| 501 |
+
|
| 502 |
+
/* ---------- Pro state ---------- */
|
| 503 |
+
function onPro(isPro) {
|
| 504 |
+
$("pro-pill").textContent = isPro ? "Pro ✓" : "Go Pro";
|
| 505 |
+
if (isPro) $("pro-cta").hidden = true;
|
| 506 |
+
limitsLine(); renderHistory(); logoUi(); toForm(); changed();
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
/* ---------- install + offline ---------- */
|
| 510 |
+
var deferred = null;
|
| 511 |
+
window.addEventListener("beforeinstallprompt", function (e) { e.preventDefault(); deferred = e; $("btn-install").hidden = false; });
|
| 512 |
+
$("btn-install").addEventListener("click", function () {
|
| 513 |
+
if (!deferred) return;
|
| 514 |
+
deferred.prompt(); deferred.userChoice.finally(function () { deferred = null; $("btn-install").hidden = true; });
|
| 515 |
+
});
|
| 516 |
+
window.addEventListener("appinstalled", function () { $("btn-install").hidden = true; });
|
| 517 |
+
if ("serviceWorker" in navigator && (location.protocol === "https:" || /^(localhost|127\.0\.0\.1)$/.test(location.hostname))) {
|
| 518 |
+
window.addEventListener("load", function () { navigator.serviceWorker.register("sw.js").catch(function () { /* offline cache is optional */ }); });
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
/* ---------- start ---------- */
|
| 522 |
+
fillSelects();
|
| 523 |
+
X.onChange(onPro);
|
| 524 |
+
var r0 = result(); renderSummary(r0); renderPreview(r0);
|
| 525 |
+
window.Hoursprig = { state: function () { return S; }, result: result, pdf: function () { return pdfFor(sheet()); } };
|
| 526 |
+
})();
|
hoursprig/icon-192.png
ADDED
|
|
hoursprig/icon-512.png
ADDED
|
|
hoursprig/icon.svg
ADDED
|
|
hoursprig/index.html
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
+
<title>Time Card Calculator with Overtime & Printable Timesheet | Hoursprig</title>
|
| 7 |
+
<meta name="description" content="Free time card calculator: enter in and out times, breaks and split or overnight shifts, get hours, overtime and pay, then print or download a signable timesheet.">
|
| 8 |
+
<meta name="keywords" content="time card calculator, timesheet calculator, hours calculator, overtime calculator, work hours calculator, biweekly timesheet, timesheet template with overtime, printable timesheet">
|
| 9 |
+
<meta name="theme-color" content="#1F62B5">
|
| 10 |
+
<link rel="canonical" href="https://cybermax-tools-cybermax.static.hf.space/hoursprig/index.html">
|
| 11 |
+
<link rel="manifest" href="manifest.webmanifest">
|
| 12 |
+
<link rel="icon" href="icon.svg" type="image/svg+xml">
|
| 13 |
+
<link rel="apple-touch-icon" href="icon-192.png">
|
| 14 |
+
<meta property="og:type" content="website">
|
| 15 |
+
<meta property="og:site_name" content="CyberMax">
|
| 16 |
+
<meta property="og:title" content="Hoursprig: time card calculator with overtime and a printable timesheet">
|
| 17 |
+
<meta property="og:description" content="Hours, overtime and pay from your in and out times, plus a timesheet ready to sign. Free, no sign-up, nothing uploaded.">
|
| 18 |
+
<meta property="og:url" content="https://cybermax-tools-cybermax.static.hf.space/hoursprig/index.html">
|
| 19 |
+
<meta property="og:image" content="https://cybermax-tools-cybermax.static.hf.space/hoursprig/og.png">
|
| 20 |
+
<meta name="twitter:card" content="summary_large_image">
|
| 21 |
+
<script type="application/ld+json">
|
| 22 |
+
{"@context":"https://schema.org","@graph":[
|
| 23 |
+
{"@type":"WebApplication","name":"Hoursprig","alternateName":"Hoursprig time card calculator","url":"https://cybermax-tools-cybermax.static.hf.space/hoursprig/index.html","image":"https://cybermax-tools-cybermax.static.hf.space/hoursprig/og.png","applicationCategory":"BusinessApplication","operatingSystem":"Any (web browser)","browserRequirements":"Requires JavaScript","description":"Time card and timesheet calculator for small employers, freelancers and staff: in and out times, split and overnight shifts, unpaid breaks, rounding, weekly and daily overtime, pay at an hourly rate, and a printable, signable weekly, bi-weekly or semi-monthly timesheet as PDF. Runs in the browser, nothing uploaded.","offers":[{"@type":"Offer","name":"Free","price":"0","priceCurrency":"USD","description":"1 employee, current pay period, weekly overtime, print and PDF with a small Hoursprig line"},{"@type":"Offer","name":"Hoursprig Pro Lifetime","price":"15","priceCurrency":"USD","description":"Multiple employees, saved periods history, CSV export for payroll, daily, double-time and 7th-day overtime rules, company logo, no footer line, JSON backup; pay once"}],"publisher":{"@type":"Organization","name":"CyberMax","email":"cybermax.tools@gmail.com"}},
|
| 24 |
+
{"@type":"FAQPage","mainEntity":[
|
| 25 |
+
{"@type":"Question","name":"Is Hoursprig really free?","acceptedAnswer":{"@type":"Answer","text":"Yes. One employee, the current pay period (weekly, bi-weekly or semi-monthly), split and overnight shifts, breaks, rounding, weekly overtime and pay, plus unlimited printing and PDF downloads with no account. Free timesheets carry a small Calculated with Hoursprig by CyberMax line."}},
|
| 26 |
+
{"@type":"Question","name":"How do I type the times?","acceptedAnswer":{"@type":"Answer","text":"Any way you like: 9, 9a, 9am, 9:30pm, 21:30, 0930 or noon. An out time without am or pm is read as the afternoon when that makes sense, so 9 to 5 is 8 hours. A shift that ends after midnight, such as 10pm to 6:30am, is counted on the day it starts."}},
|
| 27 |
+
{"@type":"Question","name":"Why not Clockify?","acceptedAnswer":{"@type":"Answer","text":"Clockify is a full time-tracking service with apps and team features, priced per seat: Basic $3.99 per seat a month billed annually or $4.99 monthly, Standard $5.49 or $6.99, Pro $7.99 or $9.99 (clockify.me/pricing, checked 2 Oct 2026). If you just need to add up time cards and print a timesheet, Hoursprig is free, and Pro is $15 once for the whole business."}},
|
| 28 |
+
{"@type":"Question","name":"Is my data private?","acceptedAnswer":{"@type":"Answer","text":"Yes. Hoursprig runs entirely in your browser. Names, times and pay rates are saved only on this device and the PDF is made on your device. Nothing is uploaded."}},
|
| 29 |
+
{"@type":"Question","name":"What does Pro add?","acceptedAnswer":{"@type":"Answer","text":"Multiple employees, a history of saved pay periods, CSV export for payroll, all overtime rules (daily overtime, double time and the 7th consecutive day rule), your company logo on timesheets, no footer line and JSON backup. It is $15 once."}},
|
| 30 |
+
{"@type":"Question","name":"Can I cancel?","acceptedAnswer":{"@type":"Answer","text":"There is nothing to cancel. Hoursprig Pro is a single $15 payment with no subscription, and the free plan stays free."}}]}
|
| 31 |
+
]}
|
| 32 |
+
</script>
|
| 33 |
+
<link rel="stylesheet" href="style.css">
|
| 34 |
+
</head>
|
| 35 |
+
<body>
|
| 36 |
+
<header class="top"><div class="wrap top-in">
|
| 37 |
+
<a class="brand" href="./" aria-label="Hoursprig home"><img src="icon.svg" alt="" width="30" height="30"><span><b>Hoursprig</b> <small>by CyberMax</small></span></a>
|
| 38 |
+
<nav class="top-nav">
|
| 39 |
+
<button class="btn ghost sm" id="btn-install" type="button" hidden>Install app</button>
|
| 40 |
+
<a href="#cmx-pro" class="top-link">Pricing</a>
|
| 41 |
+
<a href="#cmx-pro" class="pill" id="pro-pill">Pro</a>
|
| 42 |
+
</nav>
|
| 43 |
+
</div></header>
|
| 44 |
+
|
| 45 |
+
<main>
|
| 46 |
+
<div class="wrap">
|
| 47 |
+
<section class="hero">
|
| 48 |
+
<h1>Time card calculator: hours, overtime and pay</h1>
|
| 49 |
+
<p class="lede">For small employers, freelancers and staff. Type in and out times, breaks and split or overnight shifts; get total hours, overtime and pay, then print a timesheet ready to sign. <b>Free, no sign-up, nothing uploaded.</b></p>
|
| 50 |
+
<div class="hero-row">
|
| 51 |
+
<button class="btn" id="btn-example" type="button">Load example</button>
|
| 52 |
+
<label class="sel-inline" for="example-kind"><span class="sr">Example</span>
|
| 53 |
+
<select id="example-kind">
|
| 54 |
+
<option value="weekly">Weekly, split shift + weekly overtime</option>
|
| 55 |
+
<option value="night">Bi-weekly, overnight shifts</option>
|
| 56 |
+
<option value="daily">Daily overtime + 7th day (Pro rules)</option>
|
| 57 |
+
</select></label>
|
| 58 |
+
<span class="hero-note">Weekly, bi-weekly or semi-monthly · print & PDF free · works offline</span>
|
| 59 |
+
</div>
|
| 60 |
+
</section>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<section id="app" class="app wrap" aria-label="Time card calculator">
|
| 64 |
+
<div class="cols">
|
| 65 |
+
<form id="editor" class="editor" autocomplete="off" novalidate>
|
| 66 |
+
<div class="card">
|
| 67 |
+
<div class="card-head"><h2>Employee & pay period</h2><span class="plan-chip" id="plan-chip"></span></div>
|
| 68 |
+
<div class="emp-row">
|
| 69 |
+
<div class="emp-sel"><label for="f-emp">Employee</label><select id="f-emp"></select></div>
|
| 70 |
+
<button type="button" class="btn ghost sm" id="btn-add-emp">+ Add employee <span class="pro-tag">PRO</span></button>
|
| 71 |
+
<button type="button" class="btn ghost sm danger" id="btn-del-emp" hidden>Remove</button>
|
| 72 |
+
</div>
|
| 73 |
+
<div class="g3">
|
| 74 |
+
<div class="span2"><label for="f-name">Employee name</label><input id="f-name" data-emp="name" autocomplete="name" placeholder="Full name"></div>
|
| 75 |
+
<div><label for="f-ref">Employee ID <span class="opt">optional</span></label><input id="f-ref" data-emp="ref" placeholder="E-104"></div>
|
| 76 |
+
<div><label for="f-rate">Hourly rate</label><input id="f-rate" data-emp="rate" inputmode="decimal" placeholder="0.00"></div>
|
| 77 |
+
<div class="span2"><label for="f-company">Company / employer</label><input id="f-company" data-top="company" autocomplete="organization" placeholder="Business name"></div>
|
| 78 |
+
</div>
|
| 79 |
+
<div class="period-row">
|
| 80 |
+
<div class="seg" role="radiogroup" aria-label="Pay period">
|
| 81 |
+
<button type="button" role="radio" data-kind="week" aria-checked="true">Weekly</button>
|
| 82 |
+
<button type="button" role="radio" data-kind="biweek" aria-checked="false">Bi-weekly</button>
|
| 83 |
+
<button type="button" role="radio" data-kind="semimonth" aria-checked="false">Semi-monthly</button>
|
| 84 |
+
</div>
|
| 85 |
+
<div class="start"><label for="f-start">Period starts</label>
|
| 86 |
+
<div class="combo"><button type="button" class="icon-btn" id="btn-prev" aria-label="Previous period">‹</button><input id="f-start" type="date"><button type="button" class="icon-btn" id="btn-next" aria-label="Next period">›</button></div>
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
<p class="hint" id="period-hint"></p>
|
| 90 |
+
<div class="logo-row">
|
| 91 |
+
<div class="logo-prev" id="logo-prev" aria-live="polite">No logo</div>
|
| 92 |
+
<label class="btn ghost sm file-btn" for="f-logo">Company logo <span class="pro-tag">PRO</span></label>
|
| 93 |
+
<input type="file" id="f-logo" accept="image/png,image/jpeg,image/webp,image/svg+xml" hidden>
|
| 94 |
+
<button type="button" class="btn ghost sm" id="btn-logo-clear" hidden>Remove logo</button>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
<div class="card">
|
| 99 |
+
<div class="card-head"><h2>Time card</h2><span class="hint tiny">Type 9, 9a, 9:30pm or 21:30</span></div>
|
| 100 |
+
<div class="days-head" aria-hidden="true"><span>Day</span><span>In – Out</span><span>Break</span><span>Hours</span></div>
|
| 101 |
+
<div id="days"></div>
|
| 102 |
+
<div class="btns">
|
| 103 |
+
<button type="button" class="btn ghost sm" id="btn-copy">Copy first day to weekdays</button>
|
| 104 |
+
<button type="button" class="btn ghost sm" id="btn-clear">Clear times</button>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<details class="card" id="rules" open>
|
| 109 |
+
<summary><h2>Overtime & rounding</h2></summary>
|
| 110 |
+
<div class="rule">
|
| 111 |
+
<label class="check"><input type="checkbox" id="r-weeklyOn" data-set="weeklyOn"> Weekly overtime after</label>
|
| 112 |
+
<div class="combo sm"><input id="r-weeklyAfter" data-set="weeklyAfter" inputmode="decimal" aria-label="Weekly overtime after hours"><span>hours a week</span></div>
|
| 113 |
+
<p class="hint">40 hours is the US federal (FLSA) weekly default. Check your state or country.</p>
|
| 114 |
+
</div>
|
| 115 |
+
<div class="g2">
|
| 116 |
+
<div><label for="r-otMult">Overtime rate</label><div class="combo sm"><input id="r-otMult" data-set="otMult" inputmode="decimal"><span>× hourly rate</span></div></div>
|
| 117 |
+
<div><label for="r-rounding">Round clock times</label><select id="r-rounding" data-set="rounding"><option value="0">No rounding (exact minutes)</option><option value="5">Nearest 5 minutes</option><option value="6">Nearest 6 minutes (tenth of an hour)</option><option value="15">Nearest 15 minutes (quarter hour)</option></select></div>
|
| 118 |
+
</div>
|
| 119 |
+
<p class="hint" id="round-hint"></p>
|
| 120 |
+
<div class="pro-rules">
|
| 121 |
+
<div class="rule"><label class="check"><input type="checkbox" id="r-dailyOn" data-set="dailyOn" data-pro="1"> Daily overtime after <span class="pro-tag">PRO</span></label>
|
| 122 |
+
<div class="combo sm"><input id="r-dailyAfter" data-set="dailyAfter" inputmode="decimal" aria-label="Daily overtime after hours"><span>hours a day</span></div></div>
|
| 123 |
+
<div class="rule"><label class="check"><input type="checkbox" id="r-dtOn" data-set="dtOn" data-pro="1"> Double time after <span class="pro-tag">PRO</span></label>
|
| 124 |
+
<div class="combo sm"><input id="r-dtAfter" data-set="dtAfter" inputmode="decimal" aria-label="Double time after hours in a day"><span>hours a day, at</span><input id="r-dtMult" data-set="dtMult" inputmode="decimal" aria-label="Double time rate multiplier"><span>×</span></div></div>
|
| 125 |
+
<div class="rule"><label class="check"><input type="checkbox" id="r-seventhOn" data-set="seventhOn" data-pro="1"> 7th consecutive day in a workweek: first 8 h overtime, the rest double time <span class="pro-tag">PRO</span></label></div>
|
| 126 |
+
<p class="hint">Daily overtime hours are not counted again toward the weekly limit.</p>
|
| 127 |
+
</div>
|
| 128 |
+
<div class="g3">
|
| 129 |
+
<div><label for="r-currency">Currency</label><select id="r-currency" data-set="currency"></select></div>
|
| 130 |
+
<div><label for="r-h24">Clock</label><select id="r-h24" data-set="h24"><option value="">12-hour (9:30 PM)</option><option value="1">24-hour (21:30)</option></select></div>
|
| 131 |
+
<div><label for="r-paper">Paper</label><select id="r-paper" data-set="paper"><option value="">Auto</option><option value="Letter">US Letter</option><option value="A4">A4</option></select></div>
|
| 132 |
+
<div class="only-semi"><label for="r-weekStart">Workweek starts</label><select id="r-weekStart" data-set="weekStart"></select></div>
|
| 133 |
+
</div>
|
| 134 |
+
</details>
|
| 135 |
+
|
| 136 |
+
<div class="card">
|
| 137 |
+
<label for="f-notes" class="h2like">Notes on the timesheet <span class="opt">optional</span></label>
|
| 138 |
+
<textarea id="f-notes" data-top="notes" rows="2" placeholder="Approved by, job or site, mileage…"></textarea>
|
| 139 |
+
</div>
|
| 140 |
+
|
| 141 |
+
<details class="card">
|
| 142 |
+
<summary><h2>Backup</h2></summary>
|
| 143 |
+
<p class="hint">Everything lives in this browser only. Nothing is uploaded. A backup file moves your employees and saved periods to another device.</p>
|
| 144 |
+
<div class="btns"><button type="button" class="btn ghost sm" id="btn-backup">Download backup (JSON) <span class="pro-tag">PRO</span></button><label class="btn ghost sm file-btn" for="f-restore">Restore backup</label><input type="file" id="f-restore" accept="application/json,.json" hidden></div>
|
| 145 |
+
</details>
|
| 146 |
+
</form>
|
| 147 |
+
|
| 148 |
+
<aside class="preview-col" id="preview" aria-label="Totals and timesheet">
|
| 149 |
+
<div class="card sum" id="sum" aria-live="polite"></div>
|
| 150 |
+
<div class="actions card">
|
| 151 |
+
<div class="act-row">
|
| 152 |
+
<button type="button" class="btn big" id="btn-pdf">Download PDF</button>
|
| 153 |
+
<button type="button" class="btn ghost" id="btn-print">Print</button>
|
| 154 |
+
<button type="button" class="btn ghost" id="btn-csv">CSV <span class="pro-tag">PRO</span></button>
|
| 155 |
+
</div>
|
| 156 |
+
<p class="limits" id="limits"></p>
|
| 157 |
+
<p class="warn" id="warn" aria-live="polite"></p>
|
| 158 |
+
</div>
|
| 159 |
+
<div class="paper-wrap" id="paper-wrap"><div id="doc" class="paper" aria-label="Timesheet preview"></div></div>
|
| 160 |
+
</aside>
|
| 161 |
+
</div>
|
| 162 |
+
</section>
|
| 163 |
+
|
| 164 |
+
<div class="wrap">
|
| 165 |
+
<section class="pro-cta card" id="pro-cta" hidden>
|
| 166 |
+
<div>
|
| 167 |
+
<h2>Doing timesheets for a team?</h2>
|
| 168 |
+
<p>Hoursprig Pro: every employee in one place, saved pay periods, a CSV for your payroll, daily and double-time overtime, your logo and no footer line. <b>$15 once</b>, no subscription.</p>
|
| 169 |
+
</div>
|
| 170 |
+
<button type="button" class="btn" id="btn-cta">See Pro</button>
|
| 171 |
+
</section>
|
| 172 |
+
|
| 173 |
+
<section class="history card" id="history" aria-labelledby="h-history">
|
| 174 |
+
<div class="hist-head"><h2 id="h-history">Saved pay periods <span class="pro-tag">PRO</span></h2><div class="btns" id="hist-btns"><button type="button" class="btn ghost sm" id="btn-save-hist">Save this period</button><button type="button" class="btn ghost sm" id="btn-csv-all">Export CSV for payroll</button></div></div>
|
| 175 |
+
<div id="hist-body"></div>
|
| 176 |
+
</section>
|
| 177 |
+
|
| 178 |
+
<section class="how" id="how">
|
| 179 |
+
<h2>How it works</h2>
|
| 180 |
+
<ol class="steps">
|
| 181 |
+
<li><b>Type the times.</b> In and out for each day, as many pairs as a split shift needs, and the unpaid break in minutes. Shifts past midnight are handled for you.</li>
|
| 182 |
+
<li><b>Check the totals.</b> Hours in hours:minutes and decimal, regular and overtime split by your rules, and pay at the hourly rate, updated as you type.</li>
|
| 183 |
+
<li><b>Print or download.</b> A clean weekly, bi-weekly or semi-monthly timesheet with signature lines for the employee and employer, as PDF or straight to the printer.</li>
|
| 184 |
+
</ol>
|
| 185 |
+
</section>
|
| 186 |
+
|
| 187 |
+
<section class="example card" id="worked">
|
| 188 |
+
<h2>Worked example: weekly overtime</h2>
|
| 189 |
+
<p>Jordan works Monday to Saturday at $22.50 an hour: 8:00, 8:00, 9:30, 8:30, 10:00 and 4:30 hours after unpaid breaks, <b>48:30 hours</b> (48.50 decimal) in total. With the US federal weekly rule, the first 40 hours are regular and the <b>8:30 above 40 are overtime</b> at 1.5×.</p>
|
| 190 |
+
<div class="table-wrap"><table class="ht">
|
| 191 |
+
<thead><tr><th>Line</th><th class="num">Hours</th><th class="num">Rate</th><th class="num">Pay</th></tr></thead>
|
| 192 |
+
<tbody>
|
| 193 |
+
<tr><td>Regular</td><td class="num">40.00</td><td class="num">$22.50</td><td class="num">$900.00</td></tr>
|
| 194 |
+
<tr><td>Overtime (1.5×)</td><td class="num">8.50</td><td class="num">$33.75</td><td class="num">$286.88</td></tr>
|
| 195 |
+
<tr><td><b>Gross pay</b></td><td class="num"><b>48.50</b></td><td></td><td class="num"><b>$1,186.88</b></td></tr>
|
| 196 |
+
</tbody>
|
| 197 |
+
</table></div>
|
| 198 |
+
<p class="hint">This is the “Weekly, split shift” example above. Load it to see the full timesheet.</p>
|
| 199 |
+
</section>
|
| 200 |
+
|
| 201 |
+
<section class="compare" id="compare">
|
| 202 |
+
<h2>Hoursprig vs time-tracking apps</h2>
|
| 203 |
+
<div class="table-wrap">
|
| 204 |
+
<table class="cmp">
|
| 205 |
+
<thead><tr><th scope="col">Tool</th><th scope="col">Price</th><th scope="col">Good to know</th></tr></thead>
|
| 206 |
+
<tbody>
|
| 207 |
+
<tr class="us"><th scope="row">Hoursprig Free</th><td>$0</td><td>1 employee, current pay period, split and overnight shifts, rounding, weekly overtime, pay, print and PDF; no account, works offline, nothing uploaded</td></tr>
|
| 208 |
+
<tr class="us"><th scope="row">Hoursprig Pro</th><td><b>$15 once</b></td><td>Every employee, saved periods, CSV for payroll, daily, double-time and 7th-day overtime, your logo, no footer line</td></tr>
|
| 209 |
+
<tr><th scope="row"><a href="https://clockify.me/pricing" target="_blank" rel="noopener nofollow">Clockify</a></th><td>Basic $3.99/seat/month billed annually or $4.99 monthly; Standard $5.49 or $6.99; Pro $7.99 or $9.99</td><td>Full time-tracking service with clock-in apps, timers and team features</td></tr>
|
| 210 |
+
<tr><th scope="row"><a href="https://www.timely.com/blog/jibble-pricing/" target="_blank" rel="noopener nofollow">Jibble</a></th><td>Premium $2.49/user/month, Ultimate $4.99</td><td>Time clock app with clock-in apps and GPS features</td></tr>
|
| 211 |
+
</tbody>
|
| 212 |
+
</table>
|
| 213 |
+
</div>
|
| 214 |
+
<p class="hint">Rival prices checked 2 Oct 2026 from the linked pages (Jibble from a pricing summary on timely.com). Prices can change; check their sites. If your staff need to clock in from their phones or you need GPS, those apps do that and Hoursprig does not: Hoursprig is the quick calculator and the printable timesheet, paid once.</p>
|
| 215 |
+
</section>
|
| 216 |
+
|
| 217 |
+
<section class="faq" id="faq">
|
| 218 |
+
<h2>Questions</h2>
|
| 219 |
+
<details><summary>Is Hoursprig really free?</summary><p>Yes. One employee, the current pay period (weekly, bi-weekly or semi-monthly), split and overnight shifts, breaks, rounding, weekly overtime and pay, plus unlimited printing and PDF downloads, with no account. Free timesheets carry a small “Calculated with Hoursprig by CyberMax” line.</p></details>
|
| 220 |
+
<details><summary>How do I type the times?</summary><p>Any way you like: <code>9</code>, <code>9a</code>, <code>9am</code>, <code>9:30pm</code>, <code>21:30</code>, <code>0930</code> or <code>noon</code>. An out time without am or pm is read as the afternoon when that makes sense, so 9 to 5 is 8 hours. Add a second in/out pair for a split shift.</p></details>
|
| 221 |
+
<details><summary>How are overnight shifts counted?</summary><p>A shift that ends after midnight, such as 10pm to 6:30am, is counted in full on the day it starts, and the timesheet marks the end time “+1 day”.</p></details>
|
| 222 |
+
<details><summary>How does rounding work?</summary><p>Rounding moves each clock-in and clock-out time to the nearest 5, 6 or 15 minutes before the hours are added up. With 15 minutes, 8:07 becomes 8:00 and 8:08 becomes 8:15 (the “7-minute rule”); 6 minutes is a tenth of an hour. US federal rules (29 CFR 785.48) accept rounding to the nearest 5 minutes, tenth or quarter hour when it averages out fairly over time; some states are stricter. “No rounding” uses exact minutes.</p></details>
|
| 223 |
+
<details><summary>How is overtime worked out?</summary><p>Free: hours over 40 in a workweek (the US federal FLSA default; you can change the limit and the 1.5× rate). Pro adds daily overtime (for example after 8 hours a day), double time (for example after 12 hours) and the 7th consecutive day rule used in some states such as California. Hours already counted as daily overtime are not counted again toward the weekly limit. Overtime rules differ by state and country, so check yours.</p></details>
|
| 224 |
+
<details><summary>Why not Clockify?</summary><p>Clockify is a full time-tracking service with apps and team features, priced per seat: Basic $3.99 per seat a month billed annually or $4.99 monthly, Standard $5.49 or $6.99, Pro $7.99 or $9.99 (checked 2 Oct 2026). If you just need to add up time cards and print a timesheet, Hoursprig is free, and Pro is $15 once for the whole business.</p></details>
|
| 225 |
+
<details><summary>Why not Jibble?</summary><p>Jibble is a time clock app with clock-in apps and GPS features; a pricing summary lists Premium at $2.49 per user a month and Ultimate at $4.99. Choose it if staff must clock in on their phones. Hoursprig is for working out hours, overtime and pay from times you already have, with nothing to install and nothing per user.</p></details>
|
| 226 |
+
<details><summary>Is my data private?</summary><p>Yes. Hoursprig runs entirely in your browser. Names, times and pay rates are saved only on this device and the PDF is made on your device. Nothing is uploaded.</p></details>
|
| 227 |
+
<details><summary>What does Pro add?</summary><p>Multiple employees, a history of saved pay periods, CSV export for payroll, all overtime rules (daily, double time and 7th consecutive day), your company logo on timesheets, no footer line and JSON backup. It is $15 once.</p></details>
|
| 228 |
+
<details><summary>Can I cancel?</summary><p>There is nothing to cancel: Hoursprig Pro is a single $15 payment with no subscription, and the free plan stays free.</p></details>
|
| 229 |
+
<details><summary>Can the timesheet be signed?</summary><p>Yes. Every timesheet has signature and date lines for the employee and the supervisor or employer. Print it and sign it, or sign the PDF in any PDF reader.</p></details>
|
| 230 |
+
</section>
|
| 231 |
+
|
| 232 |
+
<p class="disclaimer">Hoursprig calculates from your inputs and settings; it is not legal or payroll advice. Overtime rules differ by state and country.</p>
|
| 233 |
+
</div>
|
| 234 |
+
</main>
|
| 235 |
+
|
| 236 |
+
<div class="wrap">
|
| 237 |
+
<footer class="more">
|
| 238 |
+
<div class="more-title">More free tools for business from CyberMax</div>
|
| 239 |
+
<div class="more-links">
|
| 240 |
+
<a href="https://cybermax-tools-cybermax.static.hf.space/rotasprig/index.html" target="_blank" rel="noopener">Rotasprig · staff schedules</a>
|
| 241 |
+
<a href="https://cybermax-tools-cybermax.static.hf.space/billsprig/index.html" target="_blank" rel="noopener">Billsprig · invoice your hours</a>
|
| 242 |
+
<a href="https://cybermax-tools-cybermax.static.hf.space/pitchsprig/index.html" target="_blank" rel="noopener">Pitchsprig · proposals</a>
|
| 243 |
+
<a href="https://cybermax-tools-cybermax.static.hf.space/sigsprig/index.html" target="_blank" rel="noopener">Sigsprig · email signatures</a>
|
| 244 |
+
<a href="https://cybermax-tools-cybermax.static.hf.space/platesprig/index.html" target="_blank" rel="noopener">Platesprig · menu & food cost</a>
|
| 245 |
+
<a href="https://cybermax.cybermax-tools.workers.dev/store/?utm_source=hoursprig&utm_medium=more-from" target="_blank" rel="noopener">CyberMax Store</a>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="copy">© 2026 CyberMax. All rights reserved. · Support: <a href="mailto:cybermax.tools@gmail.com">cybermax.tools@gmail.com</a></div>
|
| 248 |
+
</footer>
|
| 249 |
+
</div>
|
| 250 |
+
|
| 251 |
+
<div class="mbar" id="mbar"><a class="btn ghost" href="#preview" id="m-preview">Totals</a><button type="button" class="btn" id="m-pdf">Download PDF</button></div>
|
| 252 |
+
<div class="toast" id="toast" role="status" aria-live="polite" hidden></div>
|
| 253 |
+
<script>window.CMX_PRO={"id":"hoursprig","name":"Hoursprig","free":"1 employee and the current pay period, weekly overtime, print and PDF with a small Hoursprig line.","perks":["Multiple employees","Saved pay periods history","CSV export for payroll","All overtime rules: daily, double time and 7th day","Company logo on timesheets","No footer line on print and PDF","JSON backup"],"plans":[{"offer":"st-hoursprig-pro-lifetime","label":"Lifetime","price":"$15","per":" once","note":"Pay once, keep forever"}]};</script>
|
| 254 |
+
<script src="pro.js"></script>
|
| 255 |
+
<script src="lib/calc.js"></script>
|
| 256 |
+
<script src="lib/pdf.js"></script>
|
| 257 |
+
<script src="app.js"></script>
|
| 258 |
+
</body>
|
| 259 |
+
</html>
|
hoursprig/lib/calc.js
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Hoursprig maths: forgiving time parsing, shifts across midnight, rounding, daily/weekly/7th-day overtime, pay, CSV.
|
| 2 |
+
* Pure functions, no DOM. Works in the browser (window.HourCalc) and in Node (require).
|
| 3 |
+
* © 2026 CyberMax. All rights reserved. */
|
| 4 |
+
(function (root) {
|
| 5 |
+
"use strict";
|
| 6 |
+
|
| 7 |
+
var DAY = 1440;
|
| 8 |
+
var DOW = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
| 9 |
+
var DOW_LONG = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
| 10 |
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
| 11 |
+
var CURRENCIES = [
|
| 12 |
+
{ code: "USD", locale: "en-US" }, { code: "CAD", locale: "en-CA" }, { code: "GBP", locale: "en-GB" }, { code: "EUR", locale: "de-DE" },
|
| 13 |
+
{ code: "AUD", locale: "en-AU" }, { code: "NZD", locale: "en-NZ" }, { code: "INR", locale: "en-IN" }, { code: "ZAR", locale: "en-ZA" },
|
| 14 |
+
{ code: "MXN", locale: "es-MX" }, { code: "PHP", locale: "en-PH" }, { code: "SGD", locale: "en-SG" }, { code: "CHF", locale: "de-CH" },
|
| 15 |
+
];
|
| 16 |
+
var ROUNDING = [0, 5, 6, 15];
|
| 17 |
+
|
| 18 |
+
/* ---------- time parsing ---------- */
|
| 19 |
+
/**
|
| 20 |
+
* Parse a clock time typed the way people type it: "9", "9a", "9am", "9:30pm", "21:30", "0930", "930p", "9.30", "noon", "midnight".
|
| 21 |
+
* Returns { min: minutes after midnight (0..1439), explicit: true when am/pm or 24-hour form makes the meaning certain } or null.
|
| 22 |
+
*/
|
| 23 |
+
function parseTime(s) {
|
| 24 |
+
var t = String(s == null ? "" : s).trim().toLowerCase().replace(/\s+/g, "").replace(/\./g, ":");
|
| 25 |
+
if (!t) return null;
|
| 26 |
+
if (t === "noon" || t === "12n") return { min: 720, explicit: true };
|
| 27 |
+
if (t === "midnight" || t === "12m") return { min: 0, explicit: true };
|
| 28 |
+
var h, mi, mer = "", lead = false, m;
|
| 29 |
+
if ((m = /^(\d{1,2})(?::(\d{2}))?(am|a|pm|p)?$/.exec(t))) { h = +m[1]; mi = m[2] ? +m[2] : 0; mer = m[3] || ""; lead = m[1].length === 2 && m[1].charAt(0) === "0"; }
|
| 30 |
+
else if ((m = /^(\d{3,4})(am|a|pm|p)?$/.exec(t))) { h = +m[1].slice(0, -2); mi = +m[1].slice(-2); mer = m[2] || ""; lead = m[1].length === 4 && m[1].charAt(0) === "0"; }
|
| 31 |
+
else if ((m = /^(\d{1,2})h(\d{2})?$/.exec(t))) { h = +m[1]; mi = m[2] ? +m[2] : 0; lead = true; }
|
| 32 |
+
else return null;
|
| 33 |
+
if (mi > 59) return null;
|
| 34 |
+
if (mer) {
|
| 35 |
+
if (h < 1 || h > 12) return null;
|
| 36 |
+
if (h === 12) h = 0;
|
| 37 |
+
if (mer.charAt(0) === "p") h += 12;
|
| 38 |
+
return { min: h * 60 + mi, explicit: true };
|
| 39 |
+
}
|
| 40 |
+
if (h === 24 && mi === 0) return { min: 0, explicit: true, end: true };
|
| 41 |
+
if (h > 23) return null;
|
| 42 |
+
return { min: h * 60 + mi, explicit: h === 0 || h >= 13 || lead };
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Minutes between an in and an out time. Overnight shifts cross midnight. An out time typed without am/pm that would
|
| 47 |
+
* otherwise end before the start is read as afternoon/evening when that gives a shift under 12 hours ("9" to "5" = 8 h).
|
| 48 |
+
* Returns { start, end, minutes, overnight } (start/end in minutes from the day's midnight; end may exceed 1440) or null.
|
| 49 |
+
*/
|
| 50 |
+
function span(inStr, outStr) {
|
| 51 |
+
var a = parseTime(inStr), b = parseTime(outStr);
|
| 52 |
+
if (!a || !b) return null;
|
| 53 |
+
var start = a.min, end = b.min;
|
| 54 |
+
if (b.end && end === 0) end = DAY;
|
| 55 |
+
if (end <= start && !b.explicit && end < 720 && end + 720 > start) end += 720;
|
| 56 |
+
var overnight = false;
|
| 57 |
+
if (end <= start) { end += DAY; overnight = true; }
|
| 58 |
+
return { start: start, end: end, minutes: end - start, overnight: overnight };
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/** Round a clock time (minutes) to the nearest step (0 = exact). Half-way rounds up (7.5 min on a 15-minute step goes up). */
|
| 62 |
+
function roundTo(min, step) {
|
| 63 |
+
step = +step || 0;
|
| 64 |
+
if (!step) return min;
|
| 65 |
+
return Math.round(min / step) * step;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function fmtClock(min, h24) {
|
| 69 |
+
min = ((Math.round(min) % DAY) + DAY) % DAY;
|
| 70 |
+
var h = Math.floor(min / 60), m = min % 60;
|
| 71 |
+
if (h24) return pad(h) + ":" + pad(m);
|
| 72 |
+
var mer = h < 12 ? "AM" : "PM", hh = h % 12 || 12;
|
| 73 |
+
return hh + ":" + pad(m) + " " + mer;
|
| 74 |
+
}
|
| 75 |
+
function pad(n) { return (n < 10 ? "0" : "") + n; }
|
| 76 |
+
|
| 77 |
+
/** Normalise a typed time for display ("9a" -> "9:00 AM"); returns the input unchanged if it cannot be parsed. */
|
| 78 |
+
function normalize(str, h24) {
|
| 79 |
+
var p = parseTime(str);
|
| 80 |
+
if (!p) return String(str == null ? "" : str).trim();
|
| 81 |
+
return p.end ? (h24 ? "24:00" : "12:00 AM") : fmtClock(p.min, h24);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Tidy an in/out pair for display without changing its meaning: the out time is written from the worked span, so
|
| 86 |
+
* "9" to "5" becomes "9:00 AM" to "5:00 PM" (never 5:00 AM). Parts that cannot be read are returned as typed.
|
| 87 |
+
*/
|
| 88 |
+
function normalizePair(inStr, outStr, h24) {
|
| 89 |
+
var a = parseTime(inStr), sp = span(inStr, outStr);
|
| 90 |
+
return { in: a ? normalize(inStr, h24) : String(inStr == null ? "" : inStr).trim(), out: sp ? fmtClock(sp.end, h24) : String(outStr == null ? "" : outStr).trim() };
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/* ---------- durations ---------- */
|
| 94 |
+
/** 512 minutes -> "8:32" */
|
| 95 |
+
function hm(min) {
|
| 96 |
+
min = Math.round(min || 0);
|
| 97 |
+
var neg = min < 0; if (neg) min = -min;
|
| 98 |
+
return (neg ? "-" : "") + Math.floor(min / 60) + ":" + pad(min % 60);
|
| 99 |
+
}
|
| 100 |
+
/** 512 minutes -> "8.53" (hours, 2 decimals, half-up) */
|
| 101 |
+
function dec(min, dp) {
|
| 102 |
+
dp = dp == null ? 2 : dp;
|
| 103 |
+
return round(min / 60, dp).toFixed(dp);
|
| 104 |
+
}
|
| 105 |
+
function round(v, dp) {
|
| 106 |
+
var f = Math.pow(10, dp || 0);
|
| 107 |
+
return Math.round((v + (v >= 0 ? 1 : -1) * Number.EPSILON * Math.max(1, Math.abs(v))) * f) / f;
|
| 108 |
+
}
|
| 109 |
+
function parseNum(s) {
|
| 110 |
+
if (typeof s === "number") return isFinite(s) ? s : 0;
|
| 111 |
+
var t = String(s == null ? "" : s).replace(/[^\d,.\-]/g, "");
|
| 112 |
+
if (!t) return 0;
|
| 113 |
+
if (t.indexOf(",") > -1 && t.indexOf(".") > -1) t = t.lastIndexOf(",") > t.lastIndexOf(".") ? t.replace(/\./g, "").replace(",", ".") : t.replace(/,/g, "");
|
| 114 |
+
else if (t.indexOf(",") > -1) t = /,\d{1,2}$/.test(t) ? t.replace(",", ".") : t.replace(/,/g, "");
|
| 115 |
+
var v = parseFloat(t);
|
| 116 |
+
return isFinite(v) ? v : 0;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/* ---------- dates (ISO yyyy-mm-dd, UTC maths so DST never shifts a day) ---------- */
|
| 120 |
+
function toDate(iso) { var p = String(iso).split("-"); return new Date(Date.UTC(+p[0], +p[1] - 1, +p[2])); }
|
| 121 |
+
function iso(d) { return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()); }
|
| 122 |
+
function addDays(isoStr, n) { var d = toDate(isoStr); d.setUTCDate(d.getUTCDate() + n); return iso(d); }
|
| 123 |
+
function dow(isoStr) { return toDate(isoStr).getUTCDay(); }
|
| 124 |
+
function validISO(s) { return /^\d{4}-\d{2}-\d{2}$/.test(s || "") && !isNaN(toDate(s).getTime()); }
|
| 125 |
+
function fmtDate(isoStr, long) {
|
| 126 |
+
if (!validISO(isoStr)) return "";
|
| 127 |
+
var d = toDate(isoStr);
|
| 128 |
+
return (long ? DOW[d.getUTCDay()] + " " : "") + MONTHS[d.getUTCMonth()] + " " + d.getUTCDate() + (long === "y" || long === 2 ? ", " + d.getUTCFullYear() : "");
|
| 129 |
+
}
|
| 130 |
+
function fmtRange(a, b) {
|
| 131 |
+
var da = toDate(a), db = toDate(b);
|
| 132 |
+
var y = da.getUTCFullYear() === db.getUTCFullYear();
|
| 133 |
+
return MONTHS[da.getUTCMonth()] + " " + da.getUTCDate() + (y ? "" : ", " + da.getUTCFullYear()) + " – " + MONTHS[db.getUTCMonth()] + " " + db.getUTCDate() + ", " + db.getUTCFullYear();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/** The dates in a pay period. kind: week (7 days), biweek (14), semimonth (1st–15th or 16th–end of month). */
|
| 137 |
+
function periodDates(kind, start) {
|
| 138 |
+
if (!validISO(start)) start = iso(new Date());
|
| 139 |
+
var out = [], n;
|
| 140 |
+
if (kind === "semimonth") {
|
| 141 |
+
var d = toDate(start), y = d.getUTCFullYear(), mo = d.getUTCMonth(), first = d.getUTCDate() <= 15;
|
| 142 |
+
var from = first ? 1 : 16, to = first ? 15 : new Date(Date.UTC(y, mo + 1, 0)).getUTCDate();
|
| 143 |
+
for (n = from; n <= to; n++) out.push(iso(new Date(Date.UTC(y, mo, n))));
|
| 144 |
+
return out;
|
| 145 |
+
}
|
| 146 |
+
var len = kind === "biweek" ? 14 : 7;
|
| 147 |
+
for (n = 0; n < len; n++) out.push(addDays(start, n));
|
| 148 |
+
return out;
|
| 149 |
+
}
|
| 150 |
+
/** Start of the period that contains `date` (semimonth: 1st or 16th; week/biweek: `date` itself). */
|
| 151 |
+
function periodStart(kind, date) {
|
| 152 |
+
if (kind !== "semimonth") return date;
|
| 153 |
+
var d = toDate(date);
|
| 154 |
+
return iso(new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() <= 15 ? 1 : 16)));
|
| 155 |
+
}
|
| 156 |
+
/** Start of the next / previous period. */
|
| 157 |
+
function shiftPeriod(kind, start, dir) {
|
| 158 |
+
if (kind === "semimonth") {
|
| 159 |
+
var d = toDate(periodStart(kind, start)), day = d.getUTCDate(), y = d.getUTCFullYear(), m = d.getUTCMonth();
|
| 160 |
+
if (dir > 0) return day === 1 ? iso(new Date(Date.UTC(y, m, 16))) : iso(new Date(Date.UTC(y, m + 1, 1)));
|
| 161 |
+
return day === 16 ? iso(new Date(Date.UTC(y, m, 1))) : iso(new Date(Date.UTC(y, m - 1, 16)));
|
| 162 |
+
}
|
| 163 |
+
return addDays(start, (kind === "biweek" ? 14 : 7) * (dir > 0 ? 1 : -1));
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/* ---------- settings ---------- */
|
| 167 |
+
function defaults() {
|
| 168 |
+
return {
|
| 169 |
+
kind: "week", weekStart: 0, rounding: 0, h24: false, currency: "USD", rate: "",
|
| 170 |
+
weeklyOn: true, weeklyAfter: 40, otMult: 1.5,
|
| 171 |
+
dailyOn: false, dailyAfter: 8,
|
| 172 |
+
dtOn: false, dtAfter: 12, dtMult: 2,
|
| 173 |
+
seventhOn: false,
|
| 174 |
+
};
|
| 175 |
+
}
|
| 176 |
+
function settingsOf(s) {
|
| 177 |
+
var d = defaults(), o = {};
|
| 178 |
+
Object.keys(d).forEach(function (k) { o[k] = s && s[k] != null && s[k] !== "" ? s[k] : d[k]; });
|
| 179 |
+
["weeklyAfter", "otMult", "dailyAfter", "dtAfter", "dtMult", "rounding", "weekStart"].forEach(function (k) { o[k] = parseNum(o[k]); });
|
| 180 |
+
o.rate = parseNum(s && s.rate);
|
| 181 |
+
return o;
|
| 182 |
+
}
|
| 183 |
+
/** Pro-only rules are switched off for free users (the weekly rule stays). */
|
| 184 |
+
function freeRules(s) {
|
| 185 |
+
var o = Object.assign({}, s);
|
| 186 |
+
o.dailyOn = false; o.dtOn = false; o.seventhOn = false;
|
| 187 |
+
return o;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/* ---------- a day's worked time ---------- */
|
| 191 |
+
/**
|
| 192 |
+
* day: { date, pairs: [{in, out}], brk: unpaid break minutes, note }
|
| 193 |
+
* Returns { minutes, shifts: [{start, end, minutes, overnight}], errors: [pairIndex], brk }
|
| 194 |
+
*/
|
| 195 |
+
function dayWorked(day, rounding) {
|
| 196 |
+
var shifts = [], errors = [], sum = 0;
|
| 197 |
+
(day.pairs || []).forEach(function (p, i) {
|
| 198 |
+
var hasIn = String(p.in || "").trim(), hasOut = String(p.out || "").trim();
|
| 199 |
+
if (!hasIn && !hasOut) return;
|
| 200 |
+
var sp = span(p.in, p.out);
|
| 201 |
+
if (!sp) { errors.push(i); return; }
|
| 202 |
+
var st = roundTo(sp.start, rounding), en = roundTo(sp.end, rounding);
|
| 203 |
+
var mins = Math.max(0, en - st);
|
| 204 |
+
shifts.push({ start: st, end: en, minutes: mins, overnight: sp.overnight || en > DAY });
|
| 205 |
+
sum += mins;
|
| 206 |
+
});
|
| 207 |
+
var brk = Math.max(0, Math.round(parseNum(day.brk)));
|
| 208 |
+
return { minutes: Math.max(0, sum - (shifts.length ? brk : 0)), shifts: shifts, errors: errors, brk: shifts.length ? brk : 0 };
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/**
|
| 212 |
+
* Split worked minutes into regular / overtime / double time for a whole period.
|
| 213 |
+
* Rules: daily overtime after `dailyAfter` hours, double time after `dtAfter` hours in a day, 7th consecutive day in a
|
| 214 |
+
* workweek (first 8 h overtime, the rest double time when double time is on), weekly overtime after `weeklyAfter` hours.
|
| 215 |
+
* Hours already paid as daily overtime are not counted again toward the weekly limit (no pyramiding).
|
| 216 |
+
* Workweeks: 7-day blocks from the period start (week, bi-weekly) or starting on `weekStart` (semi-monthly).
|
| 217 |
+
*/
|
| 218 |
+
function compute(period, settingsIn) {
|
| 219 |
+
var s = settingsOf(settingsIn);
|
| 220 |
+
var dates = periodDates(period.kind || s.kind, period.start);
|
| 221 |
+
var byDate = {};
|
| 222 |
+
(period.days || []).forEach(function (d) { byDate[d.date] = d; });
|
| 223 |
+
var days = dates.map(function (date) {
|
| 224 |
+
var d = byDate[date] || { date: date, pairs: [], brk: "" };
|
| 225 |
+
var w = dayWorked(d, s.rounding);
|
| 226 |
+
return { date: date, dow: dow(date), src: d, worked: w.minutes, shifts: w.shifts, errors: w.errors, brk: w.brk, note: d.note || "", reg: 0, ot: 0, dt: 0, seventh: false };
|
| 227 |
+
});
|
| 228 |
+
// workweeks
|
| 229 |
+
var weeks = [], cur = null;
|
| 230 |
+
var kind = period.kind || s.kind;
|
| 231 |
+
days.forEach(function (d, i) {
|
| 232 |
+
var newWeek = !cur || (kind === "semimonth" ? d.dow === s.weekStart : i % 7 === 0);
|
| 233 |
+
if (newWeek) { cur = { days: [], reg: 0, ot: 0, dt: 0, worked: 0 }; weeks.push(cur); }
|
| 234 |
+
cur.days.push(d);
|
| 235 |
+
});
|
| 236 |
+
weeks.forEach(function (wk) {
|
| 237 |
+
var regSoFar = 0, consecutive = 0;
|
| 238 |
+
wk.days.forEach(function (d, idx) {
|
| 239 |
+
var m = d.worked, ot = 0, dt = 0, reg;
|
| 240 |
+
consecutive = m > 0 ? consecutive + 1 : 0;
|
| 241 |
+
if (s.seventhOn && idx === 6 && consecutive === 7 && m > 0) {
|
| 242 |
+
d.seventh = true;
|
| 243 |
+
ot = Math.min(m, 480);
|
| 244 |
+
dt = m - ot;
|
| 245 |
+
if (!s.dtOn) { ot += dt; dt = 0; }
|
| 246 |
+
reg = 0;
|
| 247 |
+
} else {
|
| 248 |
+
if (s.dtOn) dt = Math.max(0, m - s.dtAfter * 60);
|
| 249 |
+
if (s.dailyOn) ot = Math.max(0, Math.min(m, s.dtOn ? s.dtAfter * 60 : m) - s.dailyAfter * 60);
|
| 250 |
+
reg = m - ot - dt;
|
| 251 |
+
if (s.weeklyOn) {
|
| 252 |
+
var room = Math.max(0, s.weeklyAfter * 60 - regSoFar);
|
| 253 |
+
if (reg > room) { ot += reg - room; reg = room; }
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
regSoFar += reg;
|
| 257 |
+
d.reg = reg; d.ot = ot; d.dt = dt;
|
| 258 |
+
wk.reg += reg; wk.ot += ot; wk.dt += dt; wk.worked += m;
|
| 259 |
+
});
|
| 260 |
+
wk.start = wk.days[0].date; wk.end = wk.days[wk.days.length - 1].date;
|
| 261 |
+
});
|
| 262 |
+
var T = { worked: 0, reg: 0, ot: 0, dt: 0, brk: 0, daysWorked: 0, errors: 0 };
|
| 263 |
+
days.forEach(function (d) { T.worked += d.worked; T.reg += d.reg; T.ot += d.ot; T.dt += d.dt; T.brk += d.brk; if (d.worked > 0) T.daysWorked++; T.errors += d.errors.length; });
|
| 264 |
+
// pay from exact minutes, each line rounded to cents
|
| 265 |
+
var rate = s.rate;
|
| 266 |
+
T.rate = rate;
|
| 267 |
+
T.regPay = round(T.reg / 60 * rate, 2);
|
| 268 |
+
T.otPay = round(T.ot / 60 * rate * s.otMult, 2);
|
| 269 |
+
T.dtPay = round(T.dt / 60 * rate * s.dtMult, 2);
|
| 270 |
+
T.gross = round(T.regPay + T.otPay + T.dtPay, 2);
|
| 271 |
+
return { days: days, weeks: weeks, totals: T, settings: s, start: dates[0], end: dates[dates.length - 1], kind: kind };
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/* ---------- money ---------- */
|
| 275 |
+
function cur(code) { return CURRENCIES.filter(function (c) { return c.code === code; })[0] || CURRENCIES[0]; }
|
| 276 |
+
function money(v, code) {
|
| 277 |
+
var c = cur(code);
|
| 278 |
+
try { return new Intl.NumberFormat(c.locale, { style: "currency", currency: c.code }).format(v || 0); }
|
| 279 |
+
catch (e) { return c.code + " " + (v || 0).toFixed(2); }
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
/* ---------- descriptions ---------- */
|
| 283 |
+
function ruleLines(s) {
|
| 284 |
+
var o = [];
|
| 285 |
+
if (s.weeklyOn) o.push("Weekly overtime after " + s.weeklyAfter + " h at " + s.otMult + "x");
|
| 286 |
+
if (s.dailyOn) o.push("daily overtime after " + s.dailyAfter + " h");
|
| 287 |
+
if (s.dtOn) o.push("double time (" + s.dtMult + "x) after " + s.dtAfter + " h a day");
|
| 288 |
+
if (s.seventhOn) o.push("7th consecutive day rule");
|
| 289 |
+
if (!o.length) o.push("No overtime rules");
|
| 290 |
+
var r = s.rounding ? "Clock times rounded to the nearest " + s.rounding + " min" : "Exact minutes, no rounding";
|
| 291 |
+
return o.join(", ") + ". " + r + ".";
|
| 292 |
+
}
|
| 293 |
+
function shiftText(sh, h24) {
|
| 294 |
+
return sh.map(function (x) { return fmtClock(x.start, h24) + "–" + fmtClock(x.end, h24) + (x.end > DAY ? " (+1)" : ""); }).join(", ");
|
| 295 |
+
}
|
| 296 |
+
var KIND_LABEL = { week: "Weekly", biweek: "Bi-weekly", semimonth: "Semi-monthly" };
|
| 297 |
+
|
| 298 |
+
/* ---------- CSV (formula-injection guarded) ---------- */
|
| 299 |
+
function csvCell(v) {
|
| 300 |
+
var s = String(v == null ? "" : v);
|
| 301 |
+
if (/^[=+\-@\t\r]/.test(s) && !/^-?\d+(\.\d+)?$/.test(s)) s = "'" + s;
|
| 302 |
+
return /[",\n\r]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
| 303 |
+
}
|
| 304 |
+
function csvRow(a) { return a.map(csvCell).join(","); }
|
| 305 |
+
/** Day-by-day CSV for one or more timesheets: [{employee:{name, ref}, result}] */
|
| 306 |
+
function csvDays(sheets) {
|
| 307 |
+
var rows = [["Employee", "Employee ID", "Period start", "Period end", "Date", "Day", "Shifts", "Unpaid break (min)", "Hours worked", "Regular hours", "Overtime hours", "Double time hours", "Note"]];
|
| 308 |
+
sheets.forEach(function (sh) {
|
| 309 |
+
var r = sh.result, e = sh.employee || {};
|
| 310 |
+
r.days.forEach(function (d) {
|
| 311 |
+
if (!d.worked && !d.note) return;
|
| 312 |
+
rows.push([e.name || "", e.ref || "", r.start, r.end, d.date, DOW[d.dow], shiftText(d.shifts, true), d.brk || 0, dec(d.worked), dec(d.reg), dec(d.ot), dec(d.dt), d.note]);
|
| 313 |
+
});
|
| 314 |
+
});
|
| 315 |
+
return rows.map(csvRow).join("\r\n") + "\r\n";
|
| 316 |
+
}
|
| 317 |
+
/** One line per timesheet: payroll summary. */
|
| 318 |
+
function csvSummary(sheets) {
|
| 319 |
+
var rows = [["Employee", "Employee ID", "Period start", "Period end", "Hours worked", "Regular hours", "Overtime hours", "Double time hours", "Hourly rate", "Regular pay", "Overtime pay", "Double time pay", "Gross pay", "Currency"]];
|
| 320 |
+
sheets.forEach(function (sh) {
|
| 321 |
+
var r = sh.result, T = r.totals, e = sh.employee || {};
|
| 322 |
+
rows.push([e.name || "", e.ref || "", r.start, r.end, dec(T.worked), dec(T.reg), dec(T.ot), dec(T.dt), T.rate.toFixed(2), T.regPay.toFixed(2), T.otPay.toFixed(2), T.dtPay.toFixed(2), T.gross.toFixed(2), r.settings.currency]);
|
| 323 |
+
});
|
| 324 |
+
return rows.map(csvRow).join("\r\n") + "\r\n";
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
/* ---------- examples ---------- */
|
| 328 |
+
function blankPeriod(kind, start) { return { kind: kind, start: start, days: periodDates(kind, start).map(function (d) { return { date: d, pairs: [{ in: "", out: "" }], brk: "", note: "" }; }) }; }
|
| 329 |
+
function fill(period, list) {
|
| 330 |
+
list.forEach(function (x, i) { if (x) { var d = period.days[i]; d.pairs = x.p.map(function (q) { return { in: q[0], out: q[1] }; }); d.brk = x.b == null ? "" : String(x.b); d.note = x.n || ""; } });
|
| 331 |
+
return period;
|
| 332 |
+
}
|
| 333 |
+
function example(which) {
|
| 334 |
+
if (which === "night") {
|
| 335 |
+
var p2 = blankPeriod("biweek", "2026-09-20");
|
| 336 |
+
var N = { p: [["10p", "6:30a"]], b: 30 };
|
| 337 |
+
fill(p2, [null, N, N, N, N, { p: [["6p", "6:30a"]], b: 30, n: "Covered a double shift" }, N,
|
| 338 |
+
null, N, N, null, N, N, null]);
|
| 339 |
+
return { settings: Object.assign(defaults(), { kind: "biweek", rate: "19.00" }), employee: { name: "Sam Okafor", ref: "N-207" }, company: "Riverside Care Home", period: p2 };
|
| 340 |
+
}
|
| 341 |
+
if (which === "daily") {
|
| 342 |
+
var p3 = blankPeriod("week", "2026-09-27");
|
| 343 |
+
fill(p3, [{ p: [["7a", "3:30p"]], b: 30 }, { p: [["7a", "3:30p"]], b: 30 }, { p: [["6a", "6:30p"]], b: 30, n: "Inventory count" }, { p: [["7a", "5:30p"]], b: 30 },
|
| 344 |
+
{ p: [["7a", "3:30p"]], b: 30 }, { p: [["8a", "2p"]] }, { p: [["8a", "6:30p"]], b: 30 }]);
|
| 345 |
+
return { settings: Object.assign(defaults(), { kind: "week", rate: "24.00", dailyOn: true, dtOn: true, seventhOn: true }), employee: { name: "Maria Lopez", ref: "W-031" }, company: "Valley Produce Co.", period: p3 };
|
| 346 |
+
}
|
| 347 |
+
var p = blankPeriod("week", "2026-09-28");
|
| 348 |
+
fill(p, [{ p: [["7a", "11:30"], ["12", "3:30p"]], n: "Split shift" }, { p: [["7", "3:30"]], b: 30 }, { p: [["7a", "5p"]], b: 30 },
|
| 349 |
+
{ p: [["7:00", "16:00"]], b: 30 }, { p: [["7a", "5:30p"]], b: 30, n: "Delivery day" }, { p: [["8a", "12:30p"]] }, null]);
|
| 350 |
+
return { settings: Object.assign(defaults(), { kind: "week", rate: "22.50" }), employee: { name: "Jordan Rivera", ref: "E-104" }, company: "Northgate Hardware", period: p };
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
var api = {
|
| 354 |
+
DAY: DAY, DOW: DOW, DOW_LONG: DOW_LONG, CURRENCIES: CURRENCIES, ROUNDING: ROUNDING, KIND_LABEL: KIND_LABEL,
|
| 355 |
+
parseTime: parseTime, span: span, normalizePair: normalizePair, roundTo: roundTo, fmtClock: fmtClock, normalize: normalize, hm: hm, dec: dec, round: round, parseNum: parseNum,
|
| 356 |
+
addDays: addDays, dow: dow, validISO: validISO, fmtDate: fmtDate, fmtRange: fmtRange, iso: iso, toDate: toDate,
|
| 357 |
+
periodDates: periodDates, periodStart: periodStart, shiftPeriod: shiftPeriod, defaults: defaults, settingsOf: settingsOf, freeRules: freeRules,
|
| 358 |
+
dayWorked: dayWorked, compute: compute, money: money, cur: cur, ruleLines: ruleLines, shiftText: shiftText,
|
| 359 |
+
csvCell: csvCell, csvDays: csvDays, csvSummary: csvSummary, blankPeriod: blankPeriod, example: example,
|
| 360 |
+
};
|
| 361 |
+
if (typeof module === "object" && module.exports) module.exports = api; else root.HourCalc = api;
|
| 362 |
+
})(typeof self !== "undefined" ? self : this);
|
hoursprig/lib/pdf.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Hoursprig PDF writer: a small, dependency-free PDF 1.4 generator for timesheets.
|
| 2 |
+
* Text uses the built-in Helvetica fonts (WinAnsiEncoding), so it is real, selectable, searchable text.
|
| 3 |
+
* Glyph widths below come from Adobe's Core 14 AFM metrics for Helvetica and Helvetica-Bold
|
| 4 |
+
* (Copyright (c) 1985-1997 Adobe Systems Incorporated; metrics files are freely distributable).
|
| 5 |
+
* Everything else © 2026 CyberMax. All rights reserved. */
|
| 6 |
+
(function (root) {
|
| 7 |
+
"use strict";
|
| 8 |
+
var C = typeof module === "object" && module.exports ? require("./calc.js") : root.HourCalc;
|
| 9 |
+
|
| 10 |
+
// Widths (1/1000 em) for WinAnsi codes 32..255.
|
| 11 |
+
var WR = [278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584,350,556,350,222,556,333,1000,556,556,333,1000,667,333,1000,350,611,350,350,222,222,333,333,350,556,1000,333,1000,500,333,944,350,500,667,278,333,556,556,556,556,260,556,333,737,370,556,584,333,737,333,400,584,333,333,333,556,537,278,333,333,365,556,834,834,834,611,667,667,667,667,667,667,1000,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,500,556,556,556,556,278,278,278,278,556,556,556,556,556,556,556,584,611,556,556,556,556,500,556,500];
|
| 12 |
+
var WB = [278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584,350,556,350,278,556,500,1000,556,556,333,1000,667,333,1000,350,611,350,350,278,278,500,500,350,556,1000,333,1000,556,333,944,350,500,667,278,333,556,556,556,556,280,556,333,737,370,556,584,333,737,333,400,584,333,333,333,611,556,278,333,333,365,556,834,834,834,611,722,722,722,722,722,722,1000,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,556,556,556,556,556,278,278,278,278,611,611,611,611,611,611,611,584,611,611,611,611,611,556,611,556];
|
| 13 |
+
var CP = { 0x20AC: 128, 0x201A: 130, 0x0192: 131, 0x201E: 132, 0x2026: 133, 0x2020: 134, 0x2021: 135, 0x02C6: 136, 0x2030: 137, 0x0160: 138, 0x2039: 139, 0x0152: 140, 0x017D: 142,
|
| 14 |
+
0x2018: 145, 0x2019: 146, 0x201C: 147, 0x201D: 148, 0x2022: 149, 0x2013: 150, 0x2014: 151, 0x02DC: 152, 0x2122: 153, 0x0161: 154, 0x203A: 155, 0x0153: 156, 0x017E: 158, 0x0178: 159 };
|
| 15 |
+
var FALLBACK = { "ł": "l", "Ł": "L", "đ": "d", "Đ": "D", "ı": "i", "‐": "-", "‑": "-", "−": "-", " ": " ", " ": " ", " ": " ", "′": "'", "″": '"' };
|
| 16 |
+
|
| 17 |
+
function code(ch) {
|
| 18 |
+
var c = ch.codePointAt(0);
|
| 19 |
+
if (c >= 32 && c < 127) return c;
|
| 20 |
+
if (c >= 160 && c <= 255) return c;
|
| 21 |
+
if (CP[c]) return CP[c];
|
| 22 |
+
return -1;
|
| 23 |
+
}
|
| 24 |
+
/** Can every character be drawn with the built-in fonts? */
|
| 25 |
+
function canEncode(s) { for (var ch of String(s)) if (code(ch) < 0) return false; return true; }
|
| 26 |
+
/** String -> WinAnsi byte codes (accents stripped or "?" for anything the core fonts cannot draw). */
|
| 27 |
+
function encode(s) {
|
| 28 |
+
var out = [];
|
| 29 |
+
for (var ch of String(s == null ? "" : s).replace(/[\t\r\n]/g, " ")) {
|
| 30 |
+
var c = code(ch);
|
| 31 |
+
if (c < 0 && FALLBACK[ch]) c = code(FALLBACK[ch]);
|
| 32 |
+
if (c < 0) { var base = ch.normalize("NFD").charAt(0); c = code(base); }
|
| 33 |
+
out.push(c < 0 ? 63 : c);
|
| 34 |
+
}
|
| 35 |
+
return out;
|
| 36 |
+
}
|
| 37 |
+
function width(s, size, bold) {
|
| 38 |
+
var w = 0, t = bold ? WB : WR;
|
| 39 |
+
encode(s).forEach(function (c) { w += t[c - 32] || 556; });
|
| 40 |
+
return w * size / 1000;
|
| 41 |
+
}
|
| 42 |
+
/** Greedy word wrap to a width in points; long words are broken. */
|
| 43 |
+
function wrap(s, maxW, size, bold) {
|
| 44 |
+
var out = [];
|
| 45 |
+
String(s == null ? "" : s).split(/\r?\n/).forEach(function (para) {
|
| 46 |
+
var words = para.split(/\s+/).filter(Boolean), cur = "";
|
| 47 |
+
if (!words.length) { out.push(""); return; }
|
| 48 |
+
words.forEach(function (wd) {
|
| 49 |
+
while (width(wd, size, bold) > maxW && wd.length > 1) {
|
| 50 |
+
var k = wd.length - 1;
|
| 51 |
+
while (k > 1 && width(wd.slice(0, k), size, bold) > maxW) k--;
|
| 52 |
+
if (cur) { out.push(cur); cur = ""; }
|
| 53 |
+
out.push(wd.slice(0, k)); wd = wd.slice(k);
|
| 54 |
+
}
|
| 55 |
+
var next = cur ? cur + " " + wd : wd;
|
| 56 |
+
if (width(next, size, bold) <= maxW) cur = next; else { out.push(cur); cur = wd; }
|
| 57 |
+
});
|
| 58 |
+
out.push(cur);
|
| 59 |
+
});
|
| 60 |
+
return out;
|
| 61 |
+
}
|
| 62 |
+
function lit(s) {
|
| 63 |
+
return "(" + encode(s).map(function (c) {
|
| 64 |
+
if (c === 40 || c === 41 || c === 92) return "\\" + String.fromCharCode(c);
|
| 65 |
+
if (c >= 32 && c < 127) return String.fromCharCode(c);
|
| 66 |
+
return "\\" + ("00" + c.toString(8)).slice(-3);
|
| 67 |
+
}).join("") + ")";
|
| 68 |
+
}
|
| 69 |
+
function n2(v) { return (Math.round(v * 100) / 100).toString(); }
|
| 70 |
+
function rgb(hex) {
|
| 71 |
+
var m = /^#?([0-9a-f]{6})$/i.exec(hex || "") || [0, "11141b"];
|
| 72 |
+
var v = parseInt(m[1], 16);
|
| 73 |
+
return [(v >> 16 & 255) / 255, (v >> 8 & 255) / 255, (v & 255) / 255].map(function (x) { return Math.round(x * 1000) / 1000; }).join(" ");
|
| 74 |
+
}
|
| 75 |
+
function mix(hex, other, t) {
|
| 76 |
+
var a = parseInt(hex.slice(1), 16), b = parseInt(other.slice(1), 16), o = "#";
|
| 77 |
+
[16, 8, 0].forEach(function (s) { var v = Math.round((a >> s & 255) * (1 - t) + (b >> s & 255) * t); o += ("0" + v.toString(16)).slice(-2); });
|
| 78 |
+
return o;
|
| 79 |
+
}
|
| 80 |
+
function validHex(h) { return /^#[0-9a-f]{6}$/i.test(h || "") ? h : null; }
|
| 81 |
+
|
| 82 |
+
/* ---------- page writer (top-left coordinates in points) ---------- */
|
| 83 |
+
function Writer(W, H) { this.W = W; this.H = H; this.pages = []; this.add(); }
|
| 84 |
+
Writer.prototype.add = function () { this.p = { ops: [], links: [] }; this.pages.push(this.p); return this.p; };
|
| 85 |
+
Writer.prototype.on = function (i) { this.p = this.pages[i]; };
|
| 86 |
+
Writer.prototype.rect = function (x, y, w, h, fill, stroke, lw) {
|
| 87 |
+
var o = ["q"];
|
| 88 |
+
if (fill) o.push(rgb(fill) + " rg");
|
| 89 |
+
if (stroke) o.push(rgb(stroke) + " RG " + n2(lw || 1) + " w");
|
| 90 |
+
o.push(n2(x) + " " + n2(this.H - y - h) + " " + n2(w) + " " + n2(h) + " re " + (fill && stroke ? "B" : fill ? "f" : "S"), "Q");
|
| 91 |
+
this.p.ops.push(o.join(" "));
|
| 92 |
+
};
|
| 93 |
+
Writer.prototype.line = function (x1, y1, x2, y2, color, lw) {
|
| 94 |
+
this.p.ops.push("q " + rgb(color) + " RG " + n2(lw || 0.5) + " w " + n2(x1) + " " + n2(this.H - y1) + " m " + n2(x2) + " " + n2(this.H - y2) + " l S Q");
|
| 95 |
+
};
|
| 96 |
+
/** Text with its baseline at y. o: size, bold, color, align ('left'|'right'|'center'). Returns the drawn width. */
|
| 97 |
+
Writer.prototype.text = function (x, y, s, o) {
|
| 98 |
+
o = o || {};
|
| 99 |
+
var size = o.size || 10, w = width(s, size, o.bold);
|
| 100 |
+
if (o.align === "right") x -= w; else if (o.align === "center") x -= w / 2;
|
| 101 |
+
this.p.ops.push("BT /" + (o.bold ? "F2" : "F1") + " " + n2(size) + " Tf " + rgb(o.color || "#11141B") + " rg " + n2(x) + " " + n2(this.H - y) + " Td " + lit(s) + " Tj ET");
|
| 102 |
+
return w;
|
| 103 |
+
};
|
| 104 |
+
Writer.prototype.image = function (x, y, w, h) {
|
| 105 |
+
this.p.ops.push("q " + n2(w) + " 0 0 " + n2(h) + " " + n2(x) + " " + n2(this.H - y - h) + " cm /Im1 Do Q");
|
| 106 |
+
};
|
| 107 |
+
Writer.prototype.link = function (x, y, w, h, url) { this.p.links.push({ r: [x, this.H - y - h, x + w, this.H - y], url: url }); };
|
| 108 |
+
/* ---------- serialisation ---------- */
|
| 109 |
+
function serialize(wr, info, img) {
|
| 110 |
+
var chunks = [], len = 0, offsets = [];
|
| 111 |
+
function put(x) {
|
| 112 |
+
if (typeof x === "string") { var b = new Uint8Array(x.length); for (var i = 0; i < x.length; i++) b[i] = x.charCodeAt(i) & 255; x = b; }
|
| 113 |
+
chunks.push(x); len += x.length;
|
| 114 |
+
}
|
| 115 |
+
var next = img ? 7 : 6, pageNums = [], plan = [];
|
| 116 |
+
wr.pages.forEach(function (p) {
|
| 117 |
+
var pn = next++, cn = next++, an = p.links.map(function () { return next++; });
|
| 118 |
+
pageNums.push(pn); plan.push({ p: p, pn: pn, cn: cn, an: an });
|
| 119 |
+
});
|
| 120 |
+
function obj(n, body) { offsets[n] = len; put(n + " 0 obj\n"); if (typeof body === "string") put(body); else body(); put("\nendobj\n"); }
|
| 121 |
+
put("%PDF-1.4\n%âãÏÓ\n");
|
| 122 |
+
obj(1, "<< /Type /Catalog /Pages 2 0 R >>");
|
| 123 |
+
obj(2, "<< /Type /Pages /Kids [" + pageNums.map(function (n) { return n + " 0 R"; }).join(" ") + "] /Count " + pageNums.length + " >>");
|
| 124 |
+
obj(3, "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>");
|
| 125 |
+
obj(4, "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>");
|
| 126 |
+
obj(5, "<< /Title " + lit(info.title || "Document") + " /Author " + lit(info.author || "") + " /Producer (Hoursprig by CyberMax) /Creator (Hoursprig) /CreationDate (D:" + info.date + ") >>");
|
| 127 |
+
if (img) obj(6, function () {
|
| 128 |
+
put("<< /Type /XObject /Subtype /Image /Width " + img.w + " /Height " + img.h + " /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length " + img.bytes.length + " >>\nstream\n");
|
| 129 |
+
put(img.bytes); put("\nendstream");
|
| 130 |
+
});
|
| 131 |
+
plan.forEach(function (q) {
|
| 132 |
+
var content = q.p.ops.join("\n");
|
| 133 |
+
obj(q.pn, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 " + n2(wr.W) + " " + n2(wr.H) + "] /Resources << /Font << /F1 3 0 R /F2 4 0 R >>" +
|
| 134 |
+
(img ? " /XObject << /Im1 6 0 R >>" : "") + " >> /Contents " + q.cn + " 0 R" + (q.an.length ? " /Annots [" + q.an.map(function (n) { return n + " 0 R"; }).join(" ") + "]" : "") + " >>");
|
| 135 |
+
obj(q.cn, "<< /Length " + content.length + " >>\nstream\n" + content + "\nendstream");
|
| 136 |
+
q.p.links.forEach(function (l, i) {
|
| 137 |
+
obj(q.an[i], "<< /Type /Annot /Subtype /Link /Rect [" + l.r.map(n2).join(" ") + "] /Border [0 0 0] /A << /S /URI /URI " + lit(l.url) + " >> >>");
|
| 138 |
+
});
|
| 139 |
+
});
|
| 140 |
+
var xref = len, count = next;
|
| 141 |
+
var x = "xref\n0 " + count + "\n0000000000 65535 f \n";
|
| 142 |
+
for (var i = 1; i < count; i++) x += ("000000000" + (offsets[i] || 0)).slice(-10) + " 00000 n \n";
|
| 143 |
+
put(x + "trailer\n<< /Size " + count + " /Root 1 0 R /Info 5 0 R >>\nstartxref\n" + xref + "\n%%EOF\n");
|
| 144 |
+
var out = new Uint8Array(len), o = 0;
|
| 145 |
+
chunks.forEach(function (c) { out.set(c, o); o += c.length; });
|
| 146 |
+
return out;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
/* ---------- the timesheet layout ---------- */
|
| 151 |
+
var INK = "#11141B", MUTED = "#5B6170", RULE = "#D9DCE3", WHITE = "#FFFFFF", SOFT = "#F4F6FA", ACCENT = "#1F62B5";
|
| 152 |
+
var LETTER = ["USD", "CAD", "MXN", "PHP"];
|
| 153 |
+
function pageSize(paper, currency) {
|
| 154 |
+
var p = paper || (LETTER.indexOf(currency) > -1 ? "Letter" : "A4");
|
| 155 |
+
return p === "Letter" ? [612, 792] : [595.28, 841.89];
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Build a timesheet PDF.
|
| 160 |
+
* sheet: { company, employee: {name, ref}, result (HourCalc.compute output), notes }
|
| 161 |
+
* opts: { credit: bool, creditUrl, logo: {bytes, w, h} (JPEG), paper: "A4"|"Letter"|"", date: Date }
|
| 162 |
+
* Returns a Uint8Array.
|
| 163 |
+
*/
|
| 164 |
+
function build(sheet, opts) {
|
| 165 |
+
opts = opts || {};
|
| 166 |
+
var r = sheet.result, s = r.settings, T = r.totals, h24 = !!s.h24;
|
| 167 |
+
var sz = pageSize(opts.paper, s.currency), W = sz[0], H = sz[1];
|
| 168 |
+
var wr = new Writer(W, H);
|
| 169 |
+
var L = 40, R = W - 40, CW = R - L, BOTTOM = H - 56;
|
| 170 |
+
var money = function (v) { var t = C.money(v, s.currency); return canEncode(t) ? t : s.currency + " " + v.toFixed(2); };
|
| 171 |
+
var emp = sheet.employee || {};
|
| 172 |
+
var y = 40;
|
| 173 |
+
|
| 174 |
+
// ---- header ----
|
| 175 |
+
var lx = L;
|
| 176 |
+
if (opts.logo && opts.logo.bytes && opts.logo.w && opts.logo.h) {
|
| 177 |
+
var lh = 40, lw = lh * opts.logo.w / opts.logo.h;
|
| 178 |
+
if (lw > 130) { lw = 130; lh = lw * opts.logo.h / opts.logo.w; }
|
| 179 |
+
wr.image(L, y, lw, lh); lx = L + lw + 12;
|
| 180 |
+
}
|
| 181 |
+
if (sheet.company) wrap(sheet.company, R - 200 - lx, 14, true).slice(0, 2).forEach(function (t, i) { wr.text(lx, y + 15 + i * 17, t, { size: 14, bold: true }); });
|
| 182 |
+
wr.text(lx, y + (sheet.company ? 15 + 17 * Math.min(2, wrap(sheet.company, R - 200 - lx, 14, true).length) : 14), (C.KIND_LABEL[r.kind] || "") + " timesheet", { size: 9, color: MUTED });
|
| 183 |
+
wr.text(R, y + 20, "TIMESHEET", { size: 22, bold: true, color: ACCENT, align: "right" });
|
| 184 |
+
wr.text(R, y + 36, C.fmtRange(r.start, r.end), { size: 9.5, bold: true, align: "right" });
|
| 185 |
+
y += 62;
|
| 186 |
+
|
| 187 |
+
// ---- employee / period band ----
|
| 188 |
+
wr.rect(L, y, CW, 40, SOFT);
|
| 189 |
+
var cells = [["EMPLOYEE", emp.name || "—"], ["EMPLOYEE ID", emp.ref || "—"], ["PAY PERIOD", C.fmtDate(r.start, "y") + " to " + C.fmtDate(r.end, "y")], ["HOURLY RATE", T.rate ? money(T.rate) : "—"]];
|
| 190 |
+
var cw4 = [CW * 0.3, CW * 0.17, CW * 0.36, CW * 0.17], cx = L + 10;
|
| 191 |
+
cells.forEach(function (c, i) {
|
| 192 |
+
wr.text(cx, y + 15, c[0], { size: 6.5, bold: true, color: MUTED });
|
| 193 |
+
var v = c[1]; while (v.length > 3 && width(v, 9.5, true) > cw4[i] - 14) v = v.slice(0, -2);
|
| 194 |
+
if (v !== c[1]) v = v.slice(0, -1) + "…";
|
| 195 |
+
wr.text(cx, y + 30, v, { size: 9.5, bold: true });
|
| 196 |
+
cx += cw4[i];
|
| 197 |
+
});
|
| 198 |
+
y += 54;
|
| 199 |
+
|
| 200 |
+
// ---- day table ----
|
| 201 |
+
var showDT = s.dtOn || s.seventhOn || T.dt > 0;
|
| 202 |
+
var cols = [{ k: "date", t: "Date", w: 64, a: "left" }, { k: "shifts", t: "In – Out", w: 0, a: "left" }, { k: "brk", t: "Break", w: 38 },
|
| 203 |
+
{ k: "hours", t: "Hours", w: 42 }, { k: "reg", t: "Regular", w: 44 }, { k: "ot", t: "Overtime", w: 48 }];
|
| 204 |
+
if (showDT) cols.push({ k: "dt", t: "Double", w: 42 });
|
| 205 |
+
cols.push({ k: "note", t: "Note", w: 96, a: "left" });
|
| 206 |
+
var fixed = cols.reduce(function (a, c) { return a + c.w; }, 0);
|
| 207 |
+
cols[1].w = CW - fixed;
|
| 208 |
+
function header() {
|
| 209 |
+
wr.rect(L, y, CW, 20, ACCENT);
|
| 210 |
+
var x = L;
|
| 211 |
+
cols.forEach(function (c) {
|
| 212 |
+
if (c.a === "left") wr.text(x + 6, y + 13.5, c.t.toUpperCase(), { size: 6.8, bold: true, color: WHITE });
|
| 213 |
+
else wr.text(x + c.w - 6, y + 13.5, c.t.toUpperCase(), { size: 6.8, bold: true, color: WHITE, align: "right" });
|
| 214 |
+
x += c.w;
|
| 215 |
+
});
|
| 216 |
+
y += 20;
|
| 217 |
+
}
|
| 218 |
+
function row(vals, o) {
|
| 219 |
+
o = o || {};
|
| 220 |
+
var lines = {}, n = 1;
|
| 221 |
+
cols.forEach(function (c) {
|
| 222 |
+
var v = vals[c.k];
|
| 223 |
+
var arr = Array.isArray(v) ? v : [v == null ? "" : String(v)];
|
| 224 |
+
if (c.a === "left") arr = [].concat.apply([], arr.map(function (t) { return wrap(t, c.w - 12, 8.3, o.bold); }));
|
| 225 |
+
lines[c.k] = arr; n = Math.max(n, arr.length);
|
| 226 |
+
});
|
| 227 |
+
var rh = n * 11 + 8;
|
| 228 |
+
if (y + rh > BOTTOM) { wr.add(); y = 40; header(); }
|
| 229 |
+
if (o.fill) wr.rect(L, y, CW, rh, o.fill);
|
| 230 |
+
var x = L;
|
| 231 |
+
cols.forEach(function (c) {
|
| 232 |
+
lines[c.k].forEach(function (t, i) {
|
| 233 |
+
var opt = { size: 8.3, bold: !!o.bold || (c.k === "hours" && t !== "—"), color: o.dim ? "#9AA0AC" : INK };
|
| 234 |
+
if (c.k === "note" || c.k === "date") opt.color = o.dim && c.k === "date" ? MUTED : (c.k === "note" ? MUTED : INK);
|
| 235 |
+
if (c.a === "left") wr.text(x + 6, y + 12 + i * 11, t, opt);
|
| 236 |
+
else wr.text(x + c.w - 6, y + 12 + i * 11, t, Object.assign(opt, { align: "right" }));
|
| 237 |
+
});
|
| 238 |
+
x += c.w;
|
| 239 |
+
});
|
| 240 |
+
y += rh;
|
| 241 |
+
wr.line(L, y, R, y, RULE, 0.5);
|
| 242 |
+
}
|
| 243 |
+
header();
|
| 244 |
+
var multiWeek = r.weeks.length > 1;
|
| 245 |
+
r.weeks.forEach(function (wk, wi) {
|
| 246 |
+
wk.days.forEach(function (d) {
|
| 247 |
+
var on = d.worked > 0;
|
| 248 |
+
row({
|
| 249 |
+
date: C.fmtDate(d.date, true),
|
| 250 |
+
shifts: on ? d.shifts.map(function (x) { return C.fmtClock(x.start, h24) + " – " + C.fmtClock(x.end, h24) + (x.end > C.DAY ? " (+1 day)" : ""); }) : "—",
|
| 251 |
+
brk: on && d.brk ? d.brk + " min" : "", hours: on ? C.hm(d.worked) : "—", reg: on ? C.hm(d.reg) : "", ot: d.ot ? C.hm(d.ot) : "",
|
| 252 |
+
dt: d.dt ? C.hm(d.dt) : "", note: (d.seventh ? "7th day. " : "") + (d.note || ""),
|
| 253 |
+
}, { dim: !on });
|
| 254 |
+
});
|
| 255 |
+
if (multiWeek) row({ date: "Week " + (wi + 1), shifts: C.fmtDate(wk.start) + " – " + C.fmtDate(wk.end), brk: "", hours: C.hm(wk.worked), reg: C.hm(wk.reg), ot: C.hm(wk.ot), dt: showDT ? C.hm(wk.dt) : "", note: "" }, { bold: true, fill: SOFT });
|
| 256 |
+
});
|
| 257 |
+
row({ date: "Total", shifts: T.daysWorked + (T.daysWorked === 1 ? " day" : " days") + " worked", brk: T.brk ? T.brk + " min" : "", hours: C.hm(T.worked), reg: C.hm(T.reg), ot: C.hm(T.ot), dt: showDT ? C.hm(T.dt) : "", note: C.dec(T.worked) + " h decimal" }, { bold: true, fill: "#E3ECF8" });
|
| 258 |
+
y += 16;
|
| 259 |
+
|
| 260 |
+
// ---- pay summary (right) + rules (left) ----
|
| 261 |
+
var payRows = [["Regular", C.hm(T.reg) + " (" + C.dec(T.reg) + " h)", T.rate ? money(T.regPay) : ""]];
|
| 262 |
+
if (s.weeklyOn || s.dailyOn || s.seventhOn || T.ot) payRows.push(["Overtime x" + s.otMult, C.hm(T.ot) + " (" + C.dec(T.ot) + " h)", T.rate ? money(T.otPay) : ""]);
|
| 263 |
+
if (showDT) payRows.push(["Double time x" + s.dtMult, C.hm(T.dt) + " (" + C.dec(T.dt) + " h)", T.rate ? money(T.dtPay) : ""]);
|
| 264 |
+
var boxH = payRows.length * 16 + 44;
|
| 265 |
+
if (y + boxH + 120 > BOTTOM) { wr.add(); y = 40; }
|
| 266 |
+
var bx = L + CW * 0.46, by = y;
|
| 267 |
+
payRows.forEach(function (p) {
|
| 268 |
+
wr.text(bx, by + 10, p[0], { size: 9, color: MUTED });
|
| 269 |
+
wr.text(bx + CW * 0.25, by + 10, p[1], { size: 9 });
|
| 270 |
+
if (p[2]) wr.text(R, by + 10, p[2], { size: 9, align: "right" });
|
| 271 |
+
by += 16;
|
| 272 |
+
});
|
| 273 |
+
wr.line(bx, by + 2, R, by + 2, ACCENT, 1.2);
|
| 274 |
+
wr.text(bx, by + 20, T.rate ? "Gross pay" : "Total hours", { size: 11, bold: true });
|
| 275 |
+
wr.text(R, by + 20, T.rate ? money(T.gross) : C.hm(T.worked) + " (" + C.dec(T.worked) + " h)", { size: 13, bold: true, color: ACCENT, align: "right" });
|
| 276 |
+
if (T.rate) wr.text(R, by + 34, "Total hours " + C.hm(T.worked) + " (" + C.dec(T.worked) + " h)", { size: 8, color: MUTED, align: "right" });
|
| 277 |
+
var ly = y;
|
| 278 |
+
wr.text(L, ly + 8, "HOW THIS WAS CALCULATED", { size: 6.8, bold: true, color: MUTED }); ly += 14;
|
| 279 |
+
wrap(C.ruleLines(s), CW * 0.42, 8, false).forEach(function (t) { wr.text(L, ly + 8, t, { size: 8 }); ly += 11; });
|
| 280 |
+
if (sheet.notes) {
|
| 281 |
+
ly += 6;
|
| 282 |
+
wr.text(L, ly + 8, "NOTES", { size: 6.8, bold: true, color: MUTED }); ly += 14;
|
| 283 |
+
wrap(sheet.notes, CW * 0.42, 8, false).slice(0, 8).forEach(function (t) { wr.text(L, ly + 8, t, { size: 8 }); ly += 11; });
|
| 284 |
+
}
|
| 285 |
+
y = Math.max(ly, by + 40) + 26;
|
| 286 |
+
|
| 287 |
+
// ---- signatures ----
|
| 288 |
+
if (y + 92 > BOTTOM) { wr.add(); y = 60; }
|
| 289 |
+
wr.text(L, y, "I confirm the hours above are a true record of the time worked.", { size: 8.5, color: MUTED });
|
| 290 |
+
y += 42;
|
| 291 |
+
function sig(x, w, label, sub) {
|
| 292 |
+
wr.line(x, y, x + w, y, INK, 0.7);
|
| 293 |
+
wr.text(x, y + 11, label, { size: 7.5, bold: true, color: MUTED });
|
| 294 |
+
if (sub) wr.text(x, y + 22, sub, { size: 7.5, color: MUTED });
|
| 295 |
+
}
|
| 296 |
+
var gap = 14, dw = 80, sw = (CW - 2 * dw - 3 * gap) / 2;
|
| 297 |
+
sig(L, sw, "EMPLOYEE SIGNATURE", emp.name || "");
|
| 298 |
+
sig(L + sw + gap, dw, "DATE");
|
| 299 |
+
sig(L + sw + dw + 2 * gap, sw, "SUPERVISOR / EMPLOYER SIGNATURE", sheet.company || "");
|
| 300 |
+
sig(R - dw, dw, "DATE");
|
| 301 |
+
|
| 302 |
+
// ---- footer on every page ----
|
| 303 |
+
var n = wr.pages.length;
|
| 304 |
+
for (var i = 0; i < n; i++) {
|
| 305 |
+
wr.on(i);
|
| 306 |
+
if (opts.credit) {
|
| 307 |
+
var credit = "Calculated with Hoursprig by CyberMax · free time card calculator";
|
| 308 |
+
var cw = wr.text(L, H - 24, credit, { size: 7.5, color: "#7A8090" });
|
| 309 |
+
if (opts.creditUrl) wr.link(L, H - 32, cw, 11, opts.creditUrl);
|
| 310 |
+
}
|
| 311 |
+
wr.text(L, H - 36, "Calculated from the entered times and settings; not legal or payroll advice.", { size: 6.5, color: "#9AA0AC" });
|
| 312 |
+
if (n > 1) wr.text(R, H - 24, "Page " + (i + 1) + " of " + n, { size: 7.5, color: "#7A8090", align: "right" });
|
| 313 |
+
}
|
| 314 |
+
var d = opts.date || new Date();
|
| 315 |
+
var stamp = d.getUTCFullYear() + [d.getUTCMonth() + 1, d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()].map(function (v) { return ("0" + v).slice(-2); }).join("") + "Z";
|
| 316 |
+
return serialize(wr, { title: "Timesheet " + (emp.name ? emp.name + " " : "") + r.start + " to " + r.end, author: sheet.company || "", date: stamp }, opts.logo && opts.logo.bytes ? opts.logo : null);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/** Timesheet-Jordan-Rivera-2026-09-28.pdf */
|
| 320 |
+
function fileName(sheet, ext) {
|
| 321 |
+
var parts = ["Timesheet", sheet.employee && sheet.employee.name, sheet.result.start].filter(Boolean).join("-");
|
| 322 |
+
return parts.normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^A-Za-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 90) + "." + (ext || "pdf");
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
var api = { build: build, fileName: fileName, encode: encode, canEncode: canEncode, width: width, wrap: wrap, pageSize: pageSize };
|
| 326 |
+
if (typeof module === "object" && module.exports) module.exports = api; else root.HourPDF = api;
|
| 327 |
+
})(typeof self !== "undefined" ? self : this);
|
hoursprig/manifest.webmanifest
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Hoursprig: time card calculator",
|
| 3 |
+
"short_name": "Hoursprig",
|
| 4 |
+
"description": "Hours, overtime and pay from in and out times, plus a printable, signable timesheet. Free, no sign-up, nothing uploaded, works offline.",
|
| 5 |
+
"start_url": "./?utm_source=pwa",
|
| 6 |
+
"scope": "./",
|
| 7 |
+
"display": "standalone",
|
| 8 |
+
"background_color": "#F6F3EC",
|
| 9 |
+
"theme_color": "#1F62B5",
|
| 10 |
+
"categories": ["business", "productivity", "finance"],
|
| 11 |
+
"icons": [
|
| 12 |
+
{"src": "icon.svg", "sizes": "any", "type": "image/svg+xml"},
|
| 13 |
+
{"src": "icon-192.png", "sizes": "192x192", "type": "image/png"},
|
| 14 |
+
{"src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"},
|
| 15 |
+
{"src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}
|
| 16 |
+
]
|
| 17 |
+
}
|
hoursprig/og.png
ADDED
|
Git LFS Details
|
hoursprig/pro.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* CyberMax Pro unlock with plans, for static web apps (copied into each product's web/ folder; each product stays
|
| 2 |
+
* self-contained). Extends pro.js with several plans (monthly, yearly, one-time) and a re-check for subscriptions.
|
| 3 |
+
* Config before this script:
|
| 4 |
+
* window.CMX_PRO = { id, name, perks: [..], plans: [{ offer, label, price, per, note, best }], free: "one line" }
|
| 5 |
+
* Buy: counted link https://data.cybermax-tools.workers.dev/buy/<offer>?s=app-<id> -> Stripe Payment Link.
|
| 6 |
+
* After checkout Stripe sends the buyer to data.cybermax-tools.workers.dev/unlock/<id>?session_id=..., which checks the
|
| 7 |
+
* Checkout Session (and, for a subscription, that it is still active) and returns here with #cmx-pro=<session id>.
|
| 8 |
+
* The app checks that code once (/unlock/<id>?json=1&session_id=..) and remembers Pro in this browser; it re-checks every
|
| 9 |
+
* 3 days, so a cancelled subscription turns off by itself (one tiny request per buyer every 3 days, none for free users).
|
| 10 |
+
* The same code (shown on the receipt page and in the Pro box) unlocks Pro on another device. No account, no tracking.
|
| 11 |
+
* (c) 2026 CyberMax. All rights reserved. */
|
| 12 |
+
(function () {
|
| 13 |
+
"use strict";
|
| 14 |
+
var C = window.CMX_PRO || {};
|
| 15 |
+
if (!C.id) return;
|
| 16 |
+
var DATA = "https://data.cybermax-tools.workers.dev";
|
| 17 |
+
var KEY = "cmx-pro:" + C.id;
|
| 18 |
+
var SID = /^cs_(live|test)_[A-Za-z0-9]{10,200}$/;
|
| 19 |
+
var RECHECK = 3 * 864e5;
|
| 20 |
+
var listeners = [];
|
| 21 |
+
|
| 22 |
+
function get() { try { return JSON.parse(localStorage.getItem(KEY) || "null"); } catch (e) { return null; } }
|
| 23 |
+
function set(v) { try { if (v) localStorage.setItem(KEY, JSON.stringify(v)); else localStorage.removeItem(KEY); } catch (e) { /* private mode */ } mem = v; }
|
| 24 |
+
var mem = get();
|
| 25 |
+
function isPro() { return !!(mem && mem.code); }
|
| 26 |
+
|
| 27 |
+
function check(code) {
|
| 28 |
+
return fetch(DATA + "/unlock/" + encodeURIComponent(C.id) + "?json=1&session_id=" + encodeURIComponent(code))
|
| 29 |
+
.then(function (r) { return r.json(); })
|
| 30 |
+
.then(function (j) { return j && typeof j.pro === "boolean" ? j.pro : null; })
|
| 31 |
+
.catch(function () { return null; });
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function unlock(code) {
|
| 35 |
+
return check(code).then(function (ok) {
|
| 36 |
+
if (ok) { set({ code: code, at: new Date().toISOString(), checked: Date.now() }); apply(); toast("Pro unlocked. Thank you for choosing " + C.name + "!"); }
|
| 37 |
+
else if (ok === false) toast("That code is not an active " + C.name + " Pro order.");
|
| 38 |
+
else toast("Could not reach the unlock check. Try again in a minute.");
|
| 39 |
+
return ok;
|
| 40 |
+
});
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function recheck() {
|
| 44 |
+
if (!isPro() || Date.now() - (mem.checked || 0) < RECHECK) return;
|
| 45 |
+
check(mem.code).then(function (ok) {
|
| 46 |
+
if (ok === false) { set(null); apply(); toast(C.name + " Pro has ended in this browser. Everything free is still here."); }
|
| 47 |
+
else if (ok) set(Object.assign({}, mem, { checked: Date.now() }));
|
| 48 |
+
});
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function toast(msg) {
|
| 52 |
+
var t = document.getElementById("toast");
|
| 53 |
+
if (t) { t.textContent = msg; t.hidden = false; t.classList.add("show"); setTimeout(function () { t.classList.remove("show"); }, 3500); }
|
| 54 |
+
var s = document.getElementById("cmx-pro-msg");
|
| 55 |
+
if (s) s.textContent = msg;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function esc(s) { return String(s).replace(/[&<>"]/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """ }[c]; }); }
|
| 59 |
+
function buyUrl(offer, from) { return DATA + "/buy/" + offer + "?s=app-" + C.id + (from ? "-" + from : ""); }
|
| 60 |
+
|
| 61 |
+
function box() {
|
| 62 |
+
var el = document.getElementById("cmx-pro");
|
| 63 |
+
if (!el) {
|
| 64 |
+
el = document.createElement("section");
|
| 65 |
+
el.id = "cmx-pro";
|
| 66 |
+
var anchor = document.querySelector("footer.more") || document.querySelector("main footer") || document.querySelector("footer");
|
| 67 |
+
if (anchor && anchor.parentNode) anchor.parentNode.insertBefore(el, anchor); else (document.querySelector("main") || document.body).appendChild(el);
|
| 68 |
+
}
|
| 69 |
+
el.className = "cmx-pro";
|
| 70 |
+
return el;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function render() {
|
| 74 |
+
var el = box();
|
| 75 |
+
if (isPro()) {
|
| 76 |
+
el.innerHTML = '<h2>' + esc(C.name) + ' Pro <span class="cmx-pro-badge">on</span></h2><p>Thank you! Pro is on in this browser: ' + C.perks.map(esc).join(" · ") +
|
| 77 |
+
'.</p><p class="cmx-pro-small">Your unlock code (paste it on another device): <code style="user-select:all;word-break:break-all">' + esc(mem.code) +
|
| 78 |
+
'</code></p><p class="cmx-pro-small">Monthly or yearly plan? Cancel any time from the link in your Stripe receipt email.</p>';
|
| 79 |
+
return;
|
| 80 |
+
}
|
| 81 |
+
var plans = (C.plans || []).map(function (p) {
|
| 82 |
+
return '<a class="cmx-plan' + (p.best ? " best" : "") + '" href="' + buyUrl(p.offer) + '" rel="nofollow" data-offer="' + esc(p.offer) + '">' +
|
| 83 |
+
(p.best ? "<i>Best value</i>" : "") + "<b>" + esc(p.label) + '</b><span class="cmx-price">' + esc(p.price) + "<small>" + esc(p.per || "") +
|
| 84 |
+
'</small></span><span class="cmx-note">' + esc(p.note || "") + "</span></a>";
|
| 85 |
+
}).join("");
|
| 86 |
+
el.innerHTML = '<h2>' + esc(C.name) + ' Pro</h2>' + (C.free ? '<p class="cmx-pro-small">Free: ' + esc(C.free) + "</p>" : "") +
|
| 87 |
+
"<ul>" + C.perks.map(function (p) { return "<li>" + esc(p) + "</li>"; }).join("") + '</ul><div class="cmx-plans">' + plans +
|
| 88 |
+
'</div><p class="cmx-pro-small">Secure Stripe checkout. Pro turns on the moment you pay; no account needed. Subscriptions cancel any time.</p>' +
|
| 89 |
+
'<details><summary>Already bought Pro?</summary><form id="cmx-pro-form"><label>Unlock code <input id="cmx-pro-code" autocomplete="off" placeholder="cs_live_…"></label> <button class="btn ghost" type="submit">Unlock</button></form></details><p id="cmx-pro-msg" class="cmx-pro-small" aria-live="polite"></p>';
|
| 90 |
+
var f = document.getElementById("cmx-pro-form");
|
| 91 |
+
if (f) f.onsubmit = function (e) { e.preventDefault(); var c = (document.getElementById("cmx-pro-code").value || "").trim(); if (SID.test(c)) unlock(c); else toast("Paste the code from your receipt page (it starts with cs_live_)."); };
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
function apply() {
|
| 95 |
+
document.documentElement.classList.toggle("cmx-pro", isPro());
|
| 96 |
+
render();
|
| 97 |
+
listeners.forEach(function (fn) { try { fn(isPro()); } catch (e) { /* app hook */ } });
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/** Scroll to the Pro box (call when a free user hits a limit); `from` tags the counted buy links. */
|
| 101 |
+
function upsell(reason, from) {
|
| 102 |
+
var el = box();
|
| 103 |
+
if (from) Array.prototype.forEach.call(el.querySelectorAll("a.cmx-plan"), function (a) { a.href = buyUrl(a.getAttribute("data-offer"), from); });
|
| 104 |
+
if (reason) toast(reason);
|
| 105 |
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
| 106 |
+
el.classList.add("cmx-pro-flash"); setTimeout(function () { el.classList.remove("cmx-pro-flash"); }, 1600);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/** Free monthly allowance kept in this browser: quota("pdf", 5) -> {used, left, take()}. */
|
| 110 |
+
function quota(name, limit) {
|
| 111 |
+
var k = "cmx-quota:" + C.id + ":" + name, month = new Date().toISOString().slice(0, 7), q;
|
| 112 |
+
try { q = JSON.parse(localStorage.getItem(k) || "null"); } catch (e) { q = null; }
|
| 113 |
+
if (!q || q.m !== month) q = { m: month, n: 0 };
|
| 114 |
+
return {
|
| 115 |
+
used: q.n, left: Math.max(0, limit - q.n), limit: limit,
|
| 116 |
+
take: function () { if (isPro()) return true; if (q.n >= limit) return false; q.n++; try { localStorage.setItem(k, JSON.stringify(q)); } catch (e) { /* */ } this.used = q.n; this.left = Math.max(0, limit - q.n); return true; },
|
| 117 |
+
};
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function download(name, data, type) {
|
| 121 |
+
var a = document.createElement("a");
|
| 122 |
+
a.href = URL.createObjectURL(data instanceof Blob ? data : new Blob([data], { type: type || "text/csv;charset=utf-8" }));
|
| 123 |
+
a.download = name;
|
| 124 |
+
document.body.appendChild(a); a.click(); a.remove();
|
| 125 |
+
setTimeout(function () { URL.revokeObjectURL(a.href); }, 2000);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
window.CMXPro = { isPro: isPro, onChange: function (fn) { listeners.push(fn); fn(isPro()); }, upsell: upsell, quota: quota, download: download, toast: toast };
|
| 129 |
+
|
| 130 |
+
var m = /[#&]cmx-pro=([^&]+)/.exec(location.hash || "");
|
| 131 |
+
function start() {
|
| 132 |
+
if (m && SID.test(decodeURIComponent(m[1]))) {
|
| 133 |
+
var code = decodeURIComponent(m[1]);
|
| 134 |
+
history.replaceState(null, "", location.pathname + location.search);
|
| 135 |
+
apply(); unlock(code);
|
| 136 |
+
} else { apply(); recheck(); }
|
| 137 |
+
}
|
| 138 |
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start); else start();
|
| 139 |
+
})();
|
hoursprig/robots.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
User-agent: *
|
| 2 |
+
Allow: /
|
| 3 |
+
Sitemap: https://cybermax-tools-cybermax.static.hf.space/hoursprig/sitemap.xml
|
hoursprig/sitemap.xml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://cybermax-tools-cybermax.static.hf.space/hoursprig/index.html</loc><lastmod>2026-10-02</lastmod><changefreq>monthly</changefreq></url></urlset>
|
hoursprig/style.css
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Hoursprig. © 2026 CyberMax. All rights reserved. */
|
| 2 |
+
:root{
|
| 3 |
+
--accent:#1F62B5;--accent2:#154680;--ink:#11141B;--muted:#5B6170;--bg:#F6F3EC;--card:#FFFFFF;--line:#E2DED3;--field:#FFFFFF;
|
| 4 |
+
--soft:#EAF0F9;--warn:#9A4B00;--bad:#B42318;--on-accent:#FFFFFF;--shadow:0 1px 2px rgba(17,20,27,.06),0 6px 24px rgba(17,20,27,.06);
|
| 5 |
+
color-scheme:light dark;
|
| 6 |
+
}
|
| 7 |
+
@media (prefers-color-scheme:dark){
|
| 8 |
+
:root{--accent:#6EA3EC;--accent2:#A9C8F3;--ink:#ECEFF3;--muted:#A3A9B6;--bg:#12151B;--card:#1B1F27;--line:#2E3440;--field:#141820;--soft:#1C2636;--warn:#F2B66B;--bad:#FF8A80;--on-accent:#0B1220;--shadow:none}
|
| 9 |
+
}
|
| 10 |
+
*{box-sizing:border-box}
|
| 11 |
+
[hidden]{display:none!important}
|
| 12 |
+
html{-webkit-text-size-adjust:100%;scroll-padding-top:70px;scroll-padding-bottom:84px}
|
| 13 |
+
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif}
|
| 14 |
+
a{color:var(--accent)}
|
| 15 |
+
code{font:600 .9em ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--soft);padding:1px 5px;border-radius:5px}
|
| 16 |
+
.wrap{max-width:1240px;margin:0 auto;padding:0 16px}
|
| 17 |
+
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
|
| 18 |
+
h1,h2,h3{line-height:1.2;letter-spacing:-.01em}
|
| 19 |
+
h1{font-size:clamp(1.7rem,4.4vw,2.6rem);margin:18px 0 8px;font-weight:800}
|
| 20 |
+
h2,.h2like{font-size:1.15rem;margin:0;font-weight:700}
|
| 21 |
+
.h2like{display:block;color:var(--ink)}
|
| 22 |
+
:focus-visible{outline:3px solid color-mix(in srgb,var(--accent) 55%,transparent);outline-offset:2px}
|
| 23 |
+
|
| 24 |
+
/* header */
|
| 25 |
+
.top{position:sticky;top:0;z-index:20;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:blur(8px);border-bottom:1px solid var(--line)}
|
| 26 |
+
.top-in{display:flex;align-items:center;justify-content:space-between;gap:10px;min-height:56px}
|
| 27 |
+
.brand{display:flex;align-items:center;gap:9px;text-decoration:none;color:var(--ink);font-size:1.12rem;min-width:0}
|
| 28 |
+
.brand small{color:var(--muted);font-weight:500;font-size:.78rem}
|
| 29 |
+
.top-nav{display:flex;align-items:center;gap:8px}
|
| 30 |
+
.top-link{color:var(--ink);text-decoration:none;font-weight:600;font-size:.93rem;padding:6px 4px}
|
| 31 |
+
.pill{background:var(--accent);color:var(--on-accent);text-decoration:none;font-weight:800;font-size:.8rem;padding:5px 12px;border-radius:999px;letter-spacing:.02em}
|
| 32 |
+
html.cmx-pro .pill{background:transparent;color:var(--accent);border:2px solid var(--accent)}
|
| 33 |
+
|
| 34 |
+
/* hero */
|
| 35 |
+
.hero{padding:4px 0 12px}
|
| 36 |
+
.lede{font-size:1.06rem;max-width:780px;color:var(--ink);margin:0 0 14px}
|
| 37 |
+
.hero-row{display:flex;flex-wrap:wrap;align-items:center;gap:10px}
|
| 38 |
+
.hero-note{color:var(--muted);font-size:.9rem}
|
| 39 |
+
.sel-inline select{width:auto;max-width:100%}
|
| 40 |
+
|
| 41 |
+
/* controls */
|
| 42 |
+
.btn{appearance:none;border:2px solid var(--accent);background:var(--accent);color:var(--on-accent);font:inherit;font-weight:700;border-radius:10px;padding:9px 16px;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;gap:6px;line-height:1.2;justify-content:center}
|
| 43 |
+
.btn:hover{filter:brightness(1.06)}
|
| 44 |
+
.btn.ghost{background:transparent;color:var(--ink);border-color:var(--line)}
|
| 45 |
+
.btn.ghost:hover{border-color:var(--accent)}
|
| 46 |
+
.btn.sm{padding:6px 11px;font-size:.88rem;border-radius:9px}
|
| 47 |
+
.btn.big{padding:12px 22px;font-size:1.05rem;flex:1}
|
| 48 |
+
.btn.danger{color:var(--bad)}
|
| 49 |
+
.linkish{appearance:none;border:0;background:none;color:var(--accent);font:inherit;font-weight:700;text-decoration:underline;cursor:pointer;padding:0}
|
| 50 |
+
.pro-tag{display:inline-block;font-size:.66rem;font-weight:800;letter-spacing:.04em;background:var(--accent);color:var(--on-accent);border-radius:5px;padding:1px 5px;vertical-align:middle}
|
| 51 |
+
html.cmx-pro .pro-tag{display:none}
|
| 52 |
+
label{display:block;font-size:.84rem;font-weight:600;margin:10px 0 4px;color:var(--ink)}
|
| 53 |
+
.opt{font-weight:400;color:var(--muted)}
|
| 54 |
+
input,select,textarea{width:100%;font:inherit;font-size:16px;color:var(--ink);background:var(--field);border:1.5px solid var(--line);border-radius:9px;padding:9px 10px;min-width:0}
|
| 55 |
+
textarea{resize:vertical}
|
| 56 |
+
input:focus,select:focus,textarea:focus{border-color:var(--accent);outline:none;box-shadow:0 0 0 3px color-mix(in srgb,var(--accent) 22%,transparent)}
|
| 57 |
+
input.bad{border-color:var(--bad);background:color-mix(in srgb,var(--bad) 7%,var(--field))}
|
| 58 |
+
.check{display:flex;gap:8px;align-items:center;font-weight:600;flex-wrap:wrap}
|
| 59 |
+
.check input{width:20px;height:20px;flex:0 0 auto;accent-color:var(--accent)}
|
| 60 |
+
.hint{color:var(--muted);font-size:.86rem;margin:6px 0}
|
| 61 |
+
.hint.tiny{font-size:.8rem;margin:0}
|
| 62 |
+
.btns{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-top:12px}
|
| 63 |
+
.combo{display:flex;gap:6px;align-items:center}
|
| 64 |
+
.combo input{flex:1 1 60px}
|
| 65 |
+
.combo.sm input{flex:0 0 76px;width:76px}
|
| 66 |
+
.combo span{color:var(--muted);font-size:.88rem}
|
| 67 |
+
.icon-btn{appearance:none;border:1.5px solid var(--line);background:transparent;color:var(--ink);width:40px;height:40px;border-radius:9px;cursor:pointer;font-size:1.1rem;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto}
|
| 68 |
+
.icon-btn:hover{border-color:var(--accent);color:var(--accent)}
|
| 69 |
+
.icon-btn.sm{width:32px;height:32px;font-size:1rem}
|
| 70 |
+
|
| 71 |
+
/* app layout */
|
| 72 |
+
.app{padding-bottom:10px}
|
| 73 |
+
.cols{display:grid;grid-template-columns:minmax(0,1fr);gap:16px;align-items:start}
|
| 74 |
+
@media (min-width:980px){.cols{grid-template-columns:minmax(0,520px) minmax(0,1fr)}.preview-col{position:sticky;top:70px;max-height:calc(100vh - 80px);overflow:auto;padding-bottom:6px}}
|
| 75 |
+
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px 16px;box-shadow:var(--shadow)}
|
| 76 |
+
.card-head{display:flex;flex-wrap:wrap;gap:6px 12px;align-items:baseline;justify-content:space-between;margin-bottom:4px}
|
| 77 |
+
.plan-chip{font-size:.78rem;font-weight:700;color:var(--muted);border:1px solid var(--line);border-radius:999px;padding:2px 9px}
|
| 78 |
+
.editor{display:flex;flex-direction:column;gap:12px;min-width:0}
|
| 79 |
+
.editor summary{cursor:pointer;list-style:none;display:flex;align-items:center;justify-content:space-between}
|
| 80 |
+
.editor summary::-webkit-details-marker{display:none}
|
| 81 |
+
.editor summary::after{content:"";width:9px;height:9px;border-right:2px solid var(--muted);border-bottom:2px solid var(--muted);transform:rotate(45deg);margin-right:4px;transition:transform .15s}
|
| 82 |
+
.editor details[open]>summary::after{transform:rotate(225deg)}
|
| 83 |
+
.editor details[open]>summary{margin-bottom:4px}
|
| 84 |
+
.g2{display:grid;grid-template-columns:1fr 1fr;gap:0 12px}
|
| 85 |
+
.g3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:0 12px}
|
| 86 |
+
.span2{grid-column:span 2}
|
| 87 |
+
.emp-row{display:flex;flex-wrap:wrap;gap:8px;align-items:end}
|
| 88 |
+
.emp-sel{flex:1 1 180px}
|
| 89 |
+
.period-row{display:flex;flex-wrap:wrap;gap:10px 14px;align-items:end;margin-top:12px}
|
| 90 |
+
.start{flex:1 1 210px}.start label{margin-top:0}
|
| 91 |
+
.start input{text-align:center}
|
| 92 |
+
.seg{display:inline-flex;gap:3px;background:var(--bg);border:1px solid var(--line);border-radius:11px;padding:3px}
|
| 93 |
+
.seg button{appearance:none;font:inherit;font-weight:700;font-size:.9rem;border:0;background:transparent;color:var(--ink);padding:8px 11px;border-radius:8px;cursor:pointer}
|
| 94 |
+
.seg button[aria-checked=true]{background:var(--accent);color:var(--on-accent)}
|
| 95 |
+
.only-semi{display:none}
|
| 96 |
+
body.semi .only-semi{display:block}
|
| 97 |
+
.logo-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-top:10px}
|
| 98 |
+
.logo-prev{min-width:90px;height:44px;border:1.5px dashed var(--line);border-radius:9px;display:flex;align-items:center;justify-content:center;color:var(--muted);font-size:.8rem;padding:3px 8px;background:#fff}
|
| 99 |
+
@media (prefers-color-scheme:dark){.logo-prev{background:var(--field)}}
|
| 100 |
+
.logo-prev img{max-height:36px;max-width:150px}
|
| 101 |
+
.file-btn{margin:0;cursor:pointer}
|
| 102 |
+
.rule{margin:10px 0 0}
|
| 103 |
+
.rule .check{margin:0 0 6px}
|
| 104 |
+
.rule .hint{margin:4px 0 0}
|
| 105 |
+
.pro-rules{border-top:1px dashed var(--line);margin-top:12px;padding-top:2px}
|
| 106 |
+
|
| 107 |
+
/* time card */
|
| 108 |
+
.days-head{display:grid;grid-template-columns:62px minmax(0,1fr) 78px 68px;gap:8px;font-size:.74rem;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.04em;padding:6px 0 4px;border-bottom:1px solid var(--line)}
|
| 109 |
+
.days-head span:nth-child(3),.days-head span:nth-child(4){text-align:right}
|
| 110 |
+
.day{display:grid;grid-template-columns:62px minmax(0,1fr) 78px 68px;gap:6px 8px;align-items:start;padding:9px 0;border-bottom:1px dashed var(--line)}
|
| 111 |
+
.dl{display:flex;flex-direction:column;line-height:1.15;padding-top:6px}
|
| 112 |
+
.dl b{font-size:.98rem}.dl span{font-size:.8rem;color:var(--muted)}
|
| 113 |
+
.pairs{display:flex;flex-direction:column;gap:6px;min-width:0}
|
| 114 |
+
.pair{display:flex;align-items:center;gap:5px}
|
| 115 |
+
.pair input.t{flex:1 1 0;min-width:0;padding:8px 6px;text-align:center;font-variant-numeric:tabular-nums}
|
| 116 |
+
.dash{color:var(--muted)}
|
| 117 |
+
.icon-btn.add{color:var(--accent);font-weight:800}
|
| 118 |
+
.icon-btn:disabled{opacity:.35;cursor:default}
|
| 119 |
+
.brk{display:flex;align-items:center;gap:4px}
|
| 120 |
+
.brk input{padding:8px 6px;text-align:center}
|
| 121 |
+
.brk span{font-size:.78rem;color:var(--muted)}
|
| 122 |
+
.dt{text-align:right;line-height:1.2;padding-top:5px;font-variant-numeric:tabular-nums}
|
| 123 |
+
.dt b{font-size:1.06rem;display:block}
|
| 124 |
+
.dt b.z{color:var(--muted);font-weight:600}
|
| 125 |
+
.dt small{font-size:.72rem;color:var(--muted)}
|
| 126 |
+
.day .note{grid-column:2/-1;padding:5px 9px;font-size:16px;border-style:dashed}
|
| 127 |
+
.day.off .dl b{color:var(--muted)}
|
| 128 |
+
|
| 129 |
+
/* summary + actions */
|
| 130 |
+
.preview-col{min-width:0;scroll-margin-top:68px;display:flex;flex-direction:column;gap:12px}
|
| 131 |
+
#cmx-pro,#app,#history{scroll-margin-top:68px}
|
| 132 |
+
.sum-top{display:flex;flex-wrap:wrap;gap:12px 24px;justify-content:space-between}
|
| 133 |
+
.sum .k{font-size:.78rem;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
|
| 134 |
+
.sum .big{font-size:2.3rem;font-weight:800;line-height:1.1;font-variant-numeric:tabular-nums;color:var(--ink)}
|
| 135 |
+
.sum .pay .big{color:var(--accent)}
|
| 136 |
+
.sum .pay{text-align:right}
|
| 137 |
+
.sum .sub{color:var(--muted);font-size:.88rem}
|
| 138 |
+
.sum-t{width:100%;border-collapse:collapse;margin-top:10px;font-variant-numeric:tabular-nums;font-size:.94rem}
|
| 139 |
+
.sum-t th,.sum-t td{padding:5px 4px;border-bottom:1px solid var(--line);text-align:right}
|
| 140 |
+
.sum-t thead th{font-size:.74rem;color:var(--muted);text-transform:uppercase;letter-spacing:.03em}
|
| 141 |
+
.sum-t tbody th{text-align:left;font-weight:600}
|
| 142 |
+
.rules-line{font-size:.82rem;color:var(--muted);margin:8px 0 0}
|
| 143 |
+
.locked-note{font-size:.86rem;margin:8px 0 0;padding:8px 10px;border-radius:9px;background:var(--soft)}
|
| 144 |
+
.act-row{display:flex;gap:8px;flex-wrap:wrap}
|
| 145 |
+
.limits{margin:10px 0 0;font-size:.88rem;color:var(--muted)}
|
| 146 |
+
.limits b{color:var(--ink)}
|
| 147 |
+
.warn{margin:6px 0 0;color:var(--warn);font-size:.86rem;font-weight:600}
|
| 148 |
+
.warn:empty{display:none}
|
| 149 |
+
.paper-wrap{position:relative;overflow:hidden;border-radius:6px;box-shadow:0 2px 6px rgba(0,0,0,.08),0 18px 40px rgba(17,20,27,.12);flex:0 0 auto}
|
| 150 |
+
|
| 151 |
+
/* timesheet paper (mirrors the PDF) */
|
| 152 |
+
.paper{width:794px;min-height:1123px;transform-origin:0 0;background:#fff;color:#11141B;font:11.5px/1.4 Helvetica,Arial,sans-serif;padding:53px 53px 70px;position:relative}
|
| 153 |
+
.paper.letter{width:816px;min-height:1056px}
|
| 154 |
+
.paper *{box-sizing:border-box}
|
| 155 |
+
.p-head{display:flex;align-items:flex-start;gap:16px}
|
| 156 |
+
.p-logo{max-height:53px;max-width:173px}
|
| 157 |
+
.p-co{flex:1;min-width:0}
|
| 158 |
+
.p-name{font-size:19px;font-weight:700;line-height:1.2}
|
| 159 |
+
.p-kind{color:#5B6170;font-size:12px;margin-top:3px}
|
| 160 |
+
.p-title{text-align:right}
|
| 161 |
+
.p-title div{font-size:29px;font-weight:700;color:#1F62B5;line-height:1}
|
| 162 |
+
.p-title span{display:block;font-weight:700;font-size:12.5px;margin-top:6px}
|
| 163 |
+
.p-band{display:grid;grid-template-columns:30% 17% 36% 17%;background:#F4F6FA;margin:26px 0 18px;padding:12px 13px}
|
| 164 |
+
.p-band small{display:block;font-size:8.6px;font-weight:700;color:#5B6170;letter-spacing:.03em}
|
| 165 |
+
.p-band b{display:block;font-size:12.5px;margin-top:5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:8px}
|
| 166 |
+
.p-t{width:100%;border-collapse:collapse;font-size:11px;font-variant-numeric:tabular-nums}
|
| 167 |
+
.p-t th{background:#1F62B5;color:#fff;font-size:9px;text-transform:uppercase;letter-spacing:.03em;text-align:left;padding:8px 8px}
|
| 168 |
+
.p-t td{padding:6px 8px;border-bottom:.7px solid #D9DCE3;vertical-align:top}
|
| 169 |
+
.p-t .n{text-align:right;white-space:nowrap}
|
| 170 |
+
.p-t .b{font-weight:700}
|
| 171 |
+
.p-t i{font-style:normal;color:#5B6170}
|
| 172 |
+
.p-t .nt{color:#5B6170;max-width:130px}
|
| 173 |
+
.p-t tr.off td{color:#9AA0AC}
|
| 174 |
+
.p-t tr.wk td{background:#F4F6FA;font-weight:700}
|
| 175 |
+
.p-t tr.tot td{background:#E3ECF8;font-weight:700}
|
| 176 |
+
.p-bottom{display:flex;gap:24px;justify-content:space-between;margin-top:20px}
|
| 177 |
+
.p-rules{flex:0 1 42%}
|
| 178 |
+
.p-rules small{display:block;font-size:9px;font-weight:700;color:#5B6170;margin-top:4px}
|
| 179 |
+
.p-rules p{margin:4px 0 10px;font-size:10.6px}
|
| 180 |
+
.p-pay{border-collapse:collapse;font-size:12px;flex:0 1 54%;font-variant-numeric:tabular-nums;align-self:flex-start}
|
| 181 |
+
.p-pay td{padding:3px 0}
|
| 182 |
+
.p-pay td:first-child{color:#5B6170;padding-right:18px}
|
| 183 |
+
.p-pay td:last-child{text-align:right;padding-left:18px}
|
| 184 |
+
.p-pay tr.g td{border-top:1.6px solid #1F62B5;padding-top:9px;font-weight:700;font-size:14.5px;color:#11141B}
|
| 185 |
+
.p-pay tr.g td:last-child{color:#1F62B5;font-size:17px}
|
| 186 |
+
.p-confirm{color:#5B6170;font-size:11px;margin:30px 0 50px}
|
| 187 |
+
.p-sig{display:grid;grid-template-columns:1fr 106px 1fr 106px;gap:18px}
|
| 188 |
+
.p-sig span{display:block;border-top:.9px solid #11141B}
|
| 189 |
+
.p-sig small{display:block;font-size:9.4px;font-weight:700;color:#5B6170;margin-top:4px}
|
| 190 |
+
.p-sig em{display:block;font-style:normal;font-size:9.4px;color:#5B6170;margin-top:4px}
|
| 191 |
+
.p-foot{position:absolute;left:53px;right:53px;bottom:22px;display:flex;flex-direction:column;gap:3px}
|
| 192 |
+
.p-disc{font-size:8.6px;color:#9AA0AC}
|
| 193 |
+
.p-credit{font-size:10px;color:#7A8090}
|
| 194 |
+
html.cmx-pro .p-credit{display:none}
|
| 195 |
+
|
| 196 |
+
/* after the app */
|
| 197 |
+
.pro-cta{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:14px;margin:22px 0;border:2px solid var(--accent);background:var(--soft)}
|
| 198 |
+
.pro-cta p{margin:6px 0 0;max-width:760px}
|
| 199 |
+
.history{margin:22px 0}
|
| 200 |
+
.hist-head{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between}
|
| 201 |
+
.hist-head .btns{margin:0}
|
| 202 |
+
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;max-width:100%}
|
| 203 |
+
.ht{width:100%;border-collapse:collapse;font-size:.9rem;margin-top:8px}
|
| 204 |
+
.ht th,.ht td{padding:8px 6px;border-bottom:1px solid var(--line);text-align:left;white-space:nowrap}
|
| 205 |
+
.ht .num{text-align:right;font-variant-numeric:tabular-nums}
|
| 206 |
+
.locked{display:flex;flex-wrap:wrap;align-items:center;gap:12px;justify-content:space-between;color:var(--muted);margin-top:8px}
|
| 207 |
+
.locked p{margin:0;max-width:680px}
|
| 208 |
+
.example{margin:30px 0}
|
| 209 |
+
.example h2{font-size:1.3rem;margin-bottom:8px}
|
| 210 |
+
.example p{margin:8px 0}
|
| 211 |
+
section.how,section.compare,section.faq{margin:34px 0}
|
| 212 |
+
section.how h2,section.compare h2,section.faq h2{font-size:1.45rem;margin-bottom:12px}
|
| 213 |
+
.steps{display:grid;gap:12px;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));padding:0;margin:0;list-style:none;counter-reset:s}
|
| 214 |
+
.steps li{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:16px 16px 16px 58px;position:relative;counter-increment:s}
|
| 215 |
+
.steps li::before{content:counter(s);position:absolute;left:16px;top:14px;width:30px;height:30px;border-radius:50%;background:var(--accent);color:var(--on-accent);font-weight:800;display:flex;align-items:center;justify-content:center}
|
| 216 |
+
.cmp{width:100%;border-collapse:collapse;background:var(--card);border-radius:12px;overflow:hidden;font-size:.94rem}
|
| 217 |
+
.cmp th,.cmp td{padding:10px 12px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
|
| 218 |
+
.cmp thead th{background:var(--soft);font-size:.82rem;text-transform:uppercase;letter-spacing:.03em}
|
| 219 |
+
.cmp tr.us th,.cmp tr.us td{background:color-mix(in srgb,var(--accent) 7%,var(--card))}
|
| 220 |
+
.faq details{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:12px 16px;margin-bottom:8px}
|
| 221 |
+
.faq summary{cursor:pointer;font-weight:700}
|
| 222 |
+
.faq p{margin:8px 0 0}
|
| 223 |
+
.disclaimer{color:var(--muted);font-size:.88rem;border-left:3px solid var(--line);padding-left:12px}
|
| 224 |
+
footer.more{border-top:1px solid var(--line);margin-top:30px;padding:22px 0 40px}
|
| 225 |
+
.more-title{font-weight:800;margin-bottom:10px}
|
| 226 |
+
.more-links{display:flex;flex-wrap:wrap;gap:8px 16px;margin-bottom:16px}
|
| 227 |
+
.more-links a{text-decoration:none;font-weight:600}
|
| 228 |
+
.more-links a:hover{text-decoration:underline}
|
| 229 |
+
.copy{color:var(--muted);font-size:.88rem}
|
| 230 |
+
.toast{position:fixed;left:50%;bottom:20px;transform:translateX(-50%) translateY(20px);background:var(--ink);color:var(--bg);padding:10px 16px;border-radius:10px;font-weight:600;opacity:0;transition:.2s;z-index:50;max-width:calc(100% - 32px);pointer-events:none;text-align:center}
|
| 231 |
+
.toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
|
| 232 |
+
|
| 233 |
+
@media (max-width:640px){
|
| 234 |
+
.g3{grid-template-columns:1fr 1fr}.g3 .span2{grid-column:span 2}
|
| 235 |
+
.cmp thead{display:none}.cmp,.cmp tbody,.cmp tr,.cmp th,.cmp td{display:block;width:100%}
|
| 236 |
+
.cmp tr{border-bottom:1px solid var(--line);padding:6px 0}.cmp th,.cmp td{border:0;padding:3px 12px}
|
| 237 |
+
.top-link{display:none}
|
| 238 |
+
.brand small{display:none}
|
| 239 |
+
.hero-row .btn{flex:1}
|
| 240 |
+
.sel-inline{flex:1 1 100%}.sel-inline select{width:100%}
|
| 241 |
+
.seg{display:grid;grid-template-columns:repeat(3,1fr);width:100%}
|
| 242 |
+
.seg button{padding:8px 4px}
|
| 243 |
+
.days-head{display:none}
|
| 244 |
+
.day{grid-template-columns:minmax(0,1fr) auto;gap:6px 10px}
|
| 245 |
+
.dl{flex-direction:row;gap:6px;align-items:baseline;padding-top:2px}
|
| 246 |
+
.dt{grid-column:2;grid-row:1;padding-top:0}
|
| 247 |
+
.pairs{grid-column:1/-1}
|
| 248 |
+
.brk{grid-column:1;grid-row:3}
|
| 249 |
+
.brk input{width:70px;flex:0 0 70px}
|
| 250 |
+
.day .note{grid-column:2;grid-row:3;width:auto;min-width:0}
|
| 251 |
+
.day{grid-template-columns:minmax(0,auto) minmax(0,1fr)}
|
| 252 |
+
.dt{justify-self:end}
|
| 253 |
+
.sum .big{font-size:1.9rem}
|
| 254 |
+
.sum .pay{text-align:left}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/* phone action bar */
|
| 258 |
+
.mbar{display:none}
|
| 259 |
+
@media (max-width:979px){
|
| 260 |
+
.mbar{display:flex;gap:8px;position:fixed;left:0;right:0;bottom:0;z-index:30;padding:10px 16px calc(10px + env(safe-area-inset-bottom));background:color-mix(in srgb,var(--card) 94%,transparent);backdrop-filter:blur(8px);border-top:1px solid var(--line)}
|
| 261 |
+
.mbar .btn{flex:1}
|
| 262 |
+
.toast{bottom:84px}
|
| 263 |
+
body{padding-bottom:72px}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/* Pro box (shared/pro-unlock/pro-plans.css) */
|
| 267 |
+
#cmx-pro.cmx-pro{border:2px solid var(--accent,#b63a10);border-radius:16px;padding:20px;margin:28px 0;background:var(--card,#fff)}
|
| 268 |
+
#cmx-pro h2{margin:0 0 8px}
|
| 269 |
+
#cmx-pro ul{margin:8px 0 14px;padding-left:20px}
|
| 270 |
+
.cmx-pro-badge{background:var(--accent,#b63a10);color:#fff;border-radius:999px;padding:2px 10px;font-size:.7em;vertical-align:middle}
|
| 271 |
+
.cmx-pro-small{font-size:.88em;opacity:.8}
|
| 272 |
+
.cmx-plans{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;margin:10px 0}
|
| 273 |
+
.cmx-plan{position:relative;display:flex;flex-direction:column;gap:2px;padding:14px;border:1px solid var(--line,#d9d3c7);border-radius:12px;text-decoration:none;color:inherit;background:var(--bg,#faf8f3)}
|
| 274 |
+
.cmx-plan:hover,.cmx-plan:focus{border-color:var(--accent,#b63a10);outline:none}
|
| 275 |
+
.cmx-plan.best{border:2px solid var(--accent,#b63a10)}
|
| 276 |
+
.cmx-plan i{position:absolute;top:-10px;right:10px;background:var(--accent,#b63a10);color:#fff;font-style:normal;font-size:.72em;font-weight:700;border-radius:999px;padding:2px 8px}
|
| 277 |
+
.cmx-price{font-size:1.5em;font-weight:800}
|
| 278 |
+
.cmx-price small{font-size:.55em;font-weight:600;opacity:.75}
|
| 279 |
+
.cmx-note{font-size:.82em;opacity:.75}
|
| 280 |
+
.cmx-pro-flash{animation:cmxflash 1.5s ease}
|
| 281 |
+
@keyframes cmxflash{0%,100%{box-shadow:none}30%{box-shadow:0 0 0 6px color-mix(in srgb,var(--accent,#b63a10) 35%,transparent)}}
|
| 282 |
+
#cmx-pro details{margin-top:8px}
|
| 283 |
+
#cmx-pro input{max-width:280px}
|
| 284 |
+
/* layout helpers for the Pro box form in this app */
|
| 285 |
+
#cmx-pro form{display:flex;flex-wrap:wrap;gap:8px;align-items:end}
|
| 286 |
+
#cmx-pro form label{flex:1 1 220px;margin:0}
|
| 287 |
+
#cmx-pro .cmx-plans{max-width:420px}
|
| 288 |
+
|
| 289 |
+
/* print: only the timesheet */
|
| 290 |
+
@media print{
|
| 291 |
+
@page{margin:0;size:auto}
|
| 292 |
+
html,body{background:#fff!important;padding:0!important;margin:0!important}
|
| 293 |
+
body>:not(main),main>div.wrap,.editor,#sum,.actions,.toast,.mbar{display:none!important}
|
| 294 |
+
#app{padding:0!important;max-width:none!important}
|
| 295 |
+
.cols{display:block!important}
|
| 296 |
+
.preview-col{position:static!important;max-height:none!important;overflow:visible!important;display:block!important}
|
| 297 |
+
.paper-wrap{position:static;overflow:visible;box-shadow:none;height:auto!important;border-radius:0}
|
| 298 |
+
#doc{transform:none!important;width:100%!important;min-height:0;box-shadow:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}
|
| 299 |
+
#doc .p-foot{position:fixed;bottom:8mm;left:14mm;right:14mm}
|
| 300 |
+
.p-t tr{break-inside:avoid}
|
| 301 |
+
}
|
hoursprig/sw.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Hoursprig offline cache. © 2026 CyberMax. All rights reserved. */
|
| 2 |
+
var CACHE = "hoursprig-v1";
|
| 3 |
+
var FILES = ["./", "index.html", "style.css", "pro.js", "lib/calc.js", "lib/pdf.js", "app.js", "manifest.webmanifest", "icon.svg", "icon-192.png", "icon-512.png"];
|
| 4 |
+
self.addEventListener("install", function (e) {
|
| 5 |
+
e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(FILES); }).then(function () { return self.skipWaiting(); }));
|
| 6 |
+
});
|
| 7 |
+
self.addEventListener("activate", function (e) {
|
| 8 |
+
e.waitUntil(caches.keys().then(function (keys) {
|
| 9 |
+
return Promise.all(keys.filter(function (k) { return k.indexOf("hoursprig-") === 0 && k !== CACHE; }).map(function (k) { return caches.delete(k); }));
|
| 10 |
+
}).then(function () { return self.clients.claim(); }));
|
| 11 |
+
});
|
| 12 |
+
self.addEventListener("fetch", function (e) {
|
| 13 |
+
var req = e.request, url = new URL(req.url);
|
| 14 |
+
if (req.method !== "GET" || url.origin !== location.origin) return;
|
| 15 |
+
var scope = new URL(self.registration.scope);
|
| 16 |
+
if (url.pathname.indexOf(scope.pathname) !== 0) return;
|
| 17 |
+
if (req.mode === "navigate") {
|
| 18 |
+
// Network first for pages so updates arrive quickly; the cached page works offline.
|
| 19 |
+
e.respondWith(fetch(req).then(function (r) {
|
| 20 |
+
var copy = r.clone(); caches.open(CACHE).then(function (c) { c.put("index.html", copy); });
|
| 21 |
+
return r;
|
| 22 |
+
}).catch(function () { return caches.match("index.html"); }));
|
| 23 |
+
return;
|
| 24 |
+
}
|
| 25 |
+
// Cache first for static files in this app's folder, refreshed in the background.
|
| 26 |
+
e.respondWith(caches.match(req, { ignoreSearch: true }).then(function (hit) {
|
| 27 |
+
var net = fetch(req).then(function (r) {
|
| 28 |
+
if (r && r.ok) { var copy = r.clone(); caches.open(CACHE).then(function (c) { c.put(req, copy); }); }
|
| 29 |
+
return r;
|
| 30 |
+
});
|
| 31 |
+
return hit || net;
|
| 32 |
+
}));
|
| 33 |
+
});
|