Skip to content

Commit 876f21a

Browse files
committed
support for Payment details in PDF
1 parent 00eaac0 commit 876f21a

File tree

9 files changed

+261
-3
lines changed

9 files changed

+261
-3
lines changed

resources/lang/en/invoice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
'credit' => 'Credit note',
4141
'proforma' => 'Proforma invoice',
4242
],
43-
43+
4444
'page' => 'Page',
4545
];

resources/views/default/invoice.blade.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,67 @@
235235
</table>
236236

237237
@if ($invoice->description)
238-
<p class="mb-1 text-sm"><strong>{{ __('invoices::invoice.description') }}</strong></p>
238+
<p class="mb-2 text-sm">
239+
<strong> {{ __('invoices::invoice.description') }} </strong>
240+
</p>
239241
<p class="whitespace-pre-line text-xs">{!! $invoice->description !!}</p>
240242
@endif
243+
244+
@if ($invoice->paymentInstructions)
245+
<div class="mt-12">
246+
@foreach ($invoice->paymentInstructions as $paymentInstruction)
247+
<div @class([
248+
'border-b' => !$loop->last,
249+
'-ml-12 -mr-12 px-12 bg-zinc-100 py-6',
250+
])>
251+
252+
<table class="w-full">
253+
<tbody>
254+
<tr>
255+
<td class="w-full p-0 align-top">
256+
@if ($paymentInstruction->name)
257+
<p class="mb-1 text-xs">
258+
<strong>{!! $paymentInstruction->name !!}</strong>
259+
</p>
260+
@endif
261+
262+
@if ($paymentInstruction->description)
263+
<p class="mb-3 text-xs">
264+
{!! $paymentInstruction->description !!}
265+
</p>
266+
@endif
267+
268+
<table>
269+
<tbody>
270+
@foreach ($paymentInstruction->fields as $key => $value)
271+
<tr>
272+
@if (is_string($key))
273+
<td class="py-1 pr-5 text-xs">{{ $key }}</td>
274+
<td class="py-1 pl-2 text-xs text-gray-500">
275+
{!! $value !!}
276+
</td>
277+
@else
278+
<td class="py-1 pr-5 text-xs" colspan="2">
279+
{!! $value !!}
280+
</td>
281+
@endif
282+
</tr>
283+
@endforeach
284+
</tbody>
285+
</table>
286+
</td>
287+
@if ($paymentInstruction->qrcode)
288+
<td class="min-w-28 p-0 align-top">
289+
<img src="{{ $paymentInstruction->qrcode }}" class="bg-white">
290+
</td>
291+
@endif
292+
</tr>
293+
</tbody>
294+
</table>
295+
</div>
296+
@endforeach
297+
</div>
298+
@endif
299+
300+
241301
</div>

resources/views/default/style.blade.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151
5252
img {
53+
display: block;
5354
vertical-align: middle;
5455
border-style: none;
5556
}
@@ -94,6 +95,11 @@
9495
height: auto;
9596
}
9697
98+
a {
99+
color: #1d4ed8;
100+
text-decoration: none,
101+
}
102+
97103
.font-normal {
98104
font-weight: normal;
99105
}
@@ -163,6 +169,18 @@
163169
margin-bottom: 48px;
164170
}
165171
172+
.mt-12 {
173+
margin-top: 48px;
174+
}
175+
176+
.-ml-12 {
177+
margin-left: -48px;
178+
}
179+
180+
.-mr-12 {
181+
margin-right: -48px;
182+
}
183+
166184
.p-0 {
167185
padding: 0;
168186
}
@@ -177,6 +195,16 @@
177195
padding-left: 0;
178196
}
179197
198+
.py-0.5,
199+
.pt-0.5 {
200+
padding-top: 2px;
201+
}
202+
203+
.py-0.5,
204+
.pb-0.5 {
205+
padding-bottom: 2px;
206+
}
207+
180208
.pb-1 {
181209
padding-bottom: 4px;
182210
}
@@ -216,6 +244,62 @@
216244
padding-top: 0.5rem;
217245
}
218246
247+
.pt-5,
248+
.p-5 {
249+
padding-top: 1.25rem;
250+
}
251+
252+
.pb-5,
253+
.p-5 {
254+
padding-bottom: 1.25rem;
255+
}
256+
257+
.pl-5,
258+
.p-5 {
259+
padding-left: 1.25rem;
260+
}
261+
262+
.pr-5,
263+
.p-5 {
264+
padding-right: 1.25rem;
265+
}
266+
267+
.pt-6,
268+
.py-6,
269+
.p-6 {
270+
padding-top: 1.5rem;
271+
}
272+
273+
.pb-6,
274+
.py-6,
275+
.p-6 {
276+
padding-bottom: 1.5rem;
277+
}
278+
279+
.pl-6,
280+
.px-6,
281+
.p-6 {
282+
padding-left: 1.5rem;
283+
}
284+
285+
.pr-6,
286+
.px-6,
287+
.p-6 {
288+
padding-right: 1.5rem;
289+
}
290+
291+
.px-12,
292+
.pl-12,
293+
.p-12 {
294+
padding-left: 48px;
295+
}
296+
297+
.px-12,
298+
.pr-12,
299+
.p-12 {
300+
padding-right: 48px;
301+
}
302+
219303
.mb-1 {
220304
margin-bottom: 4px;
221305
}
@@ -224,6 +308,18 @@
224308
margin-top: 4px;
225309
}
226310
311+
.mb-2 {
312+
margin-bottom: 8px;
313+
}
314+
315+
.mb-3 {
316+
margin-bottom: 0.75rem;
317+
}
318+
319+
.mt-3 {
320+
margin-top: 0.75rem;
321+
}
322+
227323
.mb-5 {
228324
margin-bottom: 1.5rem;
229325
}
@@ -284,10 +380,26 @@
284380
top: 0;
285381
}
286382
383+
.min-w-28 {
384+
min-width: 7rem;
385+
}
386+
287387
.text-gray-500 {
288388
color: #6b7280;
289389
}
290390
391+
.bg-white {
392+
background-color: #fff;
393+
}
394+
395+
.bg-zinc-50 {
396+
background-color: #fafafa
397+
}
398+
399+
.bg-zinc-100 {
400+
background-color: #f4f4f5;
401+
}
402+
291403
.dompdf-page:after {
292404
content: counter(page);
293405
}

src/Pdf/PdfInvoice.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Elegantly\Invoices\Enums\InvoiceType;
1313
use Elegantly\Invoices\InvoiceDiscount;
1414
use Elegantly\Invoices\Support\Buyer;
15+
use Elegantly\Invoices\Support\PaymentInstruction;
1516
use Elegantly\Invoices\Support\Seller;
1617
use Illuminate\Http\Response;
1718
use Illuminate\Mail\Attachment;
@@ -33,6 +34,7 @@ class PdfInvoice
3334
* @param array<string, mixed> $fields Additianl fileds to display in the header
3435
* @param PdfInvoiceItem[] $items
3536
* @param InvoiceDiscount[] $discounts
37+
* @param PaymentInstruction[] $paymentInstructions
3638
* @param ?string $logo A local file path. The file must be accessible using file_get_contents.
3739
* @param array<string, mixed> $templateData
3840
*/
@@ -53,6 +55,8 @@ public function __construct(
5355
public ?string $tax_label = null,
5456
public array $discounts = [],
5557

58+
public array $paymentInstructions = [],
59+
5660
?string $template = null,
5761
public array $templateData = [],
5862

src/Support/PaymentInstruction.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Elegantly\Invoices\Support;
6+
7+
use Illuminate\Contracts\Support\Arrayable;
8+
9+
/**
10+
* @implements Arrayable<string, null|string|array<string,null|string>>
11+
*/
12+
class PaymentInstruction implements Arrayable
13+
{
14+
/**
15+
* @param array<array-key, null|int|float|string> $fields
16+
*/
17+
public function __construct(
18+
public ?string $name = null,
19+
public ?string $description = null,
20+
public ?string $qrcode = null,
21+
public array $fields = [],
22+
) {
23+
// code...
24+
}
25+
26+
/**
27+
* @param array<array-key, mixed> $values
28+
*/
29+
public static function fromArray(array $values): self
30+
{
31+
return new self(
32+
// @phpstan-ignore-next-line
33+
name: data_get($values, 'name'),
34+
// @phpstan-ignore-next-line
35+
description: data_get($values, 'description'),
36+
// @phpstan-ignore-next-line
37+
qrcode: data_get($values, 'qrcode'),
38+
// @phpstan-ignore-next-line
39+
fields: data_get($values, 'fields') ?? [],
40+
);
41+
}
42+
43+
/**
44+
* @return array{
45+
* name: ?string,
46+
* description: ?string,
47+
* fields: null|array<array-key, null|int|float|string>,
48+
* }
49+
*/
50+
public function toArray(): array
51+
{
52+
return [
53+
'name' => $this->name,
54+
'description' => $this->description,
55+
'qrcode' => $this->qrcode,
56+
'fields' => $this->fields,
57+
];
58+
}
59+
}
2.55 KB
Loading

workbench/resources/images/qrcode.svg

Lines changed: 2 additions & 0 deletions
Loading

workbench/resources/views/demo.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<script src="https://cdn.tailwindcss.com"></script>
8+
89
</head>
910

1011
<body class="bg-gray-100">
@@ -27,6 +28,9 @@
2728

2829
</div>
2930

31+
{{-- Must be added at the end to overwrite Tailwind --}}
32+
@include('invoices::default.style')
33+
3034
</body>
3135

3236
</html>

workbench/routes/web.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Elegantly\Invoices\Pdf\PdfInvoiceItem;
1212
use Elegantly\Invoices\Support\Address;
1313
use Elegantly\Invoices\Support\Buyer;
14+
use Elegantly\Invoices\Support\PaymentInstruction;
1415
use Elegantly\Invoices\Support\Seller;
1516
use Illuminate\Support\Facades\Route;
1617

@@ -179,7 +180,23 @@
179180
percent_off: 20
180181
),
181182
],
182-
tax_label: 'VAT (France)'
183+
tax_label: 'VAT (France)',
184+
description: 'A simple description',
185+
paymentInstructions: [
186+
new PaymentInstruction(
187+
name: 'Bank Transfer',
188+
description: 'Make a direct bank transfer using the details below',
189+
qrcode: "data:image/png;base64,". base64_encode(file_get_contents(__DIR__ . "/../resources/images/qrcode.png")),
190+
fields: [
191+
'Bank Name' => 'Acme Bank',
192+
'Account Number' => '12345678',
193+
'IBAN' => 'GB12ACME12345678123456',
194+
'SWIFT/BIC' => 'ACMEGB2L',
195+
'Reference' => 'INV-0032/001',
196+
'<a href="#">Pay online</a>'
197+
],
198+
),
199+
]
183200
);
184201

185202
Route::get('/', function () use ($invoice) {

0 commit comments

Comments
 (0)