Fix VAT calculation in invoice

Change-Id: I267efe42321f7b1fe539455f27fda4fc0a41475f
diff --git a/invoice.php b/invoice.php
index e5e6f19..5d888af 100644
--- a/invoice.php
+++ b/invoice.php
@@ -37,8 +37,10 @@
         $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, false, -$STUDENT_DISCOUNT);
     if($user->conference_dinner)  {
-        $invoice->addItem('Conference Dinner' . ($user->vegetarian_dinner ? " (vegetarian option)" : ""), 'The conference dinner takes place on 20 July.', 1, false, $CONFERENCE_DINNER, $CONFERENCE_DINNER * $FULL_VAT, $CONFERENCE_DINNER);
-        $vat_sum += $CONFERENCE_DINNER * $FULL_VAT;
+        $net = $CONFERENCE_DINNER / (1 + $FULL_VAT);
+        $vat = $CONFERENCE_DINNER - $net;
+        $invoice->addItem('Conference Dinner' . ($user->vegetarian_dinner ? " (vegetarian option)" : ""), 'The conference dinner takes place on 20 July.', 1, false, $net, $vat, $CONFERENCE_DINNER);
+        $vat_sum += $vat;
     }
     $lunch_count = 0;
     $lunch_details = "";
@@ -64,15 +66,20 @@
         $lunch_details .= "Day 3: " . $user->lunch_day_3;
         $i++;
     }
-    $vat_sum += $lunch_count * $LUNCH * $FULL_VAT;
 
-    if ($lunch_count > 0)
-        $invoice->addItem('Lunch', $lunch_details, $lunch_count, false, $LUNCH, $lunch_count * $LUNCH * $FULL_VAT, $lunch_count * $LUNCH);
-    // $invoice->addTotal('Discount', $STUDENT_DISCOUNT);
+    if ($lunch_count > 0) {
+        $net = $lunch_count * $LUNCH / (1 + $FULL_VAT);
+        $vat = $lunch_count * $LUNCH - $net;
+        $vat_sum += $vat;
+        $invoice->addItem('Lunch', $lunch_details, $lunch_count, false, $net,  $vat, $lunch_count * $LUNCH);
+
+    }
 
     if ($user->excursion) {
-        $vat_sum += $EXCURSION * $FULL_VAT;
-        $invoice->addItem('Guided City Walk', 'The Guided City Walk takes place in the late afternoon of 21 July.', 1, false, $EXCURSION, $EXCURSION * $FULL_VAT, $EXCURSION);
+        $net = $EXCURSION / (1 + $FULL_VAT);
+        $vat = $EXCURSION - $net;
+        $vat_sum += $vat;
+        $invoice->addItem('Guided City Walk', 'The Guided City Walk takes place in the late afternoon of 21 July.', 1, false, $net, $vat, $EXCURSION);
     }
 
     /* Add totals */