public TimeSheetPackage GetTimeSheetByUser(string User_CAI, DateTime myDateFrom, DateTime myDateTo) { TimeSheetPackage myPackage = GetTimeSheet(User_CAI, myDateFrom, myDateTo); myPackage.Date = myDateFrom; myPackage.User_CAI = User_CAI; return(myPackage); }
public TimeSheetPackage GetTimeSheetByUser(string User_CAI, DateTime myDate) { DateTime firstday = new DateTime(myDate.Year, myDate.Month, 1, 0, 0, 0); DateTime lastDay = firstday.AddMonths(1).Subtract(TimeSpan.FromDays(1)); lastDay = new DateTime(lastDay.Year, lastDay.Month, lastDay.Day, 23, 59, 59); TimeSheetPackage myPackage = GetTimeSheet(User_CAI, firstday, lastDay); myPackage.Date = myDate; myPackage.User_CAI = User_CAI; return(myPackage); }
private TimeSheetPackage GetTimeSheet(string User_CAI, DateTime firstDayOfThisMonth, DateTime lastDayOfThisMonth) { tbl_User myUser = userdb.GetUserByID(User_CAI); if (myUser.EmployeeNumber == "") myUser.EmployeeNumber = "temp"; TimeSheetPackage myPackage = new TimeSheetPackage(); myPackage.GrandTotal = 0; myPackage.DayTotals = new List<day>(); myPackage.DaySacoTotals = sacodb.SacoDays(myUser.EmployeeNumber, firstDayOfThisMonth, lastDayOfThisMonth); myPackage.TimeSheets = new List<timesheet>(); for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d= d.AddDays(1)) { myPackage.DayTotals.Add(new day() { Month = d.Month, Year = d.Year, Day = d.Day, HoursWorked = 0M }); } IQueryable<tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number); if (myResources.Count() > 0) { foreach (var res in myResources) { if (ProjectExists((int)res.Project_ID)) { timesheet resourceTimeSheet = new timesheet(); resourceTimeSheet.editStatus = true; if (res.tbl_Project.tbl_Status.Status == "CLSD" || res.tbl_Project.tbl_Status.Status == "W" || res.tbl_Project.tbl_Status.Status == "TC" ) resourceTimeSheet.editStatus = false; if (res.active == false) resourceTimeSheet.editStatus = false; resourceTimeSheet.Resource_ID = res.Resource_ID; resourceTimeSheet.Project_ID = (int)res.Project_ID; resourceTimeSheet.Project_Number = (int)res.tbl_Project.Project_Number; resourceTimeSheet.Project_Name = res.tbl_Project.Project_Name; resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name; resourceTimeSheet.SAP = res.tbl_Project.SAP_Number; resourceTimeSheet.WBS = res.tbl_Project.WBS; resourceTimeSheet.Status = res.tbl_Project.tbl_Status.Status; resourceTimeSheet.hide = res.Hide; resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M: res.ResourceHours.Value; decimal? test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), lastDayOfThisMonth).Sum(s => s.Hours); resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value; IQueryable<tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate( res.Resource_ID, DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", firstDayOfThisMonth)), DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", lastDayOfThisMonth))).OrderBy(t => t.Date); decimal Monthtotal = 0M; resourceTimeSheet.Days = new List<day>(); //Initialize Days to null values int count = 1; for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d.AddDays(1)) { resourceTimeSheet.Days.Add(new day() { Day = count, HoursWorked = null }); d = d.AddDays(1); count++; } if (timeList.Count() > 0) { foreach (var t in timeList) { foreach (var d in resourceTimeSheet.Days) { if (((DateTime)t.Date).Day == d.Day) { d.HoursWorked = (decimal)t.Hours; Monthtotal += (decimal)t.Hours; } } } } resourceTimeSheet.MonthTotal = Monthtotal; if (resourceTimeSheet.SAP != "Leave") myPackage.GrandTotal += Monthtotal; for (int j = 0; j < resourceTimeSheet.Days.Count; j++) { if (resourceTimeSheet.Days[j].HoursWorked.HasValue) { if (resourceTimeSheet.SAP != "Leave") myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value; } } if (resourceTimeSheet.MonthTotal > 0 || resourceTimeSheet.hide == false) myPackage.TimeSheets.Add(resourceTimeSheet); } } } return myPackage; }
private TimeSheetPackage GetTimeSheet(string User_CAI, DateTime firstDayOfThisMonth, DateTime lastDayOfThisMonth) { tbl_User myUser = userdb.GetUserByID(User_CAI); if (myUser.EmployeeNumber == "") { myUser.EmployeeNumber = "temp"; } TimeSheetPackage myPackage = new TimeSheetPackage(); myPackage.GrandTotal = 0; myPackage.DayTotals = new List <day>(); myPackage.DaySacoTotals = sacodb.SacoDays(myUser.EmployeeNumber, firstDayOfThisMonth, lastDayOfThisMonth); myPackage.TimeSheets = new List <timesheet>(); for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d = d.AddDays(1)) { myPackage.DayTotals.Add(new day() { Month = d.Month, Year = d.Year, Day = d.Day, HoursWorked = 0M }); } IQueryable <tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number); if (myResources.Count() > 0) { foreach (var res in myResources) { if (ProjectExists((int)res.Project_ID)) { timesheet resourceTimeSheet = new timesheet(); resourceTimeSheet.editStatus = true; if (res.tbl_Project.tbl_Status.Status == "CLSD" || res.tbl_Project.tbl_Status.Status == "W" || res.tbl_Project.tbl_Status.Status == "TC" ) { resourceTimeSheet.editStatus = false; } if (res.active == false) { resourceTimeSheet.editStatus = false; } resourceTimeSheet.Resource_ID = res.Resource_ID; resourceTimeSheet.Project_ID = (int)res.Project_ID; resourceTimeSheet.Project_Number = (int)res.tbl_Project.Project_Number; resourceTimeSheet.Project_Name = res.tbl_Project.Project_Name; resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name; resourceTimeSheet.SAP = res.tbl_Project.SAP_Number; resourceTimeSheet.WBS = res.tbl_Project.WBS; resourceTimeSheet.Status = res.tbl_Project.tbl_Status.Status; resourceTimeSheet.hide = res.Hide; resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M: res.ResourceHours.Value; decimal?test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), lastDayOfThisMonth).Sum(s => s.Hours); resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value; IQueryable <tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate( res.Resource_ID, DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", firstDayOfThisMonth)), DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", lastDayOfThisMonth))).OrderBy(t => t.Date); decimal Monthtotal = 0M; resourceTimeSheet.Days = new List <day>(); //Initialize Days to null values int count = 1; for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d.AddDays(1)) { resourceTimeSheet.Days.Add(new day() { Day = count, HoursWorked = null }); d = d.AddDays(1); count++; } if (timeList.Count() > 0) { foreach (var t in timeList) { foreach (var d in resourceTimeSheet.Days) { if (((DateTime)t.Date).Day == d.Day) { d.HoursWorked = (decimal)t.Hours; Monthtotal += (decimal)t.Hours; } } } } resourceTimeSheet.MonthTotal = Monthtotal; if (resourceTimeSheet.SAP != "Leave") { myPackage.GrandTotal += Monthtotal; } for (int j = 0; j < resourceTimeSheet.Days.Count; j++) { if (resourceTimeSheet.Days[j].HoursWorked.HasValue) { if (resourceTimeSheet.SAP != "Leave") { myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value; } } } if (resourceTimeSheet.MonthTotal > 0 || resourceTimeSheet.hide == false) { myPackage.TimeSheets.Add(resourceTimeSheet); } } } } return(myPackage); }