Skip to content

Fix: Improve recurring transaction processing logic#1

Open
Sameer184 wants to merge 1 commit intopiyush-eon:mainfrom
Sameer184:fix/recurring-transaction-processing
Open

Fix: Improve recurring transaction processing logic#1
Sameer184 wants to merge 1 commit intopiyush-eon:mainfrom
Sameer184:fix/recurring-transaction-processing

Conversation

@Sameer184
Copy link

@Sameer184 Sameer184 commented Jan 17, 2025

Fix for Recurring Transactions: Accurate Dates, Duplicate Prevention, and Missed Transaction Handling

Description

This pull request fixes some major issues in how recurring transactions are processed in the project. The current logic had some gaps, especially when handling old dates, duplicates, and missed transactions. Below are the identified issues and implemented fixes:

Scenario:

If a user creates a recurring transaction with an old date, the current script only processes one recurring transaction (and that too with the current date). Moreover, if the batch script for recurring transactions is run, it does not create transactions based on nextRecurringDate (whether daily, weekly, monthly, etc.). This caused missed records and inconsistencies.

1. Incorrect Transaction Creation Dates

  • Issue: Transactions were being created with the current date (new Date()), instead of the scheduled recurring date (nextRecurringDate).
  • Fix: Replaced new Date() with nextRecurringDate when creating transactions. Future dates are now calculated using the calculateNextRecurringDate helper function to ensure alignment with the recurring interval.

2. Duplicate Transactions

  • Issue: The script didn’t check if a transaction for the same userId, accountId, and date already existed, leading to duplicates.
  • Fix: A proper check has been added that verifies userId, accountId, and the transaction date before creating a new transaction.

3. Missed or Overdue Transactions

  • Issue: The script only processed the current recurring transaction, leaving skipped or overdue transactions unprocessed.
  • Fix: Implemented a loop to process all overdue transactions from the nextRecurringDate up to the current date. Therefore, no transactions are skipped.

4. Inconsistent updated to nextRecurringDate

  • Issue: nextRecurringDate was not getting updated properly, which resulted in skipped or incorrect scheduling.
  • Fix: Ensured that nextRecurringDate and lastProcessed are updated after each successful transaction.

Why These Fixes Are Important

  • Accurate Transactions: Transactions are now created with correct dates, which helps to maintain proper records.
  • Duplicate Prevention: Avoids redundant transactions that could clutter the database and distort account balances.
  • Missed Transactions: Any missed or overdue transactions are now processed properly, avoiding disruptions in financial records.
  • Consistent Scheduling: Reliable updates to nextRecurringDate ensure that future transactions are scheduled correctly.

Future Enhancements to Address Potential Bugs in updateTransactions Logic

  • Updating Recurring Transactions:
    • If the user attempts to modify a recurring transaction's properties (e.g., recurringInterval, isRecurring, date), ensure all changes are properly reflected, especially for nextRecurringDate.
    • For transactions part of a series (e.g., sharing the same description or accountId), we might need to decide whether related records should also be updated.
    • We might also consider disabling "Edit" button to avoid confusion, especially when it involves transactions with description containing '(Recurrring)'.

Testing and Validation

  • Checked if transactions are created with correct dates for different intervals (daily, weekly, monthly).
  • Tested the duplicate prevention logic by creating multiple transactions with the same date, userId, and accountId.
  • Validated that all missed transactions are processed up to the current date.
  • Verified that nextRecurringDate and lastProcessed attributes are updated consistently in every scenario.

@vercel
Copy link
Contributor

vercel bot commented Jan 17, 2025

@Sameer184 is attempting to deploy a commit to the piyush55dude's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants