mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Improve eager loads (#3289)
* Working on invoice designs * Working on Invoice Designs * Improve eager loads
This commit is contained in:
parent
797c3fb3f6
commit
4f82f1b903
@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Factory\ClientFactory;
|
||||
@ -481,6 +482,8 @@ class CreateTestData extends Command
|
||||
|
||||
UpdateInvoicePayment::dispatchNow($payment, $payment->company);
|
||||
}
|
||||
//@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging.
|
||||
//event(new InvoiceWasCreated($invoice, $invoice->company));
|
||||
}
|
||||
|
||||
private function createCredit($client)
|
||||
|
@ -36,10 +36,11 @@ class Designer
|
||||
* formatted HTML
|
||||
* @return string The HTML design built
|
||||
*/
|
||||
public function build(Invoice $invoice)
|
||||
public function build(Invoice $invoice) :Designer
|
||||
{
|
||||
|
||||
$this->setDesign($this->getSection('header'))
|
||||
$this->exportVariables()
|
||||
->setDesign($this->getSection('header'))
|
||||
->setDesign($this->getSection('body'))
|
||||
->setDesign($this->getTable($invoice))
|
||||
->setDesign($this->getSection('footer'));
|
||||
@ -82,8 +83,6 @@ class Designer
|
||||
*/
|
||||
public function getSection($section) :string
|
||||
{
|
||||
$this->exportVariables();
|
||||
|
||||
return str_replace(array_keys($this->exported_variables), array_values($this->exported_variables), $this->design->{$section}());
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -172,7 +172,7 @@ class LoginController extends BaseController
|
||||
|
||||
$user->setCompany($user->company_user->account->default_company);
|
||||
|
||||
$ct = CompanyUser::whereUserId($user->id);
|
||||
$ct = CompanyUser::whereUserId($user->id)->with('company');
|
||||
return $this->listResponse($ct);
|
||||
} else {
|
||||
$this->incrementLoginAttempts($request);
|
||||
|
@ -49,8 +49,8 @@ class QueryLogging
|
||||
$time = $timeEnd - $timeStart;
|
||||
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
||||
|
||||
// if($count > 50)
|
||||
// Log::info($queries);
|
||||
if($count > 50)
|
||||
Log::info($queries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,9 +94,10 @@ class Client extends BaseModel
|
||||
protected $with = [
|
||||
//'currency',
|
||||
// 'primary_contact',
|
||||
'country',
|
||||
// 'country',
|
||||
'contacts',
|
||||
// 'shipping_country',
|
||||
// 'company'
|
||||
// 'company',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -51,8 +51,8 @@ class ClientContact extends Authenticatable implements HasLocalePreference
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'client',
|
||||
'company'
|
||||
// 'client',
|
||||
// 'company'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -30,7 +30,7 @@ class CreditInvitation extends BaseModel
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'company',
|
||||
// 'company',
|
||||
];
|
||||
|
||||
public function entityType()
|
||||
|
@ -96,8 +96,8 @@ class Invoice extends BaseModel
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'company',
|
||||
'client',
|
||||
// 'company',
|
||||
// 'client',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
|
@ -30,7 +30,7 @@ class InvoiceInvitation extends BaseModel
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'company',
|
||||
// 'company',
|
||||
];
|
||||
|
||||
public function entityType()
|
||||
|
@ -71,6 +71,10 @@ class Payment extends BaseModel
|
||||
'is_deleted' => 'bool',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'paymentables',
|
||||
];
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->belongsTo(Client::class)->withTrashed();
|
||||
|
@ -53,6 +53,10 @@ class Vendor extends BaseModel
|
||||
'deleted_at' => 'timestamp',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'contacts',
|
||||
];
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
|
@ -49,8 +49,8 @@ class VendorContact extends Authenticatable implements HasLocalePreference
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'vendor',
|
||||
'company'
|
||||
// 'vendor',
|
||||
// 'company'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -33,8 +33,6 @@ trait MakesInvoiceHtml
|
||||
{
|
||||
$variables = array_merge($invoice->makeLabels(), $invoice->makeValues());
|
||||
|
||||
// uasort($variables, 'arraySort');
|
||||
|
||||
$design = str_replace(array_keys($variables), array_values($variables), $design);
|
||||
|
||||
$data['invoice'] = $invoice;
|
||||
|
@ -140,6 +140,8 @@ trait MakesInvoiceValues
|
||||
*/
|
||||
public function makeLabels() :array
|
||||
{
|
||||
$custom_fields = $this->company->custom_fields;
|
||||
|
||||
//todo we might want to translate like this
|
||||
//trans('texts.labe', [], null, $this->client->locale());
|
||||
$data = [];
|
||||
@ -148,6 +150,9 @@ trait MakesInvoiceValues
|
||||
$data['$'.$label . '_label'] = ctrans('texts.'.$label);
|
||||
}
|
||||
|
||||
if(property_exists($custom_fields,'invoice_text1'))
|
||||
$data['$invoice_text1'] = $custom_fields->invoice_text1;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -169,6 +174,11 @@ trait MakesInvoiceValues
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['$total_tax_labels'] = $this->totalTaxLabels();
|
||||
$data['$total_tax_values'] = $this->totalTaxValues();
|
||||
$data['$line_tax_labels'] = $this->lineTaxLabels();
|
||||
$data['$line_tax_values'] = $this->lineTaxValues();
|
||||
|
||||
$data['$date'] = $this->date;
|
||||
$data['$invoice.date'] = &$data['$date'];
|
||||
$data['$due_date'] = $this->due_date;
|
||||
@ -402,7 +412,7 @@ trait MakesInvoiceValues
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
||||
$table_body = '<tr class="">';
|
||||
$table_body .= '<tr class="">';
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$table_body .= '<td class="'.$css['table_body_td_class'].'">'. $item->{$column} . '</td>';
|
||||
@ -540,4 +550,58 @@ trait MakesInvoiceValues
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function totalTaxLabels() :string
|
||||
{
|
||||
$data = '';
|
||||
|
||||
if (!$this->calc()->getTotalTaxMap()) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($this->calc()->getTotalTaxMap() as $tax) {
|
||||
$data .= '<span>'. $tax['name'] .'</span>';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function totalTaxValues() :string
|
||||
{
|
||||
$data = '';
|
||||
|
||||
if (!$this->calc()->getTotalTaxMap()) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($this->calc()->getTotalTaxMap() as $tax) {
|
||||
$data .= '<span>'. Number::formatMoney($tax['total'], $this->client) .'</span>';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function lineTaxLabels() :string
|
||||
{
|
||||
$tax_map = $this->calc()->getTaxMap();
|
||||
|
||||
$data = '';
|
||||
|
||||
foreach ($tax_map as $tax)
|
||||
$data .= '<span>'. $tax['name'] .'</span>';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function lineTaxValues() :string
|
||||
{
|
||||
$tax_map = $this->calc()->getTaxMap();
|
||||
|
||||
$data = '';
|
||||
|
||||
foreach ($tax_map as $tax)
|
||||
$data .= '<span>'. Number::formatMoney($tax['total'], $this->client) .'</span>';
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user