diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 94ba71086a22..caa5d0949197 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -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 = ''; diff --git a/app/Import/Transformer/Wave/InvoiceTransformer.php b/app/Import/Transformer/Wave/InvoiceTransformer.php index 68e40115b354..60921ddee0fd 100644 --- a/app/Import/Transformer/Wave/InvoiceTransformer.php +++ b/app/Import/Transformer/Wave/InvoiceTransformer.php @@ -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, ]; diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php index ab9b23333c74..eb10aaf2a4bb 100644 --- a/app/Listeners/Invoice/CreateInvoicePdf.php +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -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")); }); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 5a028981c5f7..928051e6428f 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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(); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 7374fe18ad27..f2d5f13296cc 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -70,7 +70,6 @@ class AppServiceProvider extends ServiceProvider app()->instance(TruthSource::class, new TruthSource()); - // Model::preventLazyLoading( // !$this->app->isProduction() // ); diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index a4a771991813..6c9e361a226e 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -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 = [ diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 8ecc39274f44..e91ae43aa5b5 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -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; } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 05816b5945ed..e340f9e8ae62 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -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; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 34585a2efb06..6f1a17a54ee3 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -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');