public string Save() { // csv format that will be saved return(Name + "," + Salary.ToString("N") + "," + InvestmentIncome.ToString("N") + "," + TaxableIncome.ToString("N") + "," + FormatTaxRate() + "," + ComputeTax().ToString("N")); }
/* * The Rule Files have been designed in such a way that the same function can perform the calculations for all three Medicare, Budget and Income. */ private decimal CalculateRule(IEnumerable <CalculationRule> rules) { decimal deduction = 0; foreach (var cr in rules) { // where the upper threshold is 0, there is no upper limit if (TaxableIncome >= cr.LowerThreshold && (TaxableIncome <= cr.UpperThreshold || cr.UpperThreshold == 0)) { var expression = cr.Expression.Replace("TI", TaxableIncome.ToString(CultureInfo.InvariantCulture)); var dt = new DataTable(); try { // where the expression 0, there is no formula to compute. deduction = expression.Equals("0") ? 0 : decimal.Ceiling((decimal)dt.Compute(expression, "")); } catch (Exception ex) { Console.WriteLine("There has been an exception trying to execute one of the Rule File expressions. Please check the expression and file for any errors."); Console.WriteLine(expression); Console.WriteLine(ex.Message); } // Not sure if I like using break. // But, once we've reached this part of the execution there's no longer any need to continue the loop. // Doing so will do no harm, but breaking will also do no harm. break; } } return(deduction); }
public AssessableIncome( TaxableIncome taxableIncome, EmployeeSocialInsurance employeeSocialInsurance, EmployeeHealthCareInsurance employeeHealthCareInsurance, EmployeeUnemploymentInsurance employeeUnemploymentInsurance, EmployeeUnionFee employeeUnionFee, TotalDeduction totalDeduction) { var result = taxableIncome.Amount - employeeSocialInsurance.Amount - employeeHealthCareInsurance.Amount - employeeUnemploymentInsurance.Amount - employeeUnionFee.Amount - totalDeduction.Amount; Amount = result < Money.ZeroVND ? Money.ZeroVND : result; }
public static PayrollReportRecord[] GeneratePayRollRecord( EmployeeMonthlyRecord[] employeeMonthlyRecords, SalaryConfig salaryConfig) { return(employeeMonthlyRecords.Select(employeeMonthlyRecord => { var insuranceSalary = InsuranceCalculator.CalculateInsuranceSalary( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord); var actualGrossSalary = new ActualGrossSalary( grossContractedSalary: employeeMonthlyRecord.GrossContractedSalary, standardWorkingDays: employeeMonthlyRecord.StandardWorkingDays, probationWorkingDays: employeeMonthlyRecord.ProbationWorkingDays, workingDays: employeeMonthlyRecord.WorkingDays); var employeeSocialInsurance = InsuranceCalculator.CalculateEmployeeSocialInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employeeUnemploymentInsurance = InsuranceCalculator.CalculateEmployeeUnemploymentInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employeeHealthcareInsurance = InsuranceCalculator.CalculateEmployeeHealthCareInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employeeUnionFee = InsuranceCalculator.CalculateEmployeeUnionFee(salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employerSocialInsurance = InsuranceCalculator.CalculateEmployerSocialInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employerUnemploymentInsurance = InsuranceCalculator.CalculateEmployerUnemploymentInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employerHealthcareInsurance = InsuranceCalculator.CalculateEmployerHealthCareInsurance( salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var employerUnionFee = InsuranceCalculator.CalculateEmployerUnionFee(salaryConfig: salaryConfig, employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary); var taxableIncome = new TaxableIncome(actualGrossSalary, employeeMonthlyRecord.TaxableAllowances); var assessableIncome = new AssessableIncome( taxableIncome, employeeSocialInsurance: employeeSocialInsurance, employeeHealthCareInsurance: employeeHealthcareInsurance, employeeUnemploymentInsurance: employeeUnemploymentInsurance, employeeUnionFee: employeeUnionFee, totalDeduction: new TotalDeduction(employeeMonthlyRecord: employeeMonthlyRecord, salaryConfig: salaryConfig)); var pit = employeeMonthlyRecord.IsOnProbation() ? new PersonalIncomeTax((assessableIncome.Amount * salaryConfig.DefaultProbationTaxRate).Round()) : salaryConfig.ProgressiveTaxRateLookUpTable[assessableIncome]; var totalMonthlyIncome = new TotalMonthlyIncome( actualGrossSalary: actualGrossSalary, taxableAllowances: employeeMonthlyRecord.TaxableAllowances, nonTaxableAllowances: employeeMonthlyRecord.NonTaxableAllowances); var netIncome = new NetIncome( totalMonthlyIncome: totalMonthlyIncome, employeeHealthcareInsurance: employeeHealthcareInsurance, employeeSocialInsurance: employeeSocialInsurance, employeeUnemploymentInsurance: employeeUnemploymentInsurance, employeeUnionFee: employeeUnionFee, pit: pit); return new PayrollReportRecord( employeeMonthlyRecord: employeeMonthlyRecord, insuranceSalary: insuranceSalary.Amount, actualGrossSalary: actualGrossSalary.Amount, totalMonthlyIncome: totalMonthlyIncome.Amount, taxableIncome: taxableIncome.Amount, employeeSocialInsurance: employeeSocialInsurance.Amount, employeeHealthcareInsurance: employeeHealthcareInsurance.Amount, employeeUnemploymentInsurance: employeeUnemploymentInsurance.Amount, employeeUnionFee: employeeUnionFee.Amount, employerSocialInsurance: employerSocialInsurance.Amount, employerHealthcareInsurance: employerHealthcareInsurance.Amount, employerUnemploymentInsurance: employerUnemploymentInsurance.Amount, employerUnionFee: employerUnionFee.Amount, personalDeduction: salaryConfig.PersonalDeduction, dependantDeduction: salaryConfig.DependantDeduction * employeeMonthlyRecord.NumberOfDependants, assessableIncome: assessableIncome.Amount, netIncome: netIncome.Amount, pit: pit.Amount, totalSalaryCost: new TotalSalaryCost( totalMonthlyIncome: totalMonthlyIncome, employerSocialInsurance: employerSocialInsurance, employerHealthcareInsurance: employerHealthcareInsurance, employerUnemploymentInsurance: employerUnemploymentInsurance, employerUnionFee: employerUnionFee).Amount, netPayment: new NetPayment( netIncome: netIncome, paymentAdvance: employeeMonthlyRecord.PaymentAdvance, adjustmentAdditions: employeeMonthlyRecord.AdjustmentAdditions, adjustmentDeductions: employeeMonthlyRecord.AdjustmentDeduction ).Amount); }).ToArray()); }