Skip to content

Commit 62b4a82

Browse files
committed
feat(*.cs): Add support for editing budget reached amount
Introduces the ability to view and edit the 'Reached Amount' for budgets. Updates DTOs, models, and view models to include the new field, adds a dedicated DTO for updating reached amounts, and implements related UI changes in BudgetView.xaml. Also updates styles and minor UI text for consistency.
1 parent f598e76 commit 62b4a82

File tree

11 files changed

+354
-94
lines changed

11 files changed

+354
-94
lines changed

FinTrack/Dtos/BudgetDtos/BudgetCreateDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class BudgetCreateDto
88
public string? Description { get; set; }
99
public string Category { get; set; } = null!;
1010
public decimal AllocatedAmount { get; set; }
11+
public decimal? ReachedAmount { get; set; }
1112
public BaseCurrencyType Currency { get; set; }
1213
public DateTime StartDate { get; set; }
1314
public DateTime EndDate { get; set; }

FinTrack/Dtos/BudgetDtos/BudgetDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class BudgetDto
99
public string? Description { get; set; }
1010
public string Category { get; set; } = null!;
1111
public decimal AllocatedAmount { get; set; }
12+
public decimal? ReachedAmount { get; set; }
1213
public BaseCurrencyType Currency { get; set; }
1314
public DateTime StartDate { get; set; }
1415
public DateTime EndDate { get; set; }

FinTrack/Dtos/BudgetDtos/BudgetUpdateDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class BudgetUpdateDto
88
public string? Description { get; set; }
99
public string Category { get; set; } = null!;
1010
public decimal AllocatedAmount { get; set; }
11+
public decimal? ReachedAmount { get; set; }
1112
public BaseCurrencyType Currency { get; set; }
1213
public DateTime StartDate { get; set; }
1314
public DateTime EndDate { get; set; }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FinTrackForWindows.Dtos.BudgetDtos
2+
{
3+
public class BudgetUpdateReachedAmountDto
4+
{
5+
public int BudgetId { get; set; }
6+
public decimal? ReachedAmount { get; set; }
7+
}
8+
}

FinTrack/Models/Budget/BudgetModel.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ public partial class BudgetModel : ObservableObject
2929
private decimal currentAmount;
3030

3131
[ObservableProperty]
32-
private BaseCurrencyType currency = BaseCurrencyType.USD;
32+
[NotifyPropertyChangedFor(nameof(ProgressValue))]
33+
[NotifyPropertyChangedFor(nameof(ProgressText))]
34+
private decimal? reachedAmount;
35+
36+
[ObservableProperty]
37+
private bool isEditingReachedAmount = false;
38+
39+
[ObservableProperty]
40+
[NotifyPropertyChangedFor(nameof(ProgressText))]
41+
[NotifyPropertyChangedFor(nameof(ReachedAmountDisplayText))]
42+
private BaseCurrencyType currency;
3343

3444
[ObservableProperty]
3545
[NotifyPropertyChangedFor(nameof(RemainingTimeText))]
@@ -39,14 +49,31 @@ public partial class BudgetModel : ObservableObject
3949
[NotifyPropertyChangedFor(nameof(RemainingTimeText))]
4050
private DateTime endDate = DateTime.Today.AddMonths(1);
4151

42-
public double ProgressValue => AllocatedAmount <= 0 ? 0 : Math.Max(0, Math.Min(100, (double)(CurrentAmount / AllocatedAmount) * 100));
52+
public double ProgressValue => AllocatedAmount <= 0 ? 0 : Math.Max(0, Math.Min(100, (double)((ReachedAmount ?? 0) / AllocatedAmount) * 100));
4353

4454
public string ProgressText
4555
{
4656
get
4757
{
48-
var culture = new CultureInfo("tr-TR");
49-
return $"{CurrentAmount.ToString("C", culture)} / {AllocatedAmount.ToString("C", culture)}";
58+
var current = ReachedAmount ?? 0;
59+
string currencyCode = Currency.ToString();
60+
var culture = CultureInfo.CurrentCulture;
61+
62+
string currentText = current.ToString("N2", culture);
63+
string allocatedText = AllocatedAmount.ToString("N2", culture);
64+
65+
return $"{currentText} {currencyCode} / {allocatedText} {currencyCode}";
66+
}
67+
}
68+
69+
public string ReachedAmountDisplayText
70+
{
71+
get
72+
{
73+
var current = ReachedAmount ?? 0;
74+
string currencyCode = Currency.ToString();
75+
var culture = CultureInfo.CurrentCulture;
76+
return $"{current.ToString("N2", culture)} {currencyCode}";
5077
}
5178
}
5279

FinTrack/Services/Budgets/BudgetStore.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public async Task LoadBudgetsAsync()
5252
Description = dto.Description,
5353
Category = dto.Category,
5454
AllocatedAmount = dto.AllocatedAmount,
55+
ReachedAmount = dto.ReachedAmount,
5556
Currency = dto.Currency,
5657
StartDate = dto.StartDate,
5758
EndDate = dto.EndDate,
@@ -77,6 +78,7 @@ public async Task AddBudgetAsync(BudgetCreateDto newBudgetDto)
7778
Description = createdBudgetDto.Description,
7879
Category = createdBudgetDto.Category,
7980
AllocatedAmount = createdBudgetDto.AllocatedAmount,
81+
ReachedAmount = createdBudgetDto.ReachedAmount,
8082
Currency = createdBudgetDto.Currency,
8183
StartDate = createdBudgetDto.StartDate,
8284
EndDate = createdBudgetDto.EndDate
@@ -107,6 +109,7 @@ public async Task UpdateBudgetAsync(int budgetId, BudgetCreateDto updatedBudget)
107109
item.Description = updatedBudget.Description;
108110
item.Category = updatedBudget.Category;
109111
item.AllocatedAmount = updatedBudget.AllocatedAmount;
112+
item.ReachedAmount = updatedBudget.ReachedAmount;
110113
item.Currency = updatedBudget.Currency;
111114
item.StartDate = updatedBudget.StartDate;
112115
item.EndDate = updatedBudget.EndDate;
@@ -115,6 +118,21 @@ public async Task UpdateBudgetAsync(int budgetId, BudgetCreateDto updatedBudget)
115118
}
116119
}
117120

121+
public async Task UpdateReachedAmountAsync(BudgetUpdateReachedAmountDto updatedBudget)
122+
{
123+
var updateBudgetDto = await _apiService.PutAsync<BudgetDto>($"Budgets/Update-Reached-Amount", updatedBudget);
124+
if (updateBudgetDto != null)
125+
{
126+
foreach (var item in _budgets)
127+
{
128+
if (item.Id == updateBudgetDto.Id)
129+
{
130+
item.ReachedAmount = updatedBudget.ReachedAmount;
131+
}
132+
}
133+
}
134+
}
135+
118136
private void OnInternalCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
119137
{
120138
BudgetsChanged?.Invoke(this, e);

FinTrack/Services/Budgets/IBudgetStore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IBudgetStore
1515

1616
Task AddBudgetAsync(BudgetCreateDto newBudget);
1717
Task UpdateBudgetAsync(int budgetId, BudgetCreateDto updatedBudget);
18+
Task UpdateReachedAmountAsync(BudgetUpdateReachedAmountDto newBudget);
1819
Task DeleteBudgetAsync(int budgetId);
1920
}
2021
}

0 commit comments

Comments
 (0)