From 053765a466d444ec814e40357caf7fc0705f5cc6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 31 Oct 2025 14:06:22 +0530 Subject: [PATCH] fix: job card timer --- .../doctype/job_card/job_card.js | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.js b/erpnext/manufacturing/doctype/job_card/job_card.js index c3b0bb10fe6..9d3c646598b 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.js +++ b/erpnext/manufacturing/doctype/job_card/job_card.js @@ -408,7 +408,7 @@ frappe.ui.form.on("Job Card", { function updateStopwatch(increment) { var hours = Math.floor(increment / 3600); var minutes = Math.floor((increment - hours * 3600) / 60); - var seconds = increment - hours * 3600 - minutes * 60; + var seconds = Math.floor(increment - hours * 3600 - minutes * 60); $(section) .find(".hours") @@ -431,7 +431,7 @@ frappe.ui.form.on("Job Card", { frm.dashboard.refresh(); const timer = `
00 : 00 @@ -441,20 +441,34 @@ frappe.ui.form.on("Job Card", { var section = frm.toolbar.page.add_inner_message(timer); - let currentIncrement = frm.doc.current_time || 0; + let currentIncrement = frm.events.get_current_time(frm); if (frm.doc.started_time || frm.doc.current_time) { if (frm.doc.status == "On Hold") { updateStopwatch(currentIncrement); } else { - currentIncrement += moment(frappe.datetime.now_datetime()).diff( - moment(frm.doc.started_time), - "seconds" - ); initialiseTimer(); } } }, + get_current_time(frm) { + let current_time = 0; + + frm.doc.time_logs.forEach((d) => { + if (d.to_time) { + if (d.time_in_mins) { + current_time += flt(d.time_in_mins, 2) * 60; + } else { + current_time += get_seconds_diff(d.to_time, d.from_time); + } + } else { + current_time += get_seconds_diff(frappe.datetime.now_datetime(), d.from_time); + } + }); + + return current_time; + }, + hide_timer: function (frm) { frm.toolbar.page.inner_toolbar.find(".stopwatch").remove(); }, @@ -519,3 +533,7 @@ frappe.ui.form.on("Job Card Time Log", { frm.set_value("started_time", ""); }, }); + +function get_seconds_diff(d1, d2) { + return moment(d1).diff(d2, "seconds"); +}