mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 00:34:35 -04:00
Refactor for whereHas('client
This commit is contained in:
parent
7240f4f1e7
commit
96f980aa54
@ -62,17 +62,29 @@ class SendRemindersCron extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
Invoice::where('next_send_date', '<=', now()->toDateTimeString())
|
Invoice::where('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereNull('deleted_at')
|
->whereNull('invoices.deleted_at')
|
||||||
->where('is_deleted', 0)
|
->where('invoices.is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->whereHas('client', function ($query) {
|
|
||||||
$query->where('is_deleted', 0)
|
->leftJoin('clients', function ($join) {
|
||||||
->where('deleted_at', null);
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
})
|
->where('clients.is_deleted', 0)
|
||||||
->whereHas('company', function ($query) {
|
->whereNull('clients.deleted_at');
|
||||||
$query->where('is_disabled', 0);
|
})
|
||||||
})
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
|
|
||||||
|
// ->whereHas('client', function ($query) {
|
||||||
|
// $query->where('is_deleted', 0)
|
||||||
|
// ->where('deleted_at', null);
|
||||||
|
// })
|
||||||
|
// ->whereHas('company', function ($query) {
|
||||||
|
// $query->where('is_disabled', 0);
|
||||||
|
// })
|
||||||
|
|
||||||
->with('invitations')->cursor()->each(function ($invoice) {
|
->with('invitations')->cursor()->each(function ($invoice) {
|
||||||
if ($invoice->isPayable()) {
|
if ($invoice->isPayable()) {
|
||||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||||
|
@ -282,9 +282,11 @@ abstract class QueryFilters
|
|||||||
if($value == 'true')
|
if($value == 'true')
|
||||||
{
|
{
|
||||||
return $this->builder->leftJoin('clients', function($join) {
|
return $this->builder->leftJoin('clients', function($join) {
|
||||||
$join->on('invoices.client_id', '=', 'clients.id')
|
|
||||||
->where('clients.is_deleted', 0)
|
$join->on("{$this->builder->getQuery()->from}.client_id", '=', 'clients.id')
|
||||||
->whereNull('clients.deleted_at');
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,20 @@ class SearchController extends Controller
|
|||||||
$invoices = Invoice::query()
|
$invoices = Invoice::query()
|
||||||
->company()
|
->company()
|
||||||
->with('client')
|
->with('client')
|
||||||
->where('is_deleted', 0)
|
->where('invoices.is_deleted', 0)
|
||||||
->whereHas('client', function ($q) {
|
// ->whereHas('client', function ($q) {
|
||||||
$q->where('is_deleted', 0);
|
// $q->where('is_deleted', 0);
|
||||||
})
|
// })
|
||||||
|
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0);
|
||||||
|
})
|
||||||
|
|
||||||
->when(!$user->hasPermission('view_all') || !$user->hasPermission('view_invoice'), function ($query) use ($user) {
|
->when(!$user->hasPermission('view_all') || !$user->hasPermission('view_invoice'), function ($query) use ($user) {
|
||||||
$query->where('user_id', $user->id);
|
$query->where('invoices.user_id', $user->id);
|
||||||
})
|
})
|
||||||
->orderBy('id', 'desc')
|
->orderBy('invoices.id', 'desc')
|
||||||
->take(3000)
|
->take(3000)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
@ -48,18 +48,27 @@ class RecurringInvoicesCron
|
|||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
if (! config('ninja.db.multi_db_enabled')) {
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
$recurring_invoices = RecurringInvoice::query()->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
$recurring_invoices = RecurringInvoice::query()->where('recurring_invoices.status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('is_deleted', false)
|
->where('recurring_invoices.is_deleted', false)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('recurring_invoices.remaining_cycles', '!=', '0')
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('recurring_invoices.next_send_date')
|
||||||
->whereNull('deleted_at')
|
->whereNull('recurring_invoices.deleted_at')
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('recurring_invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
|
// })
|
||||||
|
// ->whereHas('company', function ($query) {
|
||||||
|
// $query->where('is_disabled', 0);
|
||||||
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('recurring_invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
})
|
})
|
||||||
->whereHas('company', function ($query) {
|
->leftJoin('companies', function ($join) {
|
||||||
$query->where('is_disabled', 0);
|
$join->on('recurring_invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
})
|
})
|
||||||
->with('company')
|
->with('company')
|
||||||
->cursor();
|
->cursor();
|
||||||
@ -87,18 +96,27 @@ class RecurringInvoicesCron
|
|||||||
foreach (MultiDB::$dbs as $db) {
|
foreach (MultiDB::$dbs as $db) {
|
||||||
MultiDB::setDB($db);
|
MultiDB::setDB($db);
|
||||||
|
|
||||||
$recurring_invoices = RecurringInvoice::query()->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
$recurring_invoices = RecurringInvoice::query()->where('recurring_invoices.status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('is_deleted', false)
|
->where('recurring_invoices.is_deleted', false)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('recurring_invoices.remaining_cycles', '!=', '0')
|
||||||
->whereNull('deleted_at')
|
->whereNull('recurring_invoices.deleted_at')
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('recurring_invoices.next_send_date')
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('recurring_invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
|
// })
|
||||||
|
// ->whereHas('company', function ($query) {
|
||||||
|
// $query->where('is_disabled', 0);
|
||||||
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('recurring_invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
})
|
})
|
||||||
->whereHas('company', function ($query) {
|
->leftJoin('companies', function ($join) {
|
||||||
$query->where('is_disabled', 0);
|
$join->on('recurring_invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
})
|
})
|
||||||
->with('company')
|
->with('company')
|
||||||
->cursor();
|
->cursor();
|
||||||
|
@ -51,20 +51,29 @@ class InvoiceCheckLateWebhook implements ShouldQueue
|
|||||||
->pluck('company_id');
|
->pluck('company_id');
|
||||||
|
|
||||||
Invoice::query()
|
Invoice::query()
|
||||||
->where('is_deleted', false)
|
->where('invoices.is_deleted', false)
|
||||||
->whereNull('deleted_at')
|
->whereNull('invoices.deleted_at')
|
||||||
->whereNotNull('due_date')
|
->whereNotNull('invoices.due_date')
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->whereIn('company_id', $company_ids)
|
->whereIn('invoices.company_id', $company_ids)
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
|
->whereBetween('invoices.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function ($invoice) {
|
->each(function ($invoice) {
|
||||||
(new WebhookHandler(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client'))->handle();
|
(new WebhookHandler(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client'))->handle();
|
||||||
@ -78,20 +87,29 @@ class InvoiceCheckLateWebhook implements ShouldQueue
|
|||||||
->pluck('company_id');
|
->pluck('company_id');
|
||||||
|
|
||||||
Invoice::query()
|
Invoice::query()
|
||||||
->where('is_deleted', false)
|
->where('invoices.is_deleted', false)
|
||||||
->whereNull('deleted_at')
|
->whereNull('invoices.deleted_at')
|
||||||
->whereNotNull('due_date')
|
->whereNotNull('invoices.due_date')
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->whereIn('company_id', $company_ids)
|
->whereIn('invoices.company_id', $company_ids)
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
|
->whereBetween('invoices.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function ($invoice) {
|
->each(function ($invoice) {
|
||||||
(new WebhookHandler(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client'))->handle();
|
(new WebhookHandler(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client'))->handle();
|
||||||
|
@ -49,19 +49,28 @@ class QuoteCheckExpired implements ShouldQueue
|
|||||||
{
|
{
|
||||||
if (! config('ninja.db.multi_db_enabled')) {
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
Quote::query()
|
Quote::query()
|
||||||
->where('status_id', Quote::STATUS_SENT)
|
->where('quotes.status_id', Quote::STATUS_SENT)
|
||||||
->where('is_deleted', false)
|
->where('quotes.is_deleted', false)
|
||||||
->whereNull('deleted_at')
|
->whereNull('quotes.deleted_at')
|
||||||
->whereNotNull('due_date')
|
->whereNotNull('quotes.due_date')
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
// ->where('due_date', '<='. now()->toDateTimeString())
|
->leftJoin('clients', function ($join) {
|
||||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
$join->on('quotes.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('quotes.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
|
|
||||||
|
->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function ($quote) {
|
->each(function ($quote) {
|
||||||
$this->queueExpiredQuoteNotification($quote);
|
$this->queueExpiredQuoteNotification($quote);
|
||||||
@ -71,19 +80,27 @@ class QuoteCheckExpired implements ShouldQueue
|
|||||||
MultiDB::setDB($db);
|
MultiDB::setDB($db);
|
||||||
|
|
||||||
Quote::query()
|
Quote::query()
|
||||||
->where('status_id', Quote::STATUS_SENT)
|
->where('quotes.status_id', Quote::STATUS_SENT)
|
||||||
->where('is_deleted', false)
|
->where('quotes.is_deleted', false)
|
||||||
->whereNull('deleted_at')
|
->whereNull('quotes.deleted_at')
|
||||||
->whereNotNull('due_date')
|
->whereNotNull('quotes.due_date')
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
|
// })
|
||||||
|
// ->whereHas('company', function ($query) {
|
||||||
|
// $query->where('is_disabled', 0);
|
||||||
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('quotes.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
})
|
})
|
||||||
->whereHas('company', function ($query) {
|
->leftJoin('companies', function ($join) {
|
||||||
$query->where('is_disabled', 0);
|
$join->on('quotes.company_id', '=', 'companies.id')
|
||||||
})
|
->where('companies.is_disabled', 0);
|
||||||
// ->where('due_date', '<='. now()->toDateTimeString())
|
})
|
||||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function ($quote) {
|
->each(function ($quote) {
|
||||||
$this->queueExpiredQuoteNotification($quote);
|
$this->queueExpiredQuoteNotification($quote);
|
||||||
|
@ -61,17 +61,26 @@ class QuoteReminderJob implements ShouldQueue
|
|||||||
nrlog("Sending quote reminders on ".now()->format('Y-m-d h:i:s'));
|
nrlog("Sending quote reminders on ".now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
Quote::query()
|
Quote::query()
|
||||||
->where('is_deleted', 0)
|
->where('quotes.is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT])
|
->whereIn('quotes.status_id', [Invoice::STATUS_SENT])
|
||||||
->whereNull('deleted_at')
|
->whereNull('quotes.deleted_at')
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('quotes.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('quotes.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('quotes.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
->with('invitations')->chunk(50, function ($quotes) {
|
->with('invitations')->chunk(50, function ($quotes) {
|
||||||
foreach ($quotes as $quote) {
|
foreach ($quotes as $quote) {
|
||||||
$this->sendReminderForQuote($quote);
|
$this->sendReminderForQuote($quote);
|
||||||
@ -88,17 +97,26 @@ class QuoteReminderJob implements ShouldQueue
|
|||||||
nrlog("Sending quote reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
nrlog("Sending quote reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
Quote::query()
|
Quote::query()
|
||||||
->where('is_deleted', 0)
|
->where('quotes.is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT])
|
->whereIn('quotes.status_id', [Invoice::STATUS_SENT])
|
||||||
->whereNull('deleted_at')
|
->whereNull('quotes.deleted_at')
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('quotes.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('quotes.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('quotes.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
->with('invitations')->chunk(50, function ($quotes) {
|
->with('invitations')->chunk(50, function ($quotes) {
|
||||||
|
|
||||||
foreach ($quotes as $quote) {
|
foreach ($quotes as $quote) {
|
||||||
|
@ -59,18 +59,27 @@ class ReminderJob implements ShouldQueue
|
|||||||
nrlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));
|
nrlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
Invoice::query()
|
Invoice::query()
|
||||||
->where('is_deleted', 0)
|
->where('invoices.is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->whereNull('deleted_at')
|
->whereNull('invoices.deleted_at')
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
->with('invitations')->chunk(50, function ($invoices) {
|
->with('invitations')->chunk(50, function ($invoices) {
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
$this->sendReminderForInvoice($invoice);
|
$this->sendReminderForInvoice($invoice);
|
||||||
@ -87,18 +96,27 @@ class ReminderJob implements ShouldQueue
|
|||||||
nrlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
nrlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
Invoice::query()
|
Invoice::query()
|
||||||
->where('is_deleted', 0)
|
->where('invoices.is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->whereNull('deleted_at')
|
->whereNull('invoices.deleted_at')
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
->where('invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0)
|
// $query->where('is_deleted', 0)
|
||||||
->where('deleted_at', null);
|
// ->where('deleted_at', null);
|
||||||
})
|
// })
|
||||||
->whereHas('company', function ($query) {
|
// ->whereHas('company', function ($query) {
|
||||||
$query->where('is_disabled', 0);
|
// $query->where('is_disabled', 0);
|
||||||
})
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
})
|
||||||
|
->leftJoin('companies', function ($join) {
|
||||||
|
$join->on('invoices.company_id', '=', 'companies.id')
|
||||||
|
->where('companies.is_disabled', 0);
|
||||||
|
})
|
||||||
->with('invitations')->chunk(50, function ($invoices) {
|
->with('invitations')->chunk(50, function ($invoices) {
|
||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
|
@ -129,7 +129,19 @@ class BaseModel extends Model
|
|||||||
/** @var \App\Models\User $user */
|
/** @var \App\Models\User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
$query->where('company_id', $user->companyId());
|
$query->where("{$query->getQuery()->from}.company_id", $user->companyId());
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeWithoutDeletedClients($query)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query->leftJoin('clients', function ($join) use ($query){
|
||||||
|
$join->on("{$query->getQuery()->from}.client_id", '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
|
});
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -90,15 +90,20 @@ class ARDetailReport extends BaseExport
|
|||||||
$this->csv->insertOne($this->buildHeader());
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query = Invoice::query()
|
$query = Invoice::query()
|
||||||
|
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0);
|
// $query->where('is_deleted', 0);
|
||||||
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
})
|
})
|
||||||
->where('company_id', $this->company->id)
|
->where('invoices.company_id', $this->company->id)
|
||||||
->where('is_deleted', 0)
|
->where('invoices.is_deleted', 0)
|
||||||
->where('balance', '>', 0)
|
->where('invoices.balance', '>', 0)
|
||||||
->orderBy('due_date', 'ASC')
|
->orderBy('invoices.due_date', 'ASC');
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
|
||||||
|
|
||||||
$query = $this->addDateRange($query, 'invoices');
|
$query = $this->addDateRange($query, 'invoices');
|
||||||
|
|
||||||
|
@ -265,8 +265,13 @@ class ProfitLoss
|
|||||||
->whereIn('status_id', [1, 4, 5])
|
->whereIn('status_id', [1, 4, 5])
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereBetween('date', [$this->start_date, $this->end_date])
|
->whereBetween('date', [$this->start_date, $this->end_date])
|
||||||
->whereHas('client', function ($query) {
|
// ->whereHas('client', function ($query) {
|
||||||
$query->where('is_deleted', 0);
|
// $query->where('is_deleted', 0);
|
||||||
|
// })
|
||||||
|
->leftJoin('clients', function ($join) {
|
||||||
|
$join->on('payments.client_id', '=', 'clients.id')
|
||||||
|
->where('clients.is_deleted', 0)
|
||||||
|
->whereNull('clients.deleted_at');
|
||||||
})
|
})
|
||||||
->with(['company', 'client'])
|
->with(['company', 'client'])
|
||||||
->cursor()
|
->cursor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user