Skip to content

Commit

Permalink
Merge pull request #240 from enrique-lozano/hot-fixes
Browse files Browse the repository at this point in the history
Wrong recurring transaction period amount calculation
enrique-lozano authored Nov 9, 2024
2 parents c8868df + 523e1a6 commit 9fe28e6
Showing 2 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lib/app/transactions/recurrent_transactions_page.dart
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ class _RecurrentTransactionPageState extends State<RecurrentTransactionPage> {
),
),
),
//
// --------**---------- FOOTER ----------**---------
//
const Divider(endIndent: 16, indent: 16),
Padding(
padding: const EdgeInsets.all(16),
32 changes: 18 additions & 14 deletions lib/core/models/transaction/transaction.dart
Original file line number Diff line number Diff line change
@@ -163,54 +163,58 @@ class MoneyTransaction extends TransactionInDB {
required Periodicity periodicity,
bool convertToPreferredCurrency = true,
}) {
final baseValue =
double baseValue =
convertToPreferredCurrency ? currentValueInPreferredCurrency : value;

if (recurrentInfo.isNoRecurrent) {
return baseValue;
}

final intervalEachDivider = recurrentInfo.intervalEach ?? 1;

baseValue = baseValue / intervalEachDivider;

if (periodicity == recurrentInfo.intervalPeriod) {
return baseValue / recurrentInfo.intervalEach!;
return baseValue;
} else if (recurrentInfo.intervalPeriod == Periodicity.day) {
if (periodicity == Periodicity.week) {
return baseValue / 7;
return baseValue * 7;
}
if (periodicity == Periodicity.month) {
return baseValue / 30;
return baseValue * 30;
}
if (periodicity == Periodicity.year) {
return baseValue / 365;
return baseValue * 365;
}
} else if (recurrentInfo.intervalPeriod == Periodicity.week) {
if (periodicity == Periodicity.day) {
return baseValue * 7;
return baseValue / 7;
}
if (periodicity == Periodicity.month) {
return baseValue / 4;
return baseValue * 4;
}
if (periodicity == Periodicity.year) {
return baseValue / 52;
return baseValue * 52;
}
} else if (recurrentInfo.intervalPeriod == Periodicity.month) {
if (periodicity == Periodicity.day) {
return baseValue * 30;
return baseValue / 30;
}
if (periodicity == Periodicity.week) {
return baseValue * 4;
return baseValue / 4;
}
if (periodicity == Periodicity.year) {
return baseValue / 12;
return baseValue * 12;
}
} else if (recurrentInfo.intervalPeriod == Periodicity.year) {
if (periodicity == Periodicity.day) {
return baseValue * 365;
return baseValue / 365;
}
if (periodicity == Periodicity.week) {
return baseValue * 52;
return baseValue / 52;
}
if (periodicity == Periodicity.month) {
return baseValue * 12;
return baseValue / 12;
}
}

0 comments on commit 9fe28e6

Please sign in to comment.