<?php
header('Content-Type: application/json');
include 'db/db_connect.php';
$routefk = $_REQUEST['routefk'];
$companyfk = $_REQUEST['companyfk'];
$query = mysqli_query($con, "SELECT j.journeyid,j.routefkid,j.companyfk,j.stationid,j.origin,j.destination,j.fair,j.journey_date,j.bus_number_plate,j.seat_number,COUNT(t.ticketid) AS sold_tickets
FROM journey_tb j
JOIN ticket_transactions_tb t  ON  j.journeyid = t.journeyid AND j.routefkid = t.routefk AND j.companyfk = t.companyfk
WHERE t.routefk = '$routefk' And j.companyfk = '$companyfk'
GROUP BY j.journeyid");
$data = array();
$qry_array = array();
$i = 0;
$total = mysqli_num_rows($query);
while ($row = mysqli_fetch_array($query)) {
  $data['journeyid'] = $row['journeyid'];
  $data['routefkid'] = $row['routefkid'];
  $data['companyfk'] = $row['companyfk'];
  $data['origin'] = $row['origin'];
  $data['destination'] = $row['destination'];
  $data['fair'] = $row['fair'];
  $data['journey_date'] = $row['journey_date'];
  $data['bus_number_plate'] = $row['bus_number_plate'];
  $data['seat_number'] = $row['seat_number'];
  $data['sold_tickets'] = $row['sold_tickets'];
  $qry_array[$i] = $data;
  $i++;
}

if($query){
  $response['success'] = 'true';
  $response['message'] = 'Data Loaded Successfully';
  $response['total'] = $total;
  $response['data'] = $qry_array;
}else{
  $response['success'] = 'false';
  $response['message'] = 'Data Loading Failed';
}

echo json_encode($response);



?>
