Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4)
|
Change license from CC0 to...
Hanno Böck authored 1 year ago
|
5) Written by schokokeks.org Hosting, namely
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
6) Bernd Wurst <bernd@schokokeks.org>
7) Hanno Böck <hanno@schokokeks.org>
8)
|
Change license from CC0 to...
Hanno Böck authored 1 year ago
|
9) This code is published under a 0BSD license.
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
10)
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
13)
14) require_once('session/start.php');
15) require_once('invoice.php');
16) require_once('inc/security.php');
17)
18) require_role(ROLE_CUSTOMER);
19)
|
Umstellung von filter_input...
Bernd Wurst authored 4 years ago
|
20) $invoice_id = (int) $_GET['id'];
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
21)
22) $items = invoice_items($invoice_id);
23)
24) $invoice = invoice_details($invoice_id);
25)
26)
27) $outformat = 'html';
28) if (isset($_REQUEST['out']) && $_REQUEST['out'] == 'pdf') {
29) $outformat = 'pdf';
30) }
31)
32)
33) // Footer
34) $footer = '<footer>
35) <table width="100%">
36) <tr><td>schokokeks.org GbR<br>
37) Bernd Wurst / Johannes Böck<br>
38) www.schokokeks.org<br>
39) root@schokokeks.org</td>
40)
41) <td>Steuernummer 51072/01109<br>
42) Finanzamt Backnang<br>
43) USt-ID: DE255720588</td>
44)
45) <td>Volksbank Backnang<br>
46) IBAN: DE91 6029 1120 0041 5120 06<br>
47) BIC: GENODES1VBK<br>
48) (Kto: 41512 006 / BLZ: 602 911 20)</td>
49) </tr>
50) </table></footer>';
51)
52)
53)
54)
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
55) $html = '<html><head><title>Rechnung Nr. ' . $invoice_id . '</title>
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
56) <style type="text/css">
57)
58) @media (min-width: 22cm) {
59) body {
60) margin: 2cm;
61) margin-top: 0.5cm;
62) width: 17cm;
63) }
64) }
65)
66) @media print,dompdf {
67) html {
68) margin: 0;
69) padding: 0;
70) }
71) @page {
72) margin: 0;
73) padding: 0;
74) }
75) body {
76) margin: 2cm;
77) margin-bottom: 3cm;
78) }
79) }
80)
81) body {
82) font-family: "DejaVu Sans", sans-serif;
83) font-size: 8pt;
84) padding: 0;
85) text-align: justify;
86) }
87)
88) table, th, td, tr {
89) font-size: 8pt;
90) margin: 0;
91) padding: 0;
92) border: none;
93) border-collapse: collapse;
94) vertical-align: top;
95) }
96) th {
97) text-align: left;
98) border-bottom: 1px solid black;
99) }
100)
101) @media print,dompdf {
102) #header,
103) footer {
104) position: fixed;
105) left: 0;
106) right: 0;
107) font-size: 8pt;
108) }
109) }
110)
111) #header {
112) top: 0;
113) }
114)
115) footer {
116) border-top: 1px solid #000;
117) }
118)
119) @media print,dompdf {
120) footer {
121) position: absolute;
122) bottom: -2cm;
123) }
124) }
125)
126) #header table,
127) footer table {
128) width: 100%;
129) border-collapse: collapse;
130) border: none;
131) }
132)
133) #header td,
134) footer td {
135) padding: 0;
136) width: 33%;
137) }
138)
139) .page-number {
140) text-align: center;
141) }
142)
143) .page-number:before {
144) content: "Seite " counter(page);
145) }
146)
147) #addressfield {
148) float: left;
149) position: relative;
150) top: 3cm;
151) left: 0cm;
152) width: 8.5cm;
153) min-height: 5cm;
154) }
155) #addressfield p {
156) margin-left: 0.5cm;
157) margin-top: 0.3cm;
158) font-size: 11pt;
159) }
160)
161) #addressfieldheader {
162) font-size: 8pt;
163) padding-left: 0.2cm;
164) width: 100%;
165) border-bottom: 0.1pt solid black;
166) }
167)
168)
169) #rightcolumn {
170) float: right;
171) width: 6cm;
172) }
173)
174)
175)
176) #rightcolumn img {
177) position: relative;
178) top: 0;
179) width: 4.08cm;
180) height: 3cm;
181) margin: 0;
182) padding: 0;
183) }
184)
185) td {
186) font-size: 8pt;
187) }
188)
189) p {
190) margin-bottom: 0.6cm;
191) }
192)
193) tr.even {
194) background-color: #eee;
195) }
196)
197)
198) </style>
199) </head>
200) <body>
201) ';
202) // Folding Marks
203) $html .= '
204) <div style="position: absolute; left: -2cm; top: 8.5cm; width: 0.5cm; height: 1px; border-top: 1px solid black;"></div>
205) <div style="position: absolute; left: -2cm; top: 19cm; width: 0.5cm; height: 1px; border-top: 1px solid black;"></div>
206) <div style="position: absolute; left: -2cm; top: 12.85cm; width: 0.6cm; height: 1px; border-top: 1px solid black;"></div>
207) ';
208)
209) if ($outformat == 'pdf') {
210) $html .= $footer;
211) }
212)
213) $address = invoice_address($invoice['kunde']);
214)
215) // Address Field
216) $html .= '<div id="addressfield">
217) <div id="addressfieldheader">schokokeks.org · Köchersberg 32 · 71540 Murrhardt</div>
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
218) <p>' . ($address['company'] != null ? $address['company'] . '<br>' : '') . $address['name'] . '<br>
219) ' . $address['address'] . '<br>
220) ' . ($address['country'] != 'DE' ? $address['country'] . '-' : '') . $address['zip'] . ' ' . $address['city'] . '
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
221) </p>
222) </div>';
223) // Right col
224) $html .= '<div id="rightcolumn">
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
225) <img src="' . ($outformat == 'pdf' ? '.' : '../..') . '/themes/default/images/schokokeks.png">
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
226) <p style="margin-bottom: 0.2cm;"><strong>schokokeks.org GbR</strong><br>
227) Bernd Wurst / Johannes Böck<br>
228) Köchersberg 32<br>
229) 71540 Murrhardt</p>
230) <p>Tel: 07192-936432<br>
231) E-Mail: root@schokokeks.org</p>
232) </div>';
233)
234) // Caption / Invoice-Details
235) $html .= '
236) <table style="width: 100%; clear: both;">
237) <tr><td style="width: 11cm; font-size: 11pt; font-weight: bold;">Rechnung</td><td>
238) <table>
239) <tr><td colspan="2"><strong>Bei Fragen bitte immer angeben:</strong></td></tr>
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
240) <tr><td>Rechnungsdatum:</td><td align="right">' . date("d. m. Y", strtotime($invoice['datum'])) . '</td></tr>
241) <tr><td>Rechnungsnummer:</td><td align="right">' . $invoice_id . '</td></tr>
242) <tr><td>Kundennummer:</td><td align="right">' . $invoice['kunde'] . '</td></tr>
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
243) </table>
244) </td></tr>
245) </table>';
246)
247) $anrede = 'Sehr geehrte Damen und Herren';
248)
249) $parts = explode(' ', $address['name']);
250) $nachname = array_pop($parts);
251)
252) if ($address['name']) {
253) if ($address['salutation'] == 'Herr') {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
254) $anrede = 'Sehr geehrter Herr ' . $nachname;
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
255) } elseif ($address['salutation'] == 'Frau') {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
256) $anrede = 'Sehr geehrte Frau ' . $nachname;
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
257) }
258) }
259)
260) // Salutation
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
261) $html .= '<p>' . $anrede . ',<br>
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
262) hiermit stellen wir die nachfolgend genannten Posten in Rechnung.</p>';
263)
264)
265) // Table
266) $html .= '<table style="width: 100%;">
267) <tr style="border-bottom: 1px solid black;">
268) <th style="width: 1cm; text-align: center;">Anz.</th>
|
Erlaube Admins das Abfragen...
Bernd Wurst authored 5 years ago
|
269) <th style="width: 2cm;"> </th>
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
270) <th>Beschreibung</th>
271) <th style="width: 2.5cm; text-align: center;">Einzelpreis</th>
272) <th style="width: 3cm; text-align: center;">Gesamtpreis</th></tr>';
273)
274) $vattype = null;
275) // An der ersten Zeile entscheidet sich, ob die gesamte Rechnung als Netto- oder Bruttorechnung erstellt wird
|
Codingstyle PSR12 + array s...
Hanno Böck authored 2 years ago
|
276) $einzelsummen = [];
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
277) $summe = 0.0;
278)
279) $odd = true;
280) foreach ($items as $item) {
281) if ($vattype == 'gross' && $item['brutto'] == 0) {
|
codingstyle fixes
Hanno authored 5 years ago
|
282) system_failure('Mixed gross and net positions');
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
283) } elseif ($vattype == 'net' && $item['brutto'] == 1) {
|
codingstyle fixes
Hanno authored 5 years ago
|
284) system_failure('Mixed gross and net positions');
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
285) } else {
286) $vattype = ($item['brutto'] == 1 ? 'gross' : 'net');
287) }
288)
289) $anzahl = $item['anzahl'];
290) if (round($anzahl, 0) == $anzahl) {
291) $anzahl = round($anzahl, 0);
292) }
293) $desc = $item['beschreibung'];
294) if ($item['enddatum'] == null) {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
295) $desc .= '<br />(Leistungsdatum: ' . $item['datum'] . ')';
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
296) } else {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
297) $desc .= '<br />(Leistungszeitraum: ' . $item['datum'] . ' - ' . $item['enddatum'] . ')';
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
298) }
299) $epreis = $item['betrag'];
300) if ($item['brutto'] == 0) {
301) $epreis = $epreis * (1 + ($item['mwst'] / 100));
302) }
303) $einheit = ($item['einheit'] ? $item['einheit'] : '');
304) $gesamt = $epreis * $item['anzahl'];
305) $epreis = $epreis;
306)
307) if (array_key_exists($item['mwst'], $einzelsummen)) {
308) $einzelsummen[$item['mwst']]['net'] += $gesamt / (1 + ($item['mwst'] / 100));
309) $einzelsummen[$item['mwst']]['vat'] += $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100);
310) $einzelsummen[$item['mwst']]['gross'] += $gesamt;
311) } else {
|
Codingstyle PSR12 + array s...
Hanno Böck authored 2 years ago
|
312) $einzelsummen[$item['mwst']] = ['net' => $gesamt / (1 + ($item['mwst'] / 100)),
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
313) 'vat' => $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100),
|
Codingstyle PSR12 + array s...
Hanno Böck authored 2 years ago
|
314) 'gross' => $gesamt, ];
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
315) }
316) $summe += $gesamt;
317)
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
318) $html .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><td style='text-align: right;'>{$anzahl}</td><td>{$einheit}</td>";
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
319) $html .= "<td>{$desc}</td>";
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
320) $html .= "<td style='text-align: right;'>" . number_format($epreis, 2, ',', '.') . " €</td><td style='text-align: right;'>" . number_format($gesamt, 2, ',', '.') . " €</td></tr>\n";
|
Fix not operator (!) spaces
Hanno Böck authored 7 months ago
|
321) $odd = !$odd;
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
322) }
323) $html .= '<tr><td> </td></tr>';
324)
325) foreach ($einzelsummen as $percent => $sums) {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
326) $html .= '<tr><td colspan="4" style="text-align: right;">Nettobetrag (' . number_format($percent, 1, ',', '.') . '% MwSt):</td><td style="text-align: right;">' . number_format($sums['net'], 2, ',', '.') . ' €</td></tr>
327) <tr><td colspan="4" style="text-align: right;">MwSt-Betrag ' . number_format($percent, 1, ',', '.') . '%:</td><td style="text-align: right;">' . number_format($sums['vat'], 2, ',', '.') . ' €</td></tr>';
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
328) if (count($einzelsummen) > 1) {
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
329) $html .= '<tr><td colspan="4" style="text-align: right;">Brutto-Teilbetrag ' . number_format($percent, 1, ',', '.') . '% MwSt:</td><td style="text-align: right;">' . number_format($sums['gross'], 2, ',', '.') . ' €</td></tr>';
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
330) }
331) }
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
332) $html .= '<tr style="font-weight: bold;"><td colspan="4" style="text-align: right;">Rechnungsbetrag:</td><td style="text-align: right;">' . number_format($summe, 2, ',', '.') . ' €</td></tr>
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
333) </table>';
334)
335) // Disclaimer
336) if ($invoice['abbuchung'] == 1) {
337) $sepamandat = get_sepamandat($invoice['sepamandat']);
338) $iban = substr($sepamandat['iban'], 0, 8) . '**********' . substr($sepamandat['iban'], -4);
339) $display_iban = $iban;
|
codingstyle, spaces between...
Hanno Böck authored 9 months ago
|
340) for ($i = strlen($iban) - (strlen($iban) % 4) ; $i != 0 ; $i -= 4) {
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
341) $display_iban = substr($display_iban, 0, $i) . ' ' . substr($display_iban, $i);
342) }
343) $html .= '<p><strong>Bitte nicht überweisen!</strong> Der fällige Betrag wird gemäß dem von Ihnen erteilten
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
344) Lastschrift-Mandat in wenigen Tagen vom Konto mit der IBAN ' . $display_iban . ' bei der ' . $sepamandat['bankname'] . '
345) (BIC: ' . $sepamandat['bic'] . ') abgebucht. Diese Kontodaten beruhen auf dem Mandat Nr. ' . $sepamandat['mandatsreferenz'] . '
346) vom ' . $sepamandat['erteilt'] . '. Unsere Gläubiger-ID lautet ' . $sepamandat['glaeubiger_id'] . '.</p>';
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
347) } else {
348) $html .= '<p>Bitte begleichen Sie diese Rechnung umgehend nach Erhalt ohne Abzüge auf das unten angegebene Konto. Geben Sie
|
Spaces between string conca...
Hanno Böck authored 7 months ago
|
349) im Verwendungszweck Ihrer Überweisung bitte die Rechnungsnummer ' . $invoice_id . ' an, damit Ihre Buchung korrekt
|
Erzeuge HTML als Eingabe fü...
Bernd Wurst authored 5 years ago
|
350) zugeordnet werden kann.</p>';
351) }
352)
353)
354) $html .= '<p>Wir danken Ihnen, dass Sie unser Angebot in Anspruch genommen haben und hoffen weiterhin auf eine gute
355) Zusammenarbeit. Dieser Rechnung liegen die Allgemeinen Geschäftsbedingungen zum Zeitpunkt des
356) Rechnungsdatums zugrunde, die Sie unter https://www.schokokeks.org/agb abrufen können.</p>';
357)
358)
359) if ($outformat == 'html') {
360) $html .= $footer;
361) }
362)
363) $html .= '</body>
364) </html>';
365)
366) // Composer's auto-loading functionality
367) require "vendor/autoload.php";
368)
369) use Dompdf\Dompdf;
370)
371) //generate some PDFs!
372) $dompdf = new DOMPDF(); //if you use namespaces you may use new \DOMPDF()
373) $dompdf->setPaper('A4', 'portrait');
374) $dompdf->loadHtml($html);
375) $dompdf->render();
376)
377) if ($outformat == 'pdf') {
|
codingstyle, spaces between...
Hanno Böck authored 9 months ago
|
378) $dompdf->stream("sample.pdf", ["Attachment" => 0]);
|