-
Notifications
You must be signed in to change notification settings - Fork 2
/
invoice.php
116 lines (98 loc) · 4.29 KB
/
invoice.php
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
<?php
/*
* This file is part of the famoser/pdf-generator project.
*
* (c) Florian Moser <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include '../vendor/autoload.php';
use PdfGenerator\Frontend\Content\Paragraph;
use PdfGenerator\Frontend\Content\Style\DrawingStyle;
use PdfGenerator\Frontend\Content\Style\TextStyle;
use PdfGenerator\Frontend\Layout\ContentBlock;
use PdfGenerator\Frontend\Layout\Flow;
use PdfGenerator\Frontend\Layout\Parts\Row;
use PdfGenerator\Frontend\Layout\Style\ColumnSize;
use PdfGenerator\Frontend\Layout\Table;
use PdfGenerator\Frontend\LinearDocument;
use PdfGenerator\Frontend\Resource\Font;
use PdfGenerator\IR\Document\Content\Common\Color;
$margin = 15;
$document = new LinearDocument([210, 297], $margin);
$normalFont = Font::createFromDefault();
$normalText = new TextStyle($normalFont);
$boldFont = Font::createFromDefault(Font\FontFamily::Helvetica, Font\FontWeight::Bold);
$boldText = new TextStyle($boldFont);
$headerText = new TextStyle($boldFont, $normalText->getFontSize() * 1.6);
$secondaryText = new TextStyle($normalFont, $normalText->getFontSize(), $normalText->getLineHeight(), Color::createFromHex('#6c757d'));
$sectionMargin = [10, 0, 0, 0];
// target address
$printer = $document->createPrinter(0, $margin, 60);
$printer->printText("Universität Zürich\nZentrale Informatik\nStampfenbachstrasse 73\n8006 Zürich\nSchweiz", $normalText);
// source address
$phrases = [];
$phrases[] = new Paragraph\Phrase("famoser GmbH\n", $boldText);
$phrases[] = new Paragraph\Phrase("c/o Florian Moser\nMoosburgstrasse 25\n8307 Effretikon\nSchweiz", $normalText);
$printer = $document->createPrinter(0, 160, $margin);
$printer->printPhrases($phrases);
// header
$printer = $document->createPrinter(0, $margin, 100);
$printer->printText('Invoice UZH-ZI-5', $headerText);
$printer = $printer->position(0, 8);
$printer->printRectangle(180, 0.1, new DrawingStyle(0.1));
$printer = $printer->position(0, 3);
$columns = [
"Date:\nPayment until:",
"30.06.2023\n30.07.2023",
"Performance Period:\nProject reference:",
"01.01.2023 - 30.06.2023\nZI-2812-F",
];
$columnPrinter = $printer;
foreach ($columns as $column) {
$columnPrinter->printText($column, $normalText);
$columnPrinter = $columnPrinter->position(45, 0);
}
$printer = $printer->position(0, 11);
$printer->printRectangle(180, 0.1, new DrawingStyle(0.1));
// description
$flow = new Flow();
$paragraph = new Paragraph();
$paragraph->add($headerText, "Concept & Implementation ZI-2812-F\n");
$paragraph->add($normalText, "To whom it may concern\n\nI would like to thank you for the order and the trust you have placed in me. The tasks according to the offer of 01.01.2023 were implemented on time and accepted by the client on 30.06.2023. Only the work actually incurred will be invoiced.");
$flow->addContent($paragraph);
$document->position(130);
$document->add($flow);
// cost positions
$table = new Table([ColumnSize::MINIMAL, ColumnSize::AUTO, ColumnSize::MINIMAL, ColumnSize::MINIMAL, ColumnSize::MINIMAL]);
$table->setMargin([0, 3, 0, 5]);
$textByRow = [
[$boldText, 'Pos.', 'Description', 'Quantity', 'Unit price', 'Price'],
[$normalText, '1', 'Concept work: Requirements engineering, UX concept, PoC', '12 h', '160.00', '1\'920.00'],
[$normalText, '2', 'Implementation', '34 h', '160.00', '5\'440.00'],
[$boldText, '', 'Sub-Total', '', '', '7\'360.00'],
[$secondaryText, '', 'plus VAT 14%', '', '', '1\'030.40'],
[$boldText, '', 'Total', '', '', '8\'390.40'],
];
foreach ($textByRow as $rowIndex => $rowDefinition) {
$row = new Row();
$textStyle = array_shift($rowDefinition);
foreach ($rowDefinition as $index => $text) {
$paragraph = new Paragraph();
$paragraph->add($textStyle, $text);
$content = new ContentBlock($paragraph);
$content->setPadding([1, 0.3, 1, 0.3]);
$row->set($index, $content);
}
$table->addBody($row);
}
$document->add($table);
// greeting formula
$flow = new Flow();
$paragraph = new Paragraph();
$paragraph->add($normalText, "In case of questions, please do not hesitate to ask.\n\nBest regards\nFlorian Moser");
$flow->addContent($paragraph);
$document->add($flow);
$result = $document->save();
file_put_contents('invoice.pdf', $result);