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-04 13:33:38 +02:00
|
|
|
use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader;
|
2020-07-30 17:47:40 +02:00
|
|
|
use App\Utils\Traits\MakesInvoiceValues;
|
|
|
|
|
2020-07-22 14:30:55 +02:00
|
|
|
class Plain
|
|
|
|
{
|
2020-08-04 13:33:38 +02:00
|
|
|
use MakesInvoiceValues, BuildTableHeader;
|
2020-07-30 17:47:40 +02:00
|
|
|
|
2020-08-04 13:37:51 +02:00
|
|
|
/** Global list of table elements, @var array */
|
2020-07-30 16:43:57 +02:00
|
|
|
public $elements;
|
|
|
|
|
2020-08-04 13:37:51 +02:00
|
|
|
/** @var App\Models\Client */
|
2020-07-30 17:47:40 +02:00
|
|
|
public $client;
|
|
|
|
|
2020-08-04 13:37:51 +02:00
|
|
|
/** @var App\Models\Invoice */
|
2020-07-30 17:47:40 +02:00
|
|
|
public $invoice;
|
|
|
|
|
2020-08-04 13:37:51 +02:00
|
|
|
/** Global state of the design, @var string */
|
2020-07-30 17:47:40 +02:00
|
|
|
public $context;
|
2020-07-30 16:43:57 +02:00
|
|
|
|
2020-07-29 14:53:58 +02:00
|
|
|
public function html(): ?string
|
2020-07-22 14:30:55 +02:00
|
|
|
{
|
|
|
|
return file_get_contents(
|
2020-07-30 16:43:57 +02:00
|
|
|
base_path('resources/views/pdf-designs/plain.html')
|
2020-07-22 14:30:55 +02:00
|
|
|
);
|
|
|
|
}
|
2020-07-29 14:53:58 +02:00
|
|
|
|
2020-07-30 17:47:40 +02:00
|
|
|
public function setup(): void
|
|
|
|
{
|
2020-08-04 13:37:51 +02:00
|
|
|
if (isset($this->context['client'])) {
|
|
|
|
$this->client = $this->context['client'];
|
|
|
|
}
|
2020-07-30 17:47:40 +02:00
|
|
|
|
2020-08-04 13:37:51 +02:00
|
|
|
if (isset($this->context['invoice'])) {
|
|
|
|
$this->invoice = $this->context['invoice'];
|
|
|
|
}
|
2020-07-30 17:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function elements(array $context): array
|
2020-07-29 14:53:58 +02:00
|
|
|
{
|
2020-07-30 17:47:40 +02:00
|
|
|
$this->context = $context;
|
|
|
|
$this->setup();
|
|
|
|
|
2020-07-29 14:53:58 +02:00
|
|
|
return [
|
|
|
|
'company-address' => [
|
|
|
|
'id' => 'company-address',
|
|
|
|
'elements' => [
|
|
|
|
['element' => 'p', 'content' => '$company.address1'],
|
|
|
|
],
|
|
|
|
],
|
2020-07-30 17:47:40 +02:00
|
|
|
$this->productTable(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function productTable()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 'product-table',
|
|
|
|
'elements' => [
|
|
|
|
['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->buildTableHeader()],
|
|
|
|
['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()],
|
|
|
|
['element' => 'tfoot', 'content' => '', 'elements' => [
|
|
|
|
['element' => 'tr', 'content' => '', 'elements' => [
|
|
|
|
['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => '2']],
|
|
|
|
['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' => [
|
|
|
|
['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
|
|
|
|
['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-300'], 'elements' => [
|
|
|
|
['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
|
|
|
|
['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
|
|
|
]],
|
|
|
|
]],
|
2020-07-29 14:53:58 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2020-07-30 16:43:57 +02:00
|
|
|
|
2020-07-30 17:47:40 +02:00
|
|
|
public function buildTableHeader(): array
|
2020-07-30 16:43:57 +02:00
|
|
|
{
|
2020-08-04 13:33:38 +02:00
|
|
|
$this->processTaxColumns();
|
2020-08-03 13:29:57 +02:00
|
|
|
|
2020-08-04 13:33:38 +02:00
|
|
|
$elements = [];
|
2020-08-03 13:29:57 +02:00
|
|
|
|
2020-07-30 17:47:40 +02:00
|
|
|
foreach ($this->context['product-table-columns'] as $column) {
|
2020-07-30 16:43:57 +02:00
|
|
|
$elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:47:40 +02:00
|
|
|
public function buildTableBody(): array
|
2020-07-30 16:43:57 +02:00
|
|
|
{
|
2020-07-30 17:47:40 +02:00
|
|
|
$elements = [];
|
|
|
|
|
|
|
|
$items = $this->transformLineItems($this->invoice->line_items);
|
|
|
|
|
|
|
|
if (count($items) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($items as $row) {
|
|
|
|
$element = ['element' => 'tr', 'content' => '', 'elements' => []];
|
|
|
|
|
2020-08-03 13:29:57 +02:00
|
|
|
foreach ($this->context['product-table-columns'] as $key => $cell) {
|
|
|
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']];
|
2020-07-30 17:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$elements[] = $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
2020-07-30 16:43:57 +02:00
|
|
|
}
|
|
|
|
}
|