Skip to content

Instantly share code, notes, and snippets.

@asbasawaraj
Created May 23, 2019 10:13
Show Gist options
  • Save asbasawaraj/fb0d48c72228bd8572acb0bf4f43741b to your computer and use it in GitHub Desktop.
Save asbasawaraj/fb0d48c72228bd8572acb0bf4f43741b to your computer and use it in GitHub Desktop.
Lock Timesheet for Users who do not have 'Projects Manager' Role
frappe.ui.form.on("Timesheet", "validate", function(frm) {
if (frappe.user_roles.indexOf("Projects Manager") == -1) {
const t = new Date().getDate() + (6 - new Date().getDay() - 1) - 7;
const lastFriday = new Date();
lastFriday.setDate(t);
let dd = lastFriday.getDate();
let mm = lastFriday.getMonth() + 1;
let yyyy = lastFriday.getFullYear();
frm.doc.time_logs.forEach(log => {
if (new Date(log.from_time) <= lastFriday) {
frappe.throw("You cannot add timesheet for dates before last Friday " + dd + "/" + mm + "/" + yyyy + ". Please contact your Project Manager.");
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment