Refactor total shifts calculation in generateExtra and worker row processing for improved clarity and error handling
This commit is contained in:
+12
-2
@@ -78,11 +78,11 @@ function generateExtra() {
|
|||||||
|
|
||||||
shift_counts = {};
|
shift_counts = {};
|
||||||
|
|
||||||
total_shifts = 0;
|
//total_shifts = 0;
|
||||||
days_lost = 0;
|
days_lost = 0;
|
||||||
shifts_unique.forEach(el => {
|
shifts_unique.forEach(el => {
|
||||||
shift_counts[el] = shifts.count(el);
|
shift_counts[el] = shifts.count(el);
|
||||||
total_shifts = total_shifts + shifts.count(el);
|
//total_shifts = total_shifts + shifts.count(el);
|
||||||
|
|
||||||
// why like this?
|
// why like this?
|
||||||
if (el == "night_weekend") {
|
if (el == "night_weekend") {
|
||||||
@@ -518,6 +518,16 @@ $(".table-div .worker-row .worker").each((n, tr) => {
|
|||||||
locum_shift_counts = jtr.data("locum-shift-counts")
|
locum_shift_counts = jtr.data("locum-shift-counts")
|
||||||
shift_targets = jtr.data("worker-targets")
|
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) => {
|
oshifts.forEach((s) => {
|
||||||
if (s in shift_targets && shift_targets[s] > 0) {
|
if (s in shift_targets && shift_targets[s] > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user