///<summary>Retrieve the employees weekly timesheet</summary>> public WeeklyPayslip GetEmpoyeeTimesheet( Employee employee, Company company, List <Timesheet> employeeTimesheets, PayAgreement payAgreement, double payYTD ) { //If timesheets are not of a weekly capacity throw exception if (employeeTimesheets.Capacity > 7 || employeeTimesheets.Capacity < 1) { throw new ArgumentOutOfRangeException(); } //Helper method for calculating hours worked in a day Func <Timesheet, double> hoursWorked = x => (double)((x.EndTime - x.StartTime) - x.Break).TotalHours; var firstDate = employeeTimesheets[0].Date; var startOfWeek = firstDate.AddDays(-(int)firstDate.DayOfWeek); double baseHours = 0; double satHours = 0; double sunHours = 0; foreach (var ts in employeeTimesheets) { if (ts.Date.DayOfWeek == DayOfWeek.Saturday) { satHours += hoursWorked(ts); } if (ts.Date.DayOfWeek == DayOfWeek.Sunday) { sunHours += hoursWorked(ts); } else { baseHours += hoursWorked(ts); } } //Employe pay is calculated as <(week hours) * payrate> + <weekend hours * (payrate * penalties)> var pay = (baseHours * (double)payAgreement.PayRate) + (satHours * ((double)payAgreement.PayRate * payAgreement.SaturdayRate)) + (sunHours * ((double)payAgreement.PayRate * payAgreement.SundayRate)); return(new WeeklyPayslip ( employee, company, startOfWeek, pay, payYTD, baseHours, satHours, sunHours )); }
/// <summary> /// This function activates a business service that creates an Employees timesheet for a given week /// </summary> /// <param name="employee">An Employee object</param> /// <param name="company">A Company object</param> /// <param name="employeeTimesheets">A List of all Timesheets for a given weekly period</param> /// <param name="payAgreement">An Employee pay agreement with a given Company</param> /// <param name="payYTD">An Employees Pay of the Year to Date of a given financial year</param> /// <returns>Weekly Payslip of a given Employees weekly hours worked</returns> public WeeklyPayslip EmployeeWeeklyTimeSheet( Employee employee, Company company, List <Timesheet> employeeTimesheets, PayAgreement payAgreement, double payYTD ) { return(_payservice.GetEmpoyeeTimesheet(employee, company, employeeTimesheets, payAgreement, payYTD)); }
public static PayAgreement CreatePayAgreement(string dataAreaId, string payAgreementCode, global::System.DateTimeOffset fromDate, global::System.DateTimeOffset toDate) { PayAgreement payAgreement = new PayAgreement(); payAgreement.dataAreaId = dataAreaId; payAgreement.PayAgreementCode = payAgreementCode; payAgreement.FromDate = fromDate; payAgreement.ToDate = toDate; return(payAgreement); }
public ActionResult Post(long abn, string empID, int payRate) { try { var check_emp = unitOfWork.Employees.SingleOrDefault(x => x.Id == empID); var check_cmp = unitOfWork.Companies.SingleOrDefault(x => x.ABN == abn); if (check_emp == null || check_cmp == null) { return(BadRequest("Employee or Company does not exist in system")); } var agreement = new PayAgreement { DateCreated = DateTime.Now, EmployeeID = empID, CompanyABN = abn, PayRate = payRate, SaturdayRate = 1.2, SundayRate = 1.5, PublicHolidayRate = 1.9 }; unitOfWork.PayAgreements.Add(agreement); var response = unitOfWork.Complete(); if (response > 0) { return(Ok()); } return(BadRequest("Agreement could not be saved")); } catch (Exception e) { _logger.LogError(e.Message); } return(BadRequest()); }