public PresenceHour GetPresenceHourByDate(WorkHourJson workHourJson)//JObject jsonObject) { UnitOfWork uow = new UnitOfWork(); TimeSheetManager WHM = new TimeSheetManager(uow); User currUser = new UserHelper().GetCurrent(); return(WHM.GetPresenceHourByUserIdAndDate(currUser.ID, workHourJson.Date)); }
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); }