From 12ca46381a4e5344d95cbe960fa4f61c0abc7705 Mon Sep 17 00:00:00 2001 From: Hendrik Hagendorn Date: Thu, 19 Jan 2023 20:23:15 +0100 Subject: [PATCH] bind title and subheading to the respective document --- .../View/Components/Documents/Form.php | 56 +++++++++++-------- .../View/Components/Documents/Show.php | 10 +++- .../View/Components/Documents/Template.php | 12 +++- app/Models/Document/Document.php | 2 + ...3034_add_title_subheading_to_documents.php | 34 +++++++++++ .../documents/form/company.blade.php | 13 +---- .../documents/form/metadata.blade.php | 22 ++++++++ 7 files changed, 111 insertions(+), 38 deletions(-) create mode 100644 database/migrations/2023_01_19_153034_add_title_subheading_to_documents.php diff --git a/app/Abstracts/View/Components/Documents/Form.php b/app/Abstracts/View/Components/Documents/Form.php index 34f2040b4..d24dfb815 100644 --- a/app/Abstracts/View/Components/Documents/Form.php +++ b/app/Abstracts/View/Components/Documents/Form.php @@ -58,20 +58,8 @@ abstract class Form extends Component /** @var bool */ public $hideLogo; - /** @var bool */ - public $hideDocumentTitle; - - /** @var bool */ - public $hideDocumentSubheading; - /** @var bool */ public $hideCompanyEdit; - - /** @var string */ - public $titleSetting; - - /** @var string */ - public $subheadingSetting; /* -- Company End -- */ /* -- Main Start -- */ @@ -113,6 +101,18 @@ abstract class Form extends Component /** @var string */ public $textChooseDifferentContact; + /** @var bool */ + public $hideDocumentTitle; + + /** @var bool */ + public $hideDocumentSubheading; + + /** @var string */ + public $title; + + /** @var string */ + public $subheading; + /** @var bool */ public $hideIssuedAt; @@ -269,10 +269,11 @@ abstract class Form extends Component string $type, $model = false, $document = false, $currencies = false, $currency = false, $currency_code = false, string $formId = 'document', $formRoute = '', $formMethod = '', bool $hideCompany = false, string $textSectionCompaniesTitle = '', string $textSectionCompaniesDescription = '', - bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, string $titleSetting = '', $subheadingSetting = '', + bool $hideLogo = false, bool $hideCompanyEdit = false, string $textSectionMainTitle = '', string $textSectionMainDescription = '', string $typeContact = '', string $textContact = '', $contacts = [], $contact = false, string $searchContactRoute = '', string $createContactRoute = '', string $textAddContact = '', string $textCreateNewContact = '', string $textEditContact = '', string $textContactInfo = '', string $textChooseDifferentContact = '', + bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, string $title = '', string $subheading = '', bool $hideIssuedAt = false, string $textIssuedAt = '', string $issuedAt = '', bool $hideDueAt = false, string $textDueAt = '', string $dueAt = '', $periodDueAt = '', bool $hideDocumentNumber = false, string $textDocumentNumber = '', string $documentNumber = '', bool $hideOrderNumber = false, string $textOrderNumber = '', string $orderNumber = '', bool $hideEditItemColumns = false, bool $hideItems = false, bool $hideItemName = false, string $textItemName = '', bool $hideItemDescription = false, string $textItemDescription = '', @@ -306,11 +307,7 @@ abstract class Form extends Component $this->textSectionCompaniesTitle = $this->getTextSectionCompaniesTitle($type, $textSectionCompaniesTitle); $this->textSectionCompaniesDescription = $this->getTextSectionCompaniesDescription($type, $textSectionCompaniesDescription); $this->hideLogo = $hideLogo; - $this->hideDocumentTitle = $hideDocumentTitle; - $this->hideDocumentSubheading = $hideDocumentSubheading; $this->hideCompanyEdit = $hideCompanyEdit; - $this->titleSetting = $this->getTitleSettingValue($type, $titleSetting); - $this->subheadingSetting = $this->getSubheadingSettingValue($type, $subheadingSetting); /** Company End */ /* -- Main Start -- */ @@ -332,6 +329,11 @@ abstract class Form extends Component $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo); $this->textChooseDifferentContact = $this->getTextChooseDifferentContact($type, $textChooseDifferentContact); + $this->hideDocumentTitle = $hideDocumentTitle; + $this->hideDocumentSubheading = $hideDocumentSubheading; + $this->title = $this->getTitleValue($type, $title); + $this->subheading = $this->getSubheadingValue($type, $subheading); + $this->hideIssuedAt = $hideIssuedAt; $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); $this->issuedAt = $this->getIssuedAt($type, $document, $issuedAt); @@ -1165,19 +1167,27 @@ abstract class Form extends Component return $this->getTextSectionDescription($type, 'advanced', 'documents.form_description.advanced'); } - protected function getTitleSettingValue($type, $titleSetting) + protected function getTitleValue($type, $title) { - if (! empty($titleSetting)) { - return $titleSetting; + if (! empty($title)) { + return $title; + } + + if (! empty($this->document) && $this->document->title !== '') { + return $this->document->title; } return setting($this->getSettingKey($type, 'title')); } - protected function getSubheadingSettingValue($type, $subheadingSetting) + protected function getSubheadingValue($type, $subheading) { - if (! empty($subheadingSetting)) { - return $subheadingSetting; + if (! empty($subheading)) { + return $subheading; + } + + if (! empty($this->document) && $this->document->title !== '') { + return $this->document->subheading; } return setting($this->getSettingKey($type, 'subheading')); diff --git a/app/Abstracts/View/Components/Documents/Show.php b/app/Abstracts/View/Components/Documents/Show.php index 2831b20f9..2c5ac589c 100644 --- a/app/Abstracts/View/Components/Documents/Show.php +++ b/app/Abstracts/View/Components/Documents/Show.php @@ -482,7 +482,7 @@ abstract class Show extends Component $this->hideDueAt = $hideDueAt; $this->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle); - $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading); + $this->textDocumentSubheading = $this->getTextDocumentSubheading($type, $textDocumentSubheading); $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo); $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber); @@ -994,6 +994,10 @@ abstract class Show extends Component return $textDocumentTitle; } + if (! empty($this->document) && $this->document->title !== '') { + return $this->document->title; + } + $key = $this->getSettingKey($type, 'title'); if (! empty(setting($key))) { @@ -1015,6 +1019,10 @@ abstract class Show extends Component return $textDocumentSubheading; } + if (! empty($this->document) && $this->document->subheading !== '') { + return $this->document->subheading; + } + $key = $this->getSettingKey($type, 'subheading'); if (!empty(setting($key))) { diff --git a/app/Abstracts/View/Components/Documents/Template.php b/app/Abstracts/View/Components/Documents/Template.php index f169dc0e6..f591dbca8 100644 --- a/app/Abstracts/View/Components/Documents/Template.php +++ b/app/Abstracts/View/Components/Documents/Template.php @@ -172,7 +172,7 @@ abstract class Template extends Component $this->hideDueAt = $hideDueAt; $this->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle); - $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading); + $this->textDocumentSubheading = $this->getTextDocumentSubheading($type, $textDocumentSubheading); $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo); $this->showContactRoute = $this->getShowContactRoute($type, $showContactRoute); $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); @@ -193,7 +193,7 @@ abstract class Template extends Component $this->textQuantity = $this->getTextQuantity($type, $textQuantity); $this->textPrice = $this->getTextPrice($type, $textPrice); $this->textAmount = $this->getTextAmount($type, $textAmount); - + $this->print = $this->getPrint($print); // Set Parent data @@ -295,6 +295,10 @@ abstract class Template extends Component return $textDocumentTitle; } + if (! empty($this->document) && $this->document->title !== '') { + return $this->document->title; + } + $key = $this->getSettingKey($type, 'title'); if (! empty(setting($key))) { @@ -316,6 +320,10 @@ abstract class Template extends Component return $textDocumentSubheading; } + if (! empty($this->document) && $this->document->subheading !== '') { + return $this->document->subheading; + } + $key = $this->getSettingKey($type, 'subheading'); if (! empty(setting($key))) { diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index a3eafa946..dd765e052 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -56,6 +56,8 @@ class Document extends Model 'contact_city', 'notes', 'footer', + 'title', + 'subheading', 'parent_id', 'created_from', 'created_by', diff --git a/database/migrations/2023_01_19_153034_add_title_subheading_to_documents.php b/database/migrations/2023_01_19_153034_add_title_subheading_to_documents.php new file mode 100644 index 000000000..f12930a64 --- /dev/null +++ b/database/migrations/2023_01_19_153034_add_title_subheading_to_documents.php @@ -0,0 +1,34 @@ +string('title')->nullable()->default(''); + $table->string('subheading')->nullable()->default(''); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('documents', function (Blueprint $table) { + $table->dropColumn('title'); + $table->dropColumn('subheading'); + }); + } +}; diff --git a/resources/views/components/documents/form/company.blade.php b/resources/views/components/documents/form/company.blade.php index 215908423..2aa16faa2 100644 --- a/resources/views/components/documents/form/company.blade.php +++ b/resources/views/components/documents/form/company.blade.php @@ -7,20 +7,9 @@ -
- @if (! $hideDocumentTitle) - - @endif - - @if (! $hideDocumentSubheading) - - @endif -
- -
-
@if (! $hideLogo) + @endif
diff --git a/resources/views/components/documents/form/metadata.blade.php b/resources/views/components/documents/form/metadata.blade.php index b91833d5f..028fde815 100644 --- a/resources/views/components/documents/form/metadata.blade.php +++ b/resources/views/components/documents/form/metadata.blade.php @@ -22,6 +22,28 @@
+ @stack('title_start') + + @if (! $hideDocumentTitle) + + @endif + + @stack('subheading_start') + + @if (! $hideDocumentSubheading) + + @endif + @stack('issue_start') @if (! $hideIssuedAt)