mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -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()
|
||||
{
|
||||
Invoice::where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereNull('deleted_at')
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0)
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->whereNull('invoices.deleted_at')
|
||||
->where('invoices.is_deleted', 0)
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('invoices.balance', '>', 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);
|
||||
})
|
||||
|
||||
// ->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) {
|
||||
if ($invoice->isPayable()) {
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
|
@ -282,9 +282,11 @@ abstract class QueryFilters
|
||||
if($value == 'true')
|
||||
{
|
||||
return $this->builder->leftJoin('clients', function($join) {
|
||||
$join->on('invoices.client_id', '=', 'clients.id')
|
||||
->where('clients.is_deleted', 0)
|
||||
->whereNull('clients.deleted_at');
|
||||
|
||||
$join->on("{$this->builder->getQuery()->from}.client_id", '=', 'clients.id')
|
||||
->where('clients.is_deleted', 0)
|
||||
->whereNull('clients.deleted_at');
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -81,14 +81,20 @@ class SearchController extends Controller
|
||||
$invoices = Invoice::query()
|
||||
->company()
|
||||
->with('client')
|
||||
->where('is_deleted', 0)
|
||||
->whereHas('client', function ($q) {
|
||||
$q->where('is_deleted', 0);
|
||||
})
|
||||
->where('invoices.is_deleted', 0)
|
||||
// ->whereHas('client', function ($q) {
|
||||
// $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) {
|
||||
$query->where('user_id', $user->id);
|
||||
$query->where('invoices.user_id', $user->id);
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->orderBy('invoices.id', 'desc')
|
||||
->take(3000)
|
||||
->get();
|
||||
|
||||
|
@ -48,18 +48,27 @@ class RecurringInvoicesCron
|
||||
Auth::logout();
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
$recurring_invoices = RecurringInvoice::query()->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->where('is_deleted', false)
|
||||
->where('remaining_cycles', '!=', '0')
|
||||
->whereNotNull('next_send_date')
|
||||
->whereNull('deleted_at')
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
$recurring_invoices = RecurringInvoice::query()->where('recurring_invoices.status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->where('recurring_invoices.is_deleted', false)
|
||||
->where('recurring_invoices.remaining_cycles', '!=', '0')
|
||||
->whereNotNull('recurring_invoices.next_send_date')
|
||||
->whereNull('recurring_invoices.deleted_at')
|
||||
->where('recurring_invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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) {
|
||||
$query->where('is_disabled', 0);
|
||||
->leftJoin('companies', function ($join) {
|
||||
$join->on('recurring_invoices.company_id', '=', 'companies.id')
|
||||
->where('companies.is_disabled', 0);
|
||||
})
|
||||
->with('company')
|
||||
->cursor();
|
||||
@ -87,18 +96,27 @@ class RecurringInvoicesCron
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$recurring_invoices = RecurringInvoice::query()->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->where('is_deleted', false)
|
||||
->where('remaining_cycles', '!=', '0')
|
||||
->whereNull('deleted_at')
|
||||
->whereNotNull('next_send_date')
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
$recurring_invoices = RecurringInvoice::query()->where('recurring_invoices.status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->where('recurring_invoices.is_deleted', false)
|
||||
->where('recurring_invoices.remaining_cycles', '!=', '0')
|
||||
->whereNull('recurring_invoices.deleted_at')
|
||||
->whereNotNull('recurring_invoices.next_send_date')
|
||||
->where('recurring_invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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) {
|
||||
$query->where('is_disabled', 0);
|
||||
->leftJoin('companies', function ($join) {
|
||||
$join->on('recurring_invoices.company_id', '=', 'companies.id')
|
||||
->where('companies.is_disabled', 0);
|
||||
})
|
||||
->with('company')
|
||||
->cursor();
|
||||
|
@ -51,20 +51,29 @@ class InvoiceCheckLateWebhook implements ShouldQueue
|
||||
->pluck('company_id');
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', false)
|
||||
->whereNull('deleted_at')
|
||||
->whereNotNull('due_date')
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0)
|
||||
->whereIn('company_id', $company_ids)
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->where('invoices.is_deleted', false)
|
||||
->whereNull('invoices.deleted_at')
|
||||
->whereNotNull('invoices.due_date')
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('invoices.balance', '>', 0)
|
||||
->whereIn('invoices.company_id', $company_ids)
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->where('deleted_at', null);
|
||||
// })
|
||||
// ->whereHas('company', function ($query) {
|
||||
// $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);
|
||||
})
|
||||
->whereBetween('invoices.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->cursor()
|
||||
->each(function ($invoice) {
|
||||
(new WebhookHandler(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client'))->handle();
|
||||
@ -78,20 +87,29 @@ class InvoiceCheckLateWebhook implements ShouldQueue
|
||||
->pluck('company_id');
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', false)
|
||||
->whereNull('deleted_at')
|
||||
->whereNotNull('due_date')
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0)
|
||||
->whereIn('company_id', $company_ids)
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->where('invoices.is_deleted', false)
|
||||
->whereNull('invoices.deleted_at')
|
||||
->whereNotNull('invoices.due_date')
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('invoices.balance', '>', 0)
|
||||
->whereIn('invoices.company_id', $company_ids)
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->where('deleted_at', null);
|
||||
// })
|
||||
// ->whereHas('company', function ($query) {
|
||||
// $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);
|
||||
})
|
||||
->whereBetween('invoices.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->cursor()
|
||||
->each(function ($invoice) {
|
||||
(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')) {
|
||||
Quote::query()
|
||||
->where('status_id', Quote::STATUS_SENT)
|
||||
->where('is_deleted', false)
|
||||
->whereNull('deleted_at')
|
||||
->whereNotNull('due_date')
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
// ->where('due_date', '<='. now()->toDateTimeString())
|
||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->where('quotes.status_id', Quote::STATUS_SENT)
|
||||
->where('quotes.is_deleted', false)
|
||||
->whereNull('quotes.deleted_at')
|
||||
->whereNotNull('quotes.due_date')
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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');
|
||||
})
|
||||
->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()
|
||||
->each(function ($quote) {
|
||||
$this->queueExpiredQuoteNotification($quote);
|
||||
@ -71,19 +80,27 @@ class QuoteCheckExpired implements ShouldQueue
|
||||
MultiDB::setDB($db);
|
||||
|
||||
Quote::query()
|
||||
->where('status_id', Quote::STATUS_SENT)
|
||||
->where('is_deleted', false)
|
||||
->whereNull('deleted_at')
|
||||
->whereNotNull('due_date')
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
->where('quotes.status_id', Quote::STATUS_SENT)
|
||||
->where('quotes.is_deleted', false)
|
||||
->whereNull('quotes.deleted_at')
|
||||
->whereNotNull('quotes.due_date')
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
// ->where('due_date', '<='. now()->toDateTimeString())
|
||||
->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()])
|
||||
->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()
|
||||
->each(function ($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'));
|
||||
|
||||
Quote::query()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT])
|
||||
->whereNull('deleted_at')
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->where('quotes.is_deleted', 0)
|
||||
->whereIn('quotes.status_id', [Invoice::STATUS_SENT])
|
||||
->whereNull('quotes.deleted_at')
|
||||
->where('quotes.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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');
|
||||
})
|
||||
->leftJoin('companies', function ($join) {
|
||||
$join->on('quotes.company_id', '=', 'companies.id')
|
||||
->where('companies.is_disabled', 0);
|
||||
})
|
||||
->with('invitations')->chunk(50, function ($quotes) {
|
||||
foreach ($quotes as $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'));
|
||||
|
||||
Quote::query()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT])
|
||||
->whereNull('deleted_at')
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->where('quotes.is_deleted', 0)
|
||||
->whereIn('quotes.status_id', [Invoice::STATUS_SENT])
|
||||
->whereNull('quotes.deleted_at')
|
||||
->where('quotes.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->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');
|
||||
})
|
||||
->leftJoin('companies', function ($join) {
|
||||
$join->on('quotes.company_id', '=', 'companies.id')
|
||||
->where('companies.is_disabled', 0);
|
||||
})
|
||||
->with('invitations')->chunk(50, function ($quotes) {
|
||||
|
||||
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'));
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->whereNull('deleted_at')
|
||||
->where('balance', '>', 0)
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->where('invoices.is_deleted', 0)
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->whereNull('invoices.deleted_at')
|
||||
->where('invoices.balance', '>', 0)
|
||||
->where('invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->where('deleted_at', null);
|
||||
// })
|
||||
// ->whereHas('company', function ($query) {
|
||||
// $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) {
|
||||
foreach ($invoices as $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'));
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->whereNull('deleted_at')
|
||||
->where('balance', '>', 0)
|
||||
->where('next_send_date', '<=', now()->toDateTimeString())
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0)
|
||||
->where('deleted_at', null);
|
||||
})
|
||||
->whereHas('company', function ($query) {
|
||||
$query->where('is_disabled', 0);
|
||||
})
|
||||
->where('invoices.is_deleted', 0)
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->whereNull('invoices.deleted_at')
|
||||
->where('invoices.balance', '>', 0)
|
||||
->where('invoices.next_send_date', '<=', now()->toDateTimeString())
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $query->where('is_deleted', 0)
|
||||
// ->where('deleted_at', null);
|
||||
// })
|
||||
// ->whereHas('company', function ($query) {
|
||||
// $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) {
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
|
@ -129,7 +129,19 @@ class BaseModel extends Model
|
||||
/** @var \App\Models\User $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;
|
||||
}
|
||||
|
@ -90,15 +90,20 @@ class ARDetailReport extends BaseExport
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
|
||||
$query = Invoice::query()
|
||||
->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->withTrashed()
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0);
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $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('is_deleted', 0)
|
||||
->where('balance', '>', 0)
|
||||
->orderBy('due_date', 'ASC')
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||
->where('invoices.company_id', $this->company->id)
|
||||
->where('invoices.is_deleted', 0)
|
||||
->where('invoices.balance', '>', 0)
|
||||
->orderBy('invoices.due_date', 'ASC');
|
||||
|
||||
$query = $this->addDateRange($query, 'invoices');
|
||||
|
||||
|
@ -265,8 +265,13 @@ class ProfitLoss
|
||||
->whereIn('status_id', [1, 4, 5])
|
||||
->where('is_deleted', 0)
|
||||
->whereBetween('date', [$this->start_date, $this->end_date])
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0);
|
||||
// ->whereHas('client', function ($query) {
|
||||
// $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'])
|
||||
->cursor()
|
||||
|
Loading…
x
Reference in New Issue
Block a user