forked from ucsbfinaid/Financial-Aid-Estimator-.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EfcCalculatorFactory.cs
167 lines (146 loc) · 7.48 KB
/
EfcCalculatorFactory.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Xml;
using Ucsb.Sa.FinAid.AidEstimation.EfcCalculation;
using Ucsb.Sa.FinAid.AidEstimation.EfcCalculation.Constants;
namespace Ucsb.Sa.FinAid.AidEstimation.Utility
{
/// <summary>
/// Constructs Calculator and Constants objects from XML sources
/// </summary>
public class EfcCalculatorFactory
{
private readonly XmlConstantsSource _source;
public EfcCalculatorFactory(string sourcePath)
{
_source = new XmlConstantsSource(sourcePath);
}
public EfcCalculatorFactory(XmlDocument sourceDoc)
{
_source = new XmlConstantsSource(sourceDoc);
}
public EfcCalculator GetEfcCalculator()
{
EfcCalculatorConstants constants = GetEfcCalculatorConstants();
IncomeCalculator incomeCalc = GetIncomeCalculator();
AllowanceCalculator allowanceCalc = GetAllowanceCalculator();
AssetContributionCalculator assetContrCalc = GetAssetContributionCalculator();
AaiContributionCalculator aaiContrCalc = GetAaiContributionCalculator();
return new EfcCalculator(constants, incomeCalc, allowanceCalc, assetContrCalc, aaiContrCalc);
}
public EfcCalculatorConstants GetEfcCalculatorConstants()
{
try
{
return new EfcCalculatorConstants
{
SimplifiedEfcMax = _source.GetValue<int>("SimplifiedEFCMax"),
AutoZeroEfcMax = _source.GetValue<int>("AutoZeroEFCMax"),
AltEnrollmentIncomeProtectionAllowance = _source.GetValue<int>("AltEnrollmentIncomeProtectionAllowance")
};
}
catch (Exception)
{
throw new Exception("Unable to read EFC Calculator constants");
}
}
public IncomeCalculatorConstants GetIncomeCalculatorConstants()
{
try
{
return new IncomeCalculatorConstants
{
AiAssessmentPercent = _source.GetValue<double>("AIAssessmentPercent")
};
}
catch (Exception)
{
throw new Exception("Unable to read Income Calculator constants");
}
}
public IncomeCalculator GetIncomeCalculator()
{
return new IncomeCalculator(GetIncomeCalculatorConstants());
}
public AllowanceCalculatorConstants GetAllowanceCalculatorConstants()
{
try
{
return new AllowanceCalculatorConstants
{
StateTaxAllowanceIncomeThreshold = _source.GetValue<int>("StateTaxAllowanceIncomeThreshold"),
ParentStateTaxAllowancePercents = _source.GetArray<int>("ParentStateTaxAllowancePercents"),
StudentStateTaxAllowancePercents = _source.GetArray<int>("StudentStateTaxAllowancePercents"),
SocialSecurityTaxIncomeThresholds = _source.GetArray<int>("SocialSecurityTaxIncomeThresholds"),
SocialSecurityTaxPercentages = _source.GetArray<double>("SocialSecurityTaxPercentages"),
SocialSecurityTaxBases = _source.GetArray<double>("SocialSecurityTaxBases"),
EmploymentExpensePercent = _source.GetValue<double>("EmploymentExpensePercent"),
EmploymentExpenseMaximum = _source.GetValue<int>("EmploymentExpenseMaximum"),
DependentParentIncomeProtectionAllowances = _source.GetMultiArray<int>("DepParentIncomeProtectionAllowances"),
IndependentWithDependentsIncomeProtectionAllowances = _source.GetMultiArray<int>("IndWithDepIncomeProtectionAllowances"),
DependentAdditionalStudentAllowance = _source.GetValue<int>("DepAdditionalStudentAllowance"),
DependentAdditionalFamilyAllowance = _source.GetValue<int>("DepAdditionalFamilyAllowance"),
IndependentAdditionalStudentAllowance = _source.GetValue<int>("IndAdditionalStudentAllowance"),
IndependentAdditionalFamilyAllowance = _source.GetValue<int>("IndAdditionalFamilyAllowance"),
DependentStudentIncomeProtectionAllowance = _source.GetValue<int>("DepStudentIncomeProtectionAllowance"),
SingleIndependentWithoutDependentsIncomeProtectionAllowance = _source.GetValue<int>("IndWithoutDepSingleIncomeProtectionAllowance"),
MarriedIndependentWithoutDependentsIncomeProtectionAllowance = _source.GetValue<int>("IndWithoutDepMarriedIncomeProtectionAllowance")
};
}
catch (Exception)
{
throw new Exception("Unable to read Allowance Calculator constants");
}
}
public AllowanceCalculator GetAllowanceCalculator()
{
return new AllowanceCalculator(GetAllowanceCalculatorConstants());
}
public AssetContributionCalculatorConstants GetAssetContributionCalculatorConstants()
{
try
{
return new AssetContributionCalculatorConstants
{
DependentParentAssetRate = _source.GetValue<double>("DepParentAssetRate"),
DependentStudentAssetRate = _source.GetValue<double>("DepStudentAssetRate"),
IndependentWithDependentsAssetRate = _source.GetValue<double>("IndWithDepAssetRate"),
IndependentWithoutDependentsAssetRate = _source.GetValue<double>("IndWithoutDepAssetRate"),
AssetProtectionAllowanceLowestAge = _source.GetValue<int>("AssetProtectionAllowanceLowestAge"),
MarriedAssetProtectionAllowances = _source.GetArray<int>("MarriedAssetProtectionAllowances"),
SingleAssetProtectionAllowances = _source.GetArray<int>("SingleAssetProtectionAllowances"),
BusinessFarmNetWorthAdjustmentRanges = _source.GetArray<int>("BusinessFarmNetWorthAdjustmentRanges"),
BusinessFarmNetWorthAdjustmentBases = _source.GetArray<int>("BusinessFarmNetWorthAdjustmentBases"),
BusinessFarmNetWorthAdjustmentPercents = _source.GetArray<double>("BusinessFarmNetWorthAdjustmentPercents")
};
}
catch (Exception)
{
throw new Exception("Unable to read Asset Contribution Calculator constants");
}
}
public AssetContributionCalculator GetAssetContributionCalculator()
{
return new AssetContributionCalculator(GetAssetContributionCalculatorConstants());
}
public AaiContributionCalculatorConstants GetAaiContributionCalculatorConstants()
{
try
{
return new AaiContributionCalculatorConstants
{
AaiContributionRanges = _source.GetArray<int>("AAIContributionRanges"),
AaiContributionBases = _source.GetArray<int>("AAIContributionBases"),
AaiContributionPercents = _source.GetArray<double>("AAIContributionPercents")
};
}
catch (Exception)
{
throw new Exception("Unable to read AAI Contribution Calculator constants");
}
}
public AaiContributionCalculator GetAaiContributionCalculator()
{
return new AaiContributionCalculator(GetAaiContributionCalculatorConstants());
}
}
}