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);
        }
Exemple #2
0
        public IActionResult GetDefualtConfigData()
        {
            try
            {
                var conf = this.DBContext.TimeSheetConfig.FirstOrDefault();
                if (conf == null)
                {
                    conf = new TimeSheetConfig()
                    {
                        DefualtOpenTimeSheetWeeks = 1,
                        TimeSheetLockDate         = DateTime.Today
                    };
                    this.DBContext.TimeSheetConfig.Add(conf);
                }

                return(Ok(new vmTimeSheetConfig()
                {
                    defualtOpenTimeSheetWeeks = conf.DefualtOpenTimeSheetWeeks,
                    timeSheetLockDate = DateUtility.GetPersianDate(conf.TimeSheetLockDate)
                }));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات پیش فرض سیستم"));
            }
        }
Exemple #3
0
        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 static HoliDayJson ToJson(Holiday holiday)
        {
            var json = new HoliDayJson();

            json.CalendarID = holiday.CalendarID;
            json.ID         = holiday.ID;
            json.Date       = DateUtility.GetPersianDate(holiday.Date);
            return(json);
        }
Exemple #5
0
        public static DisplayPeriod ConvertPeriodNumberDateJsonToDisplayPeriod(PeriodNumberDateJson json, IUnitOfWork uow, User currUser)
        {
            DisplayPeriodManager dpm         = new DisplayPeriodManager(uow);
            UserManager          userManager = new UserManager(uow);
            DisplayPeriod        result      = new DisplayPeriod();

            result           = dpm.GetDisplayPeriod(currUser);
            result.IsWeekly  = json.IsWeekly;
            result.NumOfDays = json.Days;
            result.StartDate = DateUtility.GetMiladiDate(json.Date);
            return(result);
        }
Exemple #6
0
        public WorkHourHistoryJson ToJson(WorkHourHistory entity)
        {
            WorkHourHistoryJson json = new WorkHourHistoryJson();

            json.Action = entity.Action;
            json.Description = entity.Description;
            json.ID = entity.ID;
            json.ManagerName = entity.Manager.UserTitle;
            json.PersianDate = DateUtility.GetPersianDate(entity.Date);
            json.Time = DateUtility.ConvertDateTimeToTime(entity.Date);
            json.StageTitle = entity.Stage.Title;

            return json;
        }
Exemple #7
0
        public HourlyMissionJson ToJson(HourlyMission hourlyMission)
        {
            HourlyMissionJson result = new HourlyMissionJson();

            result.ID              = hourlyMission.ID;
            result.RegisterDate    = DateUtility.GetPersianDate(hourlyMission.RegisterDate);
            result.MissionDate     = DateUtility.GetPersianDate(hourlyMission.Date);
            result.From            = DateUtility.ConvertDateTimeToTime(hourlyMission.From);
            result.TO              = DateUtility.ConvertDateTimeToTime(hourlyMission.To);
            result.Organisation    = hourlyMission.OrganisationId != null ? hourlyMission.Organisation.Title : "فاقد واحد سازمانی";
            result.PersonnelNumber = hourlyMission.User.Code != null ? hourlyMission.User.Code : "فاقد کد پرسنلی";
            result.ProjectTitle    = hourlyMission.Project != null ? hourlyMission.Project.Title : "فاقد پروژه";
            result.UserTitle       = hourlyMission.User.UserTitle;
            return(result);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        public WorkHourJson ToJson(WorkHour entity)
        {
            var result = new WorkHourJson();

            result.ID                 = entity.ID;
            result.Action             = entity.Action;
            result.PersianDate        = DateUtility.GetPersianDate(entity.Date);
            result.Description        = entity.Description;
            result.UserName           = entity.Employee.UserName;
            result.Hours              = entity.Hours;
            result.ProjectTitle       = entity.Project.Title;
            result.TaskTitle          = entity.Task.Title;
            result.WorkFlowStageTitle = entity.WorkflowStage.Title;
            return(result);
        }
        public static Holiday ToHoliday(HoliDayJson json, Guid id)
        {
            var holiday = new Holiday();

            holiday.CalendarID = id;
            if (json.ID == Guid.Empty)
            {
                holiday.ID = Guid.NewGuid();
            }
            else
            {
                holiday.ID = json.ID;
            }
            holiday.Date = DateUtility.GetMiladiDate(json.Date);
            return(holiday);
        }
Exemple #11
0
        public IActionResult GetDefaultPoliciesList(string ver)
        {
            try
            {
                if (!this.MainChecks(ver, out string error))
                {
                    throw new Exception(error);
                }

                var now    = DateTime.Now.Date;
                var answer = this.DBContext.TimesheetPolicies
                             .Where(p => p.IsDefault && p.Validity.Date >= now && p.UserId.HasValue)
                             .OrderBy(p => p.User.UserTitle)
                             .Select(p => new
                {
                    p.Id,
                    p.isDeactivated,
                    p.IsOpen,
                    p.Start,
                    p.Finish,
                    p.User.UserTitle,
                    p.UserId,
                    p.Validity,
                    p.UserMustHasHozoor,
                    p.CreateDate
                }).ToList().Select(p => new vmTimesheetPolicy
                {
                    id                = p.Id,
                    finish            = DateUtility.GetPersianDate(p.Finish),
                    isDeactivated     = p.isDeactivated,
                    createDate        = DateUtility.GetPersianDate(p.CreateDate),
                    isOpen            = p.IsOpen,
                    start             = DateUtility.GetPersianDate(p.Start),
                    userId            = p.UserId,
                    userTitle         = p.UserTitle,
                    userMustHasHozoor = p.UserMustHasHozoor,
                    validity          = DateUtility.GetPersianDate(p.Validity)
                });


                return(Ok(answer));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات قانون های اصلی سیستم"));
            }
        }
        public DailyLeaveJson ToJson(DailyLeave dailyLeave)
        {
            DailyLeaveJson result = new DailyLeaveJson();

            result.ID              = dailyLeave.ID;
            result.RejisterDate    = DateUtility.GetPersianDate(dailyLeave.RegisterDate);
            result.From            = DateUtility.GetPersianDate(dailyLeave.From);
            result.TO              = DateUtility.GetPersianDate(dailyLeave.To);
            result.Organisation    = dailyLeave.OrganisationId != null? dailyLeave.Organisation.Title : "فاقد واحد سازمانی";
            result.PersonnelNumber = dailyLeave.User.Code != null ?  dailyLeave.User.Code : "فاقد کد پرسنلی";
            result.ProjectTitle    = dailyLeave.Project != null? dailyLeave.Project.Title:"فاقد پروژه";
            result.Type            = Enum.IsDefined(dailyLeave.Type) ? dailyLeave.Type.GetDisplayName() :"فاقد نوع";
            result.Successor       = dailyLeave.Successor != null?dailyLeave.Successor.UserTitle.ToString() : "فاقد جانشین";

            result.UserTitle = dailyLeave.User.UserTitle;
            return(result);
        }
Exemple #13
0
        public IActionResult SaveDefualtConfigData(vmTimeSheetConfig request)
        {
            try
            {
                if (request == null)
                {
                    throw new Exception("اطلاعات ارسال نشده است");
                }
                if (!request.defualtOpenTimeSheetWeeks.HasValue)
                {
                    throw new Exception("تعداد هفته پیش فرض نمی تواند خالی باشد");
                }
                if (string.IsNullOrEmpty(request.timeSheetLockDate))
                {
                    throw new Exception("تاریخ پیش فرض نمی تواند خالی باشد");
                }

                var conf = this.DBContext.TimeSheetConfig.FirstOrDefault();
                if (conf == null)
                {
                    conf = new TimeSheetConfig()
                    {
                        DefualtOpenTimeSheetWeeks = 1,
                        TimeSheetLockDate         = DateTime.Today
                    };
                    this.DBContext.TimeSheetConfig.Add(conf);
                }

                if (conf.DefualtOpenTimeSheetWeeks != request.defualtOpenTimeSheetWeeks)
                {
                    changeDefualtOpenTimeSheetWeeks(request.defualtOpenTimeSheetWeeks.Value);
                }

                conf.DefualtOpenTimeSheetWeeks = request.defualtOpenTimeSheetWeeks.Value;
                conf.TimeSheetLockDate         = DateUtility.GetMiladiDate((request.timeSheetLockDate));
                this.DBContext.SaveChanges();

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در ثبت اطلاعات پیش فرض سیستم"));
            }
        }
        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);
        }
Exemple #15
0
        private void createPolicyForUser(Guid currentUserId)
        {
            //default policy must check maybe is deactivated
            //if isnot created, must create and today is open beacuase friday is checked in query
            //اگر زمانش گذشته باید تمدید بشه که با تاریخ های امروز یکسان بشه
            var userDefaultPolicy = this.DBContext.TimesheetPolicies.FirstOrDefault(p => p.IsDefault && p.UserId == currentUserId);
            var timeSheetConfig   = this.DBContext.TimeSheetConfig.FirstOrDefault();

            if (timeSheetConfig == null)
            {
                timeSheetConfig = new TimeSheetConfig()
                {
                    DefualtOpenTimeSheetWeeks = 1,
                    TimeSheetLockDate         = DateTime.Today
                };
                this.DBContext.TimeSheetConfig.Add(timeSheetConfig);
            }

            if (userDefaultPolicy == null)
            {
                userDefaultPolicy = new TimesheetPolicy()
                {
                    Id                = Guid.NewGuid(),
                    IsDefault         = true,
                    isDeactivated     = false,
                    IsOpen            = true,
                    UserMustHasHozoor = true,
                    UserId            = currentUserId,
                };
                this.DBContext.TimesheetPolicies.Add(userDefaultPolicy);
            }

            userDefaultPolicy.Start      = DateUtility.GetWeekStartDate(timeSheetConfig.DefualtOpenTimeSheetWeeks);
            userDefaultPolicy.Finish     = DateUtility.GetWeekEndtDate();
            userDefaultPolicy.Validity   = DateUtility.GetWeekEndtDate();
            userDefaultPolicy.CreateDate = DateTime.Now;


            this.DBContext.SaveChanges();
        }
        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);
        }
        //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);
        }
Exemple #22
0
        public async Task <IActionResult> GetTimeSheet(string ver, Guid?userId, DateTime?fromDate, DateTime?toDate)
        {
            var isWantingApprove = userId.HasValue;

            try
            {
                if (!this.MainChecks(ver, out string error))
                {
                    throw new Exception(error);
                }

                DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(this._uow);
                User currentUser = new UserHelper().GetCurrent(this._uow, this.UserName);

                if (!fromDate.HasValue)
                {
                    DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currentUser);


                    if (!fromDate.HasValue)
                    {
                        fromDate = DateTime.Now.AddDays(-7);
                    }
                    if (!toDate.HasValue)
                    {
                        toDate = DateTime.Now;
                    }

                    if (displayPeriod.IsWeekly)
                    {
                        fromDate = DateTime.Today.StartOfWeek(DayOfWeek.Saturday);
                        toDate   = DateTime.Today.EndOfWeek(DayOfWeek.Friday);
                    }
                    else
                    {
                        toDate = fromDate.Value.AddDays(displayPeriod.NumOfDays);
                    }
                }

                var mustCheckDefaultTimeSheetPolocy = false;
                var now = DateTime.Now;
                mustCheckDefaultTimeSheetPolocy = now >= fromDate && now <= toDate;

                var numberOfReset = -1;

labelForReset:

                numberOfReset++;

                IQueryable <Persistance.QueryEntities.EmployeeTimeSheetFromDB> query = null;

                if (isWantingApprove)
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundConfirmTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           userId,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }
                else
                {
                    query = this.DBContext.spFoundConfirmTimeSheet.FromSqlInterpolated(this.DBContext.spFoundEmployeeTimeSheet_str(
                                                                                           currentUser.ID,
                                                                                           fromDate.Value,
                                                                                           toDate.Value
                                                                                           ));
                }

                var items = await query.ToListAsync();

                var days = new string[] { "شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه" };

                var answer = items.GroupBy(g => g.Date)
                             .Select(gg => new vmGetTimeSheetResualt
                {
                    date           = gg.Key.Value,
                    isOpen         = gg.FirstOrDefault().IsOpen,
                    mustHaveHozoor = gg.First().UserMustHasHozoor,
                    dayTimeString  = gg.FirstOrDefault().DayTimeString,
                    date_persian   = gg.First().PersianDate,
                    day_persian    = days[gg.First().DayOfWeek.Value],
                    hozoor         = gg.First().Hozoor,
                    projects       = gg.Where(p => p.Type == "Work" && p.ProjectId.HasValue)
                                     .GroupBy(p => p.ProjectId).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.Key,
                        title    = pp.First().ProjectTitle,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => new { w.TaskId, w.State }).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.Key.TaskId,
                            state   = ww.Key.State,
                            title   = ww.First().Title,
                            minutes = ww.First().Minutes
                        }).ToList()
                    }).ToList(),

                    others = gg.Where(p => p.Type == "Other" && p.ProjectId.HasValue)
                             .GroupBy(p => p.State).Select(pp => new vmGetTimeSheetResualt_Project
                    {
                        id       = pp.First().ProjectId,
                        title    = pp.Key,
                        workouts = pp.Where(w => w.TaskId.HasValue)
                                   .GroupBy(w => w.TaskId).Select(ww => new vmGetTimeSheetResualt_Workout
                        {
                            id      = ww.First().TaskId,
                            state   = ww.First().State,
                            title   = ww.First().Title,
                            minutes = ww.Sum(www => www.Minutes)
                        }).ToList()
                    }).ToList()
                }).ToList();

                if (mustCheckDefaultTimeSheetPolocy && !answer.First(a => a.date.Value.Date == now.Date).isOpen.HasValue)
                {
                    //default policy must check maybe is deactivated
                    //if isnot created, must create and today is open beacuase friday is checked in query
                    //اگر زمانش گذشته باید تمدید بشه که با تاریخ های امروز یکسان بشه
                    var userDefaultPolicy = this.DBContext.TimesheetPolicies.FirstOrDefault(p => p.IsDefault && p.UserId == currentUser.ID);
                    if (userDefaultPolicy == null)
                    {
                        userDefaultPolicy = new TimesheetPolicy()
                        {
                            Id                = Guid.NewGuid(),
                            IsDefault         = true,
                            isDeactivated     = false,
                            IsOpen            = true,
                            UserMustHasHozoor = true,
                            UserId            = currentUser.ID,
                        };
                        this.DBContext.TimesheetPolicies.Add(userDefaultPolicy);
                    }

                    userDefaultPolicy.Start      = DateUtility.GetCompanyStartDate();
                    userDefaultPolicy.Finish     = DateUtility.GetCompanyEndDate();
                    userDefaultPolicy.Validity   = DateUtility.GetCompanyEndDate();
                    userDefaultPolicy.CreateDate = DateTime.Now;



                    this.DBContext.SaveChanges();

                    if (numberOfReset < 1)
                    {
                        goto labelForReset;
                    }
                }

                return(Ok(answer));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در دریافت اطلاعات تایم شیت"));
            }
        }
        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);
        }
Exemple #24
0
        public IActionResult SaveEditPolicy(vmTimesheetPolicy request)
        {
            try
            {
                if (request == null)
                {
                    throw new Exception("اطلاعات ارسال نشده است");
                }
                if (string.IsNullOrEmpty(request.start))
                {
                    throw new Exception("تاریخ شروع باید وارد شده باشد");
                }
                if (string.IsNullOrEmpty(request.finish))
                {
                    throw new Exception("تاریخ پایان باید وارد شده باشد");
                }
                if (string.IsNullOrEmpty(request.validity))
                {
                    throw new Exception("تاریخ اعتبار باید وارد شده باشد");
                }

                if (!request.userId.HasValue)
                {
                    throw new Exception("انتخاب کاربر ضروری است");
                }

                TimesheetPolicy policy = null;

                if (request.id == Guid.Empty)
                {
                    policy = new TimesheetPolicy()
                    {
                        Id        = Guid.NewGuid(),
                        IsDefault = false
                    };
                    this.DBContext.TimesheetPolicies.Add(policy);
                }
                else
                {
                    policy = this.DBContext.TimesheetPolicies.FirstOrDefault(p => p.Id == request.id);
                    if (policy == null)
                    {
                        throw new Exception("قانون با آی دی خواسته شده یافت نشد");
                    }
                }


                policy.CreateDate    = DateTime.Now;
                policy.isDeactivated = request.isDeactivated;

                policy.UserMustHasHozoor = request.userMustHasHozoor;
                policy.IsOpen            = request.isOpen;

                if (policy.IsDefault)
                {
                    this.DBContext.SaveChanges();
                    return(Ok(true));//قانون اصلی را فقط می توان غیر فعال کرد
                }



                policy.Start    = DateUtility.GetMiladiDate(request.start);
                policy.Finish   = DateUtility.GetMiladiDate(request.finish);
                policy.Validity = DateUtility.GetMiladiDate(request.validity);

                if (policy.Start > policy.Finish)
                {
                    throw new Exception("تاریخ شروع نمی تواند بزرگتر از تاریخ پایان باشد");
                }
                if (policy.Validity.Date < DateTime.Now.Date)
                {
                    throw new Exception("تاریخ اعتبار نمی تواند کوچکتر از امروز باشد");
                }


                policy.UserId = request.userId;


                this.DBContext.SaveChanges();

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(this.ReturnError(ex, "خطا در ثبت قانون جدید"));
            }
        }