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 | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 15 | global $FULL_VAT, $SERVICE_ACRONYM, $SERVICE_NAME, $SERVICE_LOGO, $REGULAR_CONFERENCE_FEE, $EARLYBIRD_CONFERENCE_FEE, $STUDENT_DISCOUNT, $CONFERENCE_DINNER, $LUNCH; |
| 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 | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 26 | $invoice->setFrom(['ICLC-conference / Administration', 'Leibniz-Institute for the German Language', 'R5 6-13', '68181 Mannheim', 'Germany']); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 27 | $invoice->setTo([$user->first_name . ' ' . $user->last_name, $user->organization, $user->street, $user->zip . ' ' . $user->city, $user->country]); |
| 28 | $invoice->setDue(date('Y-m-d', strtotime('+2 weeks'))); |
| 29 | // $invoice->hide_tofrom(); |
| 30 | /* Adding Items in table */ |
| 31 | if ($user->earlybird_registration) { |
| 32 | $invoice->addItem( $SERVICE_ACRONYM . ' Early Bird Registration', $SERVICE_NAME, 1, false, $EARLYBIRD_CONFERENCE_FEE, false, $EARLYBIRD_CONFERENCE_FEE); |
| 33 | } else |
| 34 | $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] | 35 | if($user->student) $invoice->addItem('Student Discount', 'Student discount', 1, false, - $STUDENT_DISCOUNT, false, -$STUDENT_DISCOUNT); |
| 36 | if($user->conference_dinner) { |
| 37 | $invoice->addItem('Conference Dinner', 'The conference dinner will take place on 20 July.', 1, false, $CONFERENCE_DINNER, $CONFERENCE_DINNER * $FULL_VAT, $CONFERENCE_DINNER); |
| 38 | $vat_sum += $CONFERENCE_DINNER * $FULL_VAT; |
| 39 | } |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 40 | /* Add totals */ |
| 41 | $invoice->addTotal('Total', $user->total_due); |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 42 | $lunch_count = 0; |
| 43 | $lunch_details = ""; |
| 44 | $i = 0; |
| 45 | if ($user->lunch_day_1) { |
| 46 | if ($i > 0) |
| 47 | $lunch_details .= ", "; |
| 48 | $lunch_count++; |
| 49 | $lunch_details .= "Day 1: " . $user->lunch_day_1; |
| 50 | $i++; |
| 51 | } |
| 52 | if ($user->lunch_day_2) { |
| 53 | if ($i > 0) |
| 54 | $lunch_details .= ", "; |
| 55 | $lunch_count++; |
| 56 | $lunch_details .= "Day 2: " . $user->lunch_day_2; |
| 57 | $i++; |
| 58 | } |
| 59 | if ($user->lunch_day_3) { |
| 60 | if ($i > 0) |
| 61 | $lunch_details .= ", "; |
| 62 | $lunch_count++; |
| 63 | $lunch_details .= "Day 3: " . $user->lunch_day_3; |
| 64 | $i++; |
| 65 | } |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 66 | $vat_sum += $lunch_count * $LUNCH * $FULL_VAT; |
Marc Kupietz | 79eaa0b | 2023-03-16 17:33:43 +0100 | [diff] [blame] | 67 | |
| 68 | if ($lunch_count > 0) |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 69 | $invoice->addItem('Lunch', $lunch_details, $lunch_count, false, $LUNCH, $lunch_count * $LUNCH * $FULL_VAT, $lunch_count * $LUNCH); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 70 | // $invoice->addTotal('Discount', $STUDENT_DISCOUNT); |
| 71 | $invoice->addTotal('Total due', $user->total_due, true); |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 72 | $invoice->addTotal('incl. VAT', $vat_sum, false); |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 73 | |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 74 | $invoice->addTitle("Payment Details"); |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 75 | |
Marc Kupietz | 81065d3 | 2023-03-10 13:54:21 +0100 | [diff] [blame] | 76 | $invoice->addParagraph("Please transfer the total amount due to our account: "); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 77 | |
| 78 | $invoice->addParagraph("Leibniz-Institute for the German Language |
Marc Kupietz | b411f46 | 2023-03-09 08:21:11 +0100 | [diff] [blame] | 79 | IBAN: DE70 6708 0050 0694 9411 00 |
| 80 | BIC: DRESDEFF670 |
| 81 | Commerzbank Mannheim |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 82 | Reference: ICLC-10-" . $user->id . " |
Marc Kupietz | 728885c | 2023-03-20 19:45:34 +0100 | [diff] [blame] | 83 | |
| 84 | VAT ID: DE 143 845 359 |
Marc Kupietz | 42f0c8f | 2023-03-20 19:47:25 +0100 | [diff] [blame^] | 85 | |
| 86 | 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] | 87 | "); |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 88 | //$invoice->setFooterNote("xx"); |
| 89 | |
| 90 | /* Render */ |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 91 | $ret = $invoice->render('example4.pdf', 'S'); /* I => Display on browser, D => Force Download, F => local path save, S => return document path */ |
| 92 | return $ret; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | $user = new User(); |
| 97 | $user->id = 107; |
| 98 | $user->first_name = "John"; |
| 99 | $user->last_name = "Урсула"; |
| 100 | $user->organization = "Урсула ACME Inc."; |
| 101 | $user->street = "123 Main St."; |
| 102 | $user->zip = "12345"; |
| 103 | $user->city = "Mannheim"; |
| 104 | $user->country = "Germany"; |
| 105 | $user->total_due = 260.0; |
| 106 | $user->student = true; |
Marc Kupietz | 7081be9 | 2023-03-20 19:46:55 +0100 | [diff] [blame] | 107 | $user->lunch_day_1 = "vegan"; |
| 108 | $user->lunch_day_2 = "non-vegetarian"; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 109 | $user->conference_dinner = true; |
| 110 | create_invoice($user); |
| 111 | */ |
| 112 | ?> |