예제 #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 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();
            }
        }
예제 #3
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();
            }
        }