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(); ?>
<?=htmlspecialchars(COMPANY_NAME)?>

INVOICE


Tel:

Bill To:
name)?>
invoice_contact_name)?>

phone) { ?> Tel: phone)?>
email) { ?> Email: email)?>
Ref:
Name: name)?>

Date:
Due Date:
Balance Due: £

getLocation(); $location_address = $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]); ?> $count) { ?> name] ?? 0; if(!$total) continue; ?>
Item Quantity Rate Amount
name)?>
dts_start . " UTC"))))?>
1 £ £
name)?> Testing £ £
label)?> - - £
Total £
VAT @ 20% £
Total (inc. VAT) £

Pay To:


Account Number:
Sort Code:

Payment is due within 30 days.

If you have any questions concerning this invoice, contact:

THANK YOU FOR YOUR BUSINESS!

VAT Number:

WriteHTML($html); // Output to browser $mpdf->Output($download_filename, "D");