From f091cbd060e3166c68f24cb3d0fe765e746967a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Wed, 6 Jul 2016 18:30:23 +0200 Subject: [PATCH 1/2] Show client name next to invoice no. on dashboard - Fix #949 and resolves #949 - Display client name next to invoice number on dashboard --- app/Models/Invoice.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 432e811bff6a9..6273ce74e408f 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -140,7 +140,9 @@ class Invoice extends EntityModel implements BalanceAffecting */ public function getDisplayName() { - return $this->is_recurring ? trans('texts.recurring') : $this->invoice_number; + return $this->is_recurring + ? trans('texts.recurring') + : $this->invoice_number.' ('.$this->client->name.')'; } /** From 42c51ea94a4c9a3fec943d98a818724c57a1c975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Wed, 6 Jul 2016 19:42:36 +0200 Subject: [PATCH 2/2] Create virtual display_name field on client - Create virtual display_name field on client - Create accessor for it --- app/Models/Client.php | 18 ++++++++++++++++++ app/Models/Invoice.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index 6d6dd0b4bc340..0949d4948f11d 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -49,6 +49,13 @@ class Client extends EntityModel 'website', ]; + /** + * @var array + */ + protected $appends = [ + 'display_name', + ]; + /** * @var string */ @@ -331,6 +338,17 @@ class Client extends EntityModel return $contact->getDisplayName(); } + /** + * Making the virtual property display_name accessible + * via an accessor + * + * @return mixed|string + */ + public function getDisplayNameAttribute() + { + return $this->getDisplayName(); + } + /** * @return string */ diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 6273ce74e408f..95a0cfaa5674a 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -142,7 +142,7 @@ class Invoice extends EntityModel implements BalanceAffecting { return $this->is_recurring ? trans('texts.recurring') - : $this->invoice_number.' ('.$this->client->name.')'; + : $this->invoice_number.' ('.$this->client->display_name.')'; } /**