Merge pull request #6573 from turbo124/v5-develop

FIxes for eager loading clients with groups.
This commit is contained in:
David Bomba 2021-09-04 17:28:50 +10:00 committed by GitHub
commit 524b1c3581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 9 deletions

View File

@ -24,6 +24,7 @@ use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\Country;
use App\Models\Credit;
use App\Models\Document;
use App\Models\Expense;
use App\Models\Product;
use App\Models\Project;
@ -230,6 +231,7 @@ class CreateTestData extends Command
'company_id' => $company->id,
]);
$this->count = $this->count * 10;
$this->info('Creating '.$this->count.' clients');
@ -387,6 +389,14 @@ class CreateTestData extends Command
'company_id' => $company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
'documentable_type' => Client::class,
'documentable_id' => $client->id
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
@ -428,6 +438,13 @@ class CreateTestData extends Command
'company_id' => $client->company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Vendor::class,
'documentable_id' => $vendor->id
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
@ -449,6 +466,14 @@ class CreateTestData extends Command
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Task::class,
'documentable_id' => $vendor->id
]);
}
private function createProject($client)
@ -457,6 +482,13 @@ class CreateTestData extends Command
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Project::class,
'documentable_id' => $vendor->id
]);
}
private function createInvoice($client)
@ -506,6 +538,13 @@ class CreateTestData extends Command
$invoice = $invoice->service()->markPaid()->save();
}
Document::factory()->count(5)->create([
'user_id' => $invoice->user->id,
'company_id' => $invoice->company_id,
'documentable_type' => Invoice::class,
'documentable_id' => $invoice->id
]);
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}

View File

@ -216,7 +216,7 @@ class BaseController extends Controller
$query->whereNotNull('updated_at')->with('documents');
},
'company.clients' => function ($query) use ($updated_at, $user) {
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents');
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents', 'group_settings');
if(!$user->hasPermission('view_client'))
$query->where('clients.user_id', $user->id)->orWhere('clients.assigned_user_id', $user->id);
@ -457,7 +457,7 @@ class BaseController extends Controller
$query->whereNotNull('created_at')->with('documents');
},
'company.clients' => function ($query) use ($created_at, $user) {
$query->where('clients.created_at', '>=', $created_at)->with('contacts.company', 'gateway_tokens', 'documents');
$query->where('clients.created_at', '>=', $created_at)->with('contacts.company', 'gateway_tokens', 'documents', 'group_settings');
if(!$user->hasPermission('view_client'))
$query->where('clients.user_id', $user->id)->orWhere('clients.assigned_user_id', $user->id);

View File

@ -52,8 +52,10 @@ class QueryLogging
$timeEnd = microtime(true);
$time = $timeEnd - $timeStart;
// if($count > 150)
// nlog($queries);
nlog("Query count = {$count}");
//if($count > 250)
nlog($queries);
$ip = '';

View File

@ -84,8 +84,6 @@ class TemplateEmail extends Mailable
else
$email_from_name = $this->company->present()->name();
nlog($email_from_name);
$this->from(config('mail.from.address'), $email_from_name);
if (strlen($settings->bcc_email) > 1)

View File

@ -213,7 +213,7 @@ class Client extends BaseModel implements HasLocalePreference
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
public function assigned_user()

View File

@ -89,6 +89,8 @@ class AutoBillInvoice extends AbstractService
return $this->invoice;
}
nlog("Gateway present - adding gateway fee");
/* $gateway fee */
$this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save();
@ -105,6 +107,8 @@ class AutoBillInvoice extends AbstractService
'fee_invoice_id' => $this->invoice->id,
]);
nlog("Payment hash created => {$payment_hash->id}");
$payment = $gateway_token->gateway
->driver($this->client)
->setPaymentHash($payment_hash)

View File

@ -82,6 +82,8 @@ class DeletePayment
$net_deletable = $paymentable_invoice->pivot->amount - $paymentable_invoice->pivot->refunded;
nlog("net deletable amount - refunded = {$net_deletable}");
$paymentable_invoice->service()
->updateBalance($net_deletable)
->updatePaidToDate($net_deletable * -1)
@ -103,8 +105,6 @@ class DeletePayment
$paymentable_invoice->service()->setStatus(Invoice::STATUS_PARTIAL)->save();
}
//fire event for this credit
//
});
}