Make dynamic invoice settings for documents
This commit is contained in:
@@ -43,6 +43,12 @@ abstract class DocumentForm extends Base
|
||||
|
||||
/** @var bool */
|
||||
public $hideCompanyEdit;
|
||||
|
||||
/** @var string */
|
||||
public $titleSetting;
|
||||
|
||||
/** @var string */
|
||||
public $subheadingSetting;
|
||||
/** Company Component End */
|
||||
|
||||
/** Content Component Start */
|
||||
@@ -72,6 +78,12 @@ abstract class DocumentForm extends Base
|
||||
|
||||
/** @var bool */
|
||||
public $hideButtons;
|
||||
|
||||
/** @var string */
|
||||
public $footerSetting;
|
||||
|
||||
/** @var string */
|
||||
public $notesSetting;
|
||||
/** Content Component End */
|
||||
|
||||
/** Metadata Component Start */
|
||||
@@ -199,10 +211,12 @@ abstract class DocumentForm extends Base
|
||||
/** Advanced Component End */
|
||||
/** Company Component Start */
|
||||
bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false,
|
||||
string $titleSetting = '', string $subheadingSetting = '',
|
||||
/** Company Component End */
|
||||
/** Content Component Start */
|
||||
string $routeStore = '', string $routeUpdate = '', string $formId = 'document', string $formSubmit = 'onSubmit', string $routeCancel = '',
|
||||
bool $hideCompany = false, bool $hideAdvanced = false, bool $hideFooter = false, bool $hideButtons = false,
|
||||
string $footerSetting = '', string $notesSetting = '',
|
||||
/** Content Component End */
|
||||
/** Metadata Component Start */
|
||||
$contacts = [], $contact = false, string $contactType = '', string $contactSearchRoute = '', string $contactCreateRoute = '',
|
||||
@@ -234,6 +248,8 @@ abstract class DocumentForm extends Base
|
||||
$this->hideDocumentTitle = $hideDocumentTitle;
|
||||
$this->hideDocumentSubheading = $hideDocumentSubheading;
|
||||
$this->hideCompanyEdit = $hideCompanyEdit;
|
||||
$this->titleSetting = $this->getTitleSettingValue($titleSetting);
|
||||
$this->subheadingSetting = $this->getSubheadingSettingValue($subheadingSetting);
|
||||
/** Company Component End */
|
||||
|
||||
/** Content Component Start */
|
||||
@@ -247,6 +263,8 @@ abstract class DocumentForm extends Base
|
||||
$this->hideAdvanced = $hideAdvanced;
|
||||
$this->hideFooter = $hideFooter;
|
||||
$this->hideButtons = $hideButtons;
|
||||
$this->footerSetting = $this->getFooterSettingValue($footerSetting);
|
||||
$this->notesSetting = $this->getNotesSettingValue($notesSetting);
|
||||
/** Content Component End */
|
||||
|
||||
/** Metadata Component Start */
|
||||
@@ -580,7 +598,7 @@ abstract class DocumentForm extends Base
|
||||
$issuedAt = Date::now()->toDateString();
|
||||
}
|
||||
|
||||
$addDays = (setting($type . '.payment_terms', 0)) ? setting($type . '.payment_terms', 0) : 0;
|
||||
$addDays = setting($this->getSettingKey($type, 'payment_terms'), 0) ?: 0;
|
||||
|
||||
$dueAt = Date::parse($issuedAt)->addDays($addDays)->toDateString();
|
||||
|
||||
@@ -689,8 +707,8 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.item_name', 'items') == 'custom') {
|
||||
if (empty($textItems = setting($type . '.item_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'item_name'), 'items') === 'custom') {
|
||||
if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
|
||||
$textItems = 'general.items';
|
||||
}
|
||||
|
||||
@@ -713,8 +731,8 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.quantity_name', 'quantity') == 'custom') {
|
||||
if (empty($textQuantity = setting($type . '.quantity_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
|
||||
if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
|
||||
$textQuantity = 'invoices.quantity';
|
||||
}
|
||||
|
||||
@@ -737,8 +755,8 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.price_name', 'price') == 'custom') {
|
||||
if (empty($textPrice = setting($type . '.price_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
|
||||
if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
|
||||
$textPrice = 'invoices.price';
|
||||
}
|
||||
|
||||
@@ -793,7 +811,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideName = setting($type . '.hide_item_name', false)) {
|
||||
if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
|
||||
return $hideName;
|
||||
}
|
||||
|
||||
@@ -814,7 +832,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDescription = setting($type . '.hide_item_description', false)) {
|
||||
if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
|
||||
return $hideDescription;
|
||||
}
|
||||
|
||||
@@ -835,7 +853,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideQuantity = setting($type . '.hide_quantity', false)) {
|
||||
if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
|
||||
return $hideQuantity;
|
||||
}
|
||||
|
||||
@@ -856,7 +874,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hidePrice = setting($type . '.hide_price', false)) {
|
||||
if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
|
||||
return $hidePrice;
|
||||
}
|
||||
|
||||
@@ -877,7 +895,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDiscount = setting($type . '.hide_discount', false)) {
|
||||
if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
|
||||
return $hideDiscount;
|
||||
}
|
||||
|
||||
@@ -898,7 +916,7 @@ abstract class DocumentForm extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideAmount = setting($type . '.hide_amount', false)) {
|
||||
if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
|
||||
return $hideAmount;
|
||||
}
|
||||
|
||||
@@ -911,4 +929,40 @@ abstract class DocumentForm extends Base
|
||||
// @todo what return value invoice or always false??
|
||||
return setting('invoice.hide_amount', $hideAmount);
|
||||
}
|
||||
|
||||
protected function getTitleSettingValue($titleSetting)
|
||||
{
|
||||
if (!empty($titleSetting)) {
|
||||
return $titleSetting;
|
||||
}
|
||||
|
||||
return setting($this->getSettingKey($this->type, 'title'));
|
||||
}
|
||||
|
||||
protected function getSubheadingSettingValue($subheadingSetting)
|
||||
{
|
||||
if (!empty($subheadingSetting)) {
|
||||
return $subheadingSetting;
|
||||
}
|
||||
|
||||
return setting($this->getSettingKey($this->type, 'subheading'));
|
||||
}
|
||||
|
||||
protected function getFooterSettingValue($footerSetting)
|
||||
{
|
||||
if (!empty($footerSetting)) {
|
||||
return $footerSetting;
|
||||
}
|
||||
|
||||
return setting($this->getSettingKey($this->type, 'footer'));
|
||||
}
|
||||
|
||||
protected function getNotesSettingValue($notesSetting)
|
||||
{
|
||||
if (!empty($notesSetting)) {
|
||||
return $notesSetting;
|
||||
}
|
||||
|
||||
return setting($this->getSettingKey($this->type, 'notes'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Abstracts\View\Components;
|
||||
use App\Abstracts\View\Components\Document as Base;
|
||||
use App\Models\Common\Media;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Documents;
|
||||
use File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
@@ -16,6 +17,7 @@ use Storage;
|
||||
abstract class DocumentShow extends Base
|
||||
{
|
||||
use DateTime;
|
||||
use Documents;
|
||||
|
||||
public $type;
|
||||
|
||||
@@ -578,7 +580,7 @@ abstract class DocumentShow extends Base
|
||||
$type = $alias . '.' . str_replace('-', '_', $type);
|
||||
}
|
||||
|
||||
$documentTemplate = setting($type . '.template') ?: 'default';
|
||||
$documentTemplate = setting($this->getSettingKey($type, 'template')) ?: 'default';
|
||||
|
||||
return $documentTemplate;
|
||||
}
|
||||
@@ -1384,7 +1386,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideName = setting($type . '.hide_item_name', false)) {
|
||||
if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
|
||||
return $hideName;
|
||||
}
|
||||
|
||||
@@ -1405,7 +1407,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDescription = setting($type . '.hide_item_description', false)) {
|
||||
if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
|
||||
return $hideDescription;
|
||||
}
|
||||
|
||||
@@ -1426,7 +1428,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideQuantity = setting($type . '.hide_quantity', false)) {
|
||||
if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
|
||||
return $hideQuantity;
|
||||
}
|
||||
|
||||
@@ -1447,7 +1449,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hidePrice = setting($type . '.hide_price', false)) {
|
||||
if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
|
||||
return $hidePrice;
|
||||
}
|
||||
|
||||
@@ -1468,7 +1470,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDiscount = setting($type . '.hide_discount', false)) {
|
||||
if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
|
||||
return $hideDiscount;
|
||||
}
|
||||
|
||||
@@ -1489,7 +1491,7 @@ abstract class DocumentShow extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideAmount = setting($type . '.hide_amount', false)) {
|
||||
if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
|
||||
return $hideAmount;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Abstracts\View\Components;
|
||||
use App\Abstracts\View\Components\Document as Base;
|
||||
use App\Models\Common\Media;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Documents;
|
||||
use File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Image;
|
||||
@@ -14,6 +15,7 @@ use Storage;
|
||||
abstract class DocumentTemplate extends Base
|
||||
{
|
||||
use DateTime;
|
||||
use Documents;
|
||||
|
||||
public $type;
|
||||
|
||||
@@ -180,7 +182,7 @@ abstract class DocumentTemplate extends Base
|
||||
return $template;
|
||||
}
|
||||
|
||||
$documentTemplate = setting($type . '.template', 'default');
|
||||
$documentTemplate = setting($this->getSettingKey($type, 'template'), 'default');
|
||||
|
||||
return $documentTemplate;
|
||||
}
|
||||
@@ -248,7 +250,7 @@ abstract class DocumentTemplate extends Base
|
||||
$type = $alias . '.' . str_replace('-', '_', $type);
|
||||
}
|
||||
|
||||
$backgroundColor = setting($type . '.color', '#55588b');
|
||||
$backgroundColor = setting($this->getSettingKey($type, 'color'), '#55588b');
|
||||
|
||||
return $backgroundColor;
|
||||
}
|
||||
@@ -368,8 +370,8 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.item_name', 'items') == 'custom') {
|
||||
if (empty($textItems = setting($type . '.item_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'item_name'), 'items') == 'custom') {
|
||||
if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
|
||||
$textItems = 'general.items';
|
||||
}
|
||||
|
||||
@@ -392,8 +394,8 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.quantity_name', 'quantity') == 'custom') {
|
||||
if (empty($textQuantity = setting($type . '.quantity_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
|
||||
if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
|
||||
$textQuantity = 'invoices.quantity';
|
||||
}
|
||||
|
||||
@@ -416,8 +418,8 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if (setting($type . '.price_name', 'price') == 'custom') {
|
||||
if (empty($textPrice = setting($type . '.price_name_input'))) {
|
||||
if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
|
||||
if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
|
||||
$textPrice = 'invoices.price';
|
||||
}
|
||||
|
||||
@@ -472,7 +474,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideName = setting($type . '.hide_item_name', false)) {
|
||||
if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
|
||||
return $hideName;
|
||||
}
|
||||
|
||||
@@ -493,7 +495,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDescription = setting($type . '.hide_item_description', false)) {
|
||||
if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
|
||||
return $hideDescription;
|
||||
}
|
||||
|
||||
@@ -514,7 +516,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideQuantity = setting($type . '.hide_quantity', false)) {
|
||||
if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
|
||||
return $hideQuantity;
|
||||
}
|
||||
|
||||
@@ -535,7 +537,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hidePrice = setting($type . '.hide_price', false)) {
|
||||
if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
|
||||
return $hidePrice;
|
||||
}
|
||||
|
||||
@@ -556,7 +558,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideDiscount = setting($type . '.hide_discount', false)) {
|
||||
if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
|
||||
return $hideDiscount;
|
||||
}
|
||||
|
||||
@@ -577,7 +579,7 @@ abstract class DocumentTemplate extends Base
|
||||
}
|
||||
|
||||
// if you use settting translation
|
||||
if ($hideAmount = setting($type . '.hide_amount', false)) {
|
||||
if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
|
||||
return $hideAmount;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user