2020-07-22 14:30:55 +02:00
|
|
|
<?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;
|
|
|
|
|
2020-08-05 14:24:10 +02:00
|
|
|
use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
|
|
|
|
use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader;
|
|
|
|
use App\Utils\Traits\MakesInvoiceValues;
|
|
|
|
|
|
|
|
class Clean extends BaseDesign
|
2020-07-22 14:30:55 +02:00
|
|
|
{
|
2020-08-05 14:24:10 +02:00
|
|
|
use MakesInvoiceValues, BuildTableHeader;
|
|
|
|
|
|
|
|
/** 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 => invoice||quote */
|
|
|
|
public $type;
|
|
|
|
|
2020-07-22 14:30:55 +02:00
|
|
|
public function html()
|
|
|
|
{
|
|
|
|
return file_get_contents(
|
2020-08-05 14:24:10 +02:00
|
|
|
base_path('resources/views/pdf-designs/clean.html')
|
2020-07-22 14:30:55 +02:00
|
|
|
);
|
|
|
|
}
|
2020-08-05 14:24:10 +02:00
|
|
|
|
|
|
|
public function elements(array $context, string $type = 'invoice'): array
|
|
|
|
{
|
|
|
|
$this->context = $context;
|
|
|
|
$this->type = $type;
|
|
|
|
|
|
|
|
$this->setup();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'company-details' => [
|
|
|
|
'id' => 'company-details',
|
|
|
|
'elements' => $this->companyDetails(),
|
|
|
|
],
|
|
|
|
'company-address' => [
|
|
|
|
'id' => 'company-address',
|
|
|
|
'elements' => $this->companyAddress(),
|
|
|
|
],
|
|
|
|
'entity-details' => [
|
|
|
|
'id' => 'entity-details',
|
|
|
|
'elements' => $this->entityDetails(),
|
|
|
|
],
|
|
|
|
'client-details' => [
|
|
|
|
'id' => 'client-details',
|
|
|
|
'elements' => $this->clientDetails(),
|
|
|
|
],
|
|
|
|
'product-table' => [
|
|
|
|
'id' => 'product-table',
|
|
|
|
'elements' => $this->productTable(),
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function companyDetails()
|
|
|
|
{
|
|
|
|
$variables = $this->entity->company->settings->pdf_variables->company_details;
|
|
|
|
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
foreach ($variables as $variable) {
|
|
|
|
$elements[] = ['element' => 'p', 'content' => $variable];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function companyAddress(): array
|
|
|
|
{
|
|
|
|
$variables = $this->entity->company->settings->pdf_variables->company_address;
|
|
|
|
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
foreach ($variables as $variable) {
|
|
|
|
$elements[] = ['element' => 'p', 'content' => $variable];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function entityDetails(): array
|
|
|
|
{
|
|
|
|
$variables = $this->entity->company->settings->pdf_variables->invoice_details;
|
|
|
|
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
foreach ($variables as $variable) {
|
|
|
|
$elements[] = ['element' => 'tr', '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']],
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clientDetails(): array
|
|
|
|
{
|
|
|
|
$variables = $this->entity->company->settings->pdf_variables->client_details;
|
|
|
|
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
foreach ($variables as $variable) {
|
|
|
|
$elements[] = ['element' => 'p', 'content' => $variable];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function productTable(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => $this->buildTableHeader()],
|
|
|
|
['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()],
|
2020-08-05 14:24:10 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildTableHeader(): array
|
|
|
|
{
|
|
|
|
$this->processTaxColumns();
|
|
|
|
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
foreach ($this->context['product-table-columns'] as $column) {
|
|
|
|
$elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-semibold px-4 py-5']];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildTableBody(): array
|
|
|
|
{
|
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
$items = $this->transformLineItems($this->entity->line_items);
|
|
|
|
|
|
|
|
if (count($items) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($items as $row) {
|
|
|
|
$element = ['element' => 'tr', 'content' => '', 'elements' => []];
|
|
|
|
|
|
|
|
foreach ($this->context['product-table-columns'] as $key => $cell) {
|
|
|
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t border-b px-4 py-4']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$elements[] = $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
2020-08-07 14:05:40 +02:00
|
|
|
|
|
|
|
public function tableFooter()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']],
|
|
|
|
['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [
|
2020-08-07 16:02:37 +02:00
|
|
|
['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => $this->calculateColspan(1)]],
|
2020-08-07 14:05:40 +02:00
|
|
|
['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
];
|
|
|
|
}
|
2020-07-22 14:30:55 +02:00
|
|
|
}
|