Пример #1
0
 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;
     }
 }
Пример #2
0
        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();
            }
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
 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();
     }
 }
Пример #5
0
        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();
            }
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
 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();
     }
 }