<?php
include("db.php");
$connect = $conn;
require("library/fpdf.php");

$pdf = new FPDF('p', 'mm', 'A3');
$pdf ->AddPage();
$pdf-> SetFont('Arial', 'B', 11);
if(isset($_POST['filter'])){
  $start = $_POST['start'] ?? '';
  $end = $_POST['end'] ?? '';
  $car = $_POST['car'] ?? '';
$result = mysqli_query($connect, "SELECT * FROM trips WHERE car='$car' ORDER BY id DESC ");
$get = mysqli_fetch_array($result);
$pdf->cell(40, 10, $get['car'] ?? $car, 0, 0, 'C');
$pdf->cell(40, 10, "Date", 1, 0, 'C');
$pdf->cell(40, 10, "Client", 1, 0, 'C');
$pdf->cell(45, 10, "Job/Employee Number", 1, 0, 'C');
$pdf->cell(30, 10, "Start Mileage", 1, 0, 'C');
$pdf->cell(30, 10, "End Mileage", 1, 0, 'C');
$pdf->cell(30, 10, "Fueling", 1, 0, 'C');
$pdf->cell(30, 10, "Total", 1, 1, 'C');



$pdf->SetFont('Arial', '', 11);
while($row = mysqli_fetch_array($result)){
  $mileage = $row['end_mileage'] - $row['start_mileage'];
$pdf->cell(40,10, '',0,0,'C');
$pdf->cell(40,10, $row['date'],1,0,'C');
$pdf->cell(40,10, $row['client'], 1, 0, 'C');
$pdf->cell(45,10, $row['job'], 1, 0, 'C');
$pdf->cell(30,10, $row['start_mileage'], 1, 0, 'C');
$pdf->cell(30,10, $row['end_mileage'], 1, 0, 'C');
$pdf->cell(30,10, $row['station_mileage'], 1, 0, 'C');
$pdf->cell(30,10, $mileage , 1, 1, 'C');
}}

$pdf->OutPut();
