public IEnumerable <WorkHourOnProjecstJson> GetThisPeriodProjectsByUserId(GetThisMonthDataByUserJson json) { List <WorkHourOnProjecstJson> result = new List <WorkHourOnProjecstJson>(); UnitOfWork uow = new UnitOfWork(); UserManager userManager = new UserManager(uow); TimeSheetManager timeSheetManager = new TimeSheetManager(uow); DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow); User currUser = userManager.GetByID(Guid.Parse(json.userid)); DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser); DateTime fromDate = json.values[0].Date; DateTime toDate = json.values[json.values.Count() - 1].Date; var all = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate); foreach (var item in all.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList()) { var addItem = new WorkHourOnProjecstJson(); addItem.ProjectId = item.ProjectId; addItem.Title = item.Project.Title; var hour = all.Where(a => a.ProjectId == item.ProjectId).Sum(d => d.Hours); addItem.Hour = DateUtility.ConvertToTimeSpan(hour); result.Add(addItem); } return(result); }
public async Task <IActionResult> GetWaitingForApproveUsers() { try { var currentUser = new UserHelper().GetCurrent(this._uow, this.UserName); var query = this.DBContext.spGetSubUsers.FromSqlInterpolated( this.DBContext.spGetSubUsers_str(currentUser.ID)); var items = await query.ToListAsync(); var answer = items.Select(i => new { id = i.UserId, fullName = i.UserTitle + (i.Minutes.HasValue ? (" " + DateUtility.ConvertToTimeSpan(i.Minutes.Value)): "") }).ToList(); return(Ok(answer)); } catch (Exception ex) { return(this.ReturnError(ex, "خطا در دریافت لیست کاربران منتظر تایید")); } }
public AllEntityJson ToJson(IEnumerable <PresenceHour> presenceHours, IEnumerable <WorkHour> workHours) { var result = new AllEntityJson(); double whHour = (workHours != null && workHours.ToList().Count >= 0) ? workHours.Sum(x => x.Hours) : 0; double pHour = (presenceHours != null && presenceHours.ToList().Count >= 0) ? presenceHours.Sum(x => x.Hours) : 0; double diferrent = pHour - whHour; result.Presencepercent = pHour; result.Workpercent = whHour; result.Defferencepercent = diferrent; result.Presence = DateUtility.ConvertToTimeSpan(pHour); result.Work = DateUtility.ConvertToTimeSpan(whHour); result.Defference = DateUtility.ConvertToTimeSpan(diferrent); return(result); }
public IEnumerable <WorkHourOnProjecstJson> GetThisMonthProjectsByUserID(GetThisMonthDataByUserJson json) { List <WorkHourOnProjecstJson> result = new List <WorkHourOnProjecstJson>(); UnitOfWork uow = new UnitOfWork(); UserManager userManager = new UserManager(uow); TimeSheetManager timeSheetManager = new TimeSheetManager(uow); //SyncWithPWA(uow); User User = userManager.GetByID(Guid.Parse(json.userid)); var all = timeSheetManager.GetWorkHoursByUser(User.ID, json.value.Date); foreach (var item in all.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList()) { var addItem = new WorkHourOnProjecstJson(); addItem.ProjectId = item.ProjectId; addItem.Title = item.Project.Title; var hour = all.Where(a => a.ProjectId == item.ProjectId).Sum(d => d.Hours); addItem.Hour = DateUtility.ConvertToTimeSpan(hour); result.Add(addItem); } return(result); }
public static List <TimeSheetJson> ToJsonsForConfirm(IEnumerable <PresenceHour> presenceHours, IEnumerable <WorkHour> workHours, User user) { UnitOfWork uow = new UnitOfWork(); TimeSheetManager timesheetMnager = new TimeSheetManager(uow); var result = new List <TimeSheetJson>(); int timeSheetID = 1; var groupingTasks = workHours.GroupBy(x => x.TaskID).Select(y => y.FirstOrDefault()).ToList(); var groupingProjects = workHours.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList(); List <WorkHour> approveItems = new List <WorkHour>(); List <WorkHour> notApproveItems = new List <WorkHour>(); foreach (var item in workHours) { if (timesheetMnager.ApprovementStatus(item, new UserHelper().GetCurrent().UserName) == "Approve") { approveItems.Add(item); } if (timesheetMnager.ApprovementStatus(item, new UserHelper().GetCurrent().UserName) == "NotApprove") { notApproveItems.Add(item); } } var groupingTasksApprove = approveItems.GroupBy(x => x.TaskID).Select(y => y.FirstOrDefault()).ToList(); var groupingProjectsApprove = approveItems.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList(); var groupingTasksNotApprove = notApproveItems.GroupBy(x => x.TaskID).Select(y => y.FirstOrDefault()).ToList(); var groupingProjectsNotApprove = notApproveItems.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList(); TimeSheetJson tsjPresHours = new TimeSheetJson(); tsjPresHours.UID = Guid.NewGuid(); tsjPresHours.id = timeSheetID++; tsjPresHours.parentId = null; tsjPresHours.Title = "حضور"; tsjPresHours.Values = new List <TimeSheetValueJson>(); List <TimeSheetJson> tsjWorkHours = new List <TimeSheetJson>(); var PrentWorkHour = new TimeSheetJson(); PrentWorkHour.UID = Guid.NewGuid(); PrentWorkHour.id = timeSheetID++; PrentWorkHour.parentId = null; PrentWorkHour.Title = "کارکرد"; PrentWorkHour.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(PrentWorkHour); foreach (var item in groupingProjects) { var ProjectChild = new TimeSheetJson(); ProjectChild.Type = "Project"; var timesheetIdwork = timeSheetID; ProjectChild.UID = item.ProjectId; ProjectChild.id = timeSheetID++; ProjectChild.parentId = 2; ProjectChild.Title = item.Project.Title; ProjectChild.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(ProjectChild); foreach (var w in groupingTasks) { if (item.ProjectId == w.ProjectId) { var TaskChilde = new TimeSheetJson(); TaskChilde.Type = "Task"; TaskChilde.UID = w.TaskID; TaskChilde.id = timeSheetID++; TaskChilde.parentId = timesheetIdwork; TaskChilde.Title = w.Task.Title; TaskChilde.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(TaskChilde); } } } TimeSheetJson tsjDiffPH_WH = new TimeSheetJson(); tsjDiffPH_WH.UID = Guid.NewGuid(); tsjDiffPH_WH.id = timeSheetID++; tsjDiffPH_WH.parentId = null; tsjDiffPH_WH.Title = "اختلاف حضور و کارکرد"; tsjDiffPH_WH.Values = new List <TimeSheetValueJson>(); tsjDiffPH_WH.Type = "Defference"; List <TimeSheetJson> approveWHs = new List <TimeSheetJson>(); var approvechiled = new TimeSheetJson(); approvechiled.UID = Guid.NewGuid(); var timesheetIdapproveproject = timeSheetID; approvechiled.id = timeSheetID++; approvechiled.parentId = null; approvechiled.Title = "تایید شده"; approvechiled.Values = new List <TimeSheetValueJson>(); approvechiled.Type = "Approve"; approveWHs.Add(approvechiled); foreach (var projectApprove in groupingProjectsApprove) { var timesheetIdapproveaskt = timeSheetID; var counter = 0; foreach (var worktask in groupingTasksApprove) { if (timesheetMnager.ApprovementStatus(worktask, new UserHelper().GetCurrent().UserName) == "Approve" && projectApprove.ProjectId == worktask.ProjectId) { if (counter == 0) { var ProjectChildapprove = new TimeSheetJson(); ProjectChildapprove.Type = "ProjectApprove"; ProjectChildapprove.UID = projectApprove.ProjectId; ProjectChildapprove.id = timeSheetID++; ProjectChildapprove.parentId = timesheetIdapproveproject; ProjectChildapprove.Title = projectApprove.Project.Title; ProjectChildapprove.Values = new List <TimeSheetValueJson>(); approveWHs.Add(ProjectChildapprove); } counter++; var approveChildetask = new TimeSheetJson(); approveChildetask.Type = "TaskApprove"; approveChildetask.UID = worktask.TaskID; approveChildetask.id = timeSheetID++; approveChildetask.parentId = timesheetIdapproveaskt; approveChildetask.Title = worktask.Task.Title; approveChildetask.Values = new List <TimeSheetValueJson>(); approveWHs.Add(approveChildetask); } } } List <TimeSheetJson> notApproveWHs = new List <TimeSheetJson>(); var reject = new TimeSheetJson(); reject.UID = Guid.NewGuid(); var timesheetIdNotapproveproject = timeSheetID; reject.id = timeSheetID++; reject.parentId = null; reject.Title = "تایید نشده"; reject.Values = new List <TimeSheetValueJson>(); reject.Type = "Reject"; notApproveWHs.Add(reject); foreach (var item in groupingProjectsNotApprove) { var counter = 0; var timesheetIdapproveaskt = timeSheetID; foreach (var w in groupingTasksNotApprove) { if (timesheetMnager.ApprovementStatus(w, new UserHelper().GetCurrent().UserName) == "NotApprove" && item.ProjectId == w.ProjectId) { if (counter == 0) { var ProjectChildNotapprove = new TimeSheetJson(); ProjectChildNotapprove.Type = "ProjectNotApprove"; ProjectChildNotapprove.UID = item.ProjectId; ProjectChildNotapprove.id = timeSheetID++; ProjectChildNotapprove.parentId = timesheetIdNotapproveproject; ProjectChildNotapprove.Title = item.Project.Title; ProjectChildNotapprove.Values = new List <TimeSheetValueJson>(); notApproveWHs.Add(ProjectChildNotapprove); } counter++; var NotapproveChildetask = new TimeSheetJson(); NotapproveChildetask.Type = "TaskNotApprove"; NotapproveChildetask.UID = w.TaskID; NotapproveChildetask.id = timeSheetID++; NotapproveChildetask.parentId = timesheetIdapproveaskt; NotapproveChildetask.Title = w.Task.Title; NotapproveChildetask.Values = new List <TimeSheetValueJson>(); notApproveWHs.Add(NotapproveChildetask); } } } presenceHours.OrderBy(phItem => phItem.Date) .ToList().ForEach(phItem => { double phHours = phItem.Hours; List <WorkHour> selWorkHour = workHours.Where(whItem => whItem.Date.Equals(phItem.Date)).ToList(); double whHours = (selWorkHour != null && selWorkHour.Count >= 0) ? selWorkHour.Sum(x => x.Hours) : 0; List <WorkHour> appWorkHour = approveItems.Where(whItem => whItem.Date.Equals(phItem.Date)).ToList(); double apphours = (appWorkHour != null && appWorkHour.Count >= 0) ? appWorkHour.Sum(x => x.Hours) : 0; List <WorkHour> notappWorkHour = notApproveItems.Where(whItem => whItem.Date.Equals(phItem.Date)).ToList(); double notapphours = (notappWorkHour != null && notappWorkHour.Count >= 0) ? notappWorkHour.Sum(x => x.Hours) : 0; //Create Columns/Values for Presence Hours TimeSheetValueJson phTSJValue = new TimeSheetValueJson(); phTSJValue.Date = phItem.Date; phTSJValue.Day = phItem.Date.DayOfWeek.ToString(); phTSJValue.PersianDate = phItem.Date.ToPersianDateString(); phTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); phTSJValue.Title = phTSJValue.PersianDate + "-" + phTSJValue.PersianDay; phTSJValue.Value = DateUtility.ConvertToTimeSpan(phHours); tsjPresHours.Values.Add(phTSJValue); //Create Columns/Values for Work Hours TimeSheetValueJson whTSJValue = new TimeSheetValueJson(); whTSJValue.Date = phItem.Date; whTSJValue.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue.Title = whTSJValue.PersianDate + "-" + whTSJValue.PersianDay; whTSJValue.Value = DateUtility.ConvertToTimeSpan(whHours); tsjWorkHours[0].Values.Add(whTSJValue); var groupingByDate = workHours.GroupBy(x => x.Date).Select(y => y.FirstOrDefault()).ToList(); var co = tsjWorkHours.Count(); for (int i = 1; i < co; i++) { TimeSheetValueJson whTSJValue1 = new TimeSheetValueJson(); whTSJValue1.Date = phItem.Date; whTSJValue1.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue1.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue1.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue1.Title = whTSJValue1.PersianDate + "-" + whTSJValue1.PersianDay; whTSJValue1.Value = " "; tsjWorkHours[i].Values.Add(whTSJValue1); if (tsjWorkHours[i].Type == "Project") { var hourCount = selWorkHour.Where(y => y.ProjectId == tsjWorkHours[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } if (tsjWorkHours[i].Type == "Task") { var hourCount = selWorkHour.Where(y => y.TaskID == tsjWorkHours[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } } //Create Row for Different between Presence Hour And Work Hour TimeSheetValueJson diffPH_WHTSJValue = new TimeSheetValueJson(); diffPH_WHTSJValue.Date = phItem.Date; diffPH_WHTSJValue.Day = phItem.Date.DayOfWeek.ToString(); diffPH_WHTSJValue.PersianDate = phItem.Date.ToPersianDateString(); diffPH_WHTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); diffPH_WHTSJValue.Title = diffPH_WHTSJValue.PersianDate + "-" + diffPH_WHTSJValue.PersianDay; diffPH_WHTSJValue.Value = DateUtility.ConvertToTimeSpan(Math.Abs(phHours - whHours)); tsjDiffPH_WH.Values.Add(diffPH_WHTSJValue); //Create Columns/Values for Approve TimeSheetValueJson appTSJValue = new TimeSheetValueJson(); appTSJValue.Date = phItem.Date; appTSJValue.Day = phItem.Date.DayOfWeek.ToString(); appTSJValue.PersianDate = phItem.Date.ToPersianDateString(); appTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); appTSJValue.Title = appTSJValue.PersianDate + "-" + appTSJValue.PersianDay; appTSJValue.Value = DateUtility.ConvertToTimeSpan(apphours); approveWHs[0].Values.Add(appTSJValue); for (int i = 1; i < approveWHs.Count(); i++) { TimeSheetValueJson whTSJValue1 = new TimeSheetValueJson(); whTSJValue1.Date = phItem.Date; whTSJValue1.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue1.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue1.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue1.Title = whTSJValue1.PersianDate + "-" + whTSJValue1.PersianDay; whTSJValue1.Value = " "; approveWHs[i].Values.Add(whTSJValue1); if (approveWHs[i].Type == "ProjectApprove") { var hourCount = appWorkHour.Where(y => y.ProjectId == approveWHs[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } if (approveWHs[i].Type == "TaskApprove") { var hourCount = appWorkHour.Where(y => y.TaskID == approveWHs[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } } //Create Columns/Values for NotApprove TimeSheetValueJson notappTSJValue = new TimeSheetValueJson(); notappTSJValue.Date = phItem.Date; notappTSJValue.Day = phItem.Date.DayOfWeek.ToString(); notappTSJValue.PersianDate = phItem.Date.ToPersianDateString(); notappTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); notappTSJValue.Title = notappTSJValue.PersianDate + "-" + notappTSJValue.PersianDay; notappTSJValue.Value = DateUtility.ConvertToTimeSpan(notapphours); notApproveWHs[0].Values.Add(notappTSJValue); for (int i = 1; i < notApproveWHs.Count(); i++) { TimeSheetValueJson whTSJValue1 = new TimeSheetValueJson(); whTSJValue1.Date = phItem.Date; whTSJValue1.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue1.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue1.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue1.Title = whTSJValue1.PersianDate + "-" + whTSJValue1.PersianDay; whTSJValue1.Value = " "; notApproveWHs[i].Values.Add(whTSJValue1); if (notApproveWHs[i].Type == "ProjectNotApprove") { var hourCount = notappWorkHour.Where(y => y.ProjectId == notApproveWHs[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } if (notApproveWHs[i].Type == "TaskNotApprove") { var hourCount = notappWorkHour.Where(y => y.TaskID == notApproveWHs[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } } }); result.Add(tsjPresHours); foreach (var item in tsjWorkHours) { result.Add(item); } result.Add(tsjDiffPH_WH); foreach (var approve in approveWHs) { result.Add(approve); } foreach (var notapprove in notApproveWHs) { result.Add(notapprove); } return(result); }
public static List <TimeSheetJson> ToJsonsForRegister(IEnumerable <PresenceHour> presenceHours, IEnumerable <WorkHour> workHours) { var result = new List <TimeSheetJson>(); int timeSheetID = 1; TimeSheetJson tsjSendWH = new TimeSheetJson(); tsjSendWH.UID = Guid.NewGuid(); tsjSendWH.id = timeSheetID++; tsjSendWH.parentId = null; tsjSendWH.Title = "عملیات"; tsjSendWH.Values = new List <TimeSheetValueJson>(); TimeSheetJson tsjPresHours = new TimeSheetJson(); tsjPresHours.UID = Guid.NewGuid(); tsjPresHours.id = timeSheetID++; tsjPresHours.parentId = null; tsjPresHours.Title = "حضور"; tsjPresHours.Values = new List <TimeSheetValueJson>(); List <TimeSheetJson> tsjWorkHours = new List <TimeSheetJson>(); //Create WorkHour Row - ایجاد ردیف کارکرد در برگه زمانی var PrentWorkHour = new TimeSheetJson(); PrentWorkHour.UID = Guid.NewGuid(); PrentWorkHour.id = timeSheetID++; PrentWorkHour.parentId = null; PrentWorkHour.Title = "کارکرد"; PrentWorkHour.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(PrentWorkHour); var groupingTasks = workHours.GroupBy(x => x.TaskID).Select(y => y.FirstOrDefault()).ToList(); var groupingProjects = workHours.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList(); foreach (var item in groupingProjects) { var ProjectChild = new TimeSheetJson(); ProjectChild.Type = "Project"; ProjectChild.UID = item.ProjectId; var timesheettest = timeSheetID; ProjectChild.id = timeSheetID++; ProjectChild.parentId = 3; ProjectChild.Title = item.Project.Title; ProjectChild.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(ProjectChild); foreach (var w in groupingTasks) { if (item.ProjectId == w.ProjectId) { var TaskChilde = new TimeSheetJson(); TaskChilde.Type = "Task"; TaskChilde.UID = w.TaskID; TaskChilde.id = timeSheetID++; TaskChilde.parentId = timesheettest; TaskChilde.Title = w.Task.Title; TaskChilde.Values = new List <TimeSheetValueJson>(); tsjWorkHours.Add(TaskChilde); } } } //Create Row for Different between Presence Hour And Work Hour - ایجاد ردیف اختلاف حضور و کارکرد در برگه زمانی TimeSheetJson tsjDiffPH_WH = new TimeSheetJson(); tsjDiffPH_WH.UID = Guid.NewGuid(); tsjDiffPH_WH.id = timeSheetID++; tsjDiffPH_WH.parentId = null; tsjDiffPH_WH.Title = "اختلاف حضور و کارکرد"; tsjDiffPH_WH.Values = new List <TimeSheetValueJson>(); tsjDiffPH_WH.Type = "Defference"; presenceHours.OrderBy(phItem => phItem.Date) .ToList().ForEach(phItem => { double phHours = phItem.Hours; List <WorkHour> selWorkHour = workHours.Where(whItem => whItem.Date.Equals(phItem.Date)).ToList(); double whHours = (selWorkHour != null && selWorkHour.Count >= 0) ? selWorkHour.Sum(x => x.Hours) : 0; //Create Columns/Values for Presence Hours TimeSheetValueJson phTSJValue = new TimeSheetValueJson(); phTSJValue.Date = phItem.Date; phTSJValue.Day = phItem.Date.DayOfWeek.ToString(); phTSJValue.PersianDate = phItem.Date.ToPersianDateString(); phTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); phTSJValue.Title = phTSJValue.PersianDate + "-" + phTSJValue.PersianDay; phTSJValue.Value = DateUtility.ConvertToTimeSpan(phHours); tsjPresHours.Values.Add(phTSJValue); //Create Columns/Values for Work Hours in first TimeSheetValueJson whTSJValue = new TimeSheetValueJson(); whTSJValue.Date = phItem.Date; whTSJValue.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue.Title = whTSJValue.PersianDate + "-" + whTSJValue.PersianDay; whTSJValue.Value = DateUtility.ConvertToTimeSpan(whHours); tsjWorkHours[0].Values.Add(whTSJValue); for (int i = 1; i < tsjWorkHours.Count(); i++) { TimeSheetValueJson whTSJValue1 = new TimeSheetValueJson(); whTSJValue1.Date = phItem.Date; whTSJValue1.Day = phItem.Date.DayOfWeek.ToString(); whTSJValue1.PersianDate = phItem.Date.ToPersianDateString(); whTSJValue1.PersianDay = phItem.Date.ToPersianDayOfWeek(); whTSJValue1.Title = whTSJValue1.PersianDate + "-" + whTSJValue1.PersianDay; whTSJValue1.Value = " "; tsjWorkHours[i].Values.Add(whTSJValue1); if (tsjWorkHours[i].Type == "Project") { var hourCount = selWorkHour.Where(y => y.ProjectId == tsjWorkHours[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } if (tsjWorkHours[i].Type == "Task") { var hourCount = selWorkHour.Where(y => y.TaskID == tsjWorkHours[i].UID).Sum(x => x.Hours); whTSJValue1.Value = DateUtility.ConvertToTimeSpan(hourCount); } } //var groupingByDate = workHours.GroupBy(x => x.Date).Select(y => y.FirstOrDefault()).ToList(); //Create Row for Different between Presence Hour And Work Hour TimeSheetValueJson diffPH_WHTSJValue = new TimeSheetValueJson(); diffPH_WHTSJValue.Date = phItem.Date; diffPH_WHTSJValue.Day = phItem.Date.DayOfWeek.ToString(); diffPH_WHTSJValue.PersianDate = phItem.Date.ToPersianDateString(); diffPH_WHTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); diffPH_WHTSJValue.Title = diffPH_WHTSJValue.PersianDate + "-" + diffPH_WHTSJValue.PersianDay; diffPH_WHTSJValue.Value = DateUtility.ConvertToTimeSpan(Math.Abs(phHours - whHours)); tsjDiffPH_WH.Values.Add(diffPH_WHTSJValue); //Create Row for Sent Work Hour TimeSheetValueJson sendWHTSJValue = new TimeSheetValueJson(); sendWHTSJValue.Date = phItem.Date; sendWHTSJValue.Day = phItem.Date.DayOfWeek.ToString(); sendWHTSJValue.PersianDate = phItem.Date.ToPersianDateString(); sendWHTSJValue.PersianDay = phItem.Date.ToPersianDayOfWeek(); sendWHTSJValue.Title = diffPH_WHTSJValue.PersianDate + "-" + diffPH_WHTSJValue.PersianDay; if (phItem.Date >= DateTime.Now.Date) { sendWHTSJValue.Value = "False False"; } if (phItem.Hours > 0 && phItem.Date <= DateTime.Now.Date) { sendWHTSJValue.Value = "True True"; } if (phItem.Hours <= 0 && phItem.Date <= DateTime.Now.Date) { sendWHTSJValue.Value = "True False"; } tsjSendWH.Values.Add(sendWHTSJValue); }); result.Add(tsjSendWH); result.Add(tsjPresHours); foreach (var item in tsjWorkHours) { result.Add(item); } result.Add(tsjDiffPH_WH); return(result); }
public FinalReport AssembleDailyOnProjects(ReportParametersFromToJson parametres) { var result = new FinalReport(); UnitOfWork uow = new UnitOfWork(); var currentUser = new UserHelper().GetCurrent(); TimeSheetManager TimeSheetManager = new TimeSheetManager(uow); var from = DateUtility.GetMiladiDate(parametres.FromDate); var to = DateUtility.GetMiladiDate(parametres.ToDate); var currentDate = from; var workHours = TimeSheetManager.GetWorkHoursByUser(currentUser, from, to); //سطر ها while (currentDate.Date <= to) { var row = new ReportRow(); row.ID = Guid.NewGuid(); row.Title = DateUtility.GetPersianDate(currentDate); result.Rowes.Add(row); currentDate = currentDate.AddDays(1).Date; } var SumTotal = new ReportRow(); SumTotal.ID = Guid.NewGuid(); SumTotal.Title = "جمع کل"; result.Rowes.Add(SumTotal); //ستون ها foreach (var wh in workHours.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList()) { var field = new Field(); field.ID = wh.ProjectId; field.Title = wh.Project.Title; result.Fields.Add(field); foreach (var row in result.Rowes) { if (row.Title == "جمع کل") { var sumWorkHour = workHours.Where(x => x.ProjectId == wh.ProjectId).Sum(x => x.Hours); var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.CalculativeValue = sumWorkHour; fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } else { var sumWorkHour = workHours.Where(x => x.Date == DateUtility.GetMiladiDate(row.Title) && x.ProjectId == wh.ProjectId).Sum(x => x.Hours); var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.CalculativeValue = sumWorkHour; fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } } } var Aggregation = new Field(); Aggregation.Title = "جمع کارکرد"; Aggregation.ID = Guid.NewGuid(); result.Fields.Add(Aggregation); var PresenceTotal = new Field(); PresenceTotal.Title = "جمع حضور"; PresenceTotal.ID = Guid.NewGuid(); result.Fields.Add(PresenceTotal); var DifferenceTotal = new Field(); DifferenceTotal.Title = "جمع اختلاف"; DifferenceTotal.ID = Guid.NewGuid(); result.Fields.Add(DifferenceTotal); foreach (var row in result.Rowes) { if (row.Title == "جمع کل") { var sumworkHourTotal = workHours.Sum(X => X.Hours); var fildvalueWork = new FieldValue(); fildvalueWork.FieldId = Guid.NewGuid(); fildvalueWork.RowId = row.ID; fildvalueWork.Value = DateUtility.ConvertToTimeSpan(sumworkHourTotal); row.Values.Add(fildvalueWork); double sumPresenceHourTotal = 0; sumPresenceHourTotal = TimeSheetManager.GetPresHoursByUser(currentUser, from, to).Sum(x => x.Hours); var fildvaluePresenceTotal = new FieldValue(); fildvaluePresenceTotal.FieldId = Guid.NewGuid(); fildvaluePresenceTotal.RowId = row.ID; fildvaluePresenceTotal.Value = DateUtility.ConvertToTimeSpan(sumPresenceHourTotal); row.Values.Add(fildvaluePresenceTotal); var fildvalueDifferencTotal = new FieldValue(); fildvalueDifferencTotal.FieldId = Guid.NewGuid(); fildvalueDifferencTotal.RowId = row.ID; fildvalueDifferencTotal.Value = DateUtility.ConvertToTimeSpan(sumPresenceHourTotal - sumworkHourTotal); row.Values.Add(fildvalueDifferencTotal); } else { var sumworkHour = row.Values.Sum(y => y.CalculativeValue); var fildvalueWork = new FieldValue(); fildvalueWork.FieldId = Guid.NewGuid(); fildvalueWork.RowId = row.ID; fildvalueWork.Value = DateUtility.ConvertToTimeSpan(sumworkHour); row.Values.Add(fildvalueWork); double sumPresenceHour = 0; sumPresenceHour = TimeSheetManager.GetPresenceHourByUserIdAndDate(currentUser.ID, DateUtility.GetMiladiDate(row.Title)) != null ? TimeSheetManager.GetPresenceHourByUserIdAndDate(currentUser.ID, DateUtility.GetMiladiDate(row.Title)).Hours : 0; var fildvaluePresence = new FieldValue(); fildvaluePresence.FieldId = Guid.NewGuid(); fildvaluePresence.RowId = row.ID; fildvaluePresence.Value = DateUtility.ConvertToTimeSpan(sumPresenceHour); row.Values.Add(fildvaluePresence); var fildvalueDifferenc = new FieldValue(); fildvalueDifferenc.FieldId = Guid.NewGuid(); fildvalueDifferenc.RowId = row.ID; fildvalueDifferenc.Value = DateUtility.ConvertToTimeSpan(sumPresenceHour - sumworkHour); row.Values.Add(fildvalueDifferenc); } } result.HeaderTitle = "گزارش روزانه پروژه ها"; result.FirstColumnTitle = "تاریخ"; return(result); }
public FinalReport AssembleTotalWorkHoursOnProjects(ReportParametersFromToJson parametres) { var result = new FinalReport(); UnitOfWork uow = new UnitOfWork(); var currentUser = new UserHelper().GetCurrent(); TimeSheetManager TimeSheetManager = new TimeSheetManager(uow); var workHours = TimeSheetManager.GetWorkHoursByUser (currentUser, DateUtility.GetMiladiDate(parametres.FromDate), DateUtility.GetMiladiDate(parametres.ToDate)).ToList(); var from = DateUtility.GetMiladiDate(parametres.FromDate); var to = DateUtility.GetMiladiDate(parametres.ToDate); var currentDate = from; foreach (var group in workHours.GroupBy(x => x.ProjectId)) { var row = new ReportRow(); row.ID = group.First().ProjectId; row.Title = group.First().Project.Title; result.Rowes.Add(row); } var SumTotal = new ReportRow(); SumTotal.ID = Guid.NewGuid(); SumTotal.Title = "جمع کل"; result.Rowes.Add(SumTotal); var field = new Field(); field.ID = Guid.NewGuid(); field.Title = "کارکرد ثبت شده"; result.Fields.Add(field); double workhours = 0; foreach (var row in result.Rowes) { if (row.Title == "جمع کل") { var sumWorkHour = workHours.Sum(x => x.Hours); workhours = sumWorkHour; var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } else { var value = workHours.Where(x => x.ProjectId == row.ID).Sum(x => x.Hours); var fieldValue = new FieldValue(); fieldValue.FieldId = field.ID; fieldValue.RowId = row.ID; fieldValue.Value = DateUtility.ConvertToTimeSpan(value); row.Values.Add(fieldValue); } } result.HeaderTitle = "گزارش کلی پروژه ها"; result.FirstColumnTitle = "عنوان پروژه"; return(result); }
public FinalReport AssemblePersonnelsAndProjects(ReportParametersJson parametres) { var result = new FinalReport(); UnitOfWork uow = new UnitOfWork(); var currentUser = new UserHelper().GetCurrent(); TimeSheetManager TimeSheetManager = new TimeSheetManager(uow); UserManager userManager = new UserManager(uow); DateTime from = DateUtility.GetMiladiDate(parametres.FromDate); DateTime to = DateUtility.GetMiladiDate(parametres.ToDate); var workHours = TimeSheetManager.GetByUserIdsAndProjectIds(parametres.UserIds, parametres.ProjetIds, from, to); //سطر ها foreach (var group in workHours.GroupBy(x => x.EmployeeID)) { var row = new ReportRow(); row.ID = group.First().EmployeeID; row.Title = group.First().Employee.UserTitle; result.Rowes.Add(row); } var SumTotal = new ReportRow(); SumTotal.ID = Guid.NewGuid(); SumTotal.Title = "جمع کل"; result.Rowes.Add(SumTotal); //ستون ها foreach (var wh in workHours.GroupBy(x => x.ProjectId).Select(y => y.FirstOrDefault()).ToList()) { var field = new Field(); field.ID = wh.ProjectId; field.Title = wh.Project.Title; result.Fields.Add(field); foreach (var row in result.Rowes) { if (row.Title == "جمع کل") { var sumWorkHour = workHours.Where(x => x.ProjectId == wh.ProjectId).Sum(x => x.Hours); var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.CalculativeValue = sumWorkHour; fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } else { var sumWorkHour = workHours.Where(x => x.EmployeeID == row.ID && x.ProjectId == wh.ProjectId).Sum(x => x.Hours); var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.CalculativeValue = sumWorkHour; fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } } } var Aggregation = new Field(); Aggregation.Title = "جمع کل"; Aggregation.ID = Guid.NewGuid(); result.Fields.Add(Aggregation); var PresenceTotal = new Field(); PresenceTotal.Title = "جمع حضور"; PresenceTotal.ID = Guid.NewGuid(); result.Fields.Add(PresenceTotal); var DifferenceTotal = new Field(); DifferenceTotal.Title = "جمع اختلاف"; DifferenceTotal.ID = Guid.NewGuid(); result.Fields.Add(DifferenceTotal); foreach (var row in result.Rowes) { //توسعه var sumworkHour = row.Values.Sum(y => y.CalculativeValue); var fildvalueWork = new FieldValue(); fildvalueWork.FieldId = Guid.NewGuid(); fildvalueWork.RowId = row.ID; fildvalueWork.Value = DateUtility.ConvertToTimeSpan(sumworkHour); row.Values.Add(fildvalueWork); if (userManager.GetByID(row.ID) != null) { var user = userManager.GetByID(row.ID); var sumPresenceHour = TimeSheetManager.GetPresHoursByUser(user, from, to).ToList().Sum(x => x.Hours); var fildvaluePresence = new FieldValue(); fildvaluePresence.FieldId = Guid.NewGuid(); fildvaluePresence.RowId = row.ID; fildvaluePresence.Value = DateUtility.ConvertToTimeSpan(sumPresenceHour); row.Values.Add(fildvaluePresence); var fildvalueDifference = new FieldValue(); fildvalueDifference.FieldId = Guid.NewGuid(); fildvalueDifference.RowId = row.ID; fildvalueDifference.Value = DateUtility.ConvertToTimeSpan(sumPresenceHour - sumworkHour); row.Values.Add(fildvalueDifference); } else { double sumPresenceHourTotal = 0; foreach (var userIds in parametres.UserIds) { var user = userManager.GetByID(userIds); sumPresenceHourTotal += TimeSheetManager.GetPresHoursByUser(user, from, to).ToList().Sum(x => x.Hours); } var fildvaluePresenceTotal = new FieldValue(); fildvaluePresenceTotal.FieldId = Guid.NewGuid(); fildvaluePresenceTotal.RowId = row.ID; fildvaluePresenceTotal.Value = DateUtility.ConvertToTimeSpan(sumPresenceHourTotal); row.Values.Add(fildvaluePresenceTotal); var fildvalueDifferencTotale = new FieldValue(); fildvalueDifferencTotale.FieldId = Guid.NewGuid(); fildvalueDifferencTotale.RowId = row.ID; fildvalueDifferencTotale.Value = DateUtility.ConvertToTimeSpan(sumPresenceHourTotal - sumworkHour); row.Values.Add(fildvalueDifferencTotale); } } result.HeaderTitle = "گزارش پروژه ها به تفکیک ماه"; result.FirstColumnTitle = "نام شخص"; return(result); }
//Assemble single project public FinalReport AssembleBreakingProjectByMonth(ReportParametrsFromToProjectIdJson parametres) { var result = new FinalReport(); UnitOfWork uow = new UnitOfWork(); var currentUser = new UserHelper().GetCurrent(); TimeSheetManager TimeSheetManager = new TimeSheetManager(uow); var from = DateUtility.GetMiladiDate(parametres.FromDate); var to = DateUtility.GetMiladiDate(parametres.ToDate); var currentDate = from; var workHours = TimeSheetManager.GetByProjectID (parametres.ProjectId, from, to).ToList(); if (workHours.Count() > 0) { foreach (var group in workHours.GroupBy(x => x.TaskID)) { var row = new ReportRow(); row.ID = group.First().TaskID; row.Title = group.First().Task.Title; result.Rowes.Add(row); } } var SumTotal = new ReportRow(); SumTotal.ID = Guid.NewGuid(); SumTotal.Title = "جمع کل"; result.Rowes.Add(SumTotal); while (currentDate.Date <= to) { var firstDayOfMonth = DateUtility.GetMiladiDate(DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate) + "/" + "1"); var day = "30"; if (DateUtility.GetPersianMonth(currentDate) < 7) { day = "31"; } var LastDayOfMonth = DateUtility.GetMiladiDate(DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate) + "/" + day); var field = new Field(); field.ID = Guid.NewGuid(); field.Title = DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate); result.Fields.Add(field); double workhours = 0; foreach (var row in result.Rowes) { if (row.Title == "جمع کل") { var sumWorkHour = workHours.Where(x => x.Date.Date <= LastDayOfMonth && x.Date.Date >= firstDayOfMonth).Sum(x => x.Hours); workhours = sumWorkHour; var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } else { var value = workHours.Where(x => x.TaskID == row.ID && x.Date.Date <= LastDayOfMonth && x.Date.Date >= firstDayOfMonth).Sum(x => x.Hours); var fieldValue = new FieldValue(); fieldValue.FieldId = field.ID; fieldValue.RowId = row.ID; fieldValue.Value = DateUtility.ConvertToTimeSpan(value); row.Values.Add(fieldValue); } } currentDate = LastDayOfMonth.AddDays(1).Date; } var Aggregation = new Field(); Aggregation.Title = "جمع کل"; Aggregation.ID = Guid.NewGuid(); result.Fields.Add(Aggregation); double Alltotalsum = 0; foreach (var row in result.Rowes) { var sum = workHours.Where(x => x.TaskID == row.ID).Sum(y => y.Hours); var fieldvalue = new FieldValue(); fieldvalue.CalculativeValue = sum; fieldvalue.FieldId = Guid.NewGuid(); fieldvalue.RowId = row.ID; fieldvalue.Value = DateUtility.ConvertToTimeSpan(sum); row.Values.Add(fieldvalue); Alltotalsum += sum; } result.Rowes[result.Rowes.Count() - 1].Values[result.Rowes[result.Rowes.Count() - 1]. Values.Count() - 1].Value = DateUtility.ConvertToTimeSpan(Alltotalsum); result.HeaderTitle = "گزارش یک پروژه به تفکیک ماه"; result.FirstColumnTitle = "عنوان وظیفه"; return(result); }
//Assemble Bounch of projects public FinalReport AssembleBreakingProjectsByMonth(ReportParametersFromToJson parametres) { var result = new FinalReport(); UnitOfWork uow = new UnitOfWork(); var currentUser = new UserHelper().GetCurrent(); TimeSheetManager TimeSheetManager = new TimeSheetManager(uow); var workHours = TimeSheetManager.GetWorkHoursByUser (currentUser, DateUtility.GetMiladiDate(parametres.FromDate), DateUtility.GetMiladiDate(parametres.ToDate)).ToList(); var from = DateUtility.GetMiladiDate(parametres.FromDate); var to = DateUtility.GetMiladiDate(parametres.ToDate); var currentDate = from; foreach (var group in workHours.GroupBy(x => x.ProjectId)) { var row = new ReportRow(); row.ID = group.First().ProjectId; row.Title = group.First().Project.Title; result.Rowes.Add(row); } var SumTotal = new ReportRow(); SumTotal.ID = Guid.NewGuid(); SumTotal.Title = "جمع کل کارکرد"; result.Rowes.Add(SumTotal); var sumPresenceHours = new ReportRow(); sumPresenceHours.ID = Guid.NewGuid(); sumPresenceHours.Title = "جمع کل حضور"; result.Rowes.Add(sumPresenceHours); var sumDifference = new ReportRow(); sumDifference.ID = Guid.NewGuid(); sumDifference.Title = "اختلاف"; result.Rowes.Add(sumDifference); while (currentDate.Date <= to) { var firstDayOfMonth = DateUtility.GetMiladiDate(DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate) + "/" + "1"); var day = "30"; if (DateUtility.GetPersianMonth(currentDate) < 7) { day = "31"; } var LastDayOfMonth = DateUtility.GetMiladiDate(DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate) + "/" + day); var field = new Field(); field.ID = Guid.NewGuid(); field.Title = DateUtility.GetPersianYear(currentDate) + "/" + DateUtility.GetPersianMonth(currentDate); result.Fields.Add(field); double workhours = 0; double presencehours = 0; foreach (var row in result.Rowes) { if (row.Title == "جمع کل کارکرد") { var sumWorkHour = workHours.Where(x => x.Date.Date <= LastDayOfMonth && x.Date.Date >= firstDayOfMonth).Sum(x => x.Hours); workhours = sumWorkHour; var fieldValuesumWorkHour = new FieldValue(); fieldValuesumWorkHour.FieldId = field.ID; fieldValuesumWorkHour.RowId = row.ID; fieldValuesumWorkHour.Value = DateUtility.ConvertToTimeSpan(sumWorkHour); row.Values.Add(fieldValuesumWorkHour); } else if (row.Title == "جمع کل حضور") { var sumPresenceHour = TimeSheetManager.GetPresHoursByUser(currentUser, firstDayOfMonth, LastDayOfMonth).Sum(x => x.Hours); presencehours = sumPresenceHour; var fieldValuesumPresenceHour = new FieldValue(); fieldValuesumPresenceHour.FieldId = field.ID; fieldValuesumPresenceHour.RowId = row.ID; fieldValuesumPresenceHour.Value = DateUtility.ConvertToTimeSpan(sumPresenceHour); row.Values.Add(fieldValuesumPresenceHour); } else if (row.Title == "اختلاف") { var sumdifference = presencehours - workhours;; var fieldValuesumdifference = new FieldValue(); fieldValuesumdifference.FieldId = field.ID; fieldValuesumdifference.RowId = row.ID; fieldValuesumdifference.Value = DateUtility.ConvertToTimeSpan(sumdifference); row.Values.Add(fieldValuesumdifference); } else { var value = workHours.Where(x => x.ProjectId == row.ID && x.Date.Date <= LastDayOfMonth && x.Date.Date >= firstDayOfMonth).Sum(x => x.Hours); var fieldValue = new FieldValue(); fieldValue.FieldId = field.ID; fieldValue.RowId = row.ID; fieldValue.Value = DateUtility.ConvertToTimeSpan(value); row.Values.Add(fieldValue); } } currentDate = LastDayOfMonth.AddDays(1).Date; } var Aggregation = new Field(); Aggregation.Title = "مجموع"; Aggregation.ID = Guid.NewGuid(); result.Fields.Add(Aggregation); foreach (var row in result.Rowes) { var sum = workHours.Where(x => x.ProjectId == row.ID).Sum(y => y.Hours); var fildvalue = new FieldValue(); fildvalue.FieldId = Guid.NewGuid(); fildvalue.RowId = row.ID; fildvalue.Value = DateUtility.ConvertToTimeSpan(sum); row.Values.Add(fildvalue); } result.HeaderTitle = "گزارش پروژه ها به تفکیک ماه"; result.FirstColumnTitle = "عنوان پروژه"; return(result); }