How to show alert each month?

Free users on my site can create and send invoices to their customer but are limited to sending 3 invoices per month. So, at the start of the next month they have a fresh 3 invoice ‘credits’.

I can search if the user has an active subscription, but how do I keep track of the date that their fresh 3 invoice ‘credits’ would renew?

Hi there, @darren.james7518… I could be off base here, but I don’t think you necessarily need to do anything to renew a user’s credits at the beginning of each month. If I understand your post correctly, couldn’t you put a condition that looks similar to the following on the element that shows the alert when a user has run out of credits?

I am showing the advanced filter in the screenshot, and the search itself would have a constraint of Created by = Current User. You would also need to add a second expression to the condition that checks to see if the user has an active subscription, but at that point, I think you’d be good to go. Oh, and you could use the same condition to, say, disable the button that enables the user to create a new invoice, too.

So, any of that make sense and seem like it could work for you?

Best…
Mike

1 Like

do what @mikeloc suggested or…

Setup the scheduler for 1st of the month and renew the each users credit count in the table.

1 Like

Thanks @mikeloc for the suggestion. I’m not sure this will work because I can’t refer to ‘this invoice’. My users create a ‘Job’ and within their Jobs they create invoices. So normally I would refer to manage-job's Job's Invoice to find a specific invoice. The issue is, if I search for manage-job's Job's Invoice like below, I am only searching for invoices within a single Job. Of course, I need to block a user from creating any more invoices, regardless of which job they relate to.

1

See the text message below in red, the condition needs to search for invoices created in the previous month and make sure they haven’t exceeded 3. I think the following setup may work, but the text in yellow becomes red (it is not working)?

Also, suppose the user downgrades on 15th of the month, would the above setup work, I assume it will be searching from the 1st of the month? I am a little confused by this!

Idea: Maybe I need a backend workflow which will trigger when a user clicks to create a new invoice AND if the user has already got 3 invoices in the last month + are not subscribed. What do you think? This would successfully prevent a new invoice from being created but it wouldn’t allow me to display the red alert text. hmmm?

What is a scheduler? Also, why the 1st of the month? As said above, suppose the user downgrades on the 15th of the month, I would then need to start counting from that date. To be clear, from the users perspective, once they downgrade I want to show some text says “You are no on the free plan and can send 3 invoices in the next month (from today)”.

1 Like

Hey, I had an idea to allow me to access the necessary data, ie;

IF Current user;

  • created >3 invoices in the last 30days
  • is not on a paid subscription

I added a field to the Invoice Datatype called ‘User_subscription’ so that I can access the invoice data via a ‘Search for User’ operation. But, the yellow text below turns red … any ideas why this isn’t working?

Maybe I’m missing something… but can’t you just use the date of their subscription renewal?

Yes, that could work thank you, but I think I may have a solution, I am left with another question though. The following is used to show an alert when a user exceeds their 3 free invoices per month.

alert

If a user starts on a free plan then this works fine because the start date is literally the date they signed up.

If a user upgrades then their status becomes ‘active’ so the alert won’t show, which is correct.

The query I have is if a user upgrades then later downgrades. In this scenario their status remains ‘active’ until the end of their payment period. So, once their payment period expires they will have a status of ‘not_active’ which will trigger my alert (if they exceed 3 invoices in the last 30 days).

So, will the Current date/time +(days) -30 start when the status of ‘not_active’ is present or will it look back to the last 30 days? I am worried that the user may send 50 invoices on the paid subscription, then downgrade and trigger the status of ‘not_active’ but that will look at the preceding 30 days so possibly assume that the user has exceeded their 3 invoices. I need to ensure that the 3 free invoices per month starts from the second ‘not_active’ is triggered.

@adamhholmes You mentioned that I could use the date of their subscription renewal so maybe when a user downgrades and ‘not_active’ is triggered I could ‘start the clock’ on the month from then - but I don’t have a clue how to do this, what to put in the condition!?
Sorry if I am not explaining clearly!

I have now solved this issue, thanks to @adamhholmes and the help from https://pronocoders.com.

I have a quick related question…

As the solution shows, when a user sends =>3 invoices in a month whilst being on a free/canceled plan then the red alert text shows.

I am basically searching for the following;

count=>3 AND
Subscription_Status is not_activated OR Subscription_Status is canceled

But this could be read and interpreted by Bubble as;

count=>3 AND Subscription_Status is not_activated
OR Subscription_Status is canceled

Which of the above does Bubble use? Should I separate into two searches like this?

count=>3 AND Subscription_Status is not_activated
count=>3 AND Subscription_Status is canceled

Which of the above does Bubble use?

Have you tested it to see?

Having just run a quick test myself, I can confirm what I already understood to be the case…

By default, conditions ‘pivot’ around the ‘Or’ operator - so anything before the ‘Or’ or anything after the ‘Or’ will be treated as a separate condition, and if either are true then the overall condition will output as true.

So in your case:

count=>3 AND Subscription_Status is not_activated
OR Subscription_Status is canceled

is how it will be read (but test it for yourself to double check)

i.e. if the count is more than or equal to three AND the subscription status is not_activated then the condition will be true.

Or

If the Subscription status is cancelled then the condition will be true.

So, knowing that, you can either make sure your conditionals are written out in the order that will make them work the way you want them to,

Or, you could use more than one conditional (if that’s a viable option for your use case)…

Or, better still, you can use the new experimental feature ‘Expression parentheses’ to have full control over the order of operations in your conditionals.

1 Like

Thanks @adamhholmes that helps a lot … I tried to test but found it difficult because I have to wait for a subscription to fully expire for results to display. I will see what I can come up with now that I know conditions ‘pivot’ around the ‘Or’ operator.

@adamhholmes Just wanted to update you, the easiest way to circumvent the issue where conditions ‘pivot’ around the ‘Or’ operator in my case was to simply show the element when not active rather than active.

lf-alert

For any Bubbler’s interested, here’s a nice video with information on how to work with Bubble’s order of operations.

1 Like