Hello, Hope you guys are doing well. I have faced an issue I need a better solution. Please read the description below,
I have an invoice management system where companies can register and will get their own dashboard where they can update their own settings and can create invoices for their clients. Now I have to send the due invoice reminder mail.
Now, the problem is as companies can set the interval.
Company A wants to send the invoice 7 days before the due and then before 2 days of the due total of 2 reminders.
Company B wants to send the invoice 5 days before the due and then before 1 day of the due date total of 2 reminders.
As I have one scheduled job for checking this,
If I query all unpaid invoices with company and company settings and check then check the date and then send the mail and in case I have 200k invoices of companies it will be costly.
Please write your approach to this problem. It will help me a lot.
and I in case I have 200k invoices of companies it will be costly.
But thats the solution you are offering? No technical solution is going to prevent you sending 2 or 3 x 200K emails, only a change in business strategy.
@Snapey I mean how you will query the invoice to send mail, Yeah we can be sending mail by the queue.
But, When there have a lot of invoices then will you query them all and do the condition check in the loop?
And I am sorry, Maybe I couldn't explain perfectly in the question. Thanks
@bmtamim your client wants to send an email for invoices that are n days before due
you don't need to care what n is, just use this value in the database query so that for that customer you only pull x invoices that meet the criteria. Then you can loop over them and send the invoice reminder, then move onto next customer
you have two reminder intervals. If you can fix at that, just query for 1st reminder, then query for 2nd reminder. If customers want more flexibility then you might need to store these intervals in a separate table. What about post due reminders (overdue) - you might need negative intervals eg -5 being 5 days late, the same mechanism should be used for both
finally, you might consider what you do if something goes wrong. If you had to restart the process you would not want to accidentally resend loads of reminders, so maybe you need to record that the reminder was sent