-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawesome-dompdf.pdf.twig
457 lines (400 loc) · 13.2 KB
/
awesome-dompdf.pdf.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
{#
You can override the following variables in your own template to customize
the template:
#}
{%- set marginTop = '21mm' -%}
{%- set marginBottom = '12mm' -%}
{%- set marginLeft = 25 -%}
{%- set marginRight = 20 -%}
{# Logo URL #}
{% set logoUrl = logoUrl|default(config('theme.branding.logo')) %}
{# set color for horizontal lines and borders #}
{% set accentColor = accentColor|default('#40514e') %}
{# set font family #}
{#
dompdf doesn't support a huge number of fonts beyond what the pdf standards
require. See:
https://github.com/dompdf/dompdf/wiki/About-Fonts-and-Character-Encoding
You can load any font from a URL though, and it will be downloaded and used
automatically...
#}
{% set fontFamily = fontFamily|default("'Helvetica', sans-serif") %}
{% set fontUrl = '' %}
{#
Set rawContact to true if you want to put raw HTML into the Contact field of
the Invoice Template (in the web UI).
It will need to be nested in one or more <tr> tags, so gives full flexibility
to the number of table rows the Contact entry contains. e.g.
<tr>
<th>Email</th>
<td><a href="mailto:[email protected]">[email protected]</a></td>
</tr>
<tr>
[...]
</tr>
#}
{% set rawContact = true %} {#rawContact|default(false) %} #}
{# set an introduction text that is displayed before the invoice positions #}
{% set introductionText = introductionText|default(false) %}
{# set the sender address that is displayed in the address window #}
{% set invoiceSenderAddress = invoiceSenderAddress|default(model.template.address|nl2str(' • ')) %}
<!DOCTYPE html>
{% set fallback = app.request is not null ? app.request.locale : 'en' %}
{% set language = model.template.language|default(fallback) %}
{% set isDecimal = model.template.decimalDuration|default(false) %}
{% set currency = model.currency %}
<html lang="{{ language }}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{% block title %}{{ model.invoiceNumber }}-{{ model.customer.company|default(model.customer.name)|u.snake }}{% endblock %}</title>
{% block invoice_styles %}
<style type="text/css">
@font-face {
font-family: {{ fontFamily|raw }};
font-style: normal;
font-weight: normal;
{% if fontUrl %}
src: url({{ fontUrl }});
{% endif %}
}
@page {
margin-top: {{ marginTop }};
margin-bottom: {{ marginBottom }};
}
body {
font-family: {{ fontFamily|raw }};
font-size: 10pt;
line-height: 14pt;
border-bottom: 1px solid {{ accentColor }};
}
header {
top: -{{ marginTop }};
position: fixed;
width: 100%;
}
.header {
font-weight: bold;
}
.header-logo {
text-align: center;
vertical-align: middle;
padding: 1em;
}
.header-logo-image {
max-width: 177.5mm;
max-height: 15mm;
}
.invoice-intro {
border-top: 1px solid {{ accentColor }};
width: 100%;
}
.invoice-address {
float:left;
padding: 0;
}
address {
font-style: normal;
}
.address-sender {
font-size: 8pt;
border-bottom: 1px dotted {{ accentColor }};
margin-bottom: 0.5em;
}
.address-recipient {
padding-top: 1mm;
}
.invoice-details {
float: right;
font-size: 8pt;
font-weight: normal;
}
.invoice-details th {
padding-right: 2mm;
}
table {
border-spacing: 0;
border-collapse: separate;
}
th, td {
padding: 0;
}
table th {
text-align: left;
}
tr.blank-row {
line-height: 0.8em;
}
.content {
/* the invoice-details section floats, so need to apply a clear to
* position the main content beneath */
clear: both;
margin-top: -1em;
}
.introduction-text {
margin-bottom: 10pt;
}
.summary-table {
margin-left: auto;
}
.items th {
color: {{ accentColor }};
border-bottom: 1px solid {{ accentColor }};
}
.items th,
.items td {
padding: 1mm 0.5em;
vertical-align: top;
}
.text-nowrap {
white-space: nowrap;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-small,
small {
font-size: 8pt;
}
footer {
/* fixed will print the footer on every page */
position: fixed;
bottom: 0;
text-align: center;
width: 100%;
/* My footer is 2 lines tall, so move at least 2 lines down into margin */
margin-bottom: -2.8em;
line-height: normal;
font-size: 8pt;
}
footer.first-page-only {
/* absolute will show the footer on just the first page */
position: absolute;
}
/* Put the page numbers on the right of the footer */
footer.page-num {
text-align: right;
/*
* This is about as good a right-alignment as I can get,
* when replacing __TPC__ with the total page count.
* The cw (character width) unit doesn't appear to work.
* ‌ (0x200c or \u{8204}) doesn't work with non-unicode fonts.
* So -5ex appears to right-align Page 1 of 1 at least.
* */
right: -5ex;
}
/* Running page counter */
.page-count:before {
content: counter(page);
}
</style>
{% endblock %}
</head>
<body>
<header>
{% block header %}
<div class="header">
{% block header_logo %}
{% if logoUrl %}
<div class="header-logo">
<img src="{{ logoUrl }}" class="header-logo-image" alt="" />
</div>
{% endif %}
{% endblock %}
</div>
{% endblock %}
</header>
{% block footer %}
<!-- This part of the footer I want just on the first page -->
<footer class="first-page-only">
{{ model.template.company }} | {{ model.template.address|nl2str(' | ') }}<br />
{{ model.template.paymentDetails| nl2str(' | ') }}
</footer>
<!-- Page number we want on every page -->
<footer class="page-num">
{{ 'export.page_of' | trans({
'%page%': '<span class="page-count"></span>',
'%pages%': '__TPC__'
}) | raw }}
<!-- Adding two line breaks aligns the page num with the footer's top -->
<br /><br />
</footer>
{% endblock %}
<div class="invoice-intro">
{% block invoice_address %}
<div class="invoice-address">
{% block invoice_address_recipient %}
<address class="address-recipient">
{{ model.customer.company|default(model.customer.name) }}<br>
{% if model.customer.contact %}
{{ model.customer.contact }}<br>
{% endif %}
{{ model.customer.address|nl2br }}<br>
{{ model.customer.country|country_name }}
</address>
{% endblock %}
</div>
{% endblock %}
{% block invoice_details %}
<div class="invoice-details">
{% block invoice_address_sender %}
<address class="address-sender">
<table>
<tr><th>{{ model.template.company }}</th></tr>
<tr><td>{{ invoiceSenderAddress|raw }}</td></tr>
</table>
</address>
{% endblock %}
<table>
{% block invoice_details_invoice_number %}
<tr>
<th>{{ 'invoice.number'|trans }}:</th>
<td>{{ model.invoiceNumber }}</td>
</tr>
{% endblock %}
{% block invoice_details_invoice_date %}
<tr>
<th>{{ 'date'|trans }}:</th>
<td>{{ model.invoiceDate|date_short }}</td>
</tr>
{% endblock %}
{% block invoice_details_service_date %}
<tr>
<th>{{ 'invoice.service_date'|trans }}:</th>
<td>{{ model.query.begin|date('d.m.Y') }}
– {{ model.query.end|date('d.m.Y') }}</td>
</tr>
{% endblock %}
{% block invoice_details_due_date %}
<tr>
<th>{{ 'invoice.due_days'|trans }}:</td>
<td>{{ model.dueDate|date_short }}</td>
</tr>
{% endblock %}
{% block invoice_details_customer_vatid %}
{% if model.template.vatId %}
<tr>
<th>{{ 'vat_id'|trans }}:</th>
<td>{{ model.customer.vatId }}</td>
</tr>
<tr class="blank-row"><td colspan="2"> </td></tr>
{% endif %}
{% endblock %}
{% block invoice_details_contact %}
{#
In the demo data, the Contact field has three modes of
contact in it: Phone, Email and Web. Frankly, this looks
really shit. So, have put an option to allow raw html in
the Contact field
#}
{% if rawContact %}
{{ model.template.contact|raw }}
{% else %}
<tr>
<th>{{ 'contact'|trans }}:</th>
<td>{{ model.template.contact|nl2br }}</td>
</tr>
{% endif %}
{% endblock %}
</table>
</div>
{% endblock %}
</div>
<br>
{% block invoice_content %}
<div class="content">
<!-- CONTENT_PART -->
{% block invoice_content_subject %}
<div class="subject">
<h1>{{ model.template.title }}</h1>
</div>
{% endblock %}
{% block invoice_content_introduction %}
{% if introductionText %}
<div class="introduction-text">
<p>{{ introductionText }}</p>
</div>
{% endif %}
{% endblock %}
{% block invoice_content_items %}
<div class="items">
<table width="100%">
<thead>
<tr>
<th class="text-left">{{ 'date'|trans }}</th>
<th class="text-left">{{ 'description'|trans }}</th>
<th class="text-right text-nowrap">{{ 'amount'|trans }}</th>
<th class="text-right text-nowrap">{{ 'unit_price'|trans }}</th>
<th class="text-right text-nowrap">{{ 'total_rate'|trans }}</th>
</tr>
</thead>
<tbody>
{% for entry in model.calculator.entries %}
<!-- CONTENT_PART -->
{% set duration = entry.duration|duration(isDecimal) %}
{% if entry.fixedRate is not null %}
{% set rate = entry.fixedRate %}
{% set duration = entry.amount|amount %}
{% else %}
{% set rate = entry.hourlyRate %}
{% endif %}
<tr>
<td class="text-left">{{ entry.begin|date("d/m/y") }}</td>
<td class="text-left">
{{ entry.project.name }}:
{% if entry.activity is not null %}
<strong>
{{ entry.activity.name }}
</strong>
{% endif %}
{% if entry.description is not empty %}
<br><small>{{ entry.description }}</small>
{% endif %}
</td>
<td class="text-right text-nowrap">{{ duration }}</td>
<td class="text-right text-nowrap">{{ rate|money(currency) }}</td>
<td class="text-right text-nowrap">{{ entry.rate|money(currency) }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="summary-table text-right">
<tbody>
<tr>
<td>{{ 'invoice.total_working_time'|trans }}</td>
<td>{{ invoice['invoice.duration_decimal'] }}</td>
</tr>
{% if model.calculator.tax > 0 or not model.isHideZeroTax() %}
<tr>
<td>{{ 'invoice.subtotal'|trans }}</td>
<td>{{ model.calculator.subtotal|money(currency) }}</td>
</tr>
<tr>
<td>{{ 'invoice.tax'|trans }} ({{ model.calculator.vat }}%)</td>
<td>{{ model.calculator.tax|money(currency) }}</td>
</tr>
{% endif %}
<tr>
<td><strong>{{ 'invoice.total'|trans }}</strong></td>
<td><strong>{{ model.calculator.total|money(currency) }}</strong></td>
</tr>
</tbody>
</table>
{% endblock %}
</div>
{% block payment_terms %}
{% if model.template.paymentTerms is not empty %}
<div class="paymentTerms text-small">
<p>
<strong>{{ 'payment_terms'|trans }}</strong>:
{{ model.template.paymentTerms|trim|nl2br }}
</p>
</div>
{% endif %}
{% endblock %}
</div>
{% endblock %}
</body>
</html>