<?php
include("config/connection.php");
include("config/session.php");

		$sql ="select tb_pemesanan_detil.*, tb_angkutan.nama as angkutan, tb_jenis_angkutan.nama as jenis_angkutan from tb_pemesanan_detil 
		inner join tb_angkutan on tb_pemesanan_detil.id_angkutan = tb_angkutan.id_angkutan 
		inner join tb_jenis_angkutan on tb_angkutan.id_jenis_angkutan = tb_jenis_angkutan.id_jenis_angkutan 
		where id_pemesanan = '".$_GET['id_pemesanan']."'";
		$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
		mysql_close($test);
		
		while($row = mysql_fetch_object($hasil)){
				
			$id_detil = $row->id_detil;
			$jadwal = $row->jadwal;
			$nama = $row->nama;
			$no_identitas = $row->no_identitas;
			$harga = $row->harga;
			$tanggal = $row->tanggal;
			$id_angkutan = $row->id_angkutan;
						
						
$id_operator = $_SESSION['id'];
$act = 1;
$id_jadwal = $jadwal;
if($id_jadwal == '1'){
	$id_jadwal = $_SESSION["jadwalpagi"];
}else{
	$id_jadwal = $_SESSION["jadwalsore"];
}

//BUAT NO TIKET
	include("config/connection.php");
	$tgl = date("Y-m-d");
	$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
	$query1 =mysql_query($sql1);
	$row = mysql_fetch_row($query1);
	$jumlah = $row[0];
	$bk=$jumlah + 1;
	$dp = date("dmy");
	$notiket = $dp.$bk;


//SIMPAN DATA
	include("config/connection.php");
	if ($act == 1){
	
		$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator) values ('".$id_jadwal."', '".$id_angkutan."', '".$harga."', '".$nama."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."')";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}
	
		include("config/connection.php");
	
		$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}
		
		
		include("config/connection.php");
	
		$sql="update tb_pemesanan set status = '2' where id_pemesanan = '".$_GET['id_pemesanan']."'";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}
		
		include("config/connection.php");
	
		$sql="update tb_pemesanan_detil set no_tiket = '".$notiket."' where id_detil = '".$id_detil."'";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}

}
?>
<script>window.location = "<?php echo $base?>tiket-booking.php?id_pemesanan=<?php echo $_GET['id_pemesanan']?>", "_blank"</script>
<?php	

		}
