Business HTML design

This commit is contained in:
Benjamin Beganović 2020-07-15 18:03:54 +02:00
parent f25bfbc8ef
commit 80df24bb2f
4 changed files with 191 additions and 23 deletions

View File

@ -52,10 +52,10 @@ $custom_css
<div class="col-span-2 p-3">
$company_logo
</div>
<div class="col-span-2 p-3 flex flex-col flex-wrap">
<div class="flex flex-col flex-wrap col-span-2 p-3">
$company_details
</div>
<div class="col-span-2 p-3 flex flex-col flex-wrap">
<div class="flex flex-col flex-wrap col-span-2 p-3">
$company_address
</div>
</div>';
@ -64,46 +64,46 @@ $custom_css
public function body()
{
return '<div class="grid grid-cols-12 gap-1 mt-8">
<div class="col-span-7 p-3 flex flex-col flex-wrap">
<div class="flex flex-col flex-wrap col-span-7 p-3">
$client_details
</div>
<div class="col-span-5 p-3 flex flex-col bg-orange-600 px-4 py-4 h-auto rounded-lg">
<div class="flex flex-col text-white flex-wrap">
<div class="flex flex-col h-auto col-span-5 p-3 px-4 py-4 bg-orange-600 rounded-lg">
<div class="flex flex-col flex-wrap text-white">
$entity_details
</div>
</div>
</div>
<table class="w-full table-auto mt-20">
<table class="w-full mt-20 table-auto">
<thead class="text-left">
$product_table_header
</thead>
<tbody class="bg-gray-200 whitespace-pre-line">
<tbody class="whitespace-pre-line bg-gray-200">
$product_table_body
</tbody>
</table>
<table class="w-full table-auto mt-20">
<table class="w-full mt-20 table-auto">
<thead class="text-left">
$task_table_header
</thead>
<tbody class="bg-gray-200 whitespace-pre-line">
<tbody class="whitespace-pre-line bg-gray-200">
$task_table_body
</tbody>
</table>
<div class="flex items-center justify-between px-4 pb-4 bg-gray-200 rounded py-2">
<div class="flex items-center justify-between px-4 py-2 pb-4 bg-gray-200 rounded">
<div class="w-1/2">
<div class="flex flex-col">
<p>$entity.public_notes</p>
</div>
</div>
<div class="w-1/3 flex flex-col">
<div class="flex flex-col w-1/3">
<div class="flex px-3 mt-2">
<section class="w-1/2 text-right flex flex-col">
<section class="flex flex-col w-1/2 text-right">
$discount_label
$total_tax_labels
$line_tax_labels
</section>
<section class="w-1/2 text-right flex flex-col">
<section class="flex flex-col w-1/2 text-right">
$discount
$total_tax_values
$line_tax_values
@ -111,17 +111,17 @@ $custom_css
</div>
</div>
</div>
<div class="flex items-center justify-between mt-4 pb-4 px-4">
<div class="flex items-center justify-between px-4 pb-4 mt-4">
<div class="w-1/2">
<div class="flex flex-col">
<p class="font-semibold">$terms_label</p>
<p>$terms</p>
</div>
</div>
<div class="flex w-2/5 flex-col">
<section class="flex py-2 bg-blue-900 px-4 py-3 rounded text-white">
<div class="flex flex-col w-2/5">
<section class="flex px-4 py-2 py-3 text-white bg-blue-900 rounded">
<p class="w-1/2">$balance_due_label</p>
<p class="text-right w-1/2">$balance_due</p>
<p class="w-1/2 text-right">$balance_due</p>
</section>
</div>
</div>
@ -142,7 +142,7 @@ $custom_css
{
return '
<footer>
<div class="div_footer flex justify-between py-8 px-12" style="page-break-inside: avoid;">
<div class="flex justify-between px-12 py-8 div_footer" style="page-break-inside: avoid;">
</div>
</footer>';
}

View File

@ -7,7 +7,7 @@ class Business
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/business.html')
base_path('tests/Feature/PdfMaker/designs/business.html')
);
}
}

View File

@ -16,7 +16,21 @@ class PdfMakerDesignsTest extends TestCase
$this->state = [
'variables' => [
'$css' => asset('css/tailwindcss@1.4.6.css'),
'#css' => asset('css/tailwindcss@1.4.6.css'),
'#global-margin' => 'm-12',
'#company-logo' => 'https://invoiceninja-invoice-templates.netlify.app/assets/images/invoiceninja-logo.png',
'#entity-number-label' => 'Invoice number',
'#entity-number' => '10000',
'#entity-date-label' => 'Invoice date',
'#entity-date' => '3th of June, 2025.',
'#due-date-label' => 'Due date',
'#due-date' => '5th of June, 2025.',
'#balance-due-label' => 'Balance due',
'#balance-due' => '$800.50',
'#terms-label' => 'Terms',
'#terms' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.',
],
];
}
@ -24,8 +38,96 @@ class PdfMakerDesignsTest extends TestCase
public function testBusiness()
{
$state = [
'template' => [],
'variables' => $this->state['variables'],
'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 '],
['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' => '', 'elements' => [
['element' => 'p', 'content' => '#entity-number-label'],
['element' => 'p', 'content' => '#entity-date-label'],
['element' => 'p', 'content' => '#due-date-label'],
['element' => 'p', 'content' => '#balance-due-label'],
]],
['element' => 'div', 'content' => '', 'elements' => [
['element' => 'p', 'content' => '#entity-number'],
['element' => 'p', 'content' => '#entity-date'],
['element' => 'p', 'content' => '#due-date'],
['element' => 'p', 'content' => '#balance-due'],
]],
],
],
'product-table' => [
'id' => 'product-table',
'elements' => [
['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => [
['element' => 'th', 'content' => 'Item', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']],
['element' => 'th', 'content' => 'Description', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']],
['element' => 'th', 'content' => 'Unit cost', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']],
['element' => 'th', 'content' => 'Quantity', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']],
['element' => 'th', 'content' => 'Line total', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']],
]],
['element' => 'tbody', 'content' => '', 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Painting service', 'properties' => ['class' => 'border-4 border-white text-orange-700 px-4 py-4 bg-gray-200']],
['element' => 'td', 'content' => '25 hours of painting', 'properties' => ['class' => 'border-4 border-white text-orange-700 px-4 py-4 bg-gray-200']],
['element' => 'td', 'content' => '885.00', 'properties' => ['class' => 'border-4 border-white text-orange-700 px-4 py-4 bg-gray-200']],
['element' => 'td', 'content' => '1', 'properties' => ['class' => 'border-4 border-white text-orange-700 px-4 py-4 bg-gray-200']],
['element' => 'td', 'content' => '$885.00', 'properties' => ['class' => 'border-4 border-white text-orange-700 px-4 py-4 bg-gray-200']],
]],
]],
['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 bg-gray-200', 'colspan' => '2']],
['element' => 'td', 'content' => 'Subtotal', 'properties' => ['class' => 'px-4 py-4 bg-gray-200 text-right', 'colspan' => '2']],
['element' => 'td', 'content' => '$0', 'properties' => ['class' => 'px-4 py-4 bg-gray-200 text-right']],
]],
['element' => 'tr', 'content' => '', 'elements' => [
['element' => 'td', 'content' => 'Paid to date', 'properties' => ['class' => 'border-l-4 border-white px-4 bg-gray-200 text-right', 'colspan' => '4']],
['element' => 'td', 'content' => '$0.00', 'properties' => ['class' => 'px-4 py-4 bg-gray-200 text-right']],
]],
]],
],
],
],
'variables' => array_merge([
'#invoice-issued-to' => 'Invoice issued to',
], $this->state['variables']),
];
$maker = new PdfMaker($state);
$maker
->design(Business::class)
->build();
exec('echo "" > storage/logs/laravel.log');
info($maker->getCompiledHTML());
}
}

View File

@ -1 +1,67 @@
php a
<!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>
<style>
thead th:first-child {
border-top-left-radius: .5rem;
border-bottom-left-radius: .3rem;
}
thead th:last-child {
border-top-right-radius: .5rem;
border-bottom-right-radius: .3rem;
}
</style>
<body class="#global-margin bg-white break-words antialiased">
<!-- Logo, company details & company address -->
<div class="flex grid items-start grid-cols-12 gap-4">
<img src="#company-logo" alt="#company-name" class="grid w-24 col-span-4 sm:w-32">
<div class="grid grid-cols-2 col-span-8 space-x-10 text-gray-700 lg:col-start-8">
<div id="company-details" class="col-span-1"></div>
<div id="company-address" class="col-span-1"></div>
</div>
</div>
<!-- Client details, entity details -->
<div class="grid grid-cols-12 gap-4 my-12">
<div class="col-span-6">
<p>#invoice-issued-to</p>
<div id="client-details" class="mt-4 text-orange-600"></div>
</div>
<div class="col-span-6">
<div class="h-auto px-4 py-4 bg-orange-600 rounded-lg">
<div class="flex justify-between text-white" id="entity-details"></div>
</div>
</div>
</div>
<!-- Product table -->
<table id="product-table" class="w-full mt-20 rounded table-auto"></table>
<!-- Balance due card -->
<div class="grid grid-cols-12 my-12">
<div class="col-span-6">
<p class="font-semibold">#terms-label</p>
<p>#terms</p>
</div>
<div class="col-span-5 col-start-8 lg:col-start-9 lg:col-span-4">
<div class="h-auto px-4 py-4 bg-orange-600 rounded-lg">
<div class="flex justify-between text-white">
<p>#balance-due-label</p>
<p>#balance-due</p>
</div>
</div>
</div>
</div>
</body>
</html>