コード例 #1
0
        private void GenerateResult(List <PayslipInfo> list)
        {
            IWorkbook workbookSource = this.ReadFile(SourceDataFilePath);
            ISheet    sheet          = workbookSource.GetSheetAt(0);

            for (int i = 1; i <= sheet.LastRowNum; i++)
            {
                IRow row = sheet.GetRow(i);
                if (row != null)
                {
                    PayslipInfo info = list[i - 1];
                    for (int j = 4; j < 10; j++)
                    {
                        ICell cell = row.GetCell(j);
                        if (cell == null)
                        {
                            row.CreateCell(j);
                        }
                    }
                    row.GetCell(4).SetCellValue(info.Employee.FullName);
                    row.GetCell(5).SetCellValue(info.PayPeriod);
                    row.GetCell(6).SetCellValue(info.GrossIncome);
                    row.GetCell(7).SetCellValue(info.IncomeTax);
                    row.GetCell(8).SetCellValue(info.NetIncome);
                    row.GetCell(9).SetCellValue(info.Super);
                }
            }
            using (FileStream file = new FileStream(Path.Combine(this.ResultOutputPath, "EmployeeSalaryData" + Guid.NewGuid().ToString().GetHashCode() + ".xlsx"), FileMode.Create))
            {
                workbookSource.Write(file);
                file.Close();
                MessageBox.Show("Done!", "OK", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
コード例 #2
0
        public void GeneratePayslipForEmployee_TestData2_ReturnExpectedData()
        {
            //Arrange
            var mockTaxCalculator = new Mock <ITaxCalculatorService>();

            mockTaxCalculator.Setup(tc => tc.CalculateIncomeTax(It.IsAny <int>(), Enums.CalculationFrequency.Monthly)).Returns(2696);
            IPayslipService _payslipService = new PayslipService(mockTaxCalculator.Object);

            var data = new EmployeeInformation()
            {
                EmployeeFirstName = "Ryan",
                EmployeeLastName  = "Chen",
                AnnualSalary      = 120000,
                PayslipFrequency  = Enums.CalculationFrequency.Monthly,
                SuperRate         = 10,
                PayPeriod         = "01 Mar-31 Mar"
            };

            var expectedResult = new PayslipInfo()
            {
                Name        = "Ryan Chen",
                GrossIncome = 10000,
                IncomeTax   = 2696,
                Super       = 1000,
                PayPeriod   = "01 Mar-31 Mar"
            };

            //Act
            var payslip = _payslipService.GeneratePayslipForEmployee(data);

            //Assert
            Assert.AreEqual(expectedResult.NetIncome, payslip.NetIncome);
            Assert.AreEqual(expectedResult.ToString(), payslip.ToString());
        }
コード例 #3
0
        public void ProcessOutputTest()
        {
            string expected = "David Rudd,01 March - 31 March,5004,922,4082,450";

            PayslipInfo payslipInfo = new PayslipInfo(new Calculator.Entities.Employee("David", "Rudd")
                                                      , "01 March - 31 March", 0.09m, 5004, 922, 4082, 450);

            var    outputProcessor = new OutputProcessor();
            string actual          = outputProcessor.Process(payslipInfo);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public static string GetPayslip(string input)
        {
            var inputProcessor   = new InputProcessor();
            var payslipGenerator = new PayslipCalculator();
            var outputProcessor  = new OutputProcessor();

            //InputProcessor will split the required Input from string
            payslipInput = inputProcessor.Process(input);

            //Payslip Generator internally will calculate tax and create tax table to prepare payslip
            payslipInfo = payslipGenerator.Calculate(payslipInput);

            //OutputProcessor will join the output in string
            return(outputProcessor.Process(payslipInfo));
        }
コード例 #5
0
        public PayslipInfo GeneratePayslipForEmployee(EmployeeInformation data)
        {
            if (!data.IsModelValid())
            {
                return null;
            }

            var payslip = new PayslipInfo
            {
                Name = string.Concat(data.EmployeeFirstName, " ", data.EmployeeLastName),
                GrossIncome = ((decimal)(data.AnnualSalary / (int)data.PayslipFrequency)).RoundToNearestInt(),
                IncomeTax = _taxCalculator.CalculateIncomeTax(data.AnnualSalary, data.PayslipFrequency),
                PayPeriod = data.PayPeriod
            };
            payslip.Super = ((decimal)(payslip.GrossIncome * data.SuperRate / 100)).RoundToNearestInt();
            return payslip;
        }
コード例 #6
0
        public PayslipInfo Calculate(EmployeeInfo employee, int month)
        {
            if (employee.AnnualSalary < 0)
            {
                throw new Exception("The annual salary must be more than 0!");
            }
            else if (employee.SuperRate < 0 || employee.SuperRate > 0.5)
            {
                throw new Exception("The super rate must be between 0 and 0.5!");
            }
            else if (month < 1 || month > 12)
            {
                throw new Exception("The month must be between 1 and 12!");
            }
            PayslipInfo result = new PayslipInfo();

            result.Employee    = employee;
            result.PayPeriod   = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month);
            result.GrossIncome = Utils.ConvertToInt(employee.AnnualSalary / 12);
            result.IncomeTax   = TaxCalculatorFactory.CreateTaxCalculator(employee.AnnualSalary).CalculateTax();
            result.NetIncome   = result.GrossIncome - result.IncomeTax;
            result.Super       = Utils.ConvertToInt(result.GrossIncome * employee.SuperRate);
            return(result);
        }
コード例 #7
0
 private void ExecuteItem(PayslipInfo item)
 {
     PayslipDocument meta = Payslip.ExportStaffPayslip(item.KeyRecibo, item.Company);
     Payslip.InsertDocument(meta);
 }