mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 01:47:32 -04:00 
			
		
		
		
	Roll back join queries
This commit is contained in:
		
							parent
							
								
									1adbd3907e
								
							
						
					
					
						commit
						f3dc80ae09
					
				| @ -66,25 +66,14 @@ 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'); | ||||
|                  ->whereHas('client', function ($query) { | ||||
|                      $query->where('is_deleted', 0) | ||||
|                            ->where('deleted_at', null); | ||||
|                  }) | ||||
|                 ->leftJoin('companies', function ($join) { | ||||
|                     $join->on('invoices.company_id', '=', 'companies.id') | ||||
|                         ->where('companies.is_disabled', 0); | ||||
|                  ->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()) { | ||||
|                          $reminder_template = $invoice->calculateTemplate('invoice'); | ||||
|  | ||||
| @ -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(); | ||||
|  | ||||
| @ -53,21 +53,12 @@ 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'); | ||||
|                  ->whereHas('client', function ($query) { | ||||
|                      $query->where('is_deleted', 0) | ||||
|                             ->where('deleted_at', null); | ||||
|                  }) | ||||
|                 ->leftJoin('companies', function ($join) { | ||||
|                     $join->on('quotes.company_id', '=', 'companies.id') | ||||
|                         ->where('companies.is_disabled', 0); | ||||
|                     ->whereHas('company', function ($query) { | ||||
|                         $query->where('is_disabled', 0); | ||||
|                     }) | ||||
|                  | ||||
|                  ->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) | ||||
| @ -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'); | ||||
|                     ->whereHas('client', function ($query) { | ||||
|                         $query->where('is_deleted', 0) | ||||
|                                ->where('deleted_at', null); | ||||
|                     }) | ||||
|                     ->leftJoin('companies', function ($join) { | ||||
|                         $join->on('quotes.company_id', '=', 'companies.id') | ||||
|                             ->where('companies.is_disabled', 0); | ||||
|                        ->whereHas('company', function ($query) { | ||||
|                            $query->where('is_disabled', 0); | ||||
|                        }) | ||||
|                      | ||||
|                     ->whereBetween('quotes.due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) | ||||
|                     ->cursor() | ||||
|                     ->each(function ($quote) { | ||||
|  | ||||
| @ -65,21 +65,12 @@ 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'); | ||||
|                  ->whereHas('client', function ($query) { | ||||
|                      $query->where('is_deleted', 0) | ||||
|                            ->where('deleted_at', null); | ||||
|                  }) | ||||
|                 ->leftJoin('companies', function ($join) { | ||||
|                     $join->on('quotes.company_id', '=', 'companies.id') | ||||
|                         ->where('companies.is_disabled', 0); | ||||
|                  ->whereHas('company', function ($query) { | ||||
|                      $query->where('is_disabled', 0); | ||||
|                  }) | ||||
|                  ->with('invitations')->chunk(50, function ($quotes) { | ||||
|                      foreach ($quotes as $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'); | ||||
|                      ->whereHas('client', function ($query) { | ||||
|                          $query->where('is_deleted', 0) | ||||
|                                ->where('deleted_at', null); | ||||
|                      }) | ||||
|                     ->leftJoin('companies', function ($join) { | ||||
|                         $join->on('quotes.company_id', '=', 'companies.id') | ||||
|                             ->where('companies.is_disabled', 0); | ||||
|                      ->whereHas('company', function ($query) { | ||||
|                          $query->where('is_disabled', 0); | ||||
|                      }) | ||||
|                      | ||||
|                      ->with('invitations')->chunk(50, function ($quotes) { | ||||
| 
 | ||||
|                          foreach ($quotes as $quote) { | ||||
|  | ||||
| @ -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) | ||||
|  | ||||
| @ -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() | ||||
|  | ||||
| @ -101,18 +101,7 @@ | ||||
|             </dl> | ||||
|         </div> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         @if($invoice->subscription && $invoice->subscription?->allow_cancellation) | ||||
|         {{-- INV2-591 --}} | ||||
|         {{-- @if(false) --}} | ||||
|         @if($invoice->subscription && $invoice->subscription?->allow_cancellation && $invoice->status_id == 2) | ||||
|         <div class="bg-white shadow sm:rounded-lg mt-4"> | ||||
|             <div class="px-4 py-5 sm:p-6"> | ||||
|                 <div class="sm:flex sm:items-start sm:justify-between"> | ||||
|  | ||||
| @ -73,7 +73,7 @@ | ||||
|             </div> | ||||
|         @endif | ||||
| 
 | ||||
|         @if($invoice->subscription && $invoice->subscription?->allow_cancellation) | ||||
|         @if($invoice->subscription && $invoice->subscription?->allow_cancellation && $invoice->status_id == 2) | ||||
|         <div class="bg-white shadow sm:rounded-lg mt-4"> | ||||
|             <div class="px-4 py-5 sm:p-6"> | ||||
|                 <div class="sm:flex sm:items-start sm:justify-between"> | ||||
| @ -92,7 +92,7 @@ | ||||
|         </div> | ||||
|         @endif | ||||
| 
 | ||||
|         @if($invoice->subscription && $invoice->subscription->allow_plan_changes) | ||||
|         @if($invoice->subscription && $invoice->subscription->allow_plan_changes && count($invoice->subscription->service()->getPlans()) > 0) | ||||
|             <div class="bg-white shadow overflow-hidden px-4 py-5 lg:rounded-lg mt-4"> | ||||
|                 <h3 class="text-lg leading-6 font-medium text-gray-900">{{ ctrans('texts.change_plan') }}</h3> | ||||
|                 <p class="mt-1 max-w-2xl text-sm leading-5 text-gray-500">{{ ctrans('texts.change_plan_description') }}</p> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user