<?php

if (!array_key_exists('id', $_GET)) {
    die("Couldn't find invoice ID");
}
$invoiceId = $_GET['id'];
$close = array_key_exists('close', $_GET) ? (bool) $_GET['close'] : true;
require_once 'API/DBase.php';
$db = new DBase();
$sql = "SELECT CAST(inv.created AS Date) as 'invoiceDate', inv.id as 'invoiceId', inv.bankDetails, cust.firstname, cust.lastname, cust.address, cust.city, cust.state, cust.postcode, c.make, c.model, c.registration FROM invoice inv INNER JOIN service serv ON (serv.id = inv.service) INNER JOIN customer cust ON (cust.id = serv.owner) INNER JOIN car c ON (serv.car = c.id) WHERE inv.id = " . $db->escape($invoiceId);
$invoice = $db->fetchOne($sql);
$invoice['invoiceDate'] = DateTime::createFromFormat('Y-m-d', $invoice['invoiceDate']);
$invoice['invoiceDate'] = $invoice['invoiceDate']->format("j F Y");
$sql = "SELECT det.*, (det.cost * det.quantity) AS total FROM detail det WHERE det.invoice = " . $db->escape($invoiceId);
$invoiceDetails = $db->fetchAll($sql);
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Invoice - Sharpie's Auto Services</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" media="all" href="css/invoice.css">
    <link rel="icon" type="image/png" href="images/favicon.png">
  </head>
  <body>
    <table>
      <tr>
<?php

if (!array_key_exists('id', $_GET)) {
    die("Couldn't find safety check ID");
}
$safetyCheckId = $_GET['id'];
require_once 'API/DBase.php';
$db = new DBase();
$sql = "select c.firstname, c.lastname, c.address, c.city, c.state, c.postcode, cast(sc.created as date) as created, ca.make, ca.registration, s.odo from safetycheck sc INNER JOIN service s ON (sc.id = s.safetyCheck) INNER JOIN customer c ON (s.owner = c.id) INNER JOIN car ca ON (s.car = ca.id) where sc.id = " . $db->escape($safetyCheckId);
$check = $db->fetchOne($sql);
$check['created'] = DateTime::createFromFormat('Y-m-d', $check['created']);
$check['created'] = $check['created']->format("d/m/Y");
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Customer - Sharpie's Auto Services</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" media="all" href="css/safetycheck.css">
    <link rel="icon" type="image/png" href="images/favicon.png">
  </head>
  <body>
    <table>
      <tr>
        <td class="logo">
          <img src="images/logo.png" />
          <div class="safetyCheckNumber">