Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 3 | include_once 'User.php'; |
| 4 | use \User as User; |
| 5 | |
| 6 | require 'vendor/autoload.php'; |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 7 | |
| 8 | use Konekt\PdfInvoice\InvoicePrinter; |
| 9 | |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 10 | #include_once '../src/InvoicePrinter.php'; |
| 11 | include 'config.php'; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 12 | $FULL_VAT=0.19; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 13 | function create_invoice(User $user) |
| 14 | { |
Marc Kupietz | 8b80c7a | 2023-03-28 21:41:39 +0200 | [diff] [blame] | 15 | global $FULL_VAT, $SERVICE_ACRONYM, $SERVICE_NAME, $SERVICE_LOGO, $REGULAR_CONFERENCE_FEE, $EARLYBIRD_CONFERENCE_FEE, $STUDENT_DISCOUNT, $CONFERENCE_DINNER, $LUNCH, $EXCURSION; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 16 | $vat_sum = 0; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 17 | $invoice = new InvoicePrinter("A4", "€", "en"); |
| 18 | $invoice->lang['product'] = "Item"; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 19 | $invoice->lang['discount'] = "VAT " . $FULL_VAT * 100 . "%"; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 20 | /* Header Settings */ |
| 21 | $invoice->setLogo(str_replace(".svg", ".png", $SERVICE_LOGO)); |
| 22 | $invoice->setColor('#4bb044'); |
| 23 | $invoice->setType('Invoice'); |
| 24 | $invoice->setReference('ICLC-10-' . $user->id); |
| 25 | $invoice->setDate(date('Y-m-d', time())); |
Marc Kupietz | 17b2e5f | 2023-04-01 17:51:48 +0200 | [diff] [blame] | 26 | $invoice->flipflop(); |
| 27 | $invoice->lang['to'] = "to"; |
| 28 | $invoice->lang['from'] = "from"; |
| 29 | $invoice->setFrom(['ICLC-conference / Administration', 'Leibniz Institute for the German Language', 'R5 6-13', '68181 Mannheim', 'Germany']); |
| 30 | $invoice->setTo([($user->title? $user->title . ' ' : ''). $user->first_name . ' ' . $user->last_name, $user->organization, $user->street, $user->zip . ' ' . $user->city, $user->country]); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 31 | $invoice->setDue(date('Y-m-d', strtotime('+2 weeks'))); |
| 32 | // $invoice->hide_tofrom(); |
| 33 | /* Adding Items in table */ |
| 34 | if ($user->earlybird_registration) { |
| 35 | $invoice->addItem( $SERVICE_ACRONYM . ' Early Bird Registration', $SERVICE_NAME, 1, false, $EARLYBIRD_CONFERENCE_FEE, false, $EARLYBIRD_CONFERENCE_FEE); |
| 36 | } else |
| 37 | $invoice->addItem( $SERVICE_ACRONYM . ' Registration', $SERVICE_NAME, 1, false, $REGULAR_CONFERENCE_FEE, false, $REGULAR_CONFERENCE_FEE); |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 38 | if($user->student) $invoice->addItem('Student Discount', 'Student discount', 1, false, - $STUDENT_DISCOUNT, false, -$STUDENT_DISCOUNT); |
| 39 | if($user->conference_dinner) { |
Marc Kupietz | 041d0ac | 2023-04-18 11:45:57 +0200 | [diff] [blame] | 40 | $net = $CONFERENCE_DINNER / (1 + $FULL_VAT); |
| 41 | $vat = $CONFERENCE_DINNER - $net; |
| 42 | $invoice->addItem('Conference Dinner' . ($user->vegetarian_dinner ? " (vegetarian option)" : ""), 'The conference dinner takes place on 20 July.', 1, false, $net, $vat, $CONFERENCE_DINNER); |
| 43 | $vat_sum += $vat; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 44 | } |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 45 | $lunch_count = 0; |
| 46 | $lunch_details = ""; |
| 47 | $i = 0; |
Marc Kupietz | 487abfe | 2023-04-15 14:00:56 +0200 | [diff] [blame] | 48 | if ($user->lunch_day_1 && $user->lunch_day_1 != "--") { |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 49 | if ($i > 0) |
| 50 | $lunch_details .= ", "; |
| 51 | $lunch_count++; |
| 52 | $lunch_details .= "Day 1: " . $user->lunch_day_1; |
| 53 | $i++; |
| 54 | } |
Marc Kupietz | 487abfe | 2023-04-15 14:00:56 +0200 | [diff] [blame] | 55 | if ($user->lunch_day_2 && $user->lunch_day_2 != "--") { |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 56 | if ($i > 0) |
| 57 | $lunch_details .= ", "; |
| 58 | $lunch_count++; |
| 59 | $lunch_details .= "Day 2: " . $user->lunch_day_2; |
| 60 | $i++; |
| 61 | } |
Marc Kupietz | 487abfe | 2023-04-15 14:00:56 +0200 | [diff] [blame] | 62 | if ($user->lunch_day_3 && $user->lunch_day_3 != "--") { |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 63 | if ($i > 0) |
| 64 | $lunch_details .= ", "; |
| 65 | $lunch_count++; |
| 66 | $lunch_details .= "Day 3: " . $user->lunch_day_3; |
| 67 | $i++; |
| 68 | } |
| 69 | |
Marc Kupietz | 041d0ac | 2023-04-18 11:45:57 +0200 | [diff] [blame] | 70 | if ($lunch_count > 0) { |
| 71 | $net = $lunch_count * $LUNCH / (1 + $FULL_VAT); |
| 72 | $vat = $lunch_count * $LUNCH - $net; |
| 73 | $vat_sum += $vat; |
| 74 | $invoice->addItem('Lunch', $lunch_details, $lunch_count, false, $net, $vat, $lunch_count * $LUNCH); |
| 75 | |
| 76 | } |
Marc Kupietz | a104b60 | 2023-03-20 21:29:34 +0100 | [diff] [blame] | 77 | |
Marc Kupietz | 8b80c7a | 2023-03-28 21:41:39 +0200 | [diff] [blame] | 78 | if ($user->excursion) { |
Marc Kupietz | 041d0ac | 2023-04-18 11:45:57 +0200 | [diff] [blame] | 79 | $net = $EXCURSION / (1 + $FULL_VAT); |
| 80 | $vat = $EXCURSION - $net; |
Marc Kupietz | 1f64cdd | 2023-04-19 07:18:09 +0200 | [diff] [blame^] | 81 | # $vat_sum += $vat; |
| 82 | # $invoice->addItem('Guided City Walk', 'The Guided City Walk takes place in the late afternoon of 21 July.', 1, false, $net, $vat, $EXCURSION); |
| 83 | $invoice->addItem('Guided City Walk', 'The Guided City Walk takes place in the late afternoon of 21 July.', 1, false, $EXCURSION, "", $EXCURSION); |
Marc Kupietz | 8b80c7a | 2023-03-28 21:41:39 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Marc Kupietz | a104b60 | 2023-03-20 21:29:34 +0100 | [diff] [blame] | 86 | /* Add totals */ |
Marc Kupietz | 42a6fb5 | 2023-04-18 12:29:23 +0200 | [diff] [blame] | 87 | $invoice->addTotal('Net Sum', $user->total_due-$vat_sum); |
Marc Kupietz | a104b60 | 2023-03-20 21:29:34 +0100 | [diff] [blame] | 88 | |
| 89 | if ($vat_sum > 0) { |
Marc Kupietz | 42a6fb5 | 2023-04-18 12:29:23 +0200 | [diff] [blame] | 90 | $invoice->addTotal("+" . $FULL_VAT * 100 . "% VAT", $vat_sum, false); |
Marc Kupietz | a104b60 | 2023-03-20 21:29:34 +0100 | [diff] [blame] | 91 | } |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 92 | $invoice->addTotal('Total due', $user->total_due, true); |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 93 | |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 94 | $invoice->addTitle("Payment Details"); |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 95 | |
Marc Kupietz | 81065d3 | 2023-03-10 13:54:21 +0100 | [diff] [blame] | 96 | $invoice->addParagraph("Please transfer the total amount due to our account: "); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 97 | |
Marc Kupietz | 3140f4b | 2023-04-19 07:12:37 +0200 | [diff] [blame] | 98 | $invoice->addParagraph("Leibniz Institute for the German Language |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 99 | IBAN: DE70 6708 0050 0694 9411 00 |
| 100 | BIC: DRESDEFF670 |
| 101 | Commerzbank Mannheim |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 102 | Reference: ICLC-10-" . $user->id . " |
Marc Kupietz | 728885c | 2023-03-20 19:45:34 +0100 | [diff] [blame] | 103 | |
Marc Kupietz | 42f0c8f | 2023-03-20 19:47:25 +0100 | [diff] [blame] | 104 | If you have any questions about this invoice, please contact us via buchhaltung@ids-mannheim.de. |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 105 | "); |
Marc Kupietz | 144d82e | 2023-03-26 15:55:42 +0200 | [diff] [blame] | 106 | $invoice->setFooterNote("Leibniz Institute for the German Language, Civil Law Foundation, VAT ID: DE 143 845 359"); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 107 | |
| 108 | /* Render */ |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 109 | $ret = $invoice->render('example4.pdf', 'S'); /* I => Display on browser, D => Force Download, F => local path save, S => return document path */ |
| 110 | return $ret; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | $user = new User(); |
| 115 | $user->id = 107; |
| 116 | $user->first_name = "John"; |
| 117 | $user->last_name = "Урсула"; |
| 118 | $user->organization = "Урсула ACME Inc."; |
| 119 | $user->street = "123 Main St."; |
| 120 | $user->zip = "12345"; |
| 121 | $user->city = "Mannheim"; |
| 122 | $user->country = "Germany"; |
Marc Kupietz | e9bcbc0 | 2023-03-20 21:29:59 +0100 | [diff] [blame] | 123 | $user->total_due = 285.0; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 124 | $user->student = true; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 125 | $user->lunch_day_1 = "vegan"; |
| 126 | $user->lunch_day_2 = "non-vegetarian"; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 127 | $user->conference_dinner = true; |
| 128 | create_invoice($user); |
| 129 | */ |
| 130 | ?> |