mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 11:14:31 -04:00
Small refactor to auto bill query
This commit is contained in:
parent
4ef2ff9bae
commit
6dc5e9927a
@ -49,17 +49,18 @@ class AutoBillCron
|
|||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
if (! config('ninja.db.multi_db_enabled')) {
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
|
|
||||||
$auto_bill_partial_invoices = Invoice::query()
|
$auto_bill_partial_invoices = Invoice::query()
|
||||||
->whereDate('partial_due_date', '<=', now())
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->where('balance', '>', 0)
|
||||||
->where('auto_bill_enabled', true)
|
->whereDate('partial_due_date', '<=', now())
|
||||||
->where('auto_bill_tries', '<', 3)
|
->where('auto_bill_enabled', true)
|
||||||
->where('balance', '>', 0)
|
->where('auto_bill_tries', '<', 3)
|
||||||
->where('is_deleted', false)
|
->whereHas('company', function ($query) {
|
||||||
->whereHas('company', function ($query) {
|
$query->where('is_disabled', 0);
|
||||||
$query->where('is_disabled', 0);
|
})
|
||||||
})
|
->where('is_deleted', false)
|
||||||
->orderBy('id', 'DESC');
|
->orderBy('id', 'DESC');
|
||||||
|
|
||||||
nlog($auto_bill_partial_invoices->count().' partial invoices to auto bill');
|
nlog($auto_bill_partial_invoices->count().' partial invoices to auto bill');
|
||||||
|
|
||||||
@ -72,18 +73,18 @@ class AutoBillCron
|
|||||||
});
|
});
|
||||||
|
|
||||||
$auto_bill_invoices = Invoice::query()
|
$auto_bill_invoices = Invoice::query()
|
||||||
->whereDate('due_date', '<=', now())
|
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->whereDate('due_date', '<=', now())
|
||||||
->where('auto_bill_enabled', true)
|
->where('auto_bill_enabled', true)
|
||||||
->where('auto_bill_tries', '<', 3)
|
->where('auto_bill_tries', '<', 3)
|
||||||
->where('balance', '>', 0)
|
|
||||||
->where('is_deleted', false)
|
|
||||||
->whereHas('company', function ($query) {
|
->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
$query->where('is_disabled', 0);
|
||||||
})
|
})
|
||||||
->whereHas('client', function ($query) {
|
->whereHas('client', function ($query) {
|
||||||
$query->has('gateway_tokens', '>=', 1);
|
$query->has('gateway_tokens', '>', 0);
|
||||||
})
|
})
|
||||||
|
->where('is_deleted', false)
|
||||||
->orderBy('id', 'DESC');
|
->orderBy('id', 'DESC');
|
||||||
|
|
||||||
nlog($auto_bill_invoices->count().' full invoices to auto bill');
|
nlog($auto_bill_invoices->count().' full invoices to auto bill');
|
||||||
@ -121,7 +122,6 @@ class AutoBillCron
|
|||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
AutoBill::dispatch($invoice->id, $db);
|
AutoBill::dispatch($invoice->id, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -146,7 +146,6 @@ class AutoBillCron
|
|||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
AutoBill::dispatch($invoice->id, $db);
|
AutoBill::dispatch($invoice->id, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user