Skip to content

Commit

Permalink
fix: Wrong recurring transaction period amount calculation
Browse files Browse the repository at this point in the history
Fixes #230
  • Loading branch information
enrique-lozano committed Nov 9, 2024
1 parent 1256e9f commit 523e1a6
Show file tree
Hide file tree
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
Expand Up @@ -61,6 +61,9 @@ class _RecurrentTransactionPageState extends State<RecurrentTransactionPage> {
),
),
),
//
// --------**---------- FOOTER ----------**---------
//
const Divider(endIndent: 16, indent: 16),
Padding(
padding: const EdgeInsets.all(16),
Expand Down
32 changes: 18 additions & 14 deletions lib/core/models/transaction/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 523e1a6

Please sign in to comment.