Get invoice in overdue and in reminders limit

This commit is contained in:
David Callizaya 2021-10-28 17:51:01 -04:00
parent dc7be8fc77
commit 2dd2bcdc57
2 changed files with 3 additions and 2 deletions

View File

@ -39,7 +39,7 @@ class InvoiceOverdueCron extends Command
public function handle()
{
// Get 'overdue' invoices
Invoice::whereOverdueReminders()
Invoice::inOverdueAndRemindersLimit()
->get()
->each(function (Invoice $invoice) {
$invoice->sendInvoiceReminder();

View File

@ -57,8 +57,9 @@ trait InvoiceReminder
/**
* Scope a query to include only the overdue invoices and at the limit of reminders.
*/
public function scopeOverdueReminders($query)
public function scopeInOverdueAndRemindersLimit($query)
{
$query->where('state', '=', 'overdue');
if ($this->hasOverdueRemindersLimit()) {
$limit = $this->getOverdueRemindersLimit();
return $query->where('reminders', '<', $limit);