Created
May 23, 2019 10:13
-
-
Save asbasawaraj/fb0d48c72228bd8572acb0bf4f43741b to your computer and use it in GitHub Desktop.
Lock Timesheet for Users who do not have 'Projects Manager' Role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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