WIP
This commit is contained in:
1 parent
2bfe914c8f
commit
4281924ee5
16 files changed
+369
-76
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using BudgetApp.Data.Entities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace BudgetApp.Components.Pages;
|
||||
|
||||
@@ -200,12 +201,14 @@ public partial class Transactions
|
||||
private string _deleteModalTitle = "Delete Transaction";
|
||||
private bool _showEditModal;
|
||||
private int? _editingTransactionId;
|
||||
private Transaction? _editingTransaction;
|
||||
private bool _editIsPartOfSeries;
|
||||
private TransactionForm _editModel = new();
|
||||
|
||||
private void OpenEditModal(Transaction t)
|
||||
{
|
||||
_editingTransactionId = t.Id;
|
||||
_editingTransaction = t;
|
||||
_editIsPartOfSeries = t.RecurrenceType != RecurrenceType.None || t.ParentTransactionId is not null;
|
||||
_editModel = new TransactionForm
|
||||
{
|
||||
@@ -221,11 +224,15 @@ public partial class Transactions
|
||||
_showEditModal = true;
|
||||
}
|
||||
|
||||
private void CloseEditModal() => _showEditModal = false;
|
||||
private void CloseEditModal()
|
||||
{
|
||||
_showEditModal = false;
|
||||
_editingTransaction = null;
|
||||
}
|
||||
|
||||
private async Task SaveEdit()
|
||||
{
|
||||
if (_userId is null || _editingTransactionId is null) return;
|
||||
if (_userId is null || _editingTransactionId is null || _editingTransaction?.SalaryId is not null) return;
|
||||
|
||||
await TransactionService.UpdateTransactionAsync(
|
||||
_editingTransactionId.Value, _userId,
|
||||
@@ -305,7 +312,28 @@ public partial class Transactions
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private sealed class TransactionForm : System.ComponentModel.DataAnnotations.IValidatableObject
|
||||
private async Task ExportCsv()
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.AppendLine("Date,Description,Type,Amount,Account,Category,Recurrence");
|
||||
foreach (var t in FilteredTransactions)
|
||||
{
|
||||
var category = t.Category?.Name ?? "";
|
||||
var recurrence = t.RecurrenceType != RecurrenceType.None ? t.RecurrenceType.ToString() : "";
|
||||
sb.AppendLine($"{t.Date:yyyy-MM-dd},{CsvEscape(t.Description)},{t.Type},{t.Amount:F2},{CsvEscape(t.Account.Name)},{CsvEscape(category)},{recurrence}");
|
||||
}
|
||||
var filename = $"transactions_{DateTime.Today:yyyy-MM-dd}.csv";
|
||||
await JS.InvokeVoidAsync("downloadCsv", filename, sb.ToString());
|
||||
}
|
||||
|
||||
private static string CsvEscape(string value)
|
||||
{
|
||||
if (value.Contains(',') || value.Contains('"') || value.Contains('\n'))
|
||||
return $"\"{value.Replace("\"", "\"\"\"")}\"";
|
||||
return value;
|
||||
}
|
||||
|
||||
private sealed class TransactionForm
|
||||
{
|
||||
[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "Description is required")]
|
||||
[System.ComponentModel.DataAnnotations.MaxLength(200)]
|
||||
|
||||
Reference in new issue
Block a user