Implement status picker and payment dialog for rent status updates

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-20 00:12:48 +01:00
parent d1d1d9fb95
commit df7705a224
2 changed files with 205 additions and 0 deletions
+62
View File
@@ -227,6 +227,68 @@ class RentController extends ChangeNotifier {
}
}
Future<void> setMonthStatusManually({
required int year,
required int month,
required PaymentStatus status,
double? paidUsd,
}) async {
_errorMessage = null;
_setLoading(true);
try {
final key = TimeService.monthKey(year, month);
if (status == PaymentStatus.notOccupied) {
throw StateError(
'Use Settings -> Unit occupied to manage not-occupied months.',
);
}
if (status == PaymentStatus.notPaid || status == PaymentStatus.pending) {
_records.remove(key);
await _storageService.saveRecords(_records);
await _notificationService.cancelForMonth(year, month);
await _syncNotificationScheduleForCurrentMonth();
return;
}
if (_isNotOccupiedMonth(year, month)) {
throw StateError('Cannot mark a non-occupied month as paid.');
}
final usd = paidUsd ?? _settings.rentUsd;
if (usd <= 0) {
throw StateError('Enter a valid paid amount in USD.');
}
final estDate = DateTime(year, month, 1);
final conversion = await _exchangeService.convertUsdToSek(
estDate: estDate,
amount: usd,
);
_records[key] = MonthlyRentRecord(
year: year,
month: month,
usdAmount: usd,
sekAmount: conversion.result,
usdToSekRate: conversion.quote,
paidAtUtc: DateTime.now().toUtc(),
onTime: status == PaymentStatus.onTime,
source: 'manual-status',
);
await _storageService.saveRecords(_records);
await _notificationService.cancelForMonth(year, month);
await _syncNotificationScheduleForCurrentMonth();
} catch (err) {
_errorMessage = err.toString();
} finally {
_setLoading(false);
}
}
Future<void> backfillLastYear() async {
_errorMessage = null;
_setLoading(true);