-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNationalInsuranceDeductor.cpp
More file actions
61 lines (50 loc) · 1.72 KB
/
NationalInsuranceDeductor.cpp
File metadata and controls
61 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "NationalInsuranceDeductor.h"
using namespace UKTax::Deductors;
namespace UKTax
{
namespace Deductors
{
double NationalInsuranceDeductor::Deduct(double amount)
{
if (0.0 >= amount)
return amount;
TaxDatabase* database = TaxDatabase::Instance();
const NationalInsuranceTax& nationalInsuranceTax = database->GetNationalInsuranceTax(this->region);
TaxValues niBands = nationalInsuranceTax.GetBands();
TaxValues niRates = nationalInsuranceTax.GetRates();
TaxValue totalTax = 0.0;
TaxValue amountTaxed = 0.0;
for (std::size_t i = 0, n = niBands.size(); i < n; ++i)
{
const TaxValue currentBand = niBands[i];
const TaxValue currentRate = niRates[i];
if (currentBand > amount)
break;
if (i < (n - 1))
{
const TaxValue nextBand = niBands[i + 1];
if (amount >= nextBand)
{
totalTax += TaxForAmount(currentBand, nextBand, currentRate);
amountTaxed += (0.0 == currentBand ? 0.0 : (nextBand - currentBand));
}
else
{
totalTax += TaxForAmount(currentBand, amount, currentRate);
amountTaxed += (0.0 == currentBand ? 0.0 : (amount - currentBand));
}
}
else
{
if (amount > currentBand)
{
totalTax += TaxForAmount(currentBand, amount, currentRate);
amountTaxed += (0.0 == currentBand ? 0.0 : (amount - currentBand));
}
}
}
std::cerr << "\nNational Insurance\n" << "Total amount taxed: " << amountTaxed << "\nTotal tax: " << totalTax << std::endl;
return BaseTaxDeductor::Deduct(amount - totalTax);
}
};
};