diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 590bd9fcff92..e1a9c2153a12 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -496,4 +496,14 @@ class Invoice extends BaseModel // } // } // } + + public function getBalanceDueAttribute() + { + return $this->balance; + } + + public function getTotalAttribute() + { + return $this->calc()->getTotal(); + } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index df0035c1bae5..b8c06d4cf7c0 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -250,4 +250,19 @@ class Quote extends BaseModel return false; } + + public function getValidUntilAttribute() + { + return $this->due_date; + } + + public function getBalanceDueAttribute() + { + return $this->balance; + } + + public function getTotalAttribute() + { + return $this->calc()->getTotal(); + } } diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index d1fa02f3bee2..ffa73edf9598 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -45,7 +45,7 @@ class Bold extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -130,7 +130,7 @@ class Bold extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index a04a3c0c8508..2aa6a816afc8 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -130,7 +130,7 @@ class Business extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 1fd3848da6a1..9c233f007bbd 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -117,7 +117,7 @@ class Clean extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 82cb3e833a32..a3043a89e8c5 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -130,7 +130,7 @@ class Creative extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index f9eea9fc16af..3cc20cbe2cc2 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -91,7 +91,7 @@ class Elegant extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index a3ee624d7452..7c217ebb77fe 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -130,7 +130,7 @@ class Hipster extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'div', 'properties' => ['class' => 'space-x-4'], 'content' => '', 'elements' => [ + $elements[] = ['element' => 'div', 'properties' => ['hidden' => $this->entityVariableCheck($variable), 'class' => 'space-x-4'], 'content' => '', 'elements' => [ ['element' => 'span', 'content' => $variable . '_label', 'properties' => ['class' => 'font-semibold uppercase text-yellow-600']], ['element' => 'span', 'content' => $variable, 'properties' => ['class' => 'uppercase']], ]]; diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 1259d14e363f..4ede0c3c9e0e 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -91,7 +91,7 @@ class Modern extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-16 lg:pr-24 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-16 lg:pr-24 font-normal']], ]]; diff --git a/app/Services/PdfMaker/Designs/Photo.php b/app/Services/PdfMaker/Designs/Photo.php deleted file mode 100644 index 68c9d799dec7..000000000000 --- a/app/Services/PdfMaker/Designs/Photo.php +++ /dev/null @@ -1,45 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/bold.html') - ); - } -} diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index c119b308a560..d08a91357ba4 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -100,10 +100,12 @@ class Plain extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $element = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-medium']], ]]; + + $elements[] = $element; } return $elements; diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index b8c2077d849a..bc9b9c6c1881 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -91,7 +91,7 @@ class Playful extends BaseDesign $elements = []; foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-medium']], ]]; diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index c298d7a9ff16..c97f2aa8ed30 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -164,4 +164,29 @@ trait DesignHelpers ['element' => 'img', 'content' => '', 'properties' => ['src' => '$app_url/images/created-by-invoiceninja-new.png', 'class' => 'h-24', 'hidden' => $this->entity->user->account->isPaid() ? 'true' : 'false']], ]]; } + + public function entityVariableCheck(string $variable): bool + { + // Extract $invoice.date => date + // so we can append date as $entity->date and not $entity->$invoice.date; + + try { + $_variable = explode('.', $variable)[1]; + } catch (\Exception $e) { + throw new \Exception('Company settings seems to be broken. Missing $entity.variable type.'); + } + + if (is_null($this->entity->{$_variable})) { + info("{$this->entity->id} $_variable is null!"); + return true; + } + + if (empty($this->entity->{$_variable})) { + info("{$this->entity->id} $_variable is empty!"); + return true; + } + + info("{$this->entity->id} $_variable ALL GOOD!!"); + return false; + } }