status != Test::STATUS_COMPLETED) throw new Exception("An invoice cannot be generated for this test yet."); if(Core::$user->id != $test->tester_id && !Core::$user->canAdmin()) throw new Exception("You do not have permission to access this resource."); $project = $test->getProject(); $template = $project->getTemplate(); $location = $test->getLocation(); $tester = $test->getTester(); $values = $test->getValues(true); $location_address = $location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]); $fee = floatval($test->test_fee) > 0 ? $test->test_fee : $project->default_tester_fee; $fee = (float) $fee; $play_spent = (float) ($values["play_spent"] ?? 0); $travel_cost = (float) http::value("travel_cost", "float"); $invoice_total = $fee + $play_spent + $travel_cost; $test->test_travel_cost = $travel_cost; $test->commit(); $address = $tester->getInvoiceAddress(); if(!$address) throw new Exception("Invoice address not found. Please set an address as the invoice address then try again."); if(!$tester->hasValidPaymentMethod()) throw new Exception("No valid payment method found. Please go to the Settings page and make sure all respective fields are filled in and then try again."); $address_parts = array_filter([ $address->address_1, $address->address_2, $address->city, $address->county, $address->postal_code, ]); $bill_to_address_parts = [ "8 Market Street", "Liskeard", "Cornwall", "PL14 3JJ", ]; $reference = "T" . str_pad($test->id, 3, "0", STR_PAD_LEFT) . "/L" . str_pad($location->id, 3, "0", STR_PAD_LEFT) . "/U" . str_pad($tester->id, 3, "0", STR_PAD_LEFT); list($date_start, $time_start) = explode(" ", $test->dts_start); list($date_end, $time_end) = explode(" ", $test->dts_end); $dt_start = new DateTime($test->dts_start); $dt_end = new DateTime($test->dts_end); $diff = $dt_start->diff($dt_end, true); $date_start = date("d/m/Y", strtotime($test->dts_start)); $tiny_font_size = 8; $small_font_size = 10; $normal_font_size = 10; $header_font_size = 14; $cell_height = 5; $cell_margin = 2; // A4 size: 210x297mm $mpdf = new Mpdf(); $mpdf->SetSubject("Test Invoice"); $mpdf->SetCreator(APP_NAME); $mpdf->SetAuthor(APP_NAME); $mpdf->SetTitle("Invoice ({$reference})"); $mpdf->useSubstitutions = true; ob_start(); ?>
| Date: | =date("d/m/Y")?> |
| Due Date: | =date("d/m/Y", time() + 2592000)?> |
| Balance Due: | £=number_format($invoice_total, 2)?> |
| Item | Quantity | Rate | Amount |
|
=htmlspecialchars($template->name)?> Test =nl2br(htmlspecialchars("$location_address\n" . date("d/m/Y H:i", strtotime($test->dts_start . " UTC"))))?> |
1 | £=number_format($fee, 2)?> | £=number_format($fee, 2)?> |
| Play Costs | 1 | £=number_format($play_spent, 2)?> | £=number_format($play_spent, 2)?> |
| Travel Costs | 1 | £=number_format($travel_cost, 2)?> | £=number_format($travel_cost, 2)?> |
| Total: | £=number_format($invoice_total, 2)?> | ||