diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 7f9cca2694ef..e0de408ca5e2 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -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) diff --git a/app/Designs/Designer.php b/app/Designs/Designer.php index 41fbc099d07c..b7ab359ab5dd 100644 --- a/app/Designs/Designer.php +++ b/app/Designs/Designer.php @@ -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}()); } diff --git a/app/Designs/Modern.php b/app/Designs/Modern.php index 1f4ab88f58a3..815116373caa 100644 --- a/app/Designs/Modern.php +++ b/app/Designs/Modern.php @@ -29,7 +29,9 @@ class Modern - + @@ -102,10 +104,12 @@ class Modern
- $total_labels + $total_tax_labels + $line_tax_labels
- $total_values + $total_tax_values + $line_tax_values
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 38a0e22b93dd..2901dc8e5ebf 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -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); diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index bae6d524a33f..cccd459ca81a 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -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); } } diff --git a/app/Models/Client.php b/app/Models/Client.php index ab7baf21d80f..55138dbf6ae8 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -94,9 +94,10 @@ class Client extends BaseModel protected $with = [ //'currency', // 'primary_contact', - 'country', + // 'country', + 'contacts', // 'shipping_country', - // 'company' + // 'company', ]; protected $casts = [ diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 3e629897aa97..0388b1775033 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -51,8 +51,8 @@ class ClientContact extends Authenticatable implements HasLocalePreference ]; protected $with = [ - 'client', - 'company' +// 'client', +// 'company' ]; protected $casts = [ diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index e1045074312c..5462c797d29b 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -30,7 +30,7 @@ class CreditInvitation extends BaseModel ]; protected $with = [ - 'company', + // 'company', ]; public function entityType() diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 1a44dbce4cf5..ea6536f44518 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -96,8 +96,8 @@ class Invoice extends BaseModel ]; protected $with = [ - 'company', - 'client', + // 'company', + // 'client', ]; protected $appends = [ diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 5bb294affd3a..beba5722eaa6 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -30,7 +30,7 @@ class InvoiceInvitation extends BaseModel ]; protected $with = [ - 'company', + // 'company', ]; public function entityType() diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 94feb80dc218..6304a9b5887b 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -71,6 +71,10 @@ class Payment extends BaseModel 'is_deleted' => 'bool', ]; + protected $with = [ + 'paymentables', + ]; + public function client() { return $this->belongsTo(Client::class)->withTrashed(); diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 31c542211dc3..c085458307b1 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -53,6 +53,10 @@ class Vendor extends BaseModel 'deleted_at' => 'timestamp', ]; + protected $with = [ + 'contacts', + ]; + public function documents() { return $this->morphMany(Document::class, 'documentable'); diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 58145fc9ec13..57bdf3a95ad8 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -49,8 +49,8 @@ class VendorContact extends Authenticatable implements HasLocalePreference ]; protected $with = [ - 'vendor', - 'company' + // 'vendor', + // 'company' ]; protected $casts = [ diff --git a/app/Utils/Traits/MakesInvoiceHtml.php b/app/Utils/Traits/MakesInvoiceHtml.php index 84965304dc82..7b121c3748eb 100644 --- a/app/Utils/Traits/MakesInvoiceHtml.php +++ b/app/Utils/Traits/MakesInvoiceHtml.php @@ -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; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 3cee087cdbf3..7d4e1b052dd8 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -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 = ''; + $table_body .= ''; foreach ($columns as $column) { $table_body .= ''. $item->{$column} . ''; @@ -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 .= ''. $tax['name'] .''; + } + + return $data; + } + + private function totalTaxValues() :string + { + $data = ''; + + if (!$this->calc()->getTotalTaxMap()) { + return $data; + } + + foreach ($this->calc()->getTotalTaxMap() as $tax) { + $data .= ''. Number::formatMoney($tax['total'], $this->client) .''; + } + + return $data; + } + + private function lineTaxLabels() :string + { + $tax_map = $this->calc()->getTaxMap(); + + $data = ''; + + foreach ($tax_map as $tax) + $data .= ''. $tax['name'] .''; + + return $data; + } + + private function lineTaxValues() :string + { + $tax_map = $this->calc()->getTaxMap(); + + $data = ''; + + foreach ($tax_map as $tax) + $data .= ''. Number::formatMoney($tax['total'], $this->client) .''; + + return $data; + } }