Erzeuge HTML als Eingabe für dompdf aus bestehenden Rechnungen aus der Datenbank
Bernd Wurst

Bernd Wurst commited on 2018-12-29 13:44:27
Zeige 4 geänderte Dateien mit 677 Einfügungen und 50 Löschungen.

... ...
@@ -7,6 +7,7 @@
7 7
         "giggsey/libphonenumber-for-php": "^8.8",
8 8
         "globalcitizen/php-iban": "^2.6",
9 9
         "mpdf/mpdf": "^7.0",
10
+        "dompdf/dompdf": "dev-master",
10 11
         "PHPGangsta/GoogleAuthenticator": "dev-master"
11 12
     }
12 13
 }
... ...
@@ -1,10 +1,10 @@
1 1
 {
2 2
     "_readme": [
3 3
         "This file locks the dependencies of your project to a known state",
4
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
4
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 5
         "This file is @generated automatically"
6 6
     ],
7
-    "content-hash": "af89b3738a8eb6b4ac7f0e66aa03b1e1",
7
+    "content-hash": "a0dd425da3b01b07ca5557067dff6794",
8 8
     "packages": [
9 9
         {
10 10
             "name": "bjeavons/zxcvbn-php",
... ...
@@ -51,18 +51,84 @@
51 51
             ],
52 52
             "time": "2017-01-06T15:43:33+00:00"
53 53
         },
54
+        {
55
+            "name": "dompdf/dompdf",
56
+            "version": "dev-master",
57
+            "source": {
58
+                "type": "git",
59
+                "url": "https://github.com/dompdf/dompdf.git",
60
+                "reference": "75f13c700009be21a1965dc2c5b68a8708c22ba2"
61
+            },
62
+            "dist": {
63
+                "type": "zip",
64
+                "url": "https://api.github.com/repos/dompdf/dompdf/zipball/75f13c700009be21a1965dc2c5b68a8708c22ba2",
65
+                "reference": "75f13c700009be21a1965dc2c5b68a8708c22ba2",
66
+                "shasum": ""
67
+            },
68
+            "require": {
69
+                "ext-dom": "*",
70
+                "ext-mbstring": "*",
71
+                "phenx/php-font-lib": "0.5.*",
72
+                "phenx/php-svg-lib": "0.3.*",
73
+                "php": ">=5.4.0"
74
+            },
75
+            "require-dev": {
76
+                "phpunit/phpunit": "^4.8|^5.5|^6.5",
77
+                "squizlabs/php_codesniffer": "2.*"
78
+            },
79
+            "suggest": {
80
+                "ext-gd": "Needed to process images",
81
+                "ext-gmagick": "Improves image processing performance",
82
+                "ext-imagick": "Improves image processing performance"
83
+            },
84
+            "type": "library",
85
+            "extra": {
86
+                "branch-alias": {
87
+                    "dev-develop": "0.7-dev"
88
+                }
89
+            },
90
+            "autoload": {
91
+                "psr-4": {
92
+                    "Dompdf\\": "src/"
93
+                },
94
+                "classmap": [
95
+                    "lib/"
96
+                ]
97
+            },
98
+            "notification-url": "https://packagist.org/downloads/",
99
+            "license": [
100
+                "LGPL-2.1"
101
+            ],
102
+            "authors": [
103
+                {
104
+                    "name": "Fabien Ménager",
105
+                    "email": "fabien.menager@gmail.com"
106
+                },
107
+                {
108
+                    "name": "Brian Sweeney",
109
+                    "email": "eclecticgeek@gmail.com"
110
+                },
111
+                {
112
+                    "name": "Gabriel Bull",
113
+                    "email": "me@gabrielbull.com"
114
+                }
115
+            ],
116
+            "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
117
+            "homepage": "https://github.com/dompdf/dompdf",
118
+            "time": "2018-12-14T02:40:31+00:00"
119
+        },
54 120
         {
55 121
             "name": "giggsey/libphonenumber-for-php",
56
-            "version": "8.9.8",
122
+            "version": "8.10.2",
57 123
             "source": {
58 124
                 "type": "git",
59 125
                 "url": "https://github.com/giggsey/libphonenumber-for-php.git",
60
-                "reference": "420621360d56499ac1b0e6293561ed8661017c6b"
126
+                "reference": "a71f260c2efce10ded8af030a20fa13edfb0e9be"
61 127
             },
62 128
             "dist": {
63 129
                 "type": "zip",
64
-                "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php/zipball/420621360d56499ac1b0e6293561ed8661017c6b",
65
-                "reference": "420621360d56499ac1b0e6293561ed8661017c6b",
130
+                "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php/zipball/a71f260c2efce10ded8af030a20fa13edfb0e9be",
131
+                "reference": "a71f260c2efce10ded8af030a20fa13edfb0e9be",
66 132
                 "shasum": ""
67 133
             },
68 134
             "require": {
... ...
@@ -75,8 +141,8 @@
75 141
                 "pear/pear_exception": "^1.0",
76 142
                 "pear/versioncontrol_git": "^0.5",
77 143
                 "phing/phing": "^2.7",
78
-                "phpunit/phpunit": "^4.8|^5.0",
79
-                "satooshi/php-coveralls": "^1.0|^2.0",
144
+                "php-coveralls/php-coveralls": "^1.0|^2.0",
145
+                "phpunit/phpunit": "^4.8.36|^5.0",
80 146
                 "symfony/console": "^2.8|^3.0"
81 147
             },
82 148
             "type": "library",
... ...
@@ -117,20 +183,20 @@
117 183
                 "phonenumber",
118 184
                 "validation"
119 185
             ],
120
-            "time": "2018-06-14T11:25:48+00:00"
186
+            "time": "2018-12-06T10:42:08+00:00"
121 187
         },
122 188
         {
123 189
             "name": "giggsey/locale",
124
-            "version": "1.5",
190
+            "version": "1.6",
125 191
             "source": {
126 192
                 "type": "git",
127 193
                 "url": "https://github.com/giggsey/Locale.git",
128
-                "reference": "3c9cc23c15851c54cb3ccd41a00fd4b5a89feeff"
194
+                "reference": "da6845720b5d104d319d7e84576f54e44dd9e4f5"
129 195
             },
130 196
             "dist": {
131 197
                 "type": "zip",
132
-                "url": "https://api.github.com/repos/giggsey/Locale/zipball/3c9cc23c15851c54cb3ccd41a00fd4b5a89feeff",
133
-                "reference": "3c9cc23c15851c54cb3ccd41a00fd4b5a89feeff",
198
+                "url": "https://api.github.com/repos/giggsey/Locale/zipball/da6845720b5d104d319d7e84576f54e44dd9e4f5",
199
+                "reference": "da6845720b5d104d319d7e84576f54e44dd9e4f5",
134 200
                 "shasum": ""
135 201
             },
136 202
             "require": {
... ...
@@ -166,20 +232,20 @@
166 232
                 }
167 233
             ],
168 234
             "description": "Locale functions required by libphonenumber-for-php",
169
-            "time": "2018-04-03T15:53:12+00:00"
235
+            "time": "2018-10-18T07:17:52+00:00"
170 236
         },
171 237
         {
172 238
             "name": "globalcitizen/php-iban",
173
-            "version": "v2.6.6",
239
+            "version": "v2.6.9",
174 240
             "source": {
175 241
                 "type": "git",
176 242
                 "url": "https://github.com/globalcitizen/php-iban.git",
177
-                "reference": "fd98bd7b4b71cc1bd2a3ecf16fd79b71b44004a1"
243
+                "reference": "16b8c416e8a4047b52dca00794f161bfa68afb7a"
178 244
             },
179 245
             "dist": {
180 246
                 "type": "zip",
181
-                "url": "https://api.github.com/repos/globalcitizen/php-iban/zipball/fd98bd7b4b71cc1bd2a3ecf16fd79b71b44004a1",
182
-                "reference": "fd98bd7b4b71cc1bd2a3ecf16fd79b71b44004a1",
247
+                "url": "https://api.github.com/repos/globalcitizen/php-iban/zipball/16b8c416e8a4047b52dca00794f161bfa68afb7a",
248
+                "reference": "16b8c416e8a4047b52dca00794f161bfa68afb7a",
183 249
                 "shasum": ""
184 250
             },
185 251
             "type": "library",
... ...
@@ -194,28 +260,28 @@
194 260
                 "LGPL-3.0"
195 261
             ],
196 262
             "description": "php-iban is a library for parsing and validating IBAN (and IIBAN) bank account information.",
197
-            "time": "2018-06-19T23:05:14+00:00"
263
+            "time": "2018-08-14T00:04:02+00:00"
198 264
         },
199 265
         {
200 266
             "name": "mpdf/mpdf",
201
-            "version": "v7.1.0",
267
+            "version": "v7.1.7",
202 268
             "source": {
203 269
                 "type": "git",
204 270
                 "url": "https://github.com/mpdf/mpdf.git",
205
-                "reference": "8e3d0d7bf74f71d04904215fb487d01e924c469a"
271
+                "reference": "ac60286a7dc5250c293afebd2bd9414e58a02466"
206 272
             },
207 273
             "dist": {
208 274
                 "type": "zip",
209
-                "url": "https://api.github.com/repos/mpdf/mpdf/zipball/8e3d0d7bf74f71d04904215fb487d01e924c469a",
210
-                "reference": "8e3d0d7bf74f71d04904215fb487d01e924c469a",
275
+                "url": "https://api.github.com/repos/mpdf/mpdf/zipball/ac60286a7dc5250c293afebd2bd9414e58a02466",
276
+                "reference": "ac60286a7dc5250c293afebd2bd9414e58a02466",
211 277
                 "shasum": ""
212 278
             },
213 279
             "require": {
214 280
                 "ext-gd": "*",
215 281
                 "ext-mbstring": "*",
216 282
                 "myclabs/deep-copy": "^1.7",
217
-                "paragonie/random_compat": "^1.4|^2.0",
218
-                "php": "^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0",
283
+                "paragonie/random_compat": "^1.4|^2.0|9.99.99",
284
+                "php": "^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0",
219 285
                 "psr/log": "^1.0",
220 286
                 "setasign/fpdi": "1.6.*"
221 287
             },
... ...
@@ -233,7 +299,7 @@
233 299
             "type": "library",
234 300
             "extra": {
235 301
                 "branch-alias": {
236
-                    "dev-development": "7.0-dev"
302
+                    "dev-development": "7.x-dev"
237 303
                 }
238 304
             },
239 305
             "autoload": {
... ...
@@ -255,14 +321,14 @@
255 321
                     "role": "Developer (retired)"
256 322
                 }
257 323
             ],
258
-            "description": "A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support",
324
+            "description": "PHP library generating PDF files from UTF-8 encoded HTML",
259 325
             "homepage": "https://mpdf.github.io",
260 326
             "keywords": [
261 327
                 "pdf",
262 328
                 "php",
263 329
                 "utf-8"
264 330
             ],
265
-            "time": "2018-05-18T05:41:37+00:00"
331
+            "time": "2018-11-29T18:21:32+00:00"
266 332
         },
267 333
         {
268 334
             "name": "myclabs/deep-copy",
... ...
@@ -314,33 +380,29 @@
314 380
         },
315 381
         {
316 382
             "name": "paragonie/random_compat",
317
-            "version": "v2.0.15",
383
+            "version": "v9.99.99",
318 384
             "source": {
319 385
                 "type": "git",
320 386
                 "url": "https://github.com/paragonie/random_compat.git",
321
-                "reference": "10bcb46e8f3d365170f6de9d05245aa066b81f09"
387
+                "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95"
322 388
             },
323 389
             "dist": {
324 390
                 "type": "zip",
325
-                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/10bcb46e8f3d365170f6de9d05245aa066b81f09",
326
-                "reference": "10bcb46e8f3d365170f6de9d05245aa066b81f09",
391
+                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
392
+                "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
327 393
                 "shasum": ""
328 394
             },
329 395
             "require": {
330
-                "php": ">=5.2.0"
396
+                "php": "^7"
331 397
             },
332 398
             "require-dev": {
333
-                "phpunit/phpunit": "4.*|5.*"
399
+                "phpunit/phpunit": "4.*|5.*",
400
+                "vimeo/psalm": "^1"
334 401
             },
335 402
             "suggest": {
336 403
                 "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
337 404
             },
338 405
             "type": "library",
339
-            "autoload": {
340
-                "files": [
341
-                    "lib/random.php"
342
-                ]
343
-            },
344 406
             "notification-url": "https://packagist.org/downloads/",
345 407
             "license": [
346 408
                 "MIT"
... ...
@@ -359,7 +421,84 @@
359 421
                 "pseudorandom",
360 422
                 "random"
361 423
             ],
362
-            "time": "2018-06-08T15:26:40+00:00"
424
+            "time": "2018-07-02T15:55:56+00:00"
425
+        },
426
+        {
427
+            "name": "phenx/php-font-lib",
428
+            "version": "0.5.1",
429
+            "source": {
430
+                "type": "git",
431
+                "url": "https://github.com/PhenX/php-font-lib.git",
432
+                "reference": "760148820110a1ae0936e5cc35851e25a938bc97"
433
+            },
434
+            "dist": {
435
+                "type": "zip",
436
+                "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/760148820110a1ae0936e5cc35851e25a938bc97",
437
+                "reference": "760148820110a1ae0936e5cc35851e25a938bc97",
438
+                "shasum": ""
439
+            },
440
+            "require-dev": {
441
+                "phpunit/phpunit": "^4.8"
442
+            },
443
+            "type": "library",
444
+            "autoload": {
445
+                "psr-4": {
446
+                    "FontLib\\": "src/FontLib"
447
+                }
448
+            },
449
+            "notification-url": "https://packagist.org/downloads/",
450
+            "license": [
451
+                "LGPL-3.0"
452
+            ],
453
+            "authors": [
454
+                {
455
+                    "name": "Fabien Ménager",
456
+                    "email": "fabien.menager@gmail.com"
457
+                }
458
+            ],
459
+            "description": "A library to read, parse, export and make subsets of different types of font files.",
460
+            "homepage": "https://github.com/PhenX/php-font-lib",
461
+            "time": "2017-09-13T16:14:37+00:00"
462
+        },
463
+        {
464
+            "name": "phenx/php-svg-lib",
465
+            "version": "v0.3.2",
466
+            "source": {
467
+                "type": "git",
468
+                "url": "https://github.com/PhenX/php-svg-lib.git",
469
+                "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c"
470
+            },
471
+            "dist": {
472
+                "type": "zip",
473
+                "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/ccc46ef6340d4b8a4a68047e68d8501ea961442c",
474
+                "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c",
475
+                "shasum": ""
476
+            },
477
+            "require": {
478
+                "sabberworm/php-css-parser": "8.1.*"
479
+            },
480
+            "require-dev": {
481
+                "phpunit/phpunit": "~5.0"
482
+            },
483
+            "type": "library",
484
+            "autoload": {
485
+                "psr-0": {
486
+                    "Svg\\": "src/"
487
+                }
488
+            },
489
+            "notification-url": "https://packagist.org/downloads/",
490
+            "license": [
491
+                "LGPL-3.0"
492
+            ],
493
+            "authors": [
494
+                {
495
+                    "name": "Fabien Ménager",
496
+                    "email": "fabien.menager@gmail.com"
497
+                }
498
+            ],
499
+            "description": "A library to read, parse and export to PDF SVG files.",
500
+            "homepage": "https://github.com/PhenX/php-svg-lib",
501
+            "time": "2018-06-03T10:10:03+00:00"
363 502
         },
364 503
         {
365 504
             "name": "phpgangsta/googleauthenticator",
... ...
@@ -406,16 +545,16 @@
406 545
         },
407 546
         {
408 547
             "name": "psr/log",
409
-            "version": "1.0.2",
548
+            "version": "1.1.0",
410 549
             "source": {
411 550
                 "type": "git",
412 551
                 "url": "https://github.com/php-fig/log.git",
413
-                "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
552
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
414 553
             },
415 554
             "dist": {
416 555
                 "type": "zip",
417
-                "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
418
-                "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
556
+                "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
557
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
419 558
                 "shasum": ""
420 559
             },
421 560
             "require": {
... ...
@@ -449,7 +588,51 @@
449 588
                 "psr",
450 589
                 "psr-3"
451 590
             ],
452
-            "time": "2016-10-10T12:19:37+00:00"
591
+            "time": "2018-11-20T15:27:04+00:00"
592
+        },
593
+        {
594
+            "name": "sabberworm/php-css-parser",
595
+            "version": "8.1.0",
596
+            "source": {
597
+                "type": "git",
598
+                "url": "https://github.com/sabberworm/PHP-CSS-Parser.git",
599
+                "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef"
600
+            },
601
+            "dist": {
602
+                "type": "zip",
603
+                "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/850cbbcbe7fbb155387a151ea562897a67e242ef",
604
+                "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef",
605
+                "shasum": ""
606
+            },
607
+            "require": {
608
+                "php": ">=5.3.2"
609
+            },
610
+            "require-dev": {
611
+                "phpunit/phpunit": "*"
612
+            },
613
+            "type": "library",
614
+            "autoload": {
615
+                "psr-0": {
616
+                    "Sabberworm\\CSS": "lib/"
617
+                }
618
+            },
619
+            "notification-url": "https://packagist.org/downloads/",
620
+            "license": [
621
+                "MIT"
622
+            ],
623
+            "authors": [
624
+                {
625
+                    "name": "Raphael Schweikert"
626
+                }
627
+            ],
628
+            "description": "Parser for CSS Files written in PHP",
629
+            "homepage": "http://www.sabberworm.com/blog/2010/6/10/php-css-parser",
630
+            "keywords": [
631
+                "css",
632
+                "parser",
633
+                "stylesheet"
634
+            ],
635
+            "time": "2016-07-19T19:14:21+00:00"
453 636
         },
454 637
         {
455 638
             "name": "setasign/fpdi",
... ...
@@ -505,6 +688,7 @@
505 688
     "aliases": [],
506 689
     "minimum-stability": "stable",
507 690
     "stability-flags": {
691
+        "dompdf/dompdf": 20,
508 692
         "phpgangsta/googleauthenticator": 20
509 693
     },
510 694
     "prefer-stable": false,
... ...
@@ -17,6 +17,8 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 require_once('inc/base.php');
18 18
 require_once('inc/security.php');
19 19
 
20
+use_module('contacts');
21
+require_once('contacts.php');
20 22
 
21 23
 function my_invoices()
22 24
 {
... ...
@@ -42,22 +44,46 @@ function get_pdf($id)
42 44
 }
43 45
 
44 46
 
45
-function invoice_details($id)
47
+function invoice_address($customer = null) 
46 48
 {
47 49
     $c = (int) $_SESSION['customerinfo']['customerno'];
50
+    if ($customer != null && have_role(ROLE_SYSADMIN)) {
51
+        $c = (int) $customer;
52
+    }
53
+    $result = db_query("SELECT contact_kunde, contact_rechnung FROM kundendaten.kunden WHERE id=?", array($c));
54
+    $kontakte = $result->fetch();
55
+    $kunde = get_contact($kontakte['contact_kunde'], $c);
56
+    if ($kontakte['contact_rechnung']) {
57
+        $rechnung = get_contact($kontakte['contact_rechnung'], $c);
58
+        foreach (array('company', 'name', 'address', 'zip', 'city', 'country', 'email') as $field) {
59
+            if ($rechnung[$field]) {
60
+                $kunde[$field] = $rechnung[$field];
61
+            }
62
+        }
63
+    }
64
+    // Hier ist $kunde der bereinigte Rechnungskontakt
65
+    return $kunde;
66
+}
67
+
68
+
69
+function invoice_details($id)
70
+{
48 71
     $id = (int) $id;
49
-    $result = db_query("SELECT kunde,datum,betrag,bezahlt,abbuchung FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id", array(":c" => $c, ":id" => $id));
72
+    $result = db_query("SELECT kunde,datum,betrag,bezahlt,sepamandat,abbuchung FROM kundendaten.ausgestellte_rechnungen WHERE id=:id", array(":id" => $id));
50 73
     if ($result->rowCount() == 0) {
51 74
         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
52 75
     }
53
-    return $result->fetch();
76
+    $data = $result->fetch();
77
+    if (!have_role(ROLE_SYSADMIN) && $data['kunde'] != (int) $_SESSION['customerinfo']['customerno']) {
78
+        system_failure('Ungültige Rechnungsnummer für diesen Login');
79
+    }
80
+    return $data;
54 81
 }
55 82
 
56 83
 function invoice_items($id)
57 84
 {
58
-    $c = (int) $_SESSION['customerinfo']['customerno'];
59 85
     $id = (int) $id;
60
-    $result = db_query("SELECT id, beschreibung, datum, enddatum, betrag, einheit, brutto, mwst, anzahl FROM kundendaten.rechnungsposten WHERE rechnungsnummer=:id AND kunde=:c", array(":c" => $c, ":id" => $id));
86
+    $result = db_query("SELECT id, beschreibung, datum, enddatum, betrag, einheit, brutto, mwst, anzahl FROM kundendaten.rechnungsposten WHERE rechnungsnummer=:id", array(":id" => $id));
61 87
     if ($result->rowCount() == 0) {
62 88
         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
63 89
     }
... ...
@@ -150,6 +176,13 @@ function get_lastschriften($mandatsreferenz)
150 176
     return $ret;
151 177
 }
152 178
 
179
+
180
+function get_sepamandat($id) 
181
+{
182
+    $result = db_query("SELECT id, kunde, mandatsreferenz, glaeubiger_id, erteilt, medium, gueltig_ab, gueltig_bis, erstlastschrift, kontoinhaber, adresse, iban, bic, bankname FROM kundendaten.sepamandat WHERE id=? OR mandatsreferenz=?", array($id, $id));
183
+    return $result->fetch();
184
+ }
185
+
153 186
 function get_sepamandate()
154 187
 {
155 188
     $cid = (int) $_SESSION['customerinfo']['customerno'];
... ...
@@ -0,0 +1,409 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2018 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+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.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('invoice.php');
19
+require_once('inc/security.php');
20
+
21
+require_role(ROLE_CUSTOMER);
22
+
23
+$invoice_id = (int) filter_input_general($_GET['id']);
24
+
25
+$items = invoice_items($invoice_id);
26
+
27
+$invoice = invoice_details($invoice_id);
28
+
29
+
30
+$outformat = 'html';
31
+if (isset($_REQUEST['out']) && $_REQUEST['out'] == 'pdf') {
32
+    $outformat = 'pdf';
33
+}
34
+
35
+
36
+// Footer
37
+$footer = '<footer>
38
+<table width="100%">
39
+<tr><td>schokokeks.org GbR<br>
40
+Bernd Wurst / Johannes Böck<br>
41
+www.schokokeks.org<br>
42
+root@schokokeks.org</td>
43
+
44
+<td>Steuernummer 51072/01109<br>
45
+Finanzamt Backnang<br>
46
+USt-ID: DE255720588</td>
47
+
48
+<td>Volksbank Backnang<br>
49
+IBAN: DE91 6029 1120 0041 5120 06<br>
50
+BIC: GENODES1VBK<br>
51
+(Kto: 41512 006 / BLZ: 602 911 20)</td>
52
+</tr>
53
+</table></footer>';
54
+
55
+
56
+
57
+
58
+$html = '<html><head><title>Rechnung Nr. '.$invoice_id.'</title>
59
+<style type="text/css">
60
+
61
+@media (min-width: 22cm) {
62
+    body {
63
+    	margin: 2cm;
64
+	    margin-top: 0.5cm;
65
+        width: 17cm;
66
+    }
67
+}
68
+
69
+@media print,dompdf {
70
+    html {
71
+        margin: 0;
72
+        padding: 0;
73
+    }
74
+    @page {
75
+        margin: 0;
76
+        padding: 0;
77
+    }
78
+    body {
79
+        margin: 2cm;
80
+        margin-bottom: 3cm;
81
+    }
82
+}
83
+
84
+body {
85
+    font-family: "DejaVu Sans", sans-serif;
86
+    font-size: 8pt;
87
+    padding: 0;
88
+    text-align: justify;
89
+}
90
+
91
+table, th, td, tr {
92
+    font-size: 8pt;
93
+    margin: 0;
94
+    padding: 0;
95
+    border: none;
96
+    border-collapse: collapse;
97
+    vertical-align: top;
98
+}
99
+th {
100
+    text-align: left;
101
+    border-bottom: 1px solid black;
102
+}
103
+
104
+@media print,dompdf {
105
+    #header,
106
+    footer {
107
+        position: fixed;
108
+        left: 0;
109
+	    right: 0;
110
+    	font-size: 8pt;
111
+    }
112
+}
113
+
114
+#header {
115
+  top: 0;
116
+}
117
+
118
+footer {
119
+  border-top: 1px solid #000;
120
+}
121
+
122
+@media print,dompdf {
123
+    footer {
124
+        position: absolute;
125
+  bottom: -2cm;
126
+    }
127
+}
128
+
129
+#header table,
130
+footer table {
131
+	width: 100%;
132
+	border-collapse: collapse;
133
+	border: none;
134
+}
135
+
136
+#header td,
137
+footer td {
138
+  padding: 0;
139
+	width: 33%;
140
+}
141
+
142
+.page-number {
143
+  text-align: center;
144
+}
145
+
146
+.page-number:before {
147
+  content: "Seite " counter(page);
148
+}
149
+
150
+#addressfield {
151
+    float: left;
152
+    position: relative;
153
+    top: 3cm;
154
+    left: 0cm;
155
+    width: 8.5cm;
156
+    min-height: 5cm;
157
+}
158
+#addressfield p {
159
+    margin-left: 0.5cm;
160
+    margin-top: 0.3cm;
161
+    font-size: 11pt;
162
+}
163
+
164
+#addressfieldheader {
165
+    font-size: 8pt;
166
+    padding-left: 0.2cm;
167
+    width: 100%;
168
+    border-bottom: 0.1pt solid black;
169
+}
170
+
171
+
172
+#rightcolumn {
173
+  float: right;
174
+  width: 6cm;
175
+}
176
+
177
+
178
+
179
+#rightcolumn img {
180
+    position: relative;
181
+    top: 0;
182
+    width: 4.08cm;
183
+    height: 3cm;
184
+    margin: 0;
185
+    padding: 0;
186
+}
187
+
188
+td {
189
+  font-size: 8pt;
190
+}
191
+
192
+p {
193
+    margin-bottom: 0.6cm;
194
+}
195
+
196
+tr.even {
197
+    background-color: #eee;
198
+}
199
+
200
+
201
+</style>
202
+</head>
203
+<body>
204
+';
205
+// Folding Marks
206
+$html .= '
207
+<div style="position: absolute; left: -2cm; top: 8.5cm; width: 0.5cm; height: 1px; border-top: 1px solid black;"></div>
208
+<div style="position: absolute; left: -2cm; top: 19cm; width: 0.5cm; height: 1px; border-top: 1px solid black;"></div>
209
+<div style="position: absolute; left: -2cm; top: 12.85cm; width: 0.6cm; height: 1px; border-top: 1px solid black;"></div>
210
+';
211
+
212
+if ($outformat == 'pdf') {
213
+    $html .= $footer;
214
+}
215
+
216
+$address = invoice_address($invoice['kunde']);
217
+
218
+// Address Field
219
+$html .= '<div id="addressfield">
220
+<div id="addressfieldheader">schokokeks.org · Köchersberg 32 · 71540 Murrhardt</div>
221
+<p>'.($address['company'] != null ? $address['company'].'<br>' : '' ).$address['name'].'<br>
222
+'.$address['address'].'<br>
223
+'.($address['country'] != 'DE' ? $address['country'].'-' : '').$address['zip'].' '.$address['city'].'
224
+</p>
225
+</div>';
226
+// Right col
227
+$html .= '<div id="rightcolumn">
228
+<img src="'.($outformat == 'pdf' ? '.' : '../..').'/themes/default/images/schokokeks.png">
229
+<p style="margin-bottom: 0.2cm;"><strong>schokokeks.org GbR</strong><br>
230
+Bernd Wurst / Johannes Böck<br>
231
+Köchersberg 32<br>
232
+71540 Murrhardt</p>
233
+<p>Tel: 07192-936432<br>
234
+E-Mail: root@schokokeks.org</p>
235
+</div>';
236
+
237
+// Caption / Invoice-Details
238
+$html .= '
239
+<table style="width: 100%; clear: both;">
240
+<tr><td style="width: 11cm; font-size: 11pt; font-weight: bold;">Rechnung</td><td>
241
+  <table>
242
+  <tr><td colspan="2"><strong>Bei Fragen bitte immer angeben:</strong></td></tr>
243
+  <tr><td>Rechnungsdatum:</td><td align="right">'.date("d. m. Y", strtotime($invoice['datum'])).'</td></tr>
244
+  <tr><td>Rechnungsnummer:</td><td align="right">'.$invoice_id.'</td></tr>
245
+  <tr><td>Kundennummer:</td><td align="right">'.$invoice['kunde'].'</td></tr>
246
+  </table>
247
+  </td></tr>
248
+</table>';
249
+
250
+$anrede = 'Sehr geehrte Damen und Herren';
251
+
252
+$parts = explode(' ', $address['name']);
253
+$nachname = array_pop($parts);
254
+
255
+if ($address['name']) {
256
+    if ($address['salutation'] == 'Herr') {
257
+        $anrede = 'Sehr geehrter Herr '.$nachname;
258
+    } elseif ($address['salutation'] == 'Frau') {
259
+        $anrede = 'Sehr geehrte Frau '.$nachname;
260
+    }
261
+}
262
+
263
+// Salutation
264
+$html .= '<p>'.$anrede.',<br>
265
+hiermit stellen wir die nachfolgend genannten Posten in Rechnung.</p>';
266
+
267
+
268
+// Table
269
+$html .= '<table style="width: 100%;">
270
+<tr style="border-bottom: 1px solid black;">
271
+<th style="width: 1cm; text-align: center;">Anz.</th>
272
+<th style="min-width: 1cm; max-width: 2cm;">&nbsp;</th>
273
+<th>Beschreibung</th>
274
+<th style="width: 2.5cm; text-align: center;">Einzelpreis</th>
275
+<th style="width: 3cm; text-align: center;">Gesamtpreis</th></tr>';
276
+
277
+$vattype = null;
278
+// An der ersten Zeile entscheidet sich, ob die gesamte Rechnung als Netto- oder Bruttorechnung erstellt wird
279
+$einzelsummen = array();
280
+$summe = 0.0;
281
+
282
+$odd = true;
283
+foreach ($items as $item) {
284
+    if ($vattype == 'gross' && $item['brutto'] == 0) {
285
+            system_failure('Mixed gross and net positions');
286
+    } elseif ($vattype == 'net' && $item['brutto'] == 1) {
287
+            system_failure('Mixed gross and net positions');
288
+    } else {
289
+        $vattype = ($item['brutto'] == 1 ? 'gross' : 'net');
290
+    }
291
+
292
+    $anzahl = $item['anzahl'];
293
+    if (round($anzahl, 0) == $anzahl) {
294
+        $anzahl = round($anzahl, 0);
295
+    }
296
+    $desc = $item['beschreibung'];
297
+    if ($item['enddatum'] == null) {
298
+        $desc .= '<br />(Leistungsdatum: '.$item['datum'].')';
299
+    } else {
300
+        $desc .= '<br />(Leistungszeitraum: '.$item['datum'].' - '.$item['enddatum'].')';
301
+    }
302
+    $epreis = $item['betrag'];
303
+    if ($item['brutto'] == 0) {
304
+        $epreis = $epreis * (1 + ($item['mwst'] / 100));
305
+    }
306
+    $einheit = ($item['einheit'] ? $item['einheit'] : '');
307
+    $gesamt = $epreis * $item['anzahl'];
308
+    $epreis = $epreis;
309
+
310
+    if (array_key_exists($item['mwst'], $einzelsummen)) {
311
+        $einzelsummen[$item['mwst']]['net'] += $gesamt / (1 + ($item['mwst'] / 100));
312
+        $einzelsummen[$item['mwst']]['vat'] += $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100);
313
+        $einzelsummen[$item['mwst']]['gross'] += $gesamt;
314
+    } else {
315
+        $einzelsummen[$item['mwst']] = array('net' => $gesamt / (1 + ($item['mwst'] / 100)), 
316
+                                             'vat' => $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100),
317
+                                             'gross' => $gesamt);
318
+    }
319
+    $summe += $gesamt;
320
+
321
+    $html .= "<tr class='".($odd ? 'odd' : 'even')."'><td style='text-align: right;'>{$anzahl}</td><td>{$einheit}</td>";
322
+    $html .= "<td>{$desc}</td>";
323
+    $html .= "<td style='text-align: right;'>".number_format($epreis, 2, ',', '.')." €</td><td style='text-align: right;'>".number_format($gesamt, 2, ',', '.')." €</td></tr>\n";
324
+    $odd = ! $odd;
325
+}
326
+$html .= '<tr><td>&nbsp;</td></tr>';
327
+
328
+foreach ($einzelsummen as $percent => $sums) {
329
+    $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>
330
+              <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>';
331
+    if (count($einzelsummen) > 1) {
332
+              $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>';
333
+    }
334
+}
335
+$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>
336
+</table>';
337
+
338
+// Disclaimer
339
+if ($invoice['abbuchung'] == 1) {
340
+    $sepamandat = get_sepamandat($invoice['sepamandat']);
341
+    $iban = substr($sepamandat['iban'], 0, 8) . '**********' . substr($sepamandat['iban'], -4);
342
+    $display_iban = $iban;
343
+    for ($i = strlen($iban)-(strlen($iban)%4) ; $i != 0 ; $i -= 4) {
344
+        $display_iban = substr($display_iban, 0, $i) . ' ' . substr($display_iban, $i);
345
+    }
346
+    $html .= '<p><strong>Bitte nicht überweisen!</strong> Der fällige Betrag wird gemäß dem von Ihnen erteilten 
347
+    Lastschrift-Mandat in wenigen Tagen vom Konto mit der IBAN '.$display_iban.' bei der '.$sepamandat['bankname'].' 
348
+    (BIC: '.$sepamandat['bic'].') abgebucht. Diese Kontodaten beruhen auf dem Mandat Nr. '.$sepamandat['mandatsreferenz'].' 
349
+    vom '.$sepamandat['erteilt'].'. Unsere Gläubiger-ID lautet '.$sepamandat['glaeubiger_id'].'.</p>';
350
+} else {
351
+    $html .= '<p>Bitte begleichen Sie diese Rechnung umgehend nach Erhalt ohne Abzüge auf das unten angegebene Konto. Geben Sie
352
+im Verwendungszweck Ihrer Überweisung bitte die Rechnungsnummer '.$invoice_id.' an, damit Ihre Buchung korrekt
353
+zugeordnet werden kann.</p>';
354
+}
355
+
356
+
357
+$html .= '<p>Wir danken Ihnen, dass Sie unser Angebot in Anspruch genommen haben und hoffen weiterhin auf eine gute
358
+Zusammenarbeit. Dieser Rechnung liegen die Allgemeinen Geschäftsbedingungen zum Zeitpunkt des
359
+Rechnungsdatums zugrunde, die Sie unter https://www.schokokeks.org/agb abrufen können.</p>';
360
+
361
+
362
+if ($outformat == 'html') {
363
+    $html .= $footer;
364
+}
365
+
366
+$html .= '</body>
367
+</html>';
368
+
369
+// Composer's auto-loading functionality
370
+require "vendor/autoload.php";
371
+
372
+use Dompdf\Dompdf;
373
+
374
+//generate some PDFs!
375
+$dompdf = new DOMPDF();  //if you use namespaces you may use new \DOMPDF()
376
+$dompdf->setPaper('A4', 'portrait');
377
+$dompdf->loadHtml($html);
378
+$dompdf->render();
379
+
380
+if ($outformat == 'pdf') {
381
+    $dompdf->stream("sample.pdf", array("Attachment"=>0));
382
+} else {
383
+    echo $html;
384
+}
385
+
386
+
387
+
388
+
389
+/*');
390
+
391
+
392
+
393
+output("<tr><td colspan=\"3\" style=\"text-align: right; font-weight: bold; border: none;\">Summe aller Posten:</td>");
394
+output("<td style=\"font-weight: bold;\">{$summe} €</td></tr>\n");
395
+output('</table><br />');
396
+
397
+$l = get_lastschrift($invoice_id);
398
+
399
+if ($invoice['bezahlt'] == 1) {
400
+    output('<p>Diese Rechnung ist bereits bezahlt.</p>');
401
+} elseif ($l && $l['status'] == 'pending') {
402
+    output('<p>Diese Rechnung wird am '.$l['buchungsdatum'].' per Lastschrift eingezogen.</p>');
403
+} elseif ($l && $l['status'] == 'done') {
404
+    output('<p>Diese Rechnung wurde am '.$l['buchungsdatum'].' per Lastschrift eingezogen.</p>');
405
+} else {
406
+    $qrcode_image = generate_qrcode_image_invoice($invoice_id);
407
+
408
+    output('<h4>GiroCode für Mobile Banking (SEPA Credit Transfer)</h4><p><img src="data:image/png;base64,'.base64_encode($qrcode_image).'" /></p>');
409
+}*/
0 410