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)); }
public async System.Threading.Tasks.Task <ActionResult> List() { var isAdmin = User.IsInRole(UserRoleName.Admin); var jobs = await _jobsRepository.GetAsync(); if (!isAdmin) { jobs = jobs.Where(x => x.JobStatusId == JobStatus.Enabled).ToList(); } var myJobs = await _jobsRepository.GetAsync(await sessionAdapter.EmployeeIdAsync()); var availableClients = await clientRepository.GetAllClients(); var availableSites = await siteRepository.GetAll(); var allEmployees = await _employeeRepository.GetAllEmployees(); var models = jobs.OrderBy(x => x.JobCode).Select(job => { var details = new JobModelDetail { Client = _mapper.Map <ClientModel>(availableClients.SingleOrDefault(z => z.ClientId == job.ClientId)), Site = _mapper.Map <SiteModel>(availableSites.SingleOrDefault(z => z.SiteID == job.SiteId)), ProjectManager = _mapper.Map <ProjectManagerModel>(allEmployees.SingleOrDefault(z => z.EmployeeId == job.ProjectManagerEmployeeId)) }; return(job, details); }).ToList(); var vm = new JobListViewModel() { AllJobsWithAssociationStatus = models.OrderBy(x => x.job.JobCode) .ToDictionary(x => x, x => myJobs.Any(z => z.JobId == x.job.JobId)), }; return(View("ListJobs", vm)); }
public async Task <IActionResult> Index([FromBody] NewEffort effort, [FromRoute(Name = "week-id")] int weekid, [FromRoute(Name = "employee-id")] int employeeId) { var currentUserId = await _sessionAdapter.EmployeeIdAsync(); if (!User.IsInRole(UserRoleName.Admin) && employeeId != currentUserId) { var msg = "You are not allowed to edit another users effort selection."; return(CreateErrorResponse(msg)); } var addResult = await _addNewJobTaskComboCommand.AddNewJobTaskCombo(employeeId, weekid, effort.SelectedTaskId, effort.SelectedJobId); if (addResult.Successful) { NotificationsController.AddNotification(User.SafeUserName(), "The selected task has been added."); return(new StatusCodeResult(StatusCodes.Status201Created)); } else { return(CreateErrorResponse(string.Join(", ", addResult.Errors))); } }
public async Task <ActionResult> Index(int?weeksToShow, string startWithDate) { if (!DateTime.TryParse(startWithDate, out var startDate)) { startDate = DateTime.Now; } return(View("WeekList", await weekIdentifierListQuery.GetWeeksAsync(weeksToShow ?? 5, await sessionAdapter.EmployeeIdAsync(), startDate))); }
public async Task <IActionResult> SetTimeForEffort([FromBody] Dictionary <DayOfWeek, Day> saveRequest, [FromRoute(Name = "week-id")] int weekid, [FromRoute(Name = "employee-id")] int employeeId, [FromRoute(Name = "job-id")] int jobId, [FromRoute(Name = "task-id")] int taskId) { var currentUserId = await _sessionAdapter.EmployeeIdAsync(); if (!User.IsInRole(UserRoleName.Admin) && employeeId != currentUserId) { var msg = "You are not allowed to edit another users effort selection."; return(CreateErrorResponse(msg)); } var currentTime = await _weekOfTimeEntriesQuery.GetFullTimeEntryViewModelAsync(new WeekOfTimeEntriesRequest() { EmployeeId = employeeId, RequestingUserIsAdmin = User.IsInRole(UserRoleName.Admin), RequestingUserName = User.SafeUserName(), WeekId = weekid }); var rowToChange = currentTime.TimeEntryRow.FirstOrDefault(x => x.SelectedJobId == jobId & x.SelectedTaskId == taskId); foreach (var day in rowToChange.AllDays()) { day.Hours = saveRequest[day.DayOfWeek].Hours; day.OvertimeHours = saveRequest[day.DayOfWeek].OvertimeHours; } var addResult = await _saveTimeEntriesCommand.SaveTimeEntriesAsync(employeeId, weekid, currentTime); if (addResult.Successful) { NotificationsController.AddNotification(User.SafeUserName(), "Time saved"); return(new StatusCodeResult(StatusCodes.Status200OK)); } else { return(CreateErrorResponse(string.Join(", ", addResult.Errors))); } }
public async Task <ActionResult> ApplyApproval(TimeApprovalModel request) { var req = new TimeApprovalRequest( approvingUserId: await sessionAdapter.EmployeeIdAsync(), approvingUserIsAdmin: User.IsInRole(UserRoleName.Admin), employeeId: request.EmployeeId, weekId: request.WeekId, newApprovalState: request.NewApprovalState ); var res = await approveTimeCommand.ApplyApproval(req); if (res.Successful) { NotificationsController.AddNotification(this.User.SafeUserName(), $"Timesheet is {request.NewApprovalState}"); return(Ok()); } else { NotificationsController.AddNotification(this.User.SafeUserName(), $"{string.Join(",",res.Errors)}"); return(Unauthorized()); } }
public async Task <ReportDTO <QuickJobTimeReportDTO> > RunAsync(QuickJobTimeReportCriteria criteria) { DateTime start = criteria.PeriodSettings.Start; DateTime end = criteria.PeriodSettings.End; int jobId = int.Parse(criteria.SelectedJobId); int?limitToEmployeeId = await _sessionAdapter.EmployeeIdAsync(); if (criteria.ShowAllEmployeesForJob) { limitToEmployeeId = null; } using (var conn = new SqlConnection(configuration.GetConnectionString("SiteConnection"))) using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = @" Select " + $" min(Convert(varchar(10),Isnull(te.Date,@WeekStart), 101)) as {nameof(QuickJobTimeReportDTO.PeriodStart)}, " + $" max(Convert(varchar(10),isnull( te.Date,@WeekEnd),101)) as {nameof(QuickJobTimeReportDTO.PeriodEnd)}, " + $" COALESCE(e.Last,'') + ', ' + COALESCE(e.First,'') as {nameof(QuickJobEmployees.EmployeeName)}, " + $" j.JobCode as {nameof(QuickJobTimeReportDTO.JobCode)}, " + $" j.JobName as {nameof(QuickJobTimeReportDTO.JobName)}," + $" c.ClientName as {nameof(QuickJobTimeReportDTO.ClientName)}, " + $" s.SiteName as {nameof(QuickJobTimeReportDTO.SiteName)}, " + $" jt.LegacyCode + ' - ' + jt.[Name] as {nameof(QuickJobEmployees.TaskName)}, " + $" tc.Name as {nameof(QuickJobEmployees.TaskCategory)}, " + $" isnull(sum(te.hours),0) as {nameof(QuickJobEmployees.Regular)}, " + $" isnull(sum(te.overtimehours),0) as {nameof(QuickJobEmployees.Overtime)}, " + $" isnull(sum(te.hours),0) + isnull(sum(te.overtimehours),0) as {nameof(QuickJobEmployees.Combined)}" + @" from dbo.Jobs j inner join dbo.Clients c on c.ClientId = j.ClientId left outer join [dbo].TimeEntries te on j.JobId = te.JobId left outer join [dbo].Employees e on e.EmployeeId = te.EmployeeId inner join dbo.[Sites] s on j.SiteId = s.SiteID left outer join dbo.JobTasks jt on jt.JobTaskId = te.TaskId inner join dbo.TaskCategories tc on tc.TaskCategoryId = jt.TaskCategoryId where (@JobId is null Or te.JobId = @JobId) and te.Date >= @WeekStart and te.Date <= @WeekEnd and ISNULL(e.[UserName],'') != '*****@*****.**' " + (limitToEmployeeId.HasValue ? $" and te.EmployeeId = { limitToEmployeeId.Value}" : string.Empty) + @" group by tc.Name,s.SiteName, j.JobCode, COALESCE(e.Last,'') + ', ' + COALESCE(e.First,'') , j.JobName, c.ClientName , jt.LegacyCode + ' - ' + jt.[Name], j.JobId Select 'Time And Expense Expenditures' as [name] ,SUM(ISNULL(e.Amount,0)) as amount from dbo.Jobs j inner join dbo.TimeAndExpenceExpenditures e on e.JobId = j.JobId where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId) AND (@JobId is null Or j.JobId = @JobId) HAVING SUM(ISNULL(e.Amount,0)) > 0 UNION ALL select 'Company Vehicle Expense' as [name] ,SUM(ISNULL((ve.TotalNumberOfDaysUsed * 125) + CASE WHEN ve.TotalMiles > 250 THEN (ve.TotalMiles * .50) - (250 * .50) ELSE 0 END,0)) as amount from dbo.Jobs j inner join dbo.CompanyVehicleExpenditures ve on ve.JobId = j.JobId where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = ve.EmployeeId) AND (@JobId is null Or j.JobId = @JobId) HAVING SUM(ISNULL((ve.TotalNumberOfDaysUsed * 125) + CASE WHEN ve.TotalMiles > 250 THEN (ve.TotalMiles * .50) - (250 * .50) ELSE 0 END,0)) > 0 UNION ALL select 'Contractor/PO Expense' as [name] ,SUM(ISNULL(ce.TotalPOContractAmount,0)) as amount from dbo.Jobs j inner join dbo.ContractorExpenditures ce on j.JobId = ce.JobId where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = ce.EmployeeId) AND (@JobId is null Or j.JobId = @JobId) HAVING SUM(ISNULL(ce.TotalPOContractAmount,0)) > 0 UNION ALL select 'Arc Flash Labels Expense' as [name] ,SUM(ISNULL(e.TotalLabelsCost,0) + ISNULL(e.TotalPostageCost,0)) as amount FROM dbo.Jobs j inner join dbo.ArcFlashlabelExpenditures e on j.jobId = e.jobId where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId) AND (@JobId is null Or j.JobId = @JobId) HAVING SUM(ISNULL(e.TotalLabelsCost,0) + ISNULL(e.TotalPostageCost,0)) > 0 UNION ALL select 'Miscellaneous Expense' as [name] ,SUM(ISNULL(e.Amount,0)) as amount from dbo.Jobs j inner join dbo.MiscExpenditures e on j.JobId = e.JobId where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId) AND (@JobId is null Or j.JobId = @JobId) HAVING SUM(ISNULL(e.Amount,0)) > 0 "; cmd.Parameters.Add(new SqlParameter("JobId", jobId)); cmd.Parameters.Add(new SqlParameter("LimitToEmployeeId", limitToEmployeeId.HasValue ? limitToEmployeeId : DBNull.Value)); cmd.Parameters.Add(new SqlParameter("WeekIdStartInclusive", WeekDTO.CreateWithWeekContaining(start).WeekId.Value)); cmd.Parameters.Add(new SqlParameter("WeekIdEndInclusive", WeekDTO.CreateWithWeekContaining(end).WeekId.Value)); cmd.Parameters.Add(new SqlParameter("WeekStart", start)); cmd.Parameters.Add(new SqlParameter("WeekEnd", end)); var rdr = cmd.ExecuteReader(); var map = GetColumnMap(rdr.GetColumnSchema()); var rpt = new QuickJobTimeReportDTO() { PeriodEnd = end, PeriodStart = start, Expenses = new Dictionary <string, decimal>() }; var employeeRows = new List <QuickJobEmployees>(); var job = (await _jobsRepository.GetAsync()).SingleOrDefault(x => x.JobId == jobId); rpt.JobCode = job.JobCode; rpt.JobName = job.JobName; rpt.SiteName = (await _sitesRepository.GetAll()).SingleOrDefault(x => x.SiteID == job.SiteId)?.SiteName; rpt.ClientName = (await _clientsRepository.GetClient(job.ClientId))?.ClientName; while (await rdr.ReadAsync()) { if (rdr.HasRows) { employeeRows.Add(new QuickJobEmployees() { Combined = rdr.GetDecimal(map[nameof(QuickJobEmployees.Combined)]), Regular = rdr.GetDecimal(map[nameof(QuickJobEmployees.Regular)]), Overtime = rdr.GetDecimal(map[nameof(QuickJobEmployees.Overtime)]), EmployeeName = rdr.GetSqlString(map[nameof(QuickJobEmployees.EmployeeName)]).Value, TaskCategory = rdr.GetSqlString(map[nameof(QuickJobEmployees.TaskCategory)]).Value, TaskName = rdr.GetSqlString(map[nameof(QuickJobEmployees.TaskName)]).Value, }); } } rpt.Employees = employeeRows; await rdr.NextResultAsync(); while (await rdr.ReadAsync()) { rpt.Expenses.Add(rdr.GetString(0), rdr.GetDecimal(1)); } return(new ReportDTO <QuickJobTimeReportDTO>() { Data = rpt, ReportName = QuickJobTimeReport.QuickJobTimeReportCriteria.QUICK_JOB_TIME_REPORT_NAME, RunSettings = new Dictionary <string, string>() { { "Generated", $"{DateTimeWithZone.EasternStandardTime.ToShortDateString()} at {DateTimeWithZone.EasternStandardTime.ToShortTimeString()}" }, { "Company", $"Orion Engineering Co., Inc." }, { "Showing Time From", criteria.ShowAllEmployeesForJob ? "All Employees" : "Self" }, } }); } }