public void checkForTimesheet(string userName, DateTime tsDate) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Timesheet resulttimesheet = new Timesheet(); DateTime startDay = tsDate.StartOfWeek(DayOfWeek.Sunday); //Check if there is a timesheet for the week that corresponds to newhours.timestamp var searchTs = from m in TimesheetDB.TimesheetList where (m.worker.CompareTo(userName) == 0) where m.periodStart <= tsDate where m.periodEnd >= tsDate select m; foreach (var item in searchTs) { resulttimesheet = item; } //if there isn't a timesheet for the pay period, then create one //If there is a timesheet for the current pay period, don't do anything if (resulttimesheet.periodStart.CompareTo(startDay) != 0) { createTimesheet(userName, startDay); return; } return; } else { return; } }
// /* Retrieves Timesheet object with specified ID and changes "submitted" and * "approved" statuses to FALSE. Also sends a notification email to the employee */ public virtual ActionResult submitRejectTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = false; ts.approved = false; //save changes to the database TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); //send an email to employee to notify them string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has been rejected by a manager. " + "Please fix it and re-submit as soon as possible.<br /><br />Thanks!"; SendEmail(ts.worker, "Rejected Timesheet", body); TempData["emailSentFlag"] = true; TempData["recipient"] = ts.worker; TempData["emailError"] = TempData["emailError"]; return RedirectToAction("userManagement", new { refDate=DateTime.Now }); } else { return View("error"); } } else { return View("error"); } }
// /* Retrieves Timesheet object with specified ID and changes "submitted" and * "approved" statuses to TRUE. Also sends a notification email to the employee */ public virtual ActionResult submitApproveTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = true; ts.approved = true; TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; //save changes to the database TimesheetDB.SaveChanges(); //send an email to employee to notify of timesheet approval string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has been approved by a manager."; SendEmail(ts.worker, "Timesheet Approved", body); return RedirectToAction("userManagement", new { refDate = DateTime.Now }); } else { return View("error"); } } else { return View("error"); } }
// /* Retrieves the Work Effort object with specified ID and checks to see if any * hours are currently billed to it in timesheets that are NOT locked yet. * Returns TRUE if there are. */ public bool checkWeForBilledHours(int id) { Timesheet tmpTimesheet = new Timesheet(); //get all hours that have been billed to the work effort var searchHours = from h in HoursDB.HoursList where h.workEffortID == id select h; foreach (var hrs in searchHours) { //If the corresponding timesheet is still active, return TRUE tmpTimesheet = getTimesheet(hrs.creator, hrs.timestamp); if (tmpTimesheet.locked == false) { return true; } } return false; //if there are no hours billed to it, return false }
// /* Returns title that is shown when hovering over a timesheet day cell in * viewTimesheet view. If the timesheet is submitted or locked, then the title * will reflect that (unless user is an Admin). Otherwise, it will show * "Add/Edit Hours" */ public virtual string getTimesheetDayCellTitle(Timesheet ts) { string title = ""; Authentication auth = new Authentication(); if ( (ts.approved == true) || (ts.locked == true) ) { if (auth.isAdmin(this)) { title = "Admin: Add/Edit Hours"; } else { title = getTimesheetStatus(ts.worker, ts.periodStart); } } else { title = "Add/Edit Hours"; } return title; }
// /* Retrieves timesheet object with specified ID and changes submitted status to TRUE. * It then saves the change and redirects to viewTimesheet() */ public virtual ActionResult submitTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = true; //save changes to the database TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); //send an email to employee to confirm timesheet submittal string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has successfully been submitted."; SendEmail(ts.worker, "Timesheet Submitted", body); return RedirectToAction("viewTimesheet", new { tsDate = ts.periodStart.AddDays(2) }); } else { return View("notLoggedOn"); } } else { return View("error"); } }
public virtual ActionResult copyTimesheet() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { string userName = User.Identity.Name; Timesheet previousTimesheet = new Timesheet(); DateTime dayFromPrevPeriod = DateTime.Now; dayFromPrevPeriod = dayFromPrevPeriod.AddDays(-7); List<Hours> resultHours = new List<Hours>(); //Select the timesheet from the previous pay period if it exists var searchTs = from m in TimesheetDB.TimesheetList where (m.worker.CompareTo(userName) == 0) where m.periodStart <= dayFromPrevPeriod where m.periodEnd >= dayFromPrevPeriod select m; foreach (var item in searchTs) { previousTimesheet = item; } //Iterate through each entry from previous week and duplicate it for this week var searchHours = from m in HoursDB.HoursList where (m.creator.CompareTo(userName) == 0) where m.timestamp >= previousTimesheet.periodStart where m.timestamp <= previousTimesheet.periodEnd select m; foreach (var item in searchHours) { resultHours.Add(item); } foreach (var copiedHours in resultHours) { copiedHours.hours = 0; copiedHours.timestamp = DateTime.Now.StartOfWeek(DayOfWeek.Sunday); addHours(copiedHours); } return RedirectToAction("viewTimesheet", new { tsDate = DateTime.Now }); } else { return View("notLoggedOn"); } }
// //Retrieves and returns a specified user's timesheet for the specified date public Timesheet getTimesheet(string user, DateTime tsDate) { Timesheet resulttimesheet = new Timesheet(); var searchTs = from m in TimesheetDB.TimesheetList where (m.worker.CompareTo(user) == 0) where m.periodStart <= tsDate where m.periodEnd >= tsDate select m; foreach (var item in searchTs) { resulttimesheet = item; return resulttimesheet; } return null; }
// //Creates an empty timesheet for the specified user and specified date public void createTimesheet(string userName, DateTime startDay) { Timesheet newTimesheet = new Timesheet(); var searchTs = from t in TimesheetDB.TimesheetList where (t.worker.CompareTo(userName) == 0) where t.periodStart == startDay select t; try { //make sure the timesheet doesn't exist already if (searchTs.Count() == 0) { //Set pay period to start on Sunday 12:00am newTimesheet.periodStart = startDay; newTimesheet.periodEnd = startDay.AddDays(6.99999); newTimesheet.worker = userName; newTimesheet.approved = false; newTimesheet.locked = false; newTimesheet.submitted = false; //add timesheet and save to the database TimesheetDB.TimesheetList.Add(newTimesheet); TimesheetDB.Entry(newTimesheet).State = System.Data.EntityState.Added; TimesheetDB.SaveChanges(); } } catch{} }
// /* Retrieves the Timesheet object for the specified employee and reference date, * changes "locked", "approved", and "submitted" fields to FALSE, and saves the * changes in the database. */ public void adminUnlockTimesheet(string username, DateTime refDate) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { Timesheet tmpTs = new Timesheet(); var searchTs = from t in TimesheetDB.TimesheetList where (t.worker.CompareTo(username) == 0) where t.periodStart <= refDate where t.periodEnd >= refDate select t; foreach (var item in searchTs) { tmpTs = item; tmpTs.locked = false; tmpTs.approved = false; tmpTs.submitted = false; } //save changes in database TimesheetDB.Entry(tmpTs).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); } return; }
// /* Locks all timesheets that ended more than two days ago. If there was a holiday during * the previous pay period, lockDate will have an extra day added to it. * (note: called from /ScheduledJobs/TarsScheduledJobs every Tuesday and Wednesday at 12am) */ public void lockTimesheets() { DateTime refDate = DateTime.Now.Date; DateTime lockDate = DateTime.Now.Date; Timesheet tmpTimesheet = new Timesheet(); List<Timesheet> tsList = new List<Timesheet>(); // If there was a holiday, allow three days after periodEnd before locking if (isHolidayWeek(refDate.AddDays(-7))) { lockDate = refDate.AddDays(-1); } else { lockDate = refDate.AddDays(-2); } var searchTimesheets = from t in TimesheetDB.TimesheetList where t.locked != true where t.periodEnd < lockDate select t; foreach (var item in searchTimesheets) { tmpTimesheet = item; tmpTimesheet.locked = true; tsList.Add(tmpTimesheet); } foreach (var item in tsList) { //save changes in database TimesheetDB.Entry(item).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); } }