Refactor total shifts calculation in generateExtra and worker row processing for improved clarity and error handling

This commit is contained in:
Ross
2026-05-19 15:33:37 +01:00
parent d741d7e23c
commit 4bb4f5b97a
+12 -2
View File
@@ -78,11 +78,11 @@ function generateExtra() {
shift_counts = {};
total_shifts = 0;
//total_shifts = 0;
days_lost = 0;
shifts_unique.forEach(el => {
shift_counts[el] = shifts.count(el);
total_shifts = total_shifts + shifts.count(el);
//total_shifts = total_shifts + shifts.count(el);
// why like this?
if (el == "night_weekend") {
@@ -518,6 +518,16 @@ $(".table-div .worker-row .worker").each((n, tr) => {
locum_shift_counts = jtr.data("locum-shift-counts")
shift_targets = jtr.data("worker-targets")
// Compute total shifts from shift_counts (sum of assigned counts)
let total_shifts = 0;
try {
if (shift_counts && typeof shift_counts === 'object') {
total_shifts = Object.values(shift_counts).reduce((a, b) => a + (parseFloat(b) || 0), 0);
}
} catch (e) {
total_shifts = 0;
}
oshifts.forEach((s) => {
if (s in shift_targets && shift_targets[s] > 0) {