Hello everyone!
A while ago, I added a new setting to the Finovara app.
What did I add?
I added a user setting for recurring revenue.
The user specifies the:
- recurring revenue amount
- revenue category
- start date
- frequency of revenue generation (daily, weekly, monthly)
How does it work?
The scheduler runs cron daily (currently every minute as a test, but will run daily at midnight).
The cron runs and checks if the revenue generation date matches.
If so, we check the condition in the code.
If it matches, a recurring revenue is created.
This is what an example implementation in a processor looks like:
for (User user : users) {
RevenueSettings settings = user.getRevenueSettings();
if(settings == null) continue;
while(settings.isRecurringRevenuesEnable() && settings.getNextExecutionDate() != null && !settings.getNextExecutionDate().isAfter(today)){
createRecurringRevenue(user, settings);
switch (settings.getRecurringStrategy()) {
case DAILY -> settings.setNextExecutionDate(settings.getNextExecutionDate().plusDays(1));
case WEEKLY -> settings.setNextExecutionDate(settings.getNextExecutionDate().plusWeeks(1));
case MONTHLY -> settings.setNextExecutionDate(settings.getNextExecutionDate().plusMonths(1));
}
}
}
Top comments (0)