public void Add(string departmentName, string departmentCode) { using (var context = new CERPContext()) { if (string.IsNullOrWhiteSpace(departmentName)) { throw new ArgumentException("Invalid department name"); } if (string.IsNullOrWhiteSpace(departmentCode)) { throw new ArgumentException("Invalid department code"); } if (context.Departments.Any(d => d.Name == departmentName.Trim())) { throw new Exception("A department with the specified name already exists"); } context.Departments.Add(new Department { Name = departmentName.Trim(), DepartmentCode = departmentCode.Trim() }); context.SaveChanges(); } }
public void AddDraft(Payroll payroll) { using (var context = new CERPContext()) { var newWagePayment = new WagePayment { PeriodName = payroll.Period, StartDate = payroll.StartDate.Date, EndDate = payroll.EndDate.Date, PaymentFrequency = payroll.PaymentFrequency, WagePaymentDetails = (from detail in payroll.PayrollDetails select new WagePaymentDetail { EmployeeID = detail.Employee.EmployeeID, GrossSalary = detail.GrossSalary, IncomeTax = detail.IncomeTax, OtherDeduction = detail.OtherDeductions, PensionContribution = detail.Pension }).ToList() }; var wagePaymentStatus = new WagePaymentStatusHistory { WagePayment = newWagePayment, WagePaymentStatusCode = "DRFT", StatusChangedDate = DateTime.Now }; context.WagePayments.Add(newWagePayment); context.WagePaymentStatusHistory.Add(wagePaymentStatus); context.SaveChanges(); payroll.PayrollID = newWagePayment.WagePaymentID; } }
public void ConfirmPayment(Payroll payroll) { AddDraft(payroll); using (var context = new CERPContext()) { var wagePayment = context.WagePayments.SingleOrDefault(w => w.WagePaymentID == payroll.PayrollID); if (wagePayment == null) { throw new Exception("Payroll not found"); } // TODO: Check the Payroll has not already been confirmed var wagePaymentStatus = new WagePaymentStatusHistory { WagePayment = wagePayment, WagePaymentStatusCode = "CNFRM", StatusChangedDate = DateTime.Now }; context.WagePaymentStatusHistory.Add(wagePaymentStatus); // Queue Payslip foreach (var wagePaymentDetail in wagePayment.WagePaymentDetails) { var payslipQueue = new PaySlipQueue { EmployeeID = wagePaymentDetail.EmployeeID, WagePaymentID = wagePaymentDetail.WagePaymentID, SentFlag = false, QueuedDate = DateTime.Now }; context.PaySlipQueues.Add(payslipQueue); } context.SaveChanges(); } }
public Payroll CreateNew(string periodName, DateTime startDate, DateTime endDate, Models.HumanResources.PaymentFrequency paymentFrequency) { using (var context = new CERPContext()) { var payFrequency = (byte)paymentFrequency; var payment = context.WagePayments.ToList().Any(m => (m.StartDate.Date == startDate.Date && m.EndDate.Date == endDate.Date) || (m.StartDate.Date == startDate.Date && m.PayFrequency == payFrequency) || (m.EndDate.Date == endDate.Date && m.PayFrequency == payFrequency)); if (payment) { throw new ArgumentException("A payment with the supplied parameters already exists"); } var payroll = new Payroll { Period = periodName, StartDate = startDate.Date, EndDate = endDate.Date, PaymentFrequency = paymentFrequency }; var employees = context.ExtendedEmployees.Where(e => e.PayFrequency == payFrequency && e.IsCurrent).ToList(); payroll.PayrollDetails = employees.Select(e => new PayrollDetail { Employee = _employeeService.GetEmployee(e.EmployeeID), GrossSalary = e.Rate, IncomeTax = CalculateIncomeTax(e.Rate), Pension = CalculatePension(e.Rate) }).ToList(); return(payroll); } }
public Employee GetEmployee(int employeeID) { using (var context = new CERPContext()) { var employee = context.ExtendedEmployees.SingleOrDefault(e => e.EmployeeID == employeeID); if (employee == null) { throw new Exception("An employee with the specified id could not be found"); } return(new Employee { EmployeeID = employee.EmployeeID, FirstName = employee.FirstName, MiddleName = employee.MiddleName, LastName = employee.LastName, Department = _departmentService.GetDepartment(employee.DepartmentID), DateOfBirth = employee.DateOfBirth.Date, Salary = employee.Rate, PaymentFrequency = employee.PaymentFrequency, Gender = employee.Gender, EmailAddress = employee.EmailAddress, MaritalStatus = employee.Status.GetValueOrDefault(), JobTitle = employee.JobTitle }); } }
public void ChangePaymentFrequency(Employee employee, Models.HumanResources.PaymentFrequency paymentFrequency) { using (var context = new CERPContext()) { var payHistory = new Models.HumanResources.EmployeePayHistory { EmployeeID = employee.EmployeeID, }; } }
public ICollection <Domain.Department> GetDepartments() { using (var context = new CERPContext()) { return((from d in context.Departments select new Domain.Department() { DepartmentID = d.DepartmentID, Name = d.Name }).ToList()); } }
public Queue <PaySlipInformation> GetQueuedPaySlips() { using (var context = new CERPContext()) { var slipQueue = new Queue <PaySlipInformation>(); var queuedSlips = (from q in context.PaySlipQueue where !q.SentFlag select q).OrderBy(q => q.QueuedDate).ToList(); var wagePayments = queuedSlips.Select(q => q.WagePayment).Distinct().ToList(); var employees = queuedSlips.Select(q => q.Employee).Distinct().ToList(); var paymentDetails = context.WagePaymentDetails.Where( p => wagePayments.Select(w => w.WagePaymentID).Contains(p.WagePaymentID)); foreach (var paySlipQueue in queuedSlips) { var slipInformation = new PaySlipInformation(); var employee = employees.Single(e => e.EmployeeID == paySlipQueue.EmployeeID); slipInformation.Employee = new Employee { EmployeeID = employee.EmployeeID, FirstName = employee.FirstName, LastName = employee.LastName, EmailAddress = employee.EmailAddress }; var wagePayment = wagePayments.Single(w => w.WagePaymentID == paySlipQueue.WagePaymentID); slipInformation.PaySlipPeriod = wagePayment.PeriodName; slipInformation.WagePaymentID = wagePayment.WagePaymentID; var paymentDetail = wagePayment.WagePaymentDetails.Single( p => p.WagePaymentID == slipInformation.WagePaymentID && p.EmployeeID == slipInformation.Employee.EmployeeID); slipInformation.Slip = new PaySlipModel { EmployeeName = slipInformation.Employee.FirstName + slipInformation.Employee.LastName, CompanyName = "International Community School", GrossIncome = paymentDetail.GrossSalary, IncomeTax = paymentDetail.IncomeTax, Pension = paymentDetail.PensionContribution, Other = paymentDetail.OtherDeduction, NetPay = paymentDetail.NetPay, PaySclipDate = DateTime.Today }; slipQueue.Enqueue(slipInformation); } return(slipQueue); } }
public Domain.Department GetDepartment(int departmentID) { using (var context = new CERPContext()) { var department = context.Departments.SingleOrDefault(d => d.DepartmentID == departmentID); if (department == null) { throw new Exception("A department with the specified id was not found."); } return(new Domain.Department() { DepartmentID = departmentID, Name = department.Name }); } }
public void Terminate(Employee employee) { using (var context = new CERPContext()) { var employeeToBeTerminated = context.Employees.SingleOrDefault(e => e.EmployeeID == employee.EmployeeID); if (employeeToBeTerminated == null) { throw new Exception("The specified employee record was not found."); } if (!employeeToBeTerminated.IsCurrent) { throw new Exception("The specified employee has already been terminated."); } employeeToBeTerminated.IsCurrent = false; context.SaveChanges(); } }
public void SendPaySlip(PaySlipInformation paySlip) { var fileName = string.Format("{0}.pdf", Guid.NewGuid()); var mail = Compose(paySlip, fileName); var recipient = new EmailAccount(paySlip.Employee.EmailAddress); _mailService.Send(mail, recipient); // Remove queue from database using (var context = new CERPContext()) { var queue = context.PaySlipQueue.Single( q => q.EmployeeID == paySlip.Employee.EmployeeID && q.WagePaymentID == paySlip.WagePaymentID); queue.SentFlag = true; context.SaveChanges(); } }
public void Cancel(Payroll payroll) { using (var context = new CERPContext()) { var wagePayment = context.WagePayments.SingleOrDefault(w => w.WagePaymentID == payroll.PayrollID); if (wagePayment == null) { throw new Exception("Payroll not found"); } // TODO: Check the Payroll has not already been confirmed var wagePaymentStatus = new WagePaymentStatusHistory { WagePayment = wagePayment, WagePaymentStatusCode = "CNCL", StatusChangedDate = DateTime.Now }; context.WagePaymentStatusHistory.Add(wagePaymentStatus); context.SaveChanges(); } }
public ICollection <Employee> GetEmployees() { using (var context = new CERPContext()) { var employees = from employee in context.ExtendedEmployees.Where(e => e.IsCurrent) select new Employee { EmployeeID = employee.EmployeeID, FirstName = employee.FirstName, MiddleName = employee.MiddleName, LastName = employee.LastName, Department = _departmentService.GetDepartment(employee.DepartmentID), DateOfBirth = employee.DateOfBirth.Date, Salary = employee.Rate, PaymentFrequency = employee.PaymentFrequency, Gender = employee.Gender, EmailAddress = employee.EmailAddress, MaritalStatus = employee.Status.GetValueOrDefault(), JobTitle = employee.JobTitle }; return(employees.ToList()); } }
public void Add(Employee employee) { using (var context = new CERPContext()) { var newEmployee = new Models.HumanResources.Employee { FirstName = employee.FirstName, LastName = employee.LastName, DateOfBirth = employee.DateOfBirth, EmailAddress = employee.EmailAddress, EmployeeMaritalStatus = employee.MaritalStatus, DateOfHire = DateTime.Today, IsCurrent = true, Gender = employee.Gender, JobTitle = employee.JobTitle, MiddleName = employee.MiddleName }; var department = new Models.HumanResources.EmployeeDepartmentHistory { Employee = newEmployee, DepartmentID = employee.Department.DepartmentID, ShiftID = 1, StartDate = DateTime.Today }; var payInfo = new Models.HumanResources.EmployeePayHistory { Employee = newEmployee, PayFrequency = (byte)employee.PaymentFrequency, Rate = employee.Salary, RateChangedDate = DateTime.Today }; context.Employees.Add(newEmployee); context.EmployeeDepartmentHistory.Add(department); context.EmployeePayHistory.Add(payInfo); context.SaveChanges(); } }
public void UpdateSalary(Employee employee, decimal newSalary) { using (var context = new CERPContext()) { } }
public void Remove(Domain.Employee employee) { using (var context = new CERPContext()) { } }