Removed tax settings
This commit is contained in:
@@ -6,7 +6,6 @@ using Budget.Infrastructure.Data;
|
||||
using Budget.Infrastructure.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Budget.Api.Controllers;
|
||||
@@ -34,10 +33,10 @@ public class SummaryController(AppDbContext db, BudgetAuthorizationService authz
|
||||
if (budget is null) return NotFound();
|
||||
|
||||
var incomes = await db.Incomes.Where(i => i.BudgetId == budgetId).ToListAsync();
|
||||
var outgos = await db.Outgos.Where(o => o.BudgetId == budgetId).ToListAsync();
|
||||
var outgos = await db.Outgos.Where(o => o.BudgetId == budgetId).ToListAsync();
|
||||
|
||||
var monthlyIncome = incomes.Sum(i => FrequencyCalculator.ToMonthly(i.Amount, i.Frequency));
|
||||
var annualIncome = monthlyIncome * 12m;
|
||||
var annualIncome = monthlyIncome * 12m;
|
||||
|
||||
var typeTargets = new Dictionary<OutgoType, int>
|
||||
{
|
||||
@@ -51,43 +50,20 @@ public class SummaryController(AppDbContext db, BudgetAuthorizationService authz
|
||||
|
||||
foreach (var (type, target) in typeTargets)
|
||||
{
|
||||
var typeOutgos = outgos.Where(o => o.Type == type).ToList();
|
||||
var monthlyTotal = typeOutgos.Sum(o => FrequencyCalculator.ToMonthly(o.Amount, o.Frequency));
|
||||
var annualTotal = monthlyTotal * 12m;
|
||||
var typeOutgos = outgos.Where(o => o.Type == type).ToList();
|
||||
var monthlyTotal = typeOutgos.Sum(o => FrequencyCalculator.ToMonthly(o.Amount, o.Frequency));
|
||||
var annualTotal = monthlyTotal * 12m;
|
||||
totalMonthlyOutgo += monthlyTotal;
|
||||
var percent = monthlyIncome > 0 ? Math.Round(monthlyTotal / monthlyIncome * 100, 2) : 0m;
|
||||
var maxAmount = monthlyIncome * target / 100m;
|
||||
var remaining = maxAmount - monthlyTotal;
|
||||
var percent = monthlyIncome > 0 ? Math.Round(monthlyTotal / monthlyIncome * 100, 2) : 0m;
|
||||
var maxAmount = monthlyIncome * target / 100m;
|
||||
var remaining = maxAmount - monthlyTotal;
|
||||
breakdown.Add(new SummaryBreakdownItem(type.ToString(), target, monthlyTotal, annualTotal, percent, maxAmount, remaining));
|
||||
}
|
||||
|
||||
var unspent = monthlyIncome - totalMonthlyOutgo;
|
||||
var unspent = monthlyIncome - totalMonthlyOutgo;
|
||||
var unspentPercent = monthlyIncome > 0 ? Math.Round(unspent / monthlyIncome * 100, 2) : 0m;
|
||||
breakdown.Add(new SummaryBreakdownItem("Unspent", null, unspent, unspent * 12m, unspentPercent, null, null));
|
||||
|
||||
var annualOutgoTotal = totalMonthlyOutgo * 12m;
|
||||
var minimumAnnualGross = budget.EffectiveTaxRate < 1m
|
||||
? annualOutgoTotal / (1m - budget.EffectiveTaxRate)
|
||||
: 0m;
|
||||
|
||||
return Ok(new SummaryDto(
|
||||
monthlyIncome,
|
||||
annualIncome,
|
||||
breakdown,
|
||||
new PreTaxIncomeDto(budget.EffectiveTaxRate, minimumAnnualGross, minimumAnnualGross / 12m)));
|
||||
}
|
||||
|
||||
[HttpPut("tax-rate")]
|
||||
[EnableRateLimiting("writes")]
|
||||
public async Task<IActionResult> UpdateTaxRate(Guid budgetId, [FromBody] UpdateTaxRateRequest req)
|
||||
{
|
||||
if (TryGetUserId(out var userId) is { } err) return err;
|
||||
if (!await authz.CanWriteAsync(budgetId, userId)) return Forbid();
|
||||
var budget = await db.Budgets.FindAsync(budgetId);
|
||||
if (budget is null) return NotFound();
|
||||
budget.EffectiveTaxRate = req.EffectiveTaxRate;
|
||||
budget.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await db.SaveChangesAsync();
|
||||
return NoContent();
|
||||
return Ok(new SummaryDto(monthlyIncome, annualIncome, breakdown));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user