Small refactor to auto bill query

This commit is contained in:
David Bomba 2024-10-01 18:25:46 +10:00
parent 4ef2ff9bae
commit 6dc5e9927a

View File

@ -49,16 +49,17 @@ class AutoBillCron
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) {
$auto_bill_partial_invoices = Invoice::query()
->whereDate('partial_due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0)
->whereDate('partial_due_date', '<=', now())
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->where('is_deleted', false)
->orderBy('id', 'DESC');
nlog($auto_bill_partial_invoices->count().' partial invoices to auto bill');
@ -72,18 +73,18 @@ class AutoBillCron
});
$auto_bill_invoices = Invoice::query()
->whereDate('due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0)
->whereDate('due_date', '<=', now())
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->whereHas('client', function ($query) {
$query->has('gateway_tokens', '>=', 1);
$query->has('gateway_tokens', '>', 0);
})
->where('is_deleted', false)
->orderBy('id', 'DESC');
nlog($auto_bill_invoices->count().' full invoices to auto bill');
@ -121,7 +122,6 @@ class AutoBillCron
foreach ($invoices as $invoice) {
AutoBill::dispatch($invoice->id, $db);
}
sleep(1);
});
@ -146,7 +146,6 @@ class AutoBillCron
foreach ($invoices as $invoice) {
AutoBill::dispatch($invoice->id, $db);
}
sleep(1);
});
}