mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Clean
This commit is contained in:
parent
2333a78775
commit
1876b228ed
@ -12,12 +12,178 @@
|
||||
|
||||
namespace App\Services\PdfMaker\Designs;
|
||||
|
||||
class Clean
|
||||
use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
|
||||
use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
|
||||
class Clean extends BaseDesign
|
||||
{
|
||||
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;
|
||||
|
||||
public function html()
|
||||
{
|
||||
return file_get_contents(
|
||||
base_path('resources/views/pdf-designs//clean.html')
|
||||
base_path('resources/views/pdf-designs/clean.html')
|
||||
);
|
||||
}
|
||||
|
||||
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()],
|
||||
['element' => 'tfoot', 'content' => '', 'elements' => [
|
||||
['element' => 'tr', 'content' => '', 'elements' => [
|
||||
['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
|
||||
['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' => '6']],
|
||||
['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
||||
]],
|
||||
['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [
|
||||
['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']],
|
||||
['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']],
|
||||
]],
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,6 @@
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
|
||||
<link rel="stylesheet" href="$css" />
|
||||
<link
|
||||
href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
</head>
|
||||
|
||||
<style>
|
||||
|
@ -1,37 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no"
|
||||
/>
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="$css" />
|
||||
</head>
|
||||
|
||||
<link rel="stylesheet" href="$css">
|
||||
</head>
|
||||
<style>
|
||||
#product-table tbody > tr:nth-child(even) {
|
||||
background-color: #f7fafc;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
#product-table tr:nth-child(even) {
|
||||
background-color: #f7fafc;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body class="$global-margin bg-white break-words antialiased">
|
||||
<!-- Company logo, company details -->
|
||||
<div class="grid grid-cols-12 px-2">
|
||||
<img src="$company-logo" alt="$company-name logo" class="grid w-24 col-span-4 sm:w-32">
|
||||
<div class="grid grid-cols-2 col-span-8 text-gray-700 lg:col-span-6">
|
||||
<div id="company-details" class="col-span-1"></div>
|
||||
<div id="company-address" class="col-span-1"></div>
|
||||
<body class="$global-margin bg-white break-words antialiased">
|
||||
<!-- Company logo, company details -->
|
||||
<div class="grid grid-cols-12 px-2">
|
||||
<img
|
||||
src="$company_logo"
|
||||
alt="$company_name logo"
|
||||
class="grid w-24 col-span-4 sm:w-32"
|
||||
/>
|
||||
<div
|
||||
class="grid grid-cols-2 col-span-8 text-gray-700 lg:col-span-6"
|
||||
>
|
||||
<div id="company-details" class="col-span-1"></div>
|
||||
<div id="company-address" class="col-span-1"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Entity labels, client details -->
|
||||
<p class="mt-10 text-xl text-blue-500 uppercase">$entity</p>
|
||||
<div class="grid grid-cols-12 px-2 py-3 mt-4 border-t border-b">
|
||||
<table class="col-span-6 lg:col-span-5" id="entity-details"></table>
|
||||
<div id="client-details" class="col-span-6"></div>
|
||||
</div>
|
||||
<!-- Entity labels, client details -->
|
||||
<p class="mt-10 text-xl text-blue-500 uppercase">$entity</p>
|
||||
<div class="grid grid-cols-12 px-2 py-3 mt-4 border-t border-b">
|
||||
<div class="col-span-6">
|
||||
<table id="entity-details"></table>
|
||||
</div>
|
||||
<div id="client-details" class="col-span-6"></div>
|
||||
</div>
|
||||
|
||||
<!-- Product table -->
|
||||
<table id="product-table" class="table-auto"></table>
|
||||
</body>
|
||||
<!-- Product table -->
|
||||
<table id="product-table" class="table-auto mt-12 w-full"></table>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace Tests\Feature\PdfMaker;
|
||||
|
||||
use App\Models\Design;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\PdfMaker\Designs\Business;
|
||||
use App\Services\PdfMaker\Designs\Clean;
|
||||
use App\Services\PdfMaker\PdfMaker;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
@ -20,7 +19,7 @@ class ExampleIntegrationTest extends TestCase
|
||||
$invitation = $invoice->invitations()->first();
|
||||
|
||||
$engine = new HtmlEngine($invitation, 'invoice');
|
||||
$design = new Business();
|
||||
$design = new Clean();
|
||||
|
||||
$product_table_columns = json_decode(
|
||||
json_encode($invoice->company->settings->pdf_variables),
|
||||
@ -39,7 +38,7 @@ class ExampleIntegrationTest extends TestCase
|
||||
$maker = new PdfMaker($state, 'invoice');
|
||||
|
||||
$maker
|
||||
->design(Business::class)
|
||||
->design(Clean::class)
|
||||
->build();
|
||||
|
||||
exec('echo "" > storage/logs/laravel.log');
|
||||
|
Loading…
x
Reference in New Issue
Block a user