Просмотр исходного кода

Added support for generating invoices to Check Policy.

Alan Lam 8 лет назад
Родитель
Сommit
3789312259
7 измененных файлов с 696 добавлено и 108 удалено
  1. 35 0
      controllers/addresses.php
  2. 518 0
      controllers/test_invoice.php
  3. 26 3
      engine/user.php
  4. 1 1
      engine/user_address.php
  5. 1 0
      routes.php
  6. 23 5
      views/addresses.php
  7. 92 99
      views/test_list_completed.php

+ 35 - 0
controllers/addresses.php

@@ -5,6 +5,41 @@ $page_title = "Addresses";
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account/addresses", $page_title);
 Core::addBreadcrumb("/account/addresses", $page_title);
 
 
+$submit = http::value("submit");
+if($submit) {
+	try {
+		Core::validateCSRFToken($submit);
+
+		$invoice = http::value("invoice", "int");
+
+		// Unset existing invoice address
+		$address = UserAddress::queryOne([
+			"user_id" => Core::$user->id,
+			"invoice" => 1,
+		]);
+		if($address) {
+			$address->invoice = 0;
+			$address->commit();
+		}
+
+		$address = UserAddress::queryOne([
+			"id" => $invoice,
+			"user_id" => Core::$user->id,
+		]);
+
+		if(!$address) throw new Exception("Address not found.");
+
+		$address->invoice = 1;
+		$success = $address->commit();
+
+		Core::addAlert("success", "Address set as invoice address successfully.");
+		HTTP::redirect("/account/addresses");
+	}
+	catch(Exception $e) {
+		Core::addAlert("danger", $e->getMessage());
+	}
+}
+
 $user = Core::$user;
 $user = Core::$user;
 $addresses = $user->getAddresses();
 $addresses = $user->getAddresses();
 
 

+ 518 - 0
controllers/test_invoice.php

@@ -0,0 +1,518 @@
+<?php
+
+$test = Test::get($id);
+if(!$test) throw new Exception("Test not found.");
+if($test->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();
+$location = $test->getLocation();
+$tester = $test->getTester();
+
+$location_address = $location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
+
+$fee = !empty($test->test_fee) ? $test->test_fee : $project->default_tester_fee;
+
+$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,
+]);
+
+$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);
+
+
+$tiny_font_size = 8;
+$small_font_size = 10;
+$normal_font_size = 10;
+$header_font_size = 14;
+
+$cell_height = 5;
+$cell_margin = 2;
+
+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));
+
+// A4 size: 210x297mm
+
+// Full Width = 210 - 20 = 190
+// Half Width = (210 - 20 - 10) / 2 = 90
+// Column 1 x = 10
+// Column 2 x = 110
+
+$pdf = new TestPDF("P", "mm", "A4");
+
+$pdf->SetSubject("Test Invoice");
+$pdf->SetCreator(APP_NAME);
+$pdf->SetAuthor(APP_NAME);
+$pdf->SetTitle("Invoice ($reference)");
+
+$pdf->AddPage();
+$pdf->SetFont("Arial");
+$pdf->SetDrawColor(240, 240, 240);
+$pdf->SetFillColor(240);
+$pdf->SetAutoPageBreak(false);
+
+// Right title
+$pdf->SetLeftMargin(110);
+$pdf->SetFont("Arial", "", 30);
+$pdf->MultiCell(90, 8, "INVOICE", 0, "R");
+$pdf->SetFontSize($normal_font_size);
+$pdf->MultiCell(90, 8, "Ref: $reference", 0, "R");
+
+$pdf->MoveY(8);
+
+$pdf->SetTextColor(128);
+$pdf->Cell(45, 8, "Date:", 0, 0, "R");
+$pdf->SetTextColor(0);
+$pdf->Cell(45, 8, date("d/m/Y"), 0, 1, "R");
+
+$pdf->SetTextColor(128);
+$pdf->Cell(45, 8, "Due Date:", 0, 0, "R");
+$pdf->SetTextColor(0);
+$pdf->Cell(45, 8, date("d/m/Y", time() + 864000), 0, 1, "R");
+
+$pdf->Rect(110, $pdf->GetY(), 90, 8, "F");
+$pdf->Cell(45, 8, "Balance Due:", 0, 0, "R");
+$pdf->SetTextColor(0);
+$pdf->Cell(45, 8, utf8_decode("£") . number_format($fee, 2), 0, 1, "R");
+
+// Left addresses
+$pdf->SetXY(10, 10);
+$pdf->SetLeftMargin(10);
+$pdf->SetTextColor(0);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(90, 4, $tester->getDisplayName(), 0, 1);
+
+$pdf->SetFont("Arial");
+$pdf->MultiCell(90, 4, implode("\n", $address_parts));
+
+$pdf->MoveY(8);
+
+$pdf->SetTextColor(128);
+$pdf->Cell(90, 4, "Bill To:", 0, 1);
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+$pdf->Cell(90, 4, APP_NAME, 0, 1);
+$pdf->SetFont("Arial");
+$pdf->MultiCell(90, 4, implode("\n", ["8 Market Street", "Liskeard", "Cornwall", "PL14 3JJ"]));
+
+// Header
+$pdf->MoveY(8);
+
+$pdf->SetFillColor(64);
+$pdf->Rect(10, $pdf->GetY(), 190, 8, "F");
+
+$pdf->SetTextColor(255);
+$pdf->Cell(115, 8, "Item");
+$pdf->Cell(15, 8, "Quantity");
+$pdf->Cell(30, 8, "Rate", 0, 0, "R");
+$pdf->Cell(30, 8, "Amount", 0, 0, "R");
+$pdf->MoveY(10);
+
+// Item
+
+$pdf->SetTextColor(0);
+$pdf->SetFont("Arial", "", $normal_font_size);
+
+$y = $pdf->GetY();
+$pdf->MultiCell(115, 5, "Age Verification Test\n$location_address\n" . date("d/m/Y H:i", strtotime($test->dts_start . " UTC")), 0, "L");
+$next_y = $pdf->GetY();
+$pdf->SetXY(125, $y);
+$pdf->Cell(15, 5, 1, 0, 0, "R");
+$pdf->Cell(30, 5, utf8_decode("£") . number_format($fee, 2), 0, 0, "R");
+$pdf->Cell(30, 5, utf8_decode("£") . number_format($fee, 2), 0, 0, "R");
+$pdf->SetXY(10, $next_y);
+
+$pdf->MoveY(10);
+
+$pdf->SetTextColor(128);
+$pdf->Cell(150, 5, "Total:", 0, 0, "R");
+$pdf->SetTextColor(0);
+$pdf->Cell(40, 5, utf8_decode("£") . number_format($fee, 2), 0, 1, "R");
+
+$pdf->MoveY(10);
+
+$pdf->SetTextColor(128);
+$pdf->MultiCell(190, 6, "Pay To:");
+$pdf->SetTextColor(0);
+$pdf->MultiCell(190, 6, $tester->getDisplayName());
+switch($tester->preferred_payment_method) {
+	case User::PAYMENT_METHOD_BANK_TRANSFER: {
+		$pdf->SetFont("Arial", "B");
+		$pdf->MultiCell(190, 6, "Bank Transfer");
+		$pdf->SetFont("Arial");
+		$pdf->MultiCell(190, 6, "Bank Name: $tester->bank_name");
+		$pdf->MultiCell(190, 6, "Sort Code: $tester->bank_sort_code");
+		$pdf->MultiCell(190, 6, "Account Number: $tester->bank_account_number");
+		break;
+	}
+
+	case User::PAYMENT_METHOD_PAYPAL: {
+		$pdf->SetFont("Arial", "B");
+		$pdf->MultiCell(190, 6, "PayPal");
+		$pdf->SetFont("Arial");
+		$pdf->MultiCell(190, 6, "PayPal Address: $tester->paypal_email");
+		break;
+	}
+}
+
+$pdf->MoveY(10);
+
+$pdf->SetTextColor(128);
+$pdf->MultiCell(190, 6, "Contact Info:");
+$pdf->SetTextColor(0);
+$pdf->MultiCell(190, 6, "Email: $tester->email");
+$pdf->MultiCell(190, 6, "Phone: $tester->phone");
+
+/*
+// Left contact info
+$y = 10;
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->SetTextColor(255, 0, 0);
+
+$pdf->SetLeftMargin(120);
+$pdf->SetY(10);
+
+$pdf->Cell(80, 4, "Test / Location ID: $test->id / $location->id", 0, 1, "R");
+
+$pdf->SetFont("Arial", "");
+$pdf->SetTextColor(0, 0, 0);
+
+
+$pdf->Cell(80, 4, "Tel: 01579 342 104", 0, 1, "R", false, "tel:01579+342+104");
+
+$pdf->SetFont("Arial", "U");
+$pdf->SetTextColor(0, 128, 255);
+
+$pdf->Cell(80, 4, "check-policy.com", 0, 1, "R", false, "https://check-policy.com");
+$pdf->Cell(80, 4, "info@check-policy.com", 0, 1, "R");
+
+$pdf->SetLeftMargin(10);
+$pdf->SetXY(10, $pdf->GetY() + $cell_margin);
+
+// Header
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+$pdf->Cell(190, 10, " Test Result", 0, 1, "L", true);
+
+// Pass/Fail
+$image_width = 130;
+
+if($test->pass) {
+	$pdf->Image("public/img/pass.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
+}
+else {
+	$pdf->Image("public/img/fail.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
+}
+
+$pdf->SetY($pdf->GetY() + 30);
+
+$pdf->SetTextColor(56, 87, 35);
+
+// Location / Tester Headers
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$tester_x = 150;
+$tester_y = $pdf->GetY();
+
+$header = " $location->name";
+if($location->internal_id) {
+	$header .= " (ID: $location->internal_id)";
+}
+
+$pdf->Cell(135, 10, $header, 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Region / Manager:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Write($cell_height, $location->region);
+$pdf->Write($cell_height, "/ ");
+$pdf->Write($cell_height, $location->area_manager);
+$pdf->SetY($pdf->GetY() + $cell_height);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Address:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->MultiCell(100, $cell_height, $location->getDisplayAddress(["address_1", "address_2", "city"], "\n"), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Postcode:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Left:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_left, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$test_details_y = $pdf->GetY();
+
+// Tester Info
+$pdf->SetXY($tester_x, $tester_y);
+$pdf->SetLeftMargin(150);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(50, 10, " Tester", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+$pdf->Cell(20, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+$pdf->Cell(20, $cell_height, "Attire:", 0, 1);
+$pdf->SetX(150);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(50, 4, $test->attire, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+
+// Test Details
+$pdf->SetLeftMargin(10);
+
+$pdf->setXY(10, $test_details_y + 5 + 2);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(190, 10, " Test Details", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Date / Time
+$id_requests_y = $pdf->GetY();
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Cell(95, $cell_height, "Date & Time", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$pdf->Cell(23, $cell_height, "Date");
+$pdf->Cell(23, $cell_height, "Entry");
+$pdf->Cell(23, $cell_height, "Exit");
+$pdf->Cell(23, $cell_height, "Duration", 0, 1);
+
+$pdf->SetFont("Arial", "", $small_font_size);
+
+$pdf->Cell(23, $cell_height, $date_start);
+$pdf->Cell(23, $cell_height, $time_start);
+$pdf->Cell(23, $cell_height, $time_end);
+$pdf->Cell(23, $cell_height, str_pad($diff->h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->i, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->s, 2, "0", STR_PAD_LEFT), 0, 1);
+
+$pdf->SetY($pdf->GetY() + 2);
+
+// Staff
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Staff", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Name:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $test->challenger_name, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $test->challenger_gender, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Description:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->challenger_description, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->additional_notes, 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Challenge
+$pdf->SetLeftMargin(107.5);
+$pdf->SetY($id_requests_y);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "ID Request", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Result:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->getPassText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "ID Stage:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->challenge_stage . " - " . $test->getChallengeStageText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->SetTextColor(0, 128, 0);
+$pdf->MultiCell(95, 4, "1: Challenge on entry", 0, 1);
+
+$pdf->SetTextColor(255, 128, 0);
+$pdf->MultiCell(95, 4, "2: Challenge while browsing
+3: Challenge during play", 0, 1);
+
+$pdf->SetTextColor(255, 0, 0);
+
+$pdf->MultiCell(95, 4, "4: Challenge on exit
+5: No challenge", 0, 1);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Eye Contact:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->challenger_eye_contact ? "Y" : "N", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(95, $cell_height, "Description:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->challenge_description, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->SetY($pdf->GetY() + 2);
+
+// Details / Signage
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Play Details & Signage", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$field_width = 50;
+$value_width = 40;
+
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Machine Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["play_machine"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_jackpot"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value);
+
+$pdf->Cell($field_width, $cell_height, "Jackpot Value:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_machine_stake"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value, 2);
+
+$pdf->Cell($field_width, $cell_height, "Stake Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Minutes Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["play_minutes"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_spent"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value, 2);
+
+$pdf->Cell($field_width, $cell_height, "Amount Spent:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["think_21_25"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["citizen_card_brochure_displayed"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Citizen Card Brochure Displayed:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["think_21_badge"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Badge Worn by Staff:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["think_21_poster"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Posters Displayed:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Poster Notes:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(95, 4, $values["think_21_poster_notes"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+*/
+
+
+// Output
+
+$pdf->Output();
+
+?>

+ 26 - 3
engine/user.php

@@ -6,9 +6,6 @@ class User extends Model {
 	protected static $id_field = "id";
 	protected static $id_field = "id";
 	protected static $fillable_fields = ["email", "old_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "phone", "verify_token", "reset_token", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "verifier_id", "verifier_notes"];
 	protected static $fillable_fields = ["email", "old_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "phone", "verify_token", "reset_token", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "verifier_id", "verifier_notes"];
 
 
-	protected static $field_map = [
-	];
-
 	// Constants
 	// Constants
 
 
 	const TITLES = ["Miss", "Mr", "Ms", "Dr"];
 	const TITLES = ["Miss", "Mr", "Ms", "Dr"];
@@ -36,6 +33,9 @@ class User extends Model {
 		128 => "Super Admin",
 		128 => "Super Admin",
 	];
 	];
 
 
+	const PAYMENT_METHOD_BANK_TRANSFER = 1;
+	const PAYMENT_METHOD_PAYPAL = 2;
+
 	const PAYMENT_METHODS = [
 	const PAYMENT_METHODS = [
 		1 => "Bank Transfer",
 		1 => "Bank Transfer",
 		2 => "PayPal",
 		2 => "PayPal",
@@ -53,6 +53,22 @@ class User extends Model {
 	}
 	}
 
 
 	// Object methods
 	// Object methods
+	public function hasValidPaymentMethod() {
+		switch($this->preferred_payment_method) {
+			case User::PAYMENT_METHOD_BANK_TRANSFER: {
+				if(empty($this->bank_name)) return false;
+				if(empty($this->bank_sort_code)) return false;
+				if(empty($this->bank_account_number)) return false;
+				break;
+			}
+			case User::PAYMENT_METHOD_PAYPAL: {
+				if(empty($this->paypal_email)) return false;
+				break;
+			}
+		}
+		return true;
+	}
+
 	public function sendActivationEmail() {
 	public function sendActivationEmail() {
 
 
 		$this->verify_token = bin2hex(random_bytes(16));
 		$this->verify_token = bin2hex(random_bytes(16));
@@ -251,6 +267,13 @@ class User extends Model {
 		return $addresses;
 		return $addresses;
 	}
 	}
 
 
+	public function getInvoiceAddress() {
+		return UserAddress::queryOne([
+			"user_id" => $this->id,
+			"invoice" => 1
+		]);
+	}
+
 	public function getCustomers() {
 	public function getCustomers() {
 
 
 		if($this->level >= User::LEVEL_ADMIN) {
 		if($this->level >= User::LEVEL_ADMIN) {

+ 1 - 1
engine/user_address.php

@@ -4,7 +4,7 @@ class UserAddress extends Model {
 
 
 	protected static $table = "user_address";
 	protected static $table = "user_address";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["user_id", "name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "latitude", "longitude", "max_radius_miles"];
+	protected static $fillable_fields = ["user_id", "name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "latitude", "longitude", "max_radius_miles", "invoice"];
 
 
 	protected static $field_map = [
 	protected static $field_map = [
 	];
 	];

+ 1 - 0
routes.php

@@ -65,6 +65,7 @@ $routes = [
 	"/^account\/tests\/$id_pattern\/result$/" => ["controller" => "test_result", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/result$/" => ["controller" => "test_result", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/pdf$/" => ["controller" => "test_pdf", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/pdf$/" => ["controller" => "test_pdf", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/(accept|decline)$/" => ["controller" => "test_confirm", "params" => ["id", "action"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern\/(accept|decline)$/" => ["controller" => "test_confirm", "params" => ["id", "action"], "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/tests\/$id_pattern\/invoice$/" => ["controller" => "test_invoice", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
 
 
 	// Templates
 	// Templates
 	"/^account\/templates$/" => ["controller" => "templates", "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/templates$/" => ["controller" => "templates", "require_user_level" => User::LEVEL_CUSTOMER],

+ 23 - 5
views/addresses.php

@@ -11,26 +11,44 @@
 	}
 	}
 	?>
 	?>
 
 
+	<form method="post">
+		<input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
 	<?php
 	<?php
 	foreach($addresses as $address) {
 	foreach($addresses as $address) {
 		?>
 		?>
 		<div class="card mb-3">
 		<div class="card mb-3">
 			<div class="card-body">
 			<div class="card-body">
 				<div class="row">
 				<div class="row">
-					<div class="col">
+					<div class="col-md mb-1 mb-md-0 align-self-center">
 						<strong><?=htmlspecialchars($address->name)?></strong>
 						<strong><?=htmlspecialchars($address->name)?></strong>
+						<?php
+						if($address->invoice) {
+							?>
+							<span class="badge badge-primary">Invoice</span>
+							<?php
+						}
+						?>
+						<br />
+						<small><?=htmlspecialchars($address->getDisplayAddress())?></small>
 					</div>
 					</div>
-					<div class="col-auto">
-						<a href="/account/addresses/edit/<?=$address->id?>">Edit</a>
+					<div class="col-md-auto align-self-center">
+						<?php
+						if(!$address->invoice) {
+							?>
+							<button type="submit" class="btn btn-outline-info" name="invoice" value="<?=$address->id?>">Set as Invoice Address</button>
+							<?php
+						}
+						?>
+
+						<a class="btn btn-outline-primary" href="/account/addresses/edit/<?=$address->id?>">Edit</a>
 					</div>
 					</div>
 				</div>
 				</div>
-				<hr />
-				<?=htmlspecialchars($address->getDisplayAddress())?>
 			</div>
 			</div>
 		</div>
 		</div>
 		<?php
 		<?php
 	}
 	}
 	?>
 	?>
+	</form>
 
 
 	<a class="btn btn-primary" href="/account/addresses/add">Add</a>
 	<a class="btn btn-primary" href="/account/addresses/add">Add</a>
 
 

+ 92 - 99
views/test_list_completed.php

@@ -25,108 +25,101 @@
 			</div>
 			</div>
 		</div>
 		</div>
 
 
-		<table class="table table-sm table-hover">
-			<thead>
-				<tr>
-					<th class="text-right">ID</th>
-					<th>Location</th>
-					<th>Attire</th>
-					<th>Selfie</th>
-					<th>Date</th>
-					<th>Time</th>
-					<th>Duration</th>
-					<th>Status</th>
-					<th>Fee</th>
-				</tr>
-			</thead>
-			<tbody>
-			<?php
+		<div class="list-group">
+		<?php
+
+		$original_timezone = date_default_timezone_get();
+
+		foreach($tests as $test) {
+			$location = $test->getLocation();
+			$project = $test->getProject();
+
+			$attire = $date_start = $time_start = $duration = "N/A";
+			$attire_class = $date_start_class = $time_start_class = $duration_class = $fee_class = "text-muted";
 
 
-			$original_timezone = date_default_timezone_get();
-
-			foreach($tests as $test) {
-				$location = $test->getLocation();
-				$project = $test->getProject();
-
-				$attire = $date_start = $time_start = $duration = "N/A";
-				$attire_class = $date_start_class = $time_start_class = $duration_class = $fee_class = "text-muted";
-
-				date_default_timezone_set("UTC");
-				if($test->dts_start) {
-					$start_dt = new DateTime($test->dts_start);
-					$date_start = $start_dt->format("d/m/Y");
-					$time_start = $start_dt->format("H:i:s");
-					$attire = $test->attire;
-
-					$attire_class = $date_start_class = $time_start_class = "";
-				}
-				if($test->dts_start && $test->dts_end) {
-					$end_dt = new DateTime($test->dts_end);
-					$diff = $start_dt->diff($end_dt, true);
-					$duration = $diff->format("%H:%I:%S");
-					$duration_class = "";
-
-
-
-				}
-
-				date_default_timezone_set($original_timezone);
-
-				$status_class = $test->getStatusClass();
-				$status_text = $test->getStatusText();
-
-				$status_class = "secondary";
-				$status_text = "Pending";
-
-				if($test->status == Test::STATUS_CANCELLED) {
-					$status_class = "danger";
-					$status_text = "Rejected";
-					$fee = "N/A";
-				}
-				if($test->status == Test::STATUS_COMPLETED) {
-					$status_class = "success";
-					$status_text = "Accepted";
-					$fee = $test->fee ? $test->fee : $project->default_tester_fee;
-					$fee = "£" . $fee;
-					$fee_class = "";
-				}
-
-				?>
-					<tr>
-						<td class="text-right">
-							<?=$test->id?>
-						</td>
-						<td>
-							<?=htmlspecialchars($location->name)?><br />
-							<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]))?></small>
-						</td>
-						<td class="<?=$attire_class?>">
-							<?=htmlspecialchars($attire)?>
-						</td>
-						<td class="align-middle">
-							<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>/selfie">View</a>
-						</td>
-						<td class="text-center align-middle <?=$date_start_class?>">
-							<?=htmlspecialchars($date_start)?>
-						</td>
-						<td class="text-center align-middle <?=$time_start_class?>">
-							<?=htmlspecialchars($time_start)?>
-						</td>
-						<td class="text-center align-middle <?=$duration_class?>">
-							<?=htmlspecialchars($duration)?>
-						</td>
-						<td class="text-center align-middle">
-							<span class="badge badge-lg badge-<?=$status_class?>"><?=htmlspecialchars($status_text)?></span>
-						</td>
-						<td class="text-center align-middle <?=$fee_class?>">
-							<?=$fee?>
-						</td>
-					</tr>
-				<?php
+			date_default_timezone_set("UTC");
+			if($test->dts_start) {
+				$start_dt = new DateTime($test->dts_start);
+				$date_start = $start_dt->format("jS M Y");
+				$time_start = $start_dt->format("H:i:s");
+				$attire = $test->attire;
+
+				$attire_class = $date_start_class = $time_start_class = "";
+			}
+			if($test->dts_start && $test->dts_end) {
+				$end_dt = new DateTime($test->dts_end);
+				$diff = $start_dt->diff($end_dt, true);
+				$duration = $diff->format("%i min. %S sec.");
+				$duration_class = "";
 			}
 			}
+
+			date_default_timezone_set($original_timezone);
+
+			$status_class = $test->getStatusClass();
+			$status_text = $test->getStatusText();
+
+			$status_class = "secondary";
+			$status_text = "Pending";
+
+			if($test->status == Test::STATUS_CANCELLED) {
+				$status_class = "danger";
+				$status_text = "Rejected";
+				$fee = "N/A";
+			}
+			if($test->status == Test::STATUS_COMPLETED) {
+				$status_class = "success";
+				$status_text = "Accepted";
+				$fee = $test->fee ? $test->fee : $project->default_tester_fee;
+				$fee = "£" . $fee;
+				$fee_class = "";
+			}
+
 			?>
 			?>
-			</tbody>
-		</table>
+				<div class="list-group-item list-group-item-action">
+					<div class="row">
+						<div class="col-xl">
+							<div class="row">
+								<div class="col order-1 order-sm-1">
+									<strong>ID: <?=$test->id?></strong><br />
+									<a href="/account/tests/<?=$test->id?>/invoice" target="_blank">
+										<i class="fal fa-fw fa-external-link"></i> Invoice
+									</a>
+								</div>
+								<div class="col-sm order-3 order-sm-2">
+									<hr class="d-block d-sm-none" />
+									<?=htmlspecialchars($location->name)?><br />
+									<small><?=htmlspecialchars($location->getDisplayAddress(["city", "postal_code"]))?></small>
+								</div>
+								<div class="col order-2 order-sm-3 text-right text-xl-center align-self-xl-center">
+									<span class="badge badge-lg badge-<?=$status_class?>"><?=htmlspecialchars($status_text)?></span>
+								</div>
+							</div>
+							<hr class="d-none d-sm-block d-xl-none" />
+						</div>
+						<div class="col-xl align-self-xl-center">
+							<div class="row">
+								<div class="col-sm <?=$date_start_class?> align-self-xl-center">
+									<hr class="d-block d-sm-none" />
+									<strong><?=htmlspecialchars($date_start)?></strong><br />
+									<small><?=htmlspecialchars($time_start)?> / <?=htmlspecialchars($duration)?></small>
+								</div>
+								<div class="col-sm <?=$fee_class?> align-self-xl-center">
+									<hr class="d-block d-sm-none" />
+									Fee: <?=$fee?>
+								</div>
+								<div class="col-sm <?=$attire_class?> align-self-xl-center">
+									<hr class="d-block d-sm-none" />
+									<?=htmlspecialchars($attire)?><br />
+									<a href="/account/tests/<?=$test->id?>/selfie">View selfie.</a>
+								</div>
+							</div>
+						</div>
+					</div>
+				</div>
+			<?php
+		}
+		?>
+		</div>
 		<?php
 		<?php
 	}
 	}