public async Task <ActionResult> Edit(int weekid, string originUrl, int expenseItemId) { var jobs = await _jobsService.GetAsync(await _sessionAdapter.EmployeeIdAsync()); var expense = await _expenseService.GetExpenseById(expenseItemId); var vm = new EditExpenseViewModel() { AvailableJobs = jobs.ToList(), ExpenseToSave = new ExpenseModel() { AddtionalNotes = expense.AddtionalNotes, Amount = expense.Amount, AttachmentName = expense.AttatchmentName, Classification = expense.Classification, RelatedJob = expense.RelatedJob, SaveDate = expense.SaveDate }, Week = WeekDTO.CreateForWeekId(weekid), CancelUrl = originUrl, WeekId = weekid, SelectedJobId = expense.RelatedJob.JobId, ExpenseItemId = expense.ExpenseItemId }; return(View("Edit", vm)); }
private async Task <NewJobTaskCombo> GenerateEmptyJobTaskAsync(int weekId, int employeeId) { var jobList = (await jobService.GetAsync(employeeId)).ToList(); var taskList = (await taskService.GetTasks()).Where(x => x.UsageStatus.Enum == JobTasks.UsageStatus.Enabled).ToList().OrderBy(x => x.LegacyCode).ThenBy(x => x.Name); var week = WeekDTO.CreateForWeekId(weekId); return(new NewJobTaskCombo() { SelectedJobId = null, SelectedTaskId = null, AvailableJobs = jobList, AvailableTasks = taskList, }); }
public async Task CopyPreviousWeekTime(int employeeId, int id) { var prev = WeekDTO.CreateForWeekId(id).Previous(); var timeEntries = await _timeService.GetAsync(prev.WeekId.Value, employeeId); foreach (var entry in timeEntries.GroupBy(x => new { x.JobId, x.JobTaskId })) { var entryForEveryDayOfWeek = _timeSpentRepository.CreateEmptyWeekForCombo(id, entry.Key.JobTaskId, entry.Key.JobId, employeeId);; foreach (var day in entryForEveryDayOfWeek) { await _timeService.SaveAsync(employeeId, day); } } }
public async Task <ActionResult> Index(int weekid, string originUrl) { var jobs = await _jobsService.GetAsync(await _sessionAdapter.EmployeeIdAsync()); var vm = new AddExpenseViewModel() { AvailableJobs = jobs.ToList(), ExpenseToSave = new ExpenseModel(), Week = WeekDTO.CreateForWeekId(weekid), CancelUrl = originUrl, WeekId = weekid, }; return(View("New", vm)); }
private WeekOfTimeDTO ToDTO(int employeeId, int weekId, FullTimeEntryViewModel vm) { var w = WeekDTO.CreateForWeekId(weekId); return(new WeekOfTimeDTO() { WeekId = weekId, Monday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Monday), vm.TimeEntryRow, x => x.Monday), Tuesday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Tuesday), vm.TimeEntryRow, x => x.Tuesday), Wednesday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Wednesday), vm.TimeEntryRow, x => x.Wednesday), Thursday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Thursday), vm.TimeEntryRow, x => x.Thursday), Friday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Friday), vm.TimeEntryRow, x => x.Friday), Saturday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Saturday), vm.TimeEntryRow, x => x.Saturday), Sunday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Sunday), vm.TimeEntryRow, x => x.Sunday) }); }
public IEnumerable <TimeEntryDTO> CreateEmptyWeekForCombo(int weekId, int JobTaskId, int JobId, int employeeId) { var week = WeekDTO.CreateForWeekId(weekId); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Monday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Tuesday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Wednesday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Thursday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Friday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Saturday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Sunday)); }
public async Task <FullTimeEntryViewModel> GetFullTimeEntryViewModelAsync(WeekOfTimeEntriesRequest request) { var employeeForWeek = await employeeService.GetSingleEmployeeAsync(request.EmployeeId); if (!request.RequestingUserIsAdmin && employeeForWeek.UserName != request.RequestingUserName) { throw new UnauthorizedAccessException($"You are not allowed to view others time sheets"); } var currentWeek = WeekDTO.CreateForWeekId(request.WeekId); var weekOfTimeEntries = await timeService.GetWeekAsync(request.EmployeeId, request.WeekId); //var timeEntries = await timeService.GetAsync(request.WeekId, request.EmployeeId); var allJobList = (await jobService.GetAsync()).ToList(); var taskList = (await taskService.GetTasks()).ToList().OrderBy(x => x.Name).ThenBy(x => x.Description); var entries = new List <TimeEntryViewModel>(); var status = await timeApprovalService.GetAsync(request.WeekId, request.EmployeeId); var existingJobWithTasks = weekOfTimeEntries.AsEnumerable().GroupBy(x => new JobWithTaskDTO() { JobId = x.JobId, TaskId = x.JobTaskId }); foreach (var entry in existingJobWithTasks) { var tasky = taskList.FirstOrDefault(x => x.TaskId == entry.Key.TaskId); var SelectedEntryTaskName = $"{tasky?.LegacyCode} - {tasky?.Name}"; var SelectedEntryJob = allJobList.FirstOrDefault(x => x.JobId == entry.Key.JobId); var jobCode = ""; if (SelectedEntryJob != null) { jobCode = SelectedEntryJob.JobCode; } var item = new TimeEntryViewModel() { SelectedJobId = entry.Key.JobId, SelectedTaskId = entry.Key.TaskId, SelectedEntryTaskName = SelectedEntryTaskName, SelectedEntryJobName = SelectedEntryJob?.JobName, SelectedJobCode = jobCode, SelectedTaskCategory = tasky?.Category?.Name, Monday = MapToViewModel(currentWeek, DayOfWeek.Monday, entry), Tuesday = MapToViewModel(currentWeek, DayOfWeek.Tuesday, entry), Wednesday = MapToViewModel(currentWeek, DayOfWeek.Wednesday, entry), Thursday = MapToViewModel(currentWeek, DayOfWeek.Thursday, entry), Friday = MapToViewModel(currentWeek, DayOfWeek.Friday, entry), Saturday = MapToViewModel(currentWeek, DayOfWeek.Saturday, entry), Sunday = MapToViewModel(currentWeek, DayOfWeek.Sunday, entry), }; entries.Add(item); } entries = entries.OrderBy(x => x.SelectedJobCode).ThenBy(x => x.SelectedTaskId).ToList(); var nextWeek = currentWeek.Next(); var prevWeek = currentWeek.Previous(); return(new FullTimeEntryViewModel() { TimeEntryRow = entries, EmployeeId = employeeForWeek.EmployeeId, EmployeeDisplayName = $"{employeeForWeek.First} {employeeForWeek.Last}", NewEntry = await GenerateEmptyJobTaskAsync(request.WeekId, request.EmployeeId), Week = new WeekIdentifier() { WeekEnd = currentWeek.WeekEnd, WeekStart = currentWeek.WeekStart, WeekId = currentWeek.WeekId.Value, Year = currentWeek.Year }, ApprovalStatus = status.TimeApprovalStatus, Expenses = await _expenseService.GetExpensesForEmployee(request.EmployeeId, request.WeekId) }); }
public async Task <IEnumerable <TimeApprovalDTO> > GetByStatus(DateTime?beginDateInclusive = null, DateTime?endDateInclusive = null, params TimeApprovalStatus[] withTimeApprovalStatus) { using (var db = _contextFactory.CreateDb()) { var allEmps = await db.Employees.Where(x => x.EmployeeId != admin_employee_id).ToListAsync(); var startWeek = beginDateInclusive.HasValue ? WeekDTO.CreateWithWeekContaining(beginDateInclusive.Value).WeekId.Value : WeekDTO.CreateWithWeekContaining(DateTime.Now.AddDays(-7)).WeekId.Value; var endWeek = endDateInclusive.HasValue ? WeekDTO.CreateWithWeekContaining(endDateInclusive.Value).WeekId.Value : WeekDTO.CreateWithWeekContaining(DateTime.Now.AddDays(31)).WeekId.Value; if (startWeek > endWeek) { endWeek = startWeek; } var approvals = await SearchForSavedApprovals(db, startWeek, endWeek, withTimeApprovalStatus); var approverNames = approvals.Values.Select(x => x.ApproverEmployeeId).Where(x => x.HasValue).Distinct().ToDictionary(x => x.Value, x => allEmps.FirstOrDefault(a => a.EmployeeId == x.Value)?.UserName); var weeklyHourTotals = await db.WeeklyData.Where(x => x.WeekId >= startWeek && x.WeekId <= endWeek).ToListAsync(); var hourTotalsByEmpAndWeek = weeklyHourTotals.ToDictionary(x => (x.EmployeeId, x.WeekId), x => (x.TotalOverTimeHours, x.TotalRegularHours)); var matches = new List <TimeApprovalDTO>(); for (int weekid = startWeek; weekid <= endWeek; weekid++) { foreach (var emp in allEmps) { if (!approvals.TryGetValue((emp.EmployeeId, weekid), out var x)) { x = new TimeSheetApproval() { Employee = emp, EmployeeId = emp.EmployeeId, IsHidden = false, WeekId = weekid }; } var temp = new TimeApprovalDTO() { ApprovalDate = x.ApprovalDate, ApproverName = approverNames.TryGetValue(x.ApproverEmployeeId ?? 0, out var approverName) ? approverName : null, EmployeeName = $"{x.Employee.Last}, {x.Employee.First}", EmployeeId = x.EmployeeId, ResponseReason = x.ResponseReason, TimeApprovalStatus = string.IsNullOrWhiteSpace(x.TimeApprovalStatus) ? TimeApprovalStatus.Unkown : Enum.Parse <TimeApprovalStatus>(x.TimeApprovalStatus), WeekId = x.WeekId, WeekStartDate = WeekDTO.CreateForWeekId(x.WeekId).WeekStart, SubmittedDate = x.SubmittedDate, TotalOverTimeHours = 0.00m, TotalRegularHours = 0.00m, IsHidden = x.IsHidden }; if (hourTotalsByEmpAndWeek.TryGetValue((emp.EmployeeId, weekid), out var fromDb)) { temp.TotalOverTimeHours = fromDb.TotalOverTimeHours; temp.TotalRegularHours = fromDb.TotalRegularHours; } matches.Add(temp); } } return(matches); } }
public async Task <Result> ApplyApproval(TimeApprovalRequest request) { var current = await timeApprovalService.GetAsync(request.WeekId, request.EmployeeId); var isValidSubmit = request.NewApprovalState == TimeEntries.TimeApprovalStatus.Submitted && !(current.TimeApprovalStatus == TimeApprovalStatus.Submitted || current.TimeApprovalStatus == TimeApprovalStatus.Approved); var isValidReject = request.NewApprovalState == TimeEntries.TimeApprovalStatus.Rejected && (current.TimeApprovalStatus == TimeApprovalStatus.Submitted || current.TimeApprovalStatus == TimeApprovalStatus.Approved) && request.ApprovingUserIsAdmin; var isValidApprove = request.NewApprovalState == TimeApprovalStatus.Approved && request.ApprovingUserIsAdmin; if (isValidSubmit) { var time = await timeService.GetAsync(request.WeekId, request.EmployeeId); var totalOt = time.Sum(x => x.OvertimeHours); var totalReg = time.Sum(x => x.Hours); current.TotalOverTimeHours = totalOt; current.TotalRegularHours = totalReg; if (totalOt > 0 || totalReg > 40) { current.TimeApprovalStatus = TimeApprovalStatus.Submitted; } else { current.TimeApprovalStatus = TimeApprovalStatus.Approved; } } if (isValidReject || isValidApprove) { current.TimeApprovalStatus = request.NewApprovalState; } if (isValidApprove) { var approvedBy = request.ApprovingUserId == request.EmployeeId ? "[AUTO APPROVED BY SYSTEM]" : "approved by manager"; var approver = await employeeService.GetSingleEmployeeAsync(request.ApprovingUserId); current.ApproverName = approver.UserName; current.ApprovalDate = DateTime.Now; var week = WeekDTO.CreateForWeekId(request.WeekId); var emp = await employeeService.GetSingleEmployeeAsync(request.EmployeeId); string finalEmailText = await CreateEmailBody(week, emp, greetingName : emp.First, action : $"Time sheet approved (for the week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()})", actionBy : approvedBy, followup : "No further action is required."); var recipient = emp.UserName; smtpProxy.SendMail(recipient, finalEmailText, $"Time approved for week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()}"); } await timeApprovalService.Save(current); if (isValidSubmit && current.TimeApprovalStatus == TimeApprovalStatus.Submitted) { var time = await timeService.GetAsync(request.WeekId, request.EmployeeId); var JobsThatCauseApprovalRequired = time.Where(x => x.OvertimeHours > 0).GroupBy(x => x.JobId); var jobDetails = await Task.WhenAll(JobsThatCauseApprovalRequired.Select(async x => (await jobService.GetForJobId(x.Key)).CoreInfo)); int[] projectManagersToNotifiy = jobDetails.Select(x => x.ProjectManagerEmployeeId).ToArray(); var week = WeekDTO.CreateForWeekId(request.WeekId); foreach (var pm in projectManagersToNotifiy) { var emp = await employeeService.GetSingleEmployeeAsync(request.EmployeeId); var approver = await employeeService.GetSingleEmployeeAsync(pm); var recipient = approver.UserName; string finalEmailText = await CreateEmailBody(week, emp, greetingName : approver.First, action : $"submitted for approval (for the week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()})", actionBy : $"{emp.First} {emp.Last}", followup : $"You will need to review the timesheet as you are marked as a project manager a job in this week."); smtpProxy.SendMail(recipient, finalEmailText, $"Time submitted for week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()}"); } } if (isValidReject) { var week = WeekDTO.CreateForWeekId(request.WeekId); var emp = await employeeService.GetSingleEmployeeAsync(request.EmployeeId); var approver = await employeeService.GetSingleEmployeeAsync(request.ApprovingUserId); var recipient = emp.UserName; string finalEmailText = await CreateEmailBody(week, emp, greetingName : emp.First, action : $"{request.NewApprovalState}", actionBy : $"{approver.First} {approver.Last}", followup : $"Please review and resubmit for the week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()}."); smtpProxy.SendMail(recipient, finalEmailText, $"Time {request.NewApprovalState} for week {week.WeekStart.ToShortDateString()}-{week.WeekEnd.ToShortDateString()}"); } return(new Result(true)); }