コード例 #1
0
        public void GenerateDeductions(DateTime payrollDate, DateTime payrollStartDate,
                                       DateTime payrollEndDate, IList <EmployeePayroll> employeePayrolls)
        {
            //If proceed is false return
            if (!_employeePayrollDeductionService
                .proceedDeduction(payrollStartDate, payrollEndDate))
            {
                return;
            }

            foreach (EmployeePayroll payroll in employeePayrolls)
            {
                //Generate deductions such as SSS, HDMF, Philhealth and TAX
                var totalDeductions =
                    _employeePayrollDeductionService.GenerateDeductionsByPayroll(payroll);

                //Update employeePayroll total deductions and taxable income
                Update(payroll);
                payroll.TaxableIncome   = payroll.TotalGross - totalDeductions;
                payroll.TotalDeduction += totalDeductions;
                payroll.TotalNet        = payroll.TotalGross - payroll.TotalDeduction;

                //Compute Tax if enabled
                int taxEnabled = Convert.ToInt32(_settingService.GetByKey(TAX_ENABLED));
                if (taxEnabled > 0)
                {
                    GenerateTax(payroll);
                }
            }

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                //Print error
            }
        }
コード例 #2
0
        public void GenerateDeduction()
        {
            Initialize();
            DeleteInfo();

            //Initialize Data
            var employee = new Employee
            {
                EmployeeCode = "11001",
                FirstName    = "Jona",
                LastName     = "Pereira",
                MiddleName   = "Aprecio",
                BirthDate    = DateTime.Parse("02/02/1991"),
                Gender       = 1,
                IsActive     = true
            };

            var employee2 = new Employee
            {
                EmployeeCode = "11002",
                FirstName    = "Cornelio Jr.",
                LastName     = "Cawicaan",
                MiddleName   = "Bue",
                BirthDate    = DateTime.Parse("10/30/1981"),
                Gender       = 1,
                IsActive     = true
            };

            var employeeInfo = new EmployeeInfo
            {
                Employee        = employee,
                SalaryFrequency = FrequencyType.Weekly,
                Salary          = 1000
            };

            var employeeInfo2 = new EmployeeInfo
            {
                Employee        = employee2,
                SalaryFrequency = FrequencyType.Weekly,
                Salary          = 900
            };

            _employeeInfoRepository.Add(employeeInfo);
            _employeeInfoRepository.Add(employeeInfo2);

            var employeeDeduction = new EmployeeDeduction
            {
                EmployeeId  = 1,
                DeductionId = HDMF_DEDUCTION_ID,
                Amount      = 100.10M
            };

            var employeeDeduction2 = new EmployeeDeduction
            {
                EmployeeId  = 1,
                DeductionId = SSS_DEDUCTION_ID,
                Amount      = 50.25M
            };

            var employeeDeduction3 = new EmployeeDeduction
            {
                EmployeeId  = 1,
                DeductionId = PHILHEALTH_DEDUCTION_ID,
                Amount      = 50.25M
            };

            var employeeDeduction4 = new EmployeeDeduction
            {
                EmployeeId  = 2,
                DeductionId = HDMF_DEDUCTION_ID,
                Amount      = 100.20M
            };

            var employeeDeduction5 = new EmployeeDeduction
            {
                EmployeeId  = 2,
                DeductionId = SSS_DEDUCTION_ID,
                Amount      = 45.5M
            };

            var employeeDeduction6 = new EmployeeDeduction
            {
                EmployeeId  = 2,
                DeductionId = PHILHEALTH_DEDUCTION_ID,
                Amount      = 55.90M
            };

            _employeeDeductionRepository.Add(employeeDeduction);
            _employeeDeductionRepository.Add(employeeDeduction2);
            _employeeDeductionRepository.Add(employeeDeduction3);
            _employeeDeductionRepository.Add(employeeDeduction4);
            _employeeDeductionRepository.Add(employeeDeduction5);
            _employeeDeductionRepository.Add(employeeDeduction6);

            var employeePayroll = new EmployeePayroll
            {
                EmployeeId      = 1,
                IsTaxed         = false,
                TaxableIncome   = 1500,
                TotalNet        = 1500,
                CutOffStartDate = DateTime.Parse("05/04/2016"),
                CutOffEndDate   = DateTime.Parse("05/10/2016"),
                PayrollDate     = DateTime.Parse("05/11/2016"),
                TotalGross      = 1500
            };

            var employeePayroll2 = new EmployeePayroll
            {
                EmployeeId      = 1,
                IsTaxed         = false,
                TaxableIncome   = 1300.25M,
                TotalNet        = 1300.25M,
                CutOffStartDate = DateTime.Parse("05/11/2016"),
                CutOffEndDate   = DateTime.Parse("05/17/2016"),
                PayrollDate     = DateTime.Parse("05/18/2016"),
                TotalGross      = 1300.25M
            };

            var employeePayroll3 = new EmployeePayroll
            {
                EmployeeId      = 1,
                IsTaxed         = false,
                TaxableIncome   = 1500.25M,
                TotalNet        = 1500.25M,
                CutOffStartDate = DateTime.Parse("05/18/2016"),
                CutOffEndDate   = DateTime.Parse("05/24/2016"),
                PayrollDate     = DateTime.Parse("05/25/2016"),
                TotalGross      = 1500.25M
            };

            var employeePayroll4 = new EmployeePayroll
            {
                EmployeeId      = 1,
                IsTaxed         = false,
                TaxableIncome   = 950.50M,
                TotalNet        = 950.50M,
                CutOffStartDate = DateTime.Parse("05/25/2016"),
                CutOffEndDate   = DateTime.Parse("05/31/2016"),
                PayrollDate     = DateTime.Parse("06/01/2016"),
                TotalGross      = 950.50M
            };

            var employeePayroll5 = new EmployeePayroll
            {
                EmployeeId      = 2,
                IsTaxed         = false,
                TaxableIncome   = 2000.05M,
                TotalNet        = 2000.05M,
                CutOffStartDate = DateTime.Parse("05/04/2016"),
                CutOffEndDate   = DateTime.Parse("05/10/2016"),
                PayrollDate     = DateTime.Parse("05/11/2016"),
                TotalGross      = 2000.05M
            };

            var employeePayroll6 = new EmployeePayroll
            {
                EmployeeId      = 2,
                IsTaxed         = false,
                TaxableIncome   = 2100,
                TotalNet        = 2100,
                CutOffStartDate = DateTime.Parse("05/11/2016"),
                CutOffEndDate   = DateTime.Parse("05/17/2016"),
                PayrollDate     = DateTime.Parse("05/18/2016"),
                TotalGross      = 2100
            };

            var employeePayroll7 = new EmployeePayroll
            {
                EmployeeId      = 2,
                IsTaxed         = false,
                TaxableIncome   = 2200.50M,
                TotalNet        = 2200.50M,
                CutOffStartDate = DateTime.Parse("05/18/2016"),
                CutOffEndDate   = DateTime.Parse("05/24/2016"),
                PayrollDate     = DateTime.Parse("05/25/2016"),
                TotalGross      = 2200.50M
            };

            var employeePayroll8 = new EmployeePayroll
            {
                EmployeeId      = 2,
                IsTaxed         = false,
                TaxableIncome   = 750.50M,
                TotalNet        = 750.50M,
                CutOffStartDate = DateTime.Parse("05/25/2016"),
                CutOffEndDate   = DateTime.Parse("05/31/2016"),
                PayrollDate     = DateTime.Parse("06/01/2016"),
                TotalGross      = 750.50M
            };


            _employeePayrollRepository.Add(employeePayroll);
            _employeePayrollRepository.Add(employeePayroll2);
            _employeePayrollRepository.Add(employeePayroll3);
            _employeePayrollRepository.Add(employeePayroll4);
            _employeePayrollRepository.Add(employeePayroll5);
            _employeePayrollRepository.Add(employeePayroll6);
            _employeePayrollRepository.Add(employeePayroll7);
            _employeePayrollRepository.Add(employeePayroll8);

            _unitOfWork.Commit();

            //Current payroll
            IList <EmployeePayroll> payrollList = new List <EmployeePayroll>();

            payrollList.Add(employeePayroll4);
            payrollList.Add(employeePayroll8);

            decimal[] results = { 200.6m, 201.6m };
            //Test
            var counter = 0;

            foreach (EmployeePayroll payroll in payrollList)
            {
                var totalDeductions = _employeePayrollDeductionService
                                      .GenerateDeductionsByPayroll(payroll);

                Assert.AreEqual(results[counter], totalDeductions);

                counter++;
            }

            _unitOfWork.Commit();

            //Verify
            var startDate = DateTime.Parse("06/01/2016");
            var endDate   = DateTime.Parse("06/01/2016");

            /*IList<EmployeePayroll> finalizedPayroll = _employeePayrollService.GetByDateRange(startDate, endDate);
             *
             * Assert.IsNotNull(finalizedPayroll);
             *
             * Assert.AreEqual(2, finalizedPayroll.Count());
             * Assert.AreEqual(1, finalizedPayroll[0].EmployeeId);
             * Assert.AreEqual(false, finalizedPayroll[0].IsTaxed);
             * Assert.AreEqual(DateTime.Parse("05/25/2016"), finalizedPayroll[0].CutOffStartDate);
             * Assert.AreEqual(DateTime.Parse("05/31/2016"), finalizedPayroll[0].CutOffEndDate);
             * Assert.AreEqual(DateTime.Parse("06/01/2016"), finalizedPayroll[0].PayrollDate);
             * Assert.AreEqual(749.9M, finalizedPayroll[0].TaxableIncome);
             * Assert.AreEqual(950.50M, finalizedPayroll[0].TotalGross);*/

            //Get all deductions
            IList <EmployeePayrollDeduction> employeePayrollDeduction
                = _employeePayrollDeductionService.GetByPayroll(4);

            Assert.AreEqual(3, employeePayrollDeduction.Count());

            Assert.AreEqual(employeePayrollDeduction[0].EmployeeId, 1);
            Assert.AreEqual(employeePayrollDeduction[0].EmployeePayrollId, 4);
            Assert.AreEqual(employeePayrollDeduction[0].Amount, 100.10M);
            Assert.AreEqual(employeePayrollDeduction[0].DeductionId, HDMF_DEDUCTION_ID);

            Assert.AreEqual(employeePayrollDeduction[1].EmployeeId, 1);
            Assert.AreEqual(employeePayrollDeduction[1].EmployeePayrollId, 4);
            Assert.AreEqual(employeePayrollDeduction[1].Amount, 50.25M);
            Assert.AreEqual(employeePayrollDeduction[1].DeductionId, SSS_DEDUCTION_ID);

            Assert.AreEqual(employeePayrollDeduction[2].EmployeeId, 1);
            Assert.AreEqual(employeePayrollDeduction[2].EmployeePayrollId, 4);
            Assert.AreEqual(employeePayrollDeduction[2].Amount, 50.25M);
            Assert.AreEqual(employeePayrollDeduction[2].DeductionId, PHILHEALTH_DEDUCTION_ID);

            //Check Tax

            /*Assert.AreEqual(employeePayrollDeduction[3].EmployeeId, 1);
             * Assert.AreEqual(employeePayrollDeduction[3].EmployeePayrollId, 4);
             * Assert.AreEqual(employeePayrollDeduction[3].Amount, 46.71M);
             * Assert.AreEqual(employeePayrollDeduction[3].DeductionId, TAX_DEDUCTION_ID);*/

            /*Assert.AreEqual(2, finalizedPayroll[1].EmployeeId);
             * Assert.AreEqual(true, finalizedPayroll[1].IsTaxed);
             * Assert.AreEqual(DateTime.Parse("05/25/2016"), finalizedPayroll[1].CutOffStartDate);
             * Assert.AreEqual(DateTime.Parse("05/31/2016"), finalizedPayroll[1].CutOffEndDate);
             * Assert.AreEqual(DateTime.Parse("06/01/2016"), finalizedPayroll[1].PayrollDate);
             * Assert.AreEqual(548.90M, finalizedPayroll[1].TaxableIncome);
             * Assert.AreEqual(750.50M, finalizedPayroll[1].TotalGross);
             * Assert.AreEqual(437.2975M, finalizedPayroll[1].TotalDeduction);
             * Assert.AreEqual(313.2025M, finalizedPayroll[1].TotalNet);*/

            employeePayrollDeduction
                = _employeePayrollDeductionService.GetByPayroll(8);

            Assert.AreEqual(3, employeePayrollDeduction.Count());

            Assert.AreEqual(employeePayrollDeduction[0].EmployeeId, 2);
            Assert.AreEqual(employeePayrollDeduction[0].EmployeePayrollId, 8);
            Assert.AreEqual(employeePayrollDeduction[0].Amount, 100.20M);
            Assert.AreEqual(employeePayrollDeduction[0].DeductionId, HDMF_DEDUCTION_ID);

            Assert.AreEqual(employeePayrollDeduction[1].EmployeeId, 2);
            Assert.AreEqual(employeePayrollDeduction[1].EmployeePayrollId, 8);
            Assert.AreEqual(employeePayrollDeduction[1].Amount, 45.5M);
            Assert.AreEqual(employeePayrollDeduction[1].DeductionId, SSS_DEDUCTION_ID);

            Assert.AreEqual(employeePayrollDeduction[2].EmployeeId, 2);
            Assert.AreEqual(employeePayrollDeduction[2].EmployeePayrollId, 8);
            Assert.AreEqual(employeePayrollDeduction[2].Amount, 55.90M);
            Assert.AreEqual(employeePayrollDeduction[2].DeductionId, PHILHEALTH_DEDUCTION_ID);

            //Check Tax

            /*Assert.AreEqual(employeePayrollDeduction[3].EmployeeId, 2);
             * Assert.AreEqual(employeePayrollDeduction[3].EmployeePayrollId, 8);
             * Assert.AreEqual(employeePayrollDeduction[3].Amount, 235.6975M);
             * Assert.AreEqual(employeePayrollDeduction[3].DeductionId, TAX_DEDUCTION_ID);*/
        }