1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
This commit is contained in:
Benjamin Beganović 2020-07-21 16:59:30 +02:00
parent 5c1bf92bf1
commit 8b0cda0c6e
3 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Tests\Feature\PdfMaker;
class Hipster
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/hipster.html')
);
}
}

View File

@ -576,4 +576,113 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true));
}
public function testHipster()
{
$state = [
'template' => [
'company-details' => [
'id' => 'company-details',
'elements' => [
['element' => 'p', 'content' => 'Ninja Sample'],
['element' => 'p', 'content' => 'contact@invoiceninja.com'],
['element' => 'p', 'content' => '1-800-555-Ninja'],
],
],
'company-address' => [
'id' => 'company-address',
'elements' => [
['element' => 'p', 'content' => '123 Ninja Blvd.'],
['element' => 'p', 'content' => 'NinjaLand, 97315'],
['element' => 'p', 'content' => 'United States'],
],
],
'client-details' => [
'id' => 'client-details',
'elements' => [
['element' => 'p', 'content' => 'Winterfield Medical Supply', 'properties' => ['class' => 'font-medium']],
['element' => 'p', 'content' => '65 Medical Complex Rd., D98'],
['element' => 'p', 'content' => 'Atlanta, GA 22546'],
['element' => 'p', 'content' => 'United States'],
['element' => 'p', 'content' => 'demo@invoiceninja.com'],
],
],
'entity-details' => [
'id' => 'entity-details',
'elements' => [
['element' => 'div', 'content' => '', 'properties' => ['class' => 'space-x-4'], 'elements' => [
['element' => 'span', 'content' => '$entity-number-label', 'properties' => ['class' => 'font-semibold uppercase text-yellow-600']],
['element' => 'span', 'content' => '$entity-number', 'properties' => ['class' => 'font-semibold uppercase text-yellow-600']],
]],
['element' => 'div', 'content' => '', 'properties' => ['class' => 'space-x-4'], 'elements' => [
['element' => 'span', 'content' => '$entity-date-label', 'properties' => ['class' => 'uppercase']],
['element' => 'span', 'content' => '$entity-date'],
]],
['element' => 'div', 'content' => '', 'properties' => ['class' => 'space-x-4'], 'elements' => [
['element' => 'span', 'content' => '$balance-due-label', 'properties' => ['class' => 'uppercase']],
['element' => 'span', 'content' => '$balance-due'],
]],
],
],
'product-table' => [
'id' => 'product-table',
'elements' => [
['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left'], 'elements' => [
['element' => 'th', 'content' => 'Item', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']],
['element' => 'th', 'content' => 'Description', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']],
['element' => 'th', 'content' => 'Unit cost', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']],
['element' => 'th', 'content' => 'Quantity', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']],
['element' => 'th', 'content' => 'Line total', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']],
]],
['element' => 'tbody', 'content' => '', 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Painting service', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '25 hours of painting', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '885.00', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '1', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '$885.00', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Painting service', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '25 hours of painting', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '885.00', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '1', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
['element' => 'td', 'content' => '$885.00', 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']],
]],
]],
['element' => 'tfoot', 'content' => '', 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => '2']],
['element' => 'td', 'content' => 'Subtotal', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']],
['element' => 'td', 'content' => '$0', 'properties' => ['class' => 'px-4 py-2 text-right']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Paid to date', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
['element' => 'td', 'content' => '$0.00', 'properties' => ['class' => 'px-4 py-2 text-right']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Discount %20', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
['element' => 'td', 'content' => '$2.00', 'properties' => ['class' => 'px-4 py-2 text-right']],
]],
['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-black text-white'], 'elements' => [
['element' => 'td', 'content' => 'Balance due', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']],
['element' => 'td', 'content' => '$2.00', 'properties' => ['class' => 'px-4 py-2 text-right']],
]],
]],
],
],
],
'variables' => array_merge([], $this->state['variables']),
];
$maker = new PdfMaker($state);
$maker
->design(Hipster::class)
->build();
exec('echo "" > storage/logs/laravel.log');
info($maker->getCompiledHTML(true));
}
}

View File

@ -0,0 +1,47 @@
<!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" />
<link rel="stylesheet" href="$css" />
</head>
<body class="$global-margin antialiased break-words bg-white">
<!-- Company details, address, client details, company logo -->
<div class="grid grid-cols-12 gap-4">
<div class="col-span-4 pl-4 border-l border-black">
<div id="company-details">
<p class="font-semibold text-yellow-600 uppercase">
$from:
</p>
</div>
<div id="company-address" class="mt-4"></div>
</div>
<div
class="col-span-5 pl-4 border-l border-black"
id="client-details"
>
<p class="font-semibold text-yellow-600 uppercase">$to:</p>
</div>
<div class="col-span-3">
<img
src="$company-logo"
alt="$company->name logo"
class="w-24 col-span-4 sm:w-32"
/>
</div>
</div>
<!-- Entity details -->
<h1 class="mt-6 text-4xl font-semibold uppercase lg:text-6xl">$entity</h1>
<div id="entity-details" class="flex items-center space-x-6"></div>
<!-- Product table -->
<table id="product-table" class="w-full mt-10 table-auto"></table>
</body>
</html>