dts_finished) throw new Exception(__("An invoice cannot be generated for this project as it has not been marked as finished.")); if(!Core::$user->canAdmin()) throw new Exception(__("You do not have permission to access this resource.")); $customer = $project->getCustomer(); $template = $project->getTemplate(); $invoice_fields = $template->getCustomerInvoiceFields(); // Calculation $default_customer_fee = $project->default_customer_fee; $tests = $project->getTests(); $invoice_field_totals = []; $test_fee_invoice_counts = []; $test_costs = 0; foreach($tests as $test) { $values = $test->getValues(true); $fee = $test->customer_fee ?? $default_customer_fee; $test_costs += $fee; $count = $test_fee_invoice_counts[$fee] ?? 0; ++$count; $test_fee_invoice_counts[$fee] = $count; foreach($invoice_fields as $field) { if(!isset($invoice_field_totals[$field->name])) { $invoice_field_totals[$field->name] = 0; } $invoice_field_totals[$field->name] += (float) ($values[$field->name] ?? 0); } } $total_ex_vat = $test_costs; $vat = round($total_ex_vat * 0.20, 2); $total_inc_vat = $total_ex_vat + $vat; // Processing usort($tests, function($a, $b) { return $a->dts_start <=> $b->dts_start; }); Location::load(array_column($tests, "location_id")); Template::load(array_column($tests, "template_id")); // Filename $reference = "P" . str_pad($project->id, 3, "0", STR_PAD_LEFT) . "/C" . str_pad($customer->id, 3, "0", STR_PAD_LEFT); $download_filename = str_replace("/", "_", $reference) . " - " . $project->name . " - Invoice.pdf"; // Initialise for PDF generation $bill_to_address_parts = array_filter([ $customer->address_1, $customer->address_2, $customer->city, implode(", ", array_filter([$customer->county, $customer->postal_code])), ]); $bill_from_address_parts = explode("\n", ADDRESS); // A4 size: 210x297mm $mpdf = new Mpdf(); $mpdf->SetSubject("Project 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() + (30 * 86400))?> |
| Balance Due: | £=number_format($total_inc_vat, 2)?> |
| Item | Quantity | Rate | Amount |
|
=htmlspecialchars($location->name)?> =nl2br(htmlspecialchars("{$location_address}\n" . date("d/m/Y H:i", strtotime($test->dts_start . " UTC"))))?> |
1 | £=number_format($default_customer_fee, 2)?> | £=number_format($default_customer_fee, 2)?> |
| =htmlspecialchars($template->name)?> Testing | =number_format($count)?> | £=number_format($fee, 2)?> | £=number_format($fee * $count, 2)?> |
| =htmlspecialchars($field->label)?> | - | - | £=number_format($total, 2)?> |
| Total | £=number_format($total_ex_vat, 2)?> | ||
| VAT @ 20% | £=number_format($vat, 2)?> | ||
| Total (inc. VAT) | £=number_format($total_inc_vat, 2)?> | ||
Payment is due within 30 days.
If you have any questions concerning this invoice, contact: =htmlspecialchars(INVOICE_CONTACT_EMAIL)?>
THANK YOU FOR YOUR BUSINESS!
VAT Number: =htmlspecialchars(INVOICE_VAT_NUMBER)?>