Added in-window compute and analyze functions

This commit is contained in:
2026-05-12 12:53:10 -04:00
parent dfbdf56ff5
commit e417b0daf4
3 changed files with 139 additions and 5 deletions
+13 -5
View File
@@ -13,6 +13,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
@@ -22,6 +23,9 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Filing Status:" Grid.Column="0" Grid.Row="0"/>
<TextBlock Text="Pay Periods:" Grid.Column="0" Grid.Row="1"/>
@@ -31,10 +35,14 @@
<TextBlock Text="Retirement Contribution:" Grid.Column="0" Grid.Row="5"/>
<ComboBox ItemsSource="{Binding FilingStatuses, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding SelectedStatusIndex, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="0"/>
<ComboBox ItemsSource="{Binding PayPeriods, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding SelectedPeriodIndex, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1"/>
<TextBox Text="{Binding Salary, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2"/>
<TextBox Text="{Binding PreTax, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="3"/>
<TextBox Text="{Binding PostTax, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="4"/>
<TextBox Text="{Binding RetirementContribution, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="5"/>
<Button Content="Debug" Command="{Binding DoDebug, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="6"/>
<TextBox Text="{Binding Salary, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" Grid.Column="1" Grid.Row="2"/>
<TextBox Text="{Binding PreTax, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" Grid.Column="1" Grid.Row="3"/>
<TextBox Text="{Binding PostTax, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" Grid.Column="1" Grid.Row="4"/>
<TextBox Text="{Binding RetirementContribution, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" Grid.Column="1" Grid.Row="5"/>
<Button Content="Calculate" Command="{Binding DoCalculate, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="6"/>
<Button Content="Analyze" Command="{Binding DoAnalyze, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="7"/>
<Button Content="Debug" Command="{Binding DoDebug, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="8"/>
<TextBlock Text="Output:" Grid.Column="2" Grid.Row="0"/>
<TextBox Text="{Binding Output, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" Grid.Column="2" Grid.Row="1" Grid.RowSpan="9" IsReadOnly="True" TextWrapping="Wrap"/>
</Grid>
</Window>
+21
View File
@@ -16,8 +16,11 @@ namespace RetirementCalculator
private FilingStatus _status;
private PayInformation _payInfo;
private DeductionInformation _deductionInfo;
private string _output;
private ICommand _doDebug;
private ICommand _doCalculate;
private ICommand _doAnalyze;
public int SelectedPeriodIndex
{
@@ -115,12 +118,27 @@ namespace RetirementCalculator
get { return _deductionInfo.RetirementPercentage; }
set { _deductionInfo.RetirementPercentage = value; OnPropertyChanged(nameof(RetirementContribution)); }
}
public string Output
{
get { return _output; }
set { SetProperty(ref _output, value, nameof(Output)); }
}
public ICommand DoDebug
{
get { return _doDebug; }
set { SetProperty(ref _doDebug, value, nameof(DoDebug)); }
}
public ICommand DoCalculate
{
get { return _doCalculate; }
set { SetProperty(ref _doCalculate, value, nameof(DoCalculate)); }
}
public ICommand DoAnalyze
{
get { return _doAnalyze; }
set { SetProperty(ref _doAnalyze, value, nameof(DoAnalyze)); }
}
public MainWindowModel()
{
@@ -130,7 +148,10 @@ namespace RetirementCalculator
_filingStatuses = new();
_payInfo = new();
_deductionInfo = new();
_output = string.Empty;
_doDebug = new RelayCommand(Placeholder);
_doCalculate = new RelayCommand(Placeholder);
_doAnalyze = new RelayCommand(Placeholder);
}
private void Placeholder(object obj)
+105
View File
@@ -41,11 +41,14 @@ namespace RetirementCalculator
];
PayInfo = new();
DeductionInfo = new();
Output = string.Empty;
}
private void InitializeCommands()
{
DoDebug = new RelayCommand(DebugDo);
DoCalculate = new RelayCommand(CalculateDo);
DoAnalyze = new RelayCommand(AnalyzeDo);
}
private void DebugDo(object obj)
@@ -103,5 +106,107 @@ namespace RetirementCalculator
th
));
}
private void CalculateDo(object obj)
{
FederalTax ft = new(Status);
TaxRates ot = new();
string MessageFormat =
"Federal Taxes: {0:0.00}\n" +
"State Taxes: {1:0.00}\n" +
"Local Taxes: {2:0.00}\n" +
"Social Security: {3:0.00}\n" +
"Medicare: {4:0.00}\n" +
"Total Taxes: {5:0.00}\n\n" +
"Retirement Contribution: {6:0.00}\n\n" +
"Takehome: {7:0.00}";
double fed = ft.CalculateTax(PayInfo, DeductionInfo);
double state = ot.CalculateStateTax(PayInfo, DeductionInfo);
double local = ot.CalculateLocalTax(PayInfo, DeductionInfo);
double ss = ot.CalculateSocialSecurityTax(PayInfo, DeductionInfo);
double med = ot.CalculateMedicareTax(PayInfo, DeductionInfo);
double tot = fed + state + local + ss + med;
double PayPeriods = 1;
switch (PayInfo.Period)
{
case PayPeriod.Annually:
PayPeriods = 1;
break;
case PayPeriod.Monthly:
PayPeriods = 12;
break;
case PayPeriod.TwiceMonthly:
PayPeriods = 24;
break;
case PayPeriod.EveryOtherWeek:
PayPeriods = 26;
break;
case PayPeriod.EveryWeek:
PayPeriods = 52;
break;
default:
PayPeriods = 1;
break;
}
double gp = (PayInfo.Salary / PayPeriods);
double ret = gp * DeductionInfo.RetirementPercentage;
double th = gp - tot - ret - DeductionInfo.PreTaxDeductions;
Output = string.Format(MessageFormat,
fed,
state,
local,
ss,
med,
tot,
ret,
th
);
}
private void AnalyzeDo(object obj)
{
FederalTax ft = new(Status);
TaxRates ot = new();
string LineFormat = "Retirement: {0:00}%, ${1:000.00} Taxes: ${2:000.00} Takehome: ${3:0000.00}\n";
string TempOutput = string.Empty;
double PayPeriods = 1;
switch (PayInfo.Period)
{
case PayPeriod.Annually:
PayPeriods = 1;
break;
case PayPeriod.Monthly:
PayPeriods = 12;
break;
case PayPeriod.TwiceMonthly:
PayPeriods = 24;
break;
case PayPeriod.EveryOtherWeek:
PayPeriods = 26;
break;
case PayPeriod.EveryWeek:
PayPeriods = 52;
break;
default:
PayPeriods = 1;
break;
}
for (int i = 0; i <= 25; i++)
{
DeductionInformation di = new() { PreTaxDeductions = DeductionInfo.PreTaxDeductions, PostTaxDeductions = DeductionInfo.PostTaxDeductions };
di.RetirementPercentage = Convert.ToDouble(i) / 100d;
double fed = ft.CalculateTax(PayInfo, di);
double state = ot.CalculateStateTax(PayInfo, di);
double local = ot.CalculateLocalTax(PayInfo, di);
double ss = ot.CalculateSocialSecurityTax(PayInfo, di);
double med = ot.CalculateMedicareTax(PayInfo, di);
double tot = fed + state + local + ss + med;
double gp = (PayInfo.Salary / PayPeriods);
double ret = gp * di.RetirementPercentage;
double th = gp - tot - ret - DeductionInfo.PreTaxDeductions;
TempOutput += string.Format(LineFormat, i, ret, tot, th);
}
Output = TempOutput;
}
}
}