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

View File

@ -83,11 +83,17 @@ class InvoiceTransformer extends BaseTransformer {
}
else {
//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[] = [
'notes' => 'Imported Invoice',
'cost' => $this->getFloat( $record, 'Invoice Total' ),
'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,
];

View File

@ -39,21 +39,21 @@ class CreateInvoicePdf implements ShouldQueue
if(isset($event->invoice))
{
$event->invoice->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation);
CreateEntityPdf::dispatch($invitation->load("invoice", "contact.client.company"));
});
}
if(isset($event->quote))
{
$event->quote->invitations->each(function ($invitation) {
CreateEntityPdf::dispatch($invitation);
CreateEntityPdf::dispatch($invitation->load("quote", "contact.client.company"));
});
}
if(isset($event->credit))
{
$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) {
if (! isset($invitation->sent_date)) {
$invitation->load('invoice');
$invitation->sent_date = Carbon::now();
$invitation->save();
}

View File

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

View File

@ -110,12 +110,20 @@ class ActivityRepository extends BaseRepository
private function generateHtml($entity)
{
$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';
} 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';
} elseif ($entity instanceof Credit) {
$entity_type = 'credit';
$entity_design_id = 'credit_design_id';
}
@ -132,7 +140,7 @@ class ActivityRepository extends BaseRepository
$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) {
$options = [

View File

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

View File

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

View File

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