diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 1c578c2c4aaa..7ce0ba0bdcdf 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -66,24 +66,13 @@ class SendRemindersCron extends Command ->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); - // }) + ->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()) { diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 8c32e62b5c2f..b9c30656a5c8 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -54,21 +54,12 @@ class RecurringInvoicesCron ->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('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); }) - ->leftJoin('companies', function ($join) { - $join->on('recurring_invoices.company_id', '=', 'companies.id') - ->where('companies.is_disabled', 0); + ->whereHas('company', function ($query) { + $query->where('is_disabled', 0); }) ->with('company') ->cursor(); diff --git a/app/Jobs/Quote/QuoteCheckExpired.php b/app/Jobs/Quote/QuoteCheckExpired.php index 9e6f278d359d..15a9ab9383de 100644 --- a/app/Jobs/Quote/QuoteCheckExpired.php +++ b/app/Jobs/Quote/QuoteCheckExpired.php @@ -53,23 +53,14 @@ class QuoteCheckExpired implements ShouldQueue ->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); - }) - + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); + }) + ->whereHas('company', function ($query) { + $query->where('is_disabled', 0); + }) + ->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) ->cursor() ->each(function ($quote) { @@ -84,22 +75,14 @@ class QuoteCheckExpired implements ShouldQueue ->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); + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); }) + ->whereHas('company', function ($query) { + $query->where('is_disabled', 0); + }) + ->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) ->cursor() ->each(function ($quote) { diff --git a/app/Jobs/Util/QuoteReminderJob.php b/app/Jobs/Util/QuoteReminderJob.php index 2df9da34f469..fdebf50198c7 100644 --- a/app/Jobs/Util/QuoteReminderJob.php +++ b/app/Jobs/Util/QuoteReminderJob.php @@ -65,22 +65,13 @@ class QuoteReminderJob implements ShouldQueue ->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); - }) + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); + }) + ->whereHas('company', function ($query) { + $query->where('is_disabled', 0); + }) ->with('invitations')->chunk(50, function ($quotes) { foreach ($quotes as $quote) { $this->sendReminderForQuote($quote); @@ -101,22 +92,14 @@ class QuoteReminderJob implements ShouldQueue ->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); - }) + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); + }) + ->whereHas('company', function ($query) { + $query->where('is_disabled', 0); + }) + ->with('invitations')->chunk(50, function ($quotes) { foreach ($quotes as $quote) { diff --git a/app/Services/Report/ARDetailReport.php b/app/Services/Report/ARDetailReport.php index c27b0e4308c9..68d2dd11be68 100644 --- a/app/Services/Report/ARDetailReport.php +++ b/app/Services/Report/ARDetailReport.php @@ -92,13 +92,8 @@ class ARDetailReport extends BaseExport $query = Invoice::query() ->whereIn('invoices.status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->withTrashed() - // ->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'); + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0); }) ->where('invoices.company_id', $this->company->id) ->where('invoices.is_deleted', 0) diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index c921df0f187e..09d392435a12 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -265,13 +265,8 @@ 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); - // }) - ->leftJoin('clients', function ($join) { - $join->on('payments.client_id', '=', 'clients.id') - ->where('clients.is_deleted', 0) - ->whereNull('clients.deleted_at'); + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0); }) ->with(['company', 'client']) ->cursor() diff --git a/resources/views/portal/ninja2020/recurring_invoices/show.blade.php b/resources/views/portal/ninja2020/recurring_invoices/show.blade.php index df9a8c59bf9d..aed229b7fbe5 100644 --- a/resources/views/portal/ninja2020/recurring_invoices/show.blade.php +++ b/resources/views/portal/ninja2020/recurring_invoices/show.blade.php @@ -101,18 +101,7 @@ - - - - - - - - - - @if($invoice->subscription && $invoice->subscription?->allow_cancellation) - {{-- INV2-591 --}} - {{-- @if(false) --}} + @if($invoice->subscription && $invoice->subscription?->allow_cancellation && $invoice->status_id == 2)
diff --git a/resources/views/portal/ninja2020/subscriptions/show.blade.php b/resources/views/portal/ninja2020/subscriptions/show.blade.php index a2e226cd928c..c3540d56b788 100644 --- a/resources/views/portal/ninja2020/subscriptions/show.blade.php +++ b/resources/views/portal/ninja2020/subscriptions/show.blade.php @@ -73,7 +73,7 @@
@endif - @if($invoice->subscription && $invoice->subscription?->allow_cancellation) + @if($invoice->subscription && $invoice->subscription?->allow_cancellation && $invoice->status_id == 2)
@@ -92,7 +92,7 @@
@endif - @if($invoice->subscription && $invoice->subscription->allow_plan_changes) + @if($invoice->subscription && $invoice->subscription->allow_plan_changes && count($invoice->subscription->service()->getPlans()) > 0)

{{ ctrans('texts.change_plan') }}

{{ ctrans('texts.change_plan_description') }}