Пример #1
0
        private async Task SendReminders()
        {
            var thisWeek = WeekDTO.CreateWithWeekContaining(DateTime.Now);

            if (thisWeek.IsPPE.Value)
            {
                var beginDate = thisWeek.Previous().WeekStart;
                var endDate   = thisWeek.WeekEnd;
                var entries   = (await _timeApprovalService.GetByStatus(beginDate, endDate, TimeApprovalStatus.Unkown)).ToList();
                var template  = await System.IO.File.ReadAllTextAsync(@"wwwroot\email-submit-time-reminder.html");

                foreach (var entry in entries.GroupBy(x => x.EmployeeId))
                {
                    try
                    {
                        var emp = await _employeeRepository.GetSingleEmployeeAsync(entry.Key);

                        _logger.Information($"sending reminder to {emp.First} {emp.Last} [{emp.UserName}]");

                        _smtpProxy.SendMail(emp.UserName, template, $"Reminder to submit time for {beginDate.ToShortDateString()}-{endDate.ToShortDateString()}");
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "error trying to send reminder");
                    }
                }
            }
        }
        private ExcelReport <PayPeriodReportCriteria> GetPayPeriodReportViewModel(bool isCurrentUserAdmin)
        {
            var vm2 = new PayPeriodReportCriteria();

            vm2.PayPeriodEnd  = WeekDTO.CreateWithWeekContaining(DateTime.Now).WeekEnd;
            vm2.PayPeriodList = PayPeriodRepository.GetPPRange(rangeSize: 25);
            var rpt = new ExcelReport <PayPeriodReportCriteria>(PayPeriodReportCriteria.PAY_PERIOD_REPORT_NAME, vm2, isCurrentUserAdmin);

            return(rpt);
        }
        private ReportingPeriod GetDefaultPeriodSettings()
        {
            var wk = WeekDTO.CreateWithWeekContaining(DateTime.Now);
            var ps = new ReportingPeriod()
            {
                Start = wk.WeekStart,
                End   = wk.WeekEnd
            };

            return(ps);
        }
Пример #4
0
        public async Task <ActionResult> Current(int?employeeId)
        {
            var emp = await sessionAdapter.EmployeeIdAsync();

            if (User.IsInRole(UserRoleName.Admin) && employeeId.HasValue)
            {
                emp = employeeId.Value;
            }

            var current = WeekDTO.CreateWithWeekContaining(DateTime.Now);

            return(RedirectToAction("Edit", new { weekId = current.WeekId.Value, employeeId = emp }));
        }
Пример #5
0
        public static PayPeriodDTO GetPPFor(DateTime date)
        {
            var currentPP   = new PayPeriodDTO();
            var currentWeek = WeekDTO.CreateWithWeekContaining(date);

            if (currentWeek.IsPPE.Value)
            {
                return(MapForPPEndWeek(currentWeek));
            }
            else
            {
                return(MapForPPStartWeek(currentWeek));
            }
        }
Пример #6
0
        public void PayPeriodsWork()
        {
            var start = WeekDTO.CreateWithWeekContaining(new DateTime(2021, 4, 20));

            Assert.IsTrue(start.IsPPE.Value);

            var next = start.Next();

            Assert.IsFalse(next.IsPPE.Value);


            var next2 = next.Next();

            Assert.IsTrue(next2.IsPPE.Value);
        }
Пример #7
0
        public void InternallyConsistandWeekCycles()
        {
            var start = new WeekDTO(new DateTime(WeekDTO.WeekEpoch.Year, WeekDTO.WeekEpoch.Month, WeekDTO.WeekEpoch.Day));

            Assert.AreEqual(0, start.WeekId.Value);
            var next = start.Next();

            Assert.AreEqual(1, next.WeekId.Value);

            var next2 = next.Next();

            Assert.AreEqual(2, next2.WeekId.Value);


            var stillNext2 = WeekDTO.CreateWithWeekContaining(next2.WeekEnd.AddDays(-2));

            Assert.AreEqual(next2, stillNext2);
        }
Пример #8
0
        protected override async Task <IProcessResult <MiscExpenditure> > Handle(UpdateMiscExpenditureMessage msg)
        {
            var existing = await _repo.FindByExternalId(msg.ExternalExpenditureId);

            if (existing == null ||
                msg.ExternalExpenditureId == default(Guid))
            {
                existing              = new DataAccess.EF.MiscExpenditure();
                existing.ExternalId   = Guid.NewGuid();
                existing.Id           = 0;
                existing.LastModified = DateTimeOffset.Now;
                existing.WeekId       = WeekDTO.CreateWithWeekContaining(msg.Model.ExpensedOn).WeekId.Value;
            }
            var updateMsg = UpdateMessage.CreateFrom(msg, existing);
            var mapped    = _mapper.Map <DataAccess.EF.MiscExpenditure>(updateMsg);

            var saved = await _repo.SaveEntity(mapped);

            return(Success(_mapper.Map <MiscExpenditure>(saved)));
        }
Пример #9
0
        private async Task <DataAccess.EF.ScheduleTask> CreateReminderTask(string taskName, bool isPpeOnly)
        {
            var thisWeek = WeekDTO.CreateWithWeekContaining(DateTime.Now);

            if (isPpeOnly)
            {
                if (!thisWeek.IsPPE.Value)
                {
                    thisWeek = thisWeek.Previous();
                }
            }
            _logger.Information($"Creating new Reminder Task [{taskName}]");
            return(await _scheduleTaskRepo.CreateNewScheduledTask(new BLL.ScheduledTasks.NewScheduledTask()
            {
                EndDate = null,
                OnFriday = true,
                RecurEveryNWeeks = isPpeOnly ? 2 : 1,
                StartDate = thisWeek.WeekStart,
                TaskName = taskName
            }));
        }
Пример #10
0
        public async Task <ReportDTO <PayPeriodReportDTO> > RunAsync(DateTime payPeriodEnd)
        {
            using (var conn = new SqlConnection(configuration.GetConnectionString("SiteConnection")))
                using (var cmd = conn.CreateCommand())
                {
                    await conn.OpenAsync();


                    cmd.CommandText = @"

declare @regularReportingType as int = 0
declare @PtoReportingType as int = 1
declare @HolidayReportingType as int = 2
declare @ExcusedWithPayReportingType as int = 3
declare @ExcusedWithOutPayReportingType as int = 4

Select "
                                      + $"	e.{nameof(PayPeriodEmployees.EmployeeId)}, "
                                      + $"    COALESCE(e.Last,'') + ', ' + COALESCE(e.First,'') as {nameof(PayPeriodEmployees.EmployeeName)},"
                                      + $"	IsNull(sum(regular.hours), 0) as {nameof(PayPeriodEmployees.Regular)}, "
                                      + $"	IsNull(sum(regular.overtimehours), 0) as {nameof(PayPeriodEmployees.Overtime)}, "
                                      + $"	IsNull(sum(pto.hours) + sum(pto.overtimehours), 0) as {nameof(PayPeriodEmployees.PTO)},"
                                      + $"	IsNull(sum(holiday.hours) + sum(holiday.overtimehours), 0) as {nameof(PayPeriodEmployees.Holiday)},"
                                      + $"	IsNull(sum(excusedNoPay.hours) + sum(excusedNoPay.overtimehours), 0) as {nameof(PayPeriodEmployees.ExcusedNoPay)},"
                                      + $"	IsNull(sum(excusedWithPay.hours) + sum(excusedWithPay.overtimehours), 0) as {nameof(PayPeriodEmployees.ExcusedWithPay)},"
                                      + $"	e.{nameof(PayPeriodEmployees.IsExempt)},"
                                      + $"	IsNull(sum(te.hours) + sum(te.overtimehours),0) as {nameof(PayPeriodEmployees.Combined)} "
                                      +
                                      @"from 
[dbo].Employees e
left outer join [dbo].TimeEntries te
	on e.EmployeeId = te.EmployeeId
left outer join [dbo].JobTasks jt
	on jt.JobTaskId = te.TaskId
left outer join dbo.TimeEntries regular
	on te.TimeEntryId = regular.TimeEntryId
	and jt.[ReportingClassificationId] = @regularReportingType
left outer join dbo.TimeEntries pto
	on te.TimeEntryId = pto.TimeEntryId
	and jt.[ReportingClassificationId] = @PtoReportingType
left outer join dbo.TimeEntries holiday
	on te.TimeEntryId = holiday.TimeEntryId
	and jt.[ReportingClassificationId] = @HolidayReportingType
left outer join dbo.TimeEntries excusedNoPay
	on te.TimeEntryId = excusedNoPay.TimeEntryId
	and jt.[ReportingClassificationId] = @ExcusedWithOutPayReportingType
left outer join dbo.TimeEntries excusedWithPay
	on te.TimeEntryId = excusedWithPay.TimeEntryId
	and jt.[ReportingClassificationId] = @ExcusedWithPayReportingType
where 
    (te.Date >= @payPeriodStart and te.Date <= @payPeriodEnd)
    and ISNULL(e.[UserName],'') != '*****@*****.**'
group by e.EmployeeId, 
	COALESCE(e.Last,'') + ', ' + COALESCE(e.First,''),
	e.IsExempt
	  "    ;

                    var end = WeekDTO.CreateWithWeekContaining(payPeriodEnd);
                    var ppe = end.WeekEnd;
                    var pps = end.Previous().WeekStart;
                    cmd.Parameters.Add(new SqlParameter("payPeriodStart", end.Previous().WeekStart));
                    cmd.Parameters.Add(new SqlParameter("payPeriodEnd", end.WeekEnd));

                    var data = new PayPeriodReportDTO()
                    {
                        PayPeriodEnd   = ppe,
                        PayPeriodState = pps
                    };
                    var emps = new List <PayPeriodEmployees>();
                    try
                    {
                        var rdr = await cmd.ExecuteReaderAsync();

                        var map = GetColumnMap(rdr.GetColumnSchema());
                        while (await rdr.ReadAsync())
                        {
                            emps.Add(new PayPeriodEmployees()
                            {
                                Combined       = rdr.GetDecimal(map[nameof(PayPeriodEmployees.Combined)]),
                                EmployeeName   = rdr.IsDBNull(map[nameof(PayPeriodEmployees.EmployeeName)]) ? "" : rdr.GetSqlString(map[nameof(PayPeriodEmployees.EmployeeName)]).Value,
                                ExcusedNoPay   = rdr.GetDecimal(map[nameof(PayPeriodEmployees.ExcusedNoPay)]),
                                ExcusedWithPay = rdr.GetDecimal(map[nameof(PayPeriodEmployees.ExcusedWithPay)]),
                                Holiday        = rdr.GetDecimal(map[nameof(PayPeriodEmployees.Holiday)]),
                                IsExempt       = rdr.GetBoolean(map[nameof(PayPeriodEmployees.IsExempt)]),
                                Overtime       = rdr.GetDecimal(map[nameof(PayPeriodEmployees.Overtime)]),
                                Regular        = rdr.GetDecimal(map[nameof(PayPeriodEmployees.Regular)]),
                                PTO            = rdr.GetDecimal(map[nameof(PayPeriodEmployees.PTO)]),
                            });
                        }
                        data.Employees = emps;
                        return(new ReportDTO <PayPeriodReportDTO>()
                        {
                            Data = data,
                            ReportName = "Pay Period Report",
                            RunSettings =
                                new Dictionary <string, string>()
                            {
                                { "Pay Period", $"{pps.ToShortDateString()} thru {ppe.ToShortDateString()}" },
                                { "Check Date/Pay Date", $"{ppe.AddDays(7).ToShortDateString()}" },
                                { "Generated", $"{DateTimeWithZone.EasternStandardTime.ToShortDateString()} at {DateTimeWithZone.EasternStandardTime.ToShortTimeString()}" },
                                { "Company", $"Orion Engineering Co., Inc." },
                            }
                        });
                    }
                    catch (Exception e)
                    {
                        logger.LogError(e, $"Error while running {cmd.CommandText}");
                        throw;
                    }
                }
        }
Пример #11
0
        private static PayPeriodDTO GetPreviousPP(PayPeriodDTO currentPP)
        {
            var week = WeekDTO.CreateWithWeekContaining(currentPP.PayPeriodStart.AddDays(-1));

            return(MapForPPEndWeek(week));
        }
Пример #12
0
        private static PayPeriodDTO GetNextPP(PayPeriodDTO currentPP)
        {
            var week = WeekDTO.CreateWithWeekContaining(currentPP.PayPeriodEnd.AddDays(1));

            return(MapForPPStartWeek(week));
        }
Пример #13
0
        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" },
                        }
                    });
                }
        }
Пример #14
0
        public OrionProfile()
        {
            CreateMap <ClientDTO, DataAccess.EF.Client>().ReverseMap();
            CreateMap <ClientModel, ClientDTO>().ReverseMap();
            CreateMap <SiteModel, SiteDTO>().ReverseMap();
            CreateMap <JobStatusModel, JobStatusDTO>().ReverseMap();
            CreateMap <ProjectManagerModel, ProjectManagerDTO>().ReverseMap();
            CreateMap <DataAccess.EF.Site, SiteDTO>().ReverseMap();
            CreateMap <CreateJobDto, DataAccess.EF.Job>()
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.ProjectManagerEmployeeId))
            .ForMember(x => x.JobStatusId, opt => opt.MapFrom(x => (int)x.JobStatusId))
            .ForMember(x => x.Client, opt => opt.Ignore())
            .ForMember(x => x.JobStatus, opt => opt.Ignore())
            .ForMember(x => x.ProjectManager, opt => opt.Ignore())
            .ForMember(x => x.Site, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.Ignore());

            CreateMap <UpdateJobDto, DataAccess.EF.Job>()
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.ProjectManagerEmployeeId))
            .ForMember(x => x.JobStatusId, opt => opt.MapFrom(x => (int)x.JobStatusId))
            .ForMember(x => x.Client, opt => opt.Ignore())
            .ForMember(x => x.JobStatus, opt => opt.Ignore())
            .ForMember(x => x.ProjectManager, opt => opt.Ignore())
            .ForMember(x => x.Site, opt => opt.Ignore());
            CreateMap <DataAccess.EF.Job, CoreJobDto>()
            .ForMember(x => x.ProjectManagerEmployeeId, opt => opt.MapFrom(z => z.EmployeeId))
            .ForMember(x => x.FullJobCodeWithName, opt => opt.Ignore());

            CreateMap <EmployeeDTO, ProjectManagerModel>()
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.EmployeeName, opt => opt.MapFrom(x => $"{x.Last}, {x.First}"));

            CreateMap <NewScheduledTask, ScheduleTask>()
            .ForMember(x => x.ScheduleTaskId, opt => opt.Ignore());


            //api model <=> ef model
            CreateMap <UpdateMessage <UpdateArcFlashLabelExpenditureMessage, DataAccess.EF.ArcFlashLabelExpenditure>, DataAccess.EF.ArcFlashLabelExpenditure>()
            .ForMember(x => x.DateOfInvoice, opt => opt.MapFrom(x => x.NewValue.model.DateOfInvoice))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.NewValue.model.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.Existing.ExternalId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.Existing.Id))
            .ForMember(x => x.Job, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.NewValue.model.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => DateTimeOffset.Now))
            .ForMember(x => x.Quantity, opt => opt.MapFrom(x => x.NewValue.model.Quantity))
            .ForMember(x => x.TotalLabelsCost, opt => opt.MapFrom(x => x.NewValue.model.TotalLabelsCost))
            .ForMember(x => x.TotalPostageCost, opt => opt.MapFrom(x => x.NewValue.model.TotalPostageCost))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => WeekDTO.CreateWithWeekContaining(x.NewValue.model.DateOfInvoice).WeekId.Value));

            CreateMap <UpdateMessage <UpdateMiscExpenditureMessage, DataAccess.EF.MiscExpenditure>, DataAccess.EF.MiscExpenditure>()
            .ForMember(x => x.ExpensedOn, opt => opt.MapFrom(x => x.NewValue.Model.ExpensedOn))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.NewValue.Model.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.Existing.ExternalId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.Existing.Id))
            .ForMember(x => x.Job, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.NewValue.Model.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => DateTimeOffset.Now))
            .ForMember(x => x.Amount, opt => opt.MapFrom(x => x.NewValue.Model.Amount))
            .ForMember(x => x.Description, opt => opt.MapFrom(x => x.NewValue.Model.Description))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => WeekDTO.CreateWithWeekContaining(x.NewValue.Model.ExpensedOn).WeekId.Value));

            CreateMap <UpdateMessage <UpdateContractorMessage, DataAccess.EF.ContractorExpenditure>, DataAccess.EF.ContractorExpenditure>()
            .ForMember(x => x.ExpensedOn, opt => opt.MapFrom(x => x.NewValue.Model.ExpensedOn))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.NewValue.Model.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.Existing.ExternalId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.Existing.Id))
            .ForMember(x => x.Job, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.NewValue.Model.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => DateTimeOffset.Now))
            .ForMember(x => x.TotalPOContractAmount, opt => opt.MapFrom(x => x.NewValue.Model.TotalPOContractAmount))
            .ForMember(x => x.OrionPONumber, opt => opt.MapFrom(x => x.NewValue.Model.OrionPONumber))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => WeekDTO.CreateWithWeekContaining(x.NewValue.Model.ExpensedOn).WeekId.Value));

            CreateMap <UpdateMessage <UpdateTimeAndExpenseExpenditureMessage, DataAccess.EF.TimeAndExpenceExpenditure>, DataAccess.EF.TimeAndExpenceExpenditure>()
            .ForMember(x => x.ExpenseOnDate, opt => opt.MapFrom(x => x.NewValue.Model.ExpenseOnDate))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.NewValue.Model.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.Existing.ExternalId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.Existing.Id))
            .ForMember(x => x.Job, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.NewValue.Model.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => DateTimeOffset.Now))
            .ForMember(x => x.Amount, opt => opt.MapFrom(x => x.NewValue.Model.Amount))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => WeekDTO.CreateWithWeekContaining(x.NewValue.Model.ExpenseOnDate).WeekId.Value));

            CreateMap <UpdateMessage <UpdateCompanyVehicleExpenditureMessage, DataAccess.EF.CompanyVehicleExpenditure>, DataAccess.EF.CompanyVehicleExpenditure>()
            .ForMember(x => x.DateVehicleFirstUsed, opt => opt.MapFrom(x => x.NewValue.Model.DateVehicleFirstUsed))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.NewValue.Model.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.Existing.ExternalId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.Existing.Id))
            .ForMember(x => x.Job, opt => opt.Ignore())
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.NewValue.Model.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => DateTimeOffset.Now))
            .ForMember(x => x.CompanyVehicle, opt => opt.Ignore())
            .ForMember(x => x.CompanyVehicleId, opt => opt.MapFrom(x => (int)x.NewValue.Model.Vehicle))
            .ForMember(x => x.TotalMiles, opt => opt.MapFrom(x => x.NewValue.Model.TotalMiles))
            .ForMember(x => x.TotalNumberOfDaysUsed, opt => opt.MapFrom(x => x.NewValue.Model.TotalNumberOfDaysUsed))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.Existing.WeekId));


            CreateMap <DataAccess.EF.ArcFlashLabelExpenditure, orion.web.api.expenditures.Models.ArcFlashLabelExpenditure>()
            .ForMember(x => x.DateOfInvoice, opt => opt.MapFrom(x => x.DateOfInvoice))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.ExternalId))
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => x.LastModified))
            .ForMember(x => x.Quantity, opt => opt.MapFrom(x => x.Quantity))
            .ForMember(x => x.TotalLabelsCost, opt => opt.MapFrom(x => x.TotalLabelsCost))
            .ForMember(x => x.TotalPostageCost, opt => opt.MapFrom(x => x.TotalPostageCost))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.WeekId));

            CreateMap <DataAccess.EF.CompanyVehicleExpenditure, orion.web.api.expenditures.Models.CompanyVehicleExpenditure>()
            .ForMember(x => x.DateVehicleFirstUsed, opt => opt.MapFrom(x => x.DateVehicleFirstUsed))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.ExternalId))
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => x.LastModified))
            .ForMember(x => x.TotalMiles, opt => opt.MapFrom(x => x.TotalMiles))
            .ForMember(x => x.TotalNumberOfDaysUsed, opt => opt.MapFrom(x => x.TotalNumberOfDaysUsed))
            .ForMember(x => x.Vehicle, opt => opt.MapFrom(x => (CompanyVehicleDescriptor)x.CompanyVehicleId))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.WeekId));

            CreateMap <DataAccess.EF.ContractorExpenditure, orion.web.api.expenditures.Models.ContractorExpenditure>()
            .ForMember(x => x.CompanyName, opt => opt.MapFrom(x => x.CompanyName))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.ExternalId, opt => opt.MapFrom(x => x.ExternalId))
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => x.LastModified))
            .ForMember(x => x.OrionPONumber, opt => opt.MapFrom(x => x.OrionPONumber))
            .ForMember(x => x.TotalPOContractAmount, opt => opt.MapFrom(x => x.TotalPOContractAmount))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.WeekId));

            CreateMap <DataAccess.EF.MiscExpenditure, orion.web.api.expenditures.Models.MiscExpenditure>()
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.ExternalId))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.Amount, opt => opt.MapFrom(x => x.Amount))
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => x.LastModified))
            .ForMember(x => x.Description, opt => opt.MapFrom(x => x.Description))
            .ForMember(x => x.ExpensedOn, opt => opt.MapFrom(x => x.ExpensedOn))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.WeekId));

            CreateMap <DataAccess.EF.TimeAndExpenceExpenditure, orion.web.api.expenditures.Models.TimeAndExpenceExpenditure>()
            .ForMember(x => x.Id, opt => opt.MapFrom(x => x.ExternalId))
            .ForMember(x => x.EmployeeId, opt => opt.MapFrom(x => x.EmployeeId))
            .ForMember(x => x.Amount, opt => opt.MapFrom(x => x.Amount))
            .ForMember(x => x.JobId, opt => opt.MapFrom(x => x.JobId))
            .ForMember(x => x.LastModified, opt => opt.MapFrom(x => x.LastModified))
            .ForMember(x => x.ExpenseOnDate, opt => opt.MapFrom(x => x.ExpenseOnDate))
            .ForMember(x => x.WeekId, opt => opt.MapFrom(x => x.WeekId));
        }
Пример #15
0
        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);
            }
        }