Merge pull request #3986 from beganovich/v2-1408-pdf-maker-improvements

PdfMaker improvements
This commit is contained in:
David Bomba 2020-08-15 07:58:56 +10:00 committed by GitHub
commit e800c216be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 62 additions and 55 deletions

View File

@ -496,4 +496,14 @@ class Invoice extends BaseModel
// }
// }
// }
public function getBalanceDueAttribute()
{
return $this->balance;
}
public function getTotalAttribute()
{
return $this->calc()->getTotal();
}
}

View File

@ -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();
}
}

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -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']],
]];

View File

@ -1,45 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
/** @deprecated */
class Photo extends BaseDesign
{
use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
/** @var App\Models\Client */
public $client;
/** @var App\Models\Invoice || @var App\Models\Quote */
public $entity;
/** Global state of the design, @var array */
public $context;
/** Type of entity => product||task */
public $type;
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs/bold.html')
);
}
}

View File

@ -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;

View File

@ -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']],
]];

View File

@ -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;
}
}