Send pdf invoce with confirmation
Change-Id: Ie5b7b20043d11879f758af6536b55961314188eb
diff --git a/invoice.php b/invoice.php
index d1de840..53bba3d 100644
--- a/invoice.php
+++ b/invoice.php
@@ -1,41 +1,76 @@
<?php
-require '../vendor/autoload.php';
+include_once 'User.php';
+use \User as User;
+
+require 'vendor/autoload.php';
use Konekt\PdfInvoice\InvoicePrinter;
-include '../src/InvoicePrinter.php';
-$invoice = new InvoicePrinter("A4", "€", "en");
-$invoice->lang['product'] = "Item";
-/* Header Settings */
-$invoice->setLogo('images/iclc-logo.png');
-$invoice->setColor('#4bb044');
-$invoice->setType('Invoice');
-$invoice->setReference('55033645');
-$invoice->setDate(date('Y-m-d', time()));
-$invoice->setFrom(['', 'Leibniz-Institute for the German Language', 'R5 6-13', '68181 Mannheim', 'Germany']);
-$invoice->setTo(['', 'Marc Kupietz', 'U4 4', '68161 Mannheim', 'Germany']);
+#include_once '../src/InvoicePrinter.php';
+include 'config.php';
-$invoice->setDue(date('Y-m-d', strtotime('+2 weeks')));
-// $invoice->hide_tofrom();
-/* Adding Items in table */
-$invoice->addItem('ICLC-10 Early Bird Standard Registration', '10ᵗʰ International Contrastive Linguistics Conference, 18-21 July in Mannheim (Germany)', 1, false, 280, false, 280);
-$invoice->addItem('Conference Dinner', 'The conference dinner will take place on 20 July.', 1, false, 60, false, 60);
-/* Add totals */
-$invoice->addTotal('Total', 340);
-$invoice->addTotal('Total due', 340, true);
+function create_invoice(User $user)
+{
+ global $SERVICE_ACRONYM, $SERVICE_NAME, $SERVICE_LOGO, $REGULAR_CONFERENCE_FEE, $EARLYBIRD_CONFERENCE_FEE, $STUDENT_DISCOUNT, $CONFERENCE_DINNER;
-$invoice->addTitle("Payment Details");
+ $invoice = new InvoicePrinter("A4", "€", "en");
+ $invoice->lang['product'] = "Item";
+ /* Header Settings */
+ $invoice->setLogo(str_replace(".svg", ".png", $SERVICE_LOGO));
+ $invoice->setColor('#4bb044');
+ $invoice->setType('Invoice');
+ $invoice->setReference('ICLC-10-' . $user->id);
+ $invoice->setDate(date('Y-m-d', time()));
+ $invoice->setFrom(['', 'Leibniz-Institute for the German Language', 'R5 6-13', '68181 Mannheim', 'Germany']);
+ $invoice->setTo([$user->first_name . ' ' . $user->last_name, $user->organization, $user->street, $user->zip . ' ' . $user->city, $user->country]);
+ $invoice->setDue(date('Y-m-d', strtotime('+2 weeks')));
+ // $invoice->hide_tofrom();
+ /* Adding Items in table */
+ if ($user->earlybird_registration) {
+ $invoice->addItem( $SERVICE_ACRONYM . ' Early Bird Registration', $SERVICE_NAME, 1, false, $EARLYBIRD_CONFERENCE_FEE, false, $EARLYBIRD_CONFERENCE_FEE);
+ } else
+ $invoice->addItem( $SERVICE_ACRONYM . ' Registration', $SERVICE_NAME, 1, false, $REGULAR_CONFERENCE_FEE, false, $REGULAR_CONFERENCE_FEE);
+ if($user->student) $invoice->addItem('Student Discount', 'Student discount', 1, false, "", $STUDENT_DISCOUNT, -$STUDENT_DISCOUNT);
+ if($user->conference_dinner)
+ $invoice->addItem('Conference Dinner', 'The conference dinner will take place on 20 July.', 1, false, $CONFERENCE_DINNER, false, $CONFERENCE_DINNER);
+ /* Add totals */
+ $invoice->addTotal('Total', $user->total_due);
+ // $invoice->addTotal('Discount', $STUDENT_DISCOUNT);
+ $invoice->addTotal('Total due', $user->total_due, true);
-$invoice->addParagraph("Please make payment by Bank Transfer, quoting the above REFERENCE and INVOICE NUMBER as shown above. Bank details are given below:");
+ $invoice->addTitle("Payment Details");
-$invoice->addParagraph("Leibniz-Institute for the German Language
+ $invoice->addParagraph("Please transfer the total amount to the following account: ");
+
+ $invoice->addParagraph("Leibniz-Institute for the German Language
IBAN: DE70 6708 0050 0694 9411 00
BIC: DRESDEFF670
Commerzbank Mannheim
-
-VAT ID: DE 143845359
+
+Reference: ICLC-10-" . $user->id . "
");
-$invoice->setFooterNote("xx");
-/* Render */
-$invoice->render('example2.pdf', 'I'); /* I => Display on browser, D => Force Download, F => local path save, S => return document path */
+ //$invoice->setFooterNote("xx");
+
+ /* Render */
+ $path = tempnam(sys_get_temp_dir(), 'prefix');
+ $ret = $invoice->render('example4.pdf', 'S'); /* I => Display on browser, D => Force Download, F => local path save, S => return document path */
+ return $ret;
+}
+
+/*
+$user = new User();
+$user->id = 107;
+$user->first_name = "John";
+$user->last_name = "Урсула";
+$user->organization = "Урсула ACME Inc.";
+$user->street = "123 Main St.";
+$user->zip = "12345";
+$user->city = "Mannheim";
+$user->country = "Germany";
+$user->total_due = 260.0;
+$user->student = true;
+$user->conference_dinner = true;
+create_invoice($user);
+*/
+?>
\ No newline at end of file