Improve queries for recurring objects to exclusive disabled companies

This commit is contained in:
David Bomba 2021-10-02 12:49:18 +10:00
parent 5ddbc0f507
commit 63e6b1c26d
4 changed files with 36 additions and 11 deletions

View File

@ -52,6 +52,9 @@ class AutoBillCron
->where('auto_bill_enabled', true)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company');
nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill");
@ -65,6 +68,9 @@ class AutoBillCron
->where('auto_bill_enabled', true)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company');
nlog($auto_bill_invoices->count(). " full invoices to auto bill");
@ -85,6 +91,9 @@ class AutoBillCron
->where('auto_bill_enabled', true)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company');
nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill db = {$db}");
@ -98,6 +107,9 @@ class AutoBillCron
->where('auto_bill_enabled', true)
->where('balance', '>', 0)
->where('is_deleted', false)
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company');
nlog($auto_bill_invoices->count(). " full invoices to auto bill db = {$db}");

View File

@ -66,6 +66,9 @@ class RecurringExpensesCron
->whereNull('deleted_at')
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('remaining_cycles', '!=', '0')
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company')
->cursor();

View File

@ -53,15 +53,19 @@ class RecurringInvoicesCron
$query->where('is_deleted',0)
->where('deleted_at', NULL);
})
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company')
->cursor();
nlog(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count());
$recurring_invoices->each(function ($recurring_invoice, $key) {
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
if (!$recurring_invoice->company->is_disabled) {
nlog("Trying to send {$recurring_invoice->number}");
try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
@ -69,7 +73,7 @@ class RecurringInvoicesCron
catch(\Exception $e){
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
}
}
});
} else {
//multiDB environment, need to
@ -86,6 +90,9 @@ class RecurringInvoicesCron
$query->where('is_deleted',0)
->where('deleted_at', NULL);
})
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('company')
->cursor();
@ -94,7 +101,7 @@ class RecurringInvoicesCron
$recurring_invoices->each(function ($recurring_invoice, $key) {
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date ." Recurring #id = ". $recurring_invoice->id);
if (!$recurring_invoice->company->is_disabled) {
nlog("Trying to send {$recurring_invoice->number}");
try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
@ -102,7 +109,7 @@ class RecurringInvoicesCron
catch(\Exception $e){
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
}
}
});
}
}

View File

@ -70,6 +70,9 @@ class ReminderJob implements ShouldQueue
$query->where('is_deleted',0)
->where('deleted_at', NULL);
})
->whereHas('company', function ($query) {
$query->where('is_disabled',0);
})
->with('invitations')->cursor()->each(function ($invoice) {
if ($invoice->isPayable()) {