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