Fixes for eager loading

This commit is contained in:
David Bomba 2022-04-20 11:55:33 +10:00
parent fde59d0cd8
commit 127683ee29
9 changed files with 34 additions and 19 deletions

View File

@ -35,9 +35,9 @@ class QueryLogging
{ {
// Enable query logging for development // Enable query logging for development
if (!Ninja::isHosted() || !config('beacon.enabled')) { // if (!Ninja::isHosted() || !config('beacon.enabled')) {
return $next($request); // return $next($request);
} // }
$timeStart = microtime(true); $timeStart = microtime(true);
DB::enableQueryLog(); DB::enableQueryLog();
@ -52,11 +52,12 @@ class QueryLogging
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
// info("Query count = {$count}"); // info("Query count = {$count}");
$url = urldecode($request->url());
if($count > 175){ $method = $request->method();
nlog("Query count = {$count}"); // if($count > 175){
nlog($queries); nlog("Query count = {$count} - {$method} - {$url} ");
} // nlog($queries);
// }
$ip = ''; $ip = '';

View File

@ -83,11 +83,17 @@ class InvoiceTransformer extends BaseTransformer {
} }
else { else {
//could be a generate invoices.csv file //could be a generate invoices.csv file
$calculated_tax_rate = 0;
if($this->getFloat( $record, 'Invoice Tax Total' ) != 0 && $this->getFloat( $record, 'Invoice Total' ) != 0)
$calculated_tax_rate = round($this->getFloat( $record, 'Invoice Tax Total' ) / $this->getFloat( $record, 'Invoice Total' ) * 100,2);
$line_items[] = [ $line_items[] = [
'notes' => 'Imported Invoice', 'notes' => 'Imported Invoice',
'cost' => $this->getFloat( $record, 'Invoice Total' ), 'cost' => $this->getFloat( $record, 'Invoice Total' ),
'tax_name1' => 'Tax', 'tax_name1' => 'Tax',
'tax_rate1' => round($this->getFloat( $record, 'Invoice Tax Total' ) / $this->getFloat( $record, 'Invoice Total' ) * 100,2), 'tax_rate1' => $calculated_tax_rate,
'quantity' => 1, 'quantity' => 1,
]; ];

View File

@ -39,21 +39,21 @@ class CreateInvoicePdf implements ShouldQueue
if(isset($event->invoice)) if(isset($event->invoice))
{ {
$event->invoice->invitations->each(function ($invitation) { $event->invoice->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation); CreateEntityPdf::dispatch($invitation->load("invoice", "contact.client.company"));
}); });
} }
if(isset($event->quote)) if(isset($event->quote))
{ {
$event->quote->invitations->each(function ($invitation) { $event->quote->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation); CreateEntityPdf::dispatch($invitation->load("quote", "contact.client.company"));
}); });
} }
if(isset($event->credit)) if(isset($event->credit))
{ {
$event->credit->invitations->each(function ($invitation) { $event->credit->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation); CreateEntityPdf::dispatch($invitation->load("credit", "contact.client.company"));
}); });
} }

View File

@ -466,6 +466,7 @@ class Invoice extends BaseModel
{ {
$this->invitations->each(function ($invitation) { $this->invitations->each(function ($invitation) {
if (! isset($invitation->sent_date)) { if (! isset($invitation->sent_date)) {
$invitation->load('invoice');
$invitation->sent_date = Carbon::now(); $invitation->sent_date = Carbon::now();
$invitation->save(); $invitation->save();
} }

View File

@ -70,7 +70,6 @@ class AppServiceProvider extends ServiceProvider
app()->instance(TruthSource::class, new TruthSource()); app()->instance(TruthSource::class, new TruthSource());
// Model::preventLazyLoading( // Model::preventLazyLoading(
// !$this->app->isProduction() // !$this->app->isProduction()
// ); // );

View File

@ -110,12 +110,20 @@ class ActivityRepository extends BaseRepository
private function generateHtml($entity) private function generateHtml($entity)
{ {
$entity_design_id = ''; $entity_design_id = '';
$entity_type = '';
if ($entity instanceof Invoice || $entity instanceof RecurringInvoice) { if ($entity instanceof Invoice ) {
$entity_type = 'invoice';
$entity_design_id = 'invoice_design_id'; $entity_design_id = 'invoice_design_id';
} elseif ($entity instanceof Quote) { } elseif ($entity instanceof RecurringInvoice){
$entity_type = 'recurring_invoice';
$entity_design_id = 'invoice_design_id';
}
elseif ($entity instanceof Quote) {
$entity_type = 'quote';
$entity_design_id = 'quote_design_id'; $entity_design_id = 'quote_design_id';
} elseif ($entity instanceof Credit) { } elseif ($entity instanceof Credit) {
$entity_type = 'credit';
$entity_design_id = 'credit_design_id'; $entity_design_id = 'credit_design_id';
} }
@ -132,7 +140,7 @@ class ActivityRepository extends BaseRepository
$entity->load('client.company', 'invitations'); $entity->load('client.company', 'invitations');
$html = new HtmlEngine($entity->invitations->first()); $html = new HtmlEngine($entity->invitations->first()->load($entity_type, "contact"));
if ($design->is_custom) { if ($design->is_custom) {
$options = [ $options = [

View File

@ -242,7 +242,7 @@ class InvoiceService
public function triggeredActions($request) public function triggeredActions($request)
{ {
$this->invoice = (new TriggeredActions($this->invoice, $request))->run(); $this->invoice = (new TriggeredActions($this->invoice->load('invitations'), $request))->run();
return $this; return $this;
} }

View File

@ -221,7 +221,7 @@ class QuoteService
public function triggeredActions($request) public function triggeredActions($request)
{ {
$this->quote = (new TriggeredActions($this->quote, $request))->run(); $this->quote = (new TriggeredActions($this->quote->load('invitations'), $request))->run();
return $this; return $this;
} }

View File

@ -58,7 +58,7 @@ class HtmlEngine
$this->company = $invitation->company; $this->company = $invitation->company;
$this->contact = $invitation->contact; $this->contact = $invitation->contact->load('client');
$this->client = $this->contact->client->load('company','country'); $this->client = $this->contact->client->load('company','country');