feat: categoria is_tax exclui impostos do denominador do savings_pct

savings_pct = (receita - despesas) / (receita - impostos).
Toggle IMPOSTO no CRUD de categorias; badge dourado na lista.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-27 15:53:53 -03:00
co-authored by Claude Sonnet 4.6
parent 2cf6d94a03
commit 7dae05cabf
10 changed files with 90 additions and 35 deletions
+2 -2
View File
@@ -32,14 +32,14 @@ func (s *CategoryService) Create(ctx context.Context, in model.CategoryInput) (*
if err := validateInput(in); err != nil {
return nil, err
}
return s.repo.Create(ctx, strings.TrimSpace(in.Name), in.Color)
return s.repo.Create(ctx, strings.TrimSpace(in.Name), in.Color, in.IsTax)
}
func (s *CategoryService) Update(ctx context.Context, id int, in model.CategoryInput) (*model.Category, error) {
if err := validateInput(in); err != nil {
return nil, err
}
return s.repo.Update(ctx, id, strings.TrimSpace(in.Name), in.Color)
return s.repo.Update(ctx, id, strings.TrimSpace(in.Name), in.Color, in.IsTax)
}
func (s *CategoryService) Delete(ctx context.Context, id int) error {
+10 -2
View File
@@ -8,6 +8,7 @@ import (
type DashboardRepo interface {
MonthlySummary(ctx context.Context, month string) (income, expenses float64, err error)
TotalTaxes(ctx context.Context, month string) (float64, error)
ByCategory(ctx context.Context, month string) ([]model.CategoryTotal, error)
MonthlyEvolution(ctx context.Context, month string) ([]model.MonthEvolution, error)
RecentTransactions(ctx context.Context, month string) ([]model.RecentTransaction, error)
@@ -34,6 +35,11 @@ func (s *DashboardService) Get(ctx context.Context, month string) (*model.Dashbo
return nil, err
}
taxes, err := s.repo.TotalTaxes(ctx, month)
if err != nil {
return nil, err
}
byCategory, err := s.repo.ByCategory(ctx, month)
if err != nil {
return nil, err
@@ -49,9 +55,11 @@ func (s *DashboardService) Get(ctx context.Context, month string) (*model.Dashbo
return nil, err
}
// savings_pct uses net income (gross - taxes) as denominator (Option B)
var savingsPct float64
if income > 0 {
savingsPct = (income - expenses) / income * 100
netIncome := income - taxes
if netIncome > 0 {
savingsPct = (income - expenses) / netIncome * 100
}
statuses, err := s.recurrSvc.MonthlyStatus(ctx, month)
@@ -16,6 +16,9 @@ type mockDashboardRepo struct {
func (m *mockDashboardRepo) MonthlySummary(_ context.Context, _ string) (float64, float64, error) {
return m.income, m.expenses, nil
}
func (m *mockDashboardRepo) TotalTaxes(_ context.Context, _ string) (float64, error) {
return 0, nil
}
func (m *mockDashboardRepo) ByCategory(_ context.Context, _ string) ([]model.CategoryTotal, error) {
return nil, nil
}