<link href="<?php echo $base?>plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $base?>plugins/iCheck/all.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $base?>plugins/timepicker/bootstrap-timepicker.min.css" rel="stylesheet"/>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/timepicker/bootstrap-timepicker.min.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/iCheck/icheck.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $base?>plugins/autocomplete/shieldui-all.css" />
<link href="<?php echo $base?>bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="<?php echo $base?>bootstrap/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?php echo $base?>bootstrap/js/locales/bootstrap-datetimepicker.id.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?php echo $base?>plugins/autocomplete/shieldui-all.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
	var base = <?php echo json_encode($base);?>;
	
	$('#reset').click(function(e){
		alert("reset");
	});
	
  });
   
</script>
<script type="text/javascript">
 function hourChange(selectObj) {
   var selectIndex=selectObj.selectedIndex;
   var selectValue=selectObj.options[selectIndex].text;
	   
   if (selectIndex == 0){
		$('#penumpang').show();
		$('#kendaraan').hide();
		var e = document.getElementById("cbpenumpang");
		var str = e.options[e.selectedIndex].text;
		var harga = document.getElementById('cbpenumpang').value;
		var jmltiket = document.getElementById('jmltiket').value;
		var harga = harga * jmltiket;
		var harga1 = harga.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		$("#total").html("Rp. "+harga1);
   } else if (selectIndex == 1){
	   document.getElementById("cbkendaraan").selectedIndex = "0";
		$('#penumpang').hide();
		$('#kendaraan').show();
		var e = document.getElementById("cbkendaraan");
		var str = e.options[e.selectedIndex].text;
		var harga = document.getElementById('cbkendaraan').value;
		var jmltiket = document.getElementById('jmltiket').value;
		var harga = harga * jmltiket;
		var harga1 = harga.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		$("#total").html("Rp. "+harga1);
   }	
 }
</script>
<script type="text/javascript">
 function hourChange2(selectObj) {
		var harga = document.getElementById('cbpenumpang').value;
		var jmltiket = document.getElementById('jmltiket').value;
		var harga = harga * jmltiket;
		var harga1 = harga.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		$("#total").html("Rp. "+harga1);
 }
</script>
<script type="text/javascript">
 function hourChange3(selectObj) {
		var harga = document.getElementById('cbkendaraan').value;
		var jmltiket = document.getElementById('jmltiket').value;
		var harga = harga * jmltiket;
		var harga1 = harga.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		$("#total").html("Rp. "+harga1);
 }
</script>
<script type="text/javascript">
 function totalan() {
   
 }
</script>
<script type="text/javascript">
 function hourChangejml(selectObj) {
		var jenisangkutan = document.getElementById('jenisangkutan').value;
		if(jenisangkutan == 2){
			var harga = document.getElementById('cbkendaraan').value;
		}else{
			var harga = document.getElementById('cbpenumpang').value;
		}
		var jmltiket = document.getElementById('jmltiket').value;
		var harga = harga * jmltiket;
		var harga1 = harga.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		$("#total").html("Rp. "+harga1);
 }
</script>

<aside class="right-side">                
                <section class="content-header">
                    <h1>
                        Pembelian Tiket
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="home"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="#">Tiket</a></li>
                        <li class="active">Transaksi Pembelian Tiket</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header" style="font-size:16px">
                                    <a href="<?php echo $base?>daftar-jadwal" class="btn btn-primary" style="color:#FFF; float:right; margin-right:40px;"><i class="fa fa-bars"></i> Daftar Jadwal</a>
                                </div><!-- /.box-header -->
                               <?php
								$idjadwal = $xcode;

							    	if($idjadwal==""){
	
								?> 
									<script>window.location = "<?php echo $base?>daftar-jadwal"</script>
                                <?php
                                }
				    include("config/connection.php");
              		$sql ="select tb_jadwal.*, DATE_FORMAT(tb_jadwal.tanggal,'%d-%m-%Y') as tgl, tb_kapal.Nama as namakapal, tb_nahkoda.Nahkoda, pDari.Nama as dari, pTujuan.Nama as tujuan, tb_jenis_kapal.Jenis
							from tb_jadwal inner join tb_kapal on tb_jadwal.Id_Kapal = tb_kapal.Id_Kapal
							inner join tb_nahkoda on tb_jadwal.Id_Nahkoda = tb_nahkoda.Id_Nahkoda
							inner join tb_pelabuhan pDari on (pDari.Id_Pelabuhan = tb_jadwal.Dari)
							inner join tb_pelabuhan pTujuan on (pTujuan.Id_Pelabuhan = tb_jadwal.Tujuan)
							inner join tb_jenis_kapal on tb_kapal.Id_Jenis = tb_jenis_kapal.Id
							where tb_jadwal.Status = '1' and tb_jadwal.Id_Jadwal = '".$idjadwal."'";
					$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
					mysql_close($test);
					
					$row = mysql_fetch_object($hasil);
						$id = $row->Id_Jadwal;
						$namakapal = $row->namakapal;
						$Nahkoda = $row->Nahkoda;
						$dari = $row->dari;
						$tujuan = $row->tujuan;
						$Kuota_Order = $row->Kuota_Order;
						$Sisa = $row->Sisa;
						$tanggal = $row->tgl;
						$Waktu = $row->Waktu;
						$Jenis = $row->Jenis;
						
			?>
        <div class="box-body">
        	<div class="col-sm-8">
                <form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo $base?>pemesanan-tiket-proses">
                    <input type="hidden" name="id_jadwal" value="<?php echo $idjadwal?>" id="idjadwal">
                    <input type="hidden" name="act" value="1">
                    <div  style="min-height:30px;">
								<?php  
                                    include("config/connection.php");
                                    $sql ="select tb_angkutan.*, tb_detil_angkutan_def.harga from tb_angkutan inner join tb_detil_angkutan_def on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan where tb_angkutan.id_jenis_angkutan = 1 and tb_angkutan.id_angkutan = 1 ";
                                    $hasil = mysql_query($sql) or die("Kesalahan Pada SQLs");
                                    mysql_close($test);
                                    
                                    $row = mysql_fetch_object($hasil);
										$harga = $row->harga;
                                ?>

                        <h2 class="modal-title" id="myModalLabel" style="float:right">
                            <div id="total" style="font-size:40px">
                            	Rp. <?php echo number_format($harga);?>
                            </div>
                        </h2>
                    </div>
                    <div class="modal-body" >
                        <div class="form-group">
                        	<label for="Operator" class="control-label" >Jumlah Tiket</label>
                            <select name="jumlahtiket" class="form-control" style="height:45px" id="jmltiket" onchange="hourChangejml(this);">
                            	<option value="1" selected="selected">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="Operator" class="control-label" >Jenis Angkutan</label>
                            <select name="jenisangkutan" class="form-control" onchange="hourChange(this);" id="jenisangkutan" style="height:45px">
								<?php  
                                    include("config/connection.php");
                                    $sql ="select * from tb_jenis_angkutan ";
                                    $hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
                                    mysql_close($test);
                                    
                                    while($row = mysql_fetch_object($hasil)){
                                        $id_jenis_angkutan = $row->id_jenis_angkutan;
                                        $namajenis = $row->nama;
                                ?>
                                <option value="<?php echo $id_jenis_angkutan?>"><?php echo $namajenis?></option>
                                <?php } ?>
                            </select>
                         </div>
                        <div class="form-group" id="penumpang" style="border-bottom:#CCC solid thin; padding-bottom:30px;">
                            <label for="Operator" class="control-label" >Penumpang</label>
                            <select name="penumpang" class="form-control" onChange="hourChange2(this);" id="cbpenumpang" style="height:45px">
								<?php  
                                    include("config/connection.php");
                                    $sql ="select tb_angkutan.*, tb_detil_angkutan_def.harga from tb_angkutan inner join tb_detil_angkutan_def on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan where tb_angkutan.id_jenis_angkutan = 1 ";
                                    $hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
                                    mysql_close($test);
                                    
                                    while($row = mysql_fetch_object($hasil)){
                                        $id_angkutan = $row->id_angkutan;
                                        $namaangkutan = $row->nama;
										$harga = $row->harga;
                                ?>
                                <option value="<?php echo $harga?>"><?php echo $namaangkutan?></option>
                                <?php } ?>
                            </select>
                         </div>
                        <div class="form-group" id="kendaraan" style="display:none; border-bottom:#CCC solid thin; padding-bottom:30px;">
                            <label for="Operator" class="control-label">Kendaraan</label>
                            <select name="kendaraan" class="form-control" onChange="hourChange3(this);" id="cbkendaraan" style="height:45px">
								<?php  
                                    include("config/connection.php");
                                    $sql ="select tb_angkutan.*, tb_detil_angkutan_def.harga from tb_angkutan inner join tb_detil_angkutan_def on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan where tb_angkutan.id_jenis_angkutan = 2 ";
                                    $hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
                                    mysql_close($test);
                                    
                                    while($row = mysql_fetch_object($hasil)){
                                        $id_angkutan = $row->id_angkutan;
                                        $namaangkutan = $row->nama;
										$harga = $row->harga;
                                ?>
                                <option value="<?php echo $harga?>"><?php echo $namaangkutan?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="Operator" class="control-label">Nama</label>
                            <input type="text" name="nama" required="required" class="form-control" style="height:45px">
                         </div>
                        <div class="form-group">
                            <label for="Operator" class="control-label">No. Identitas (KTP/SIM/Lainnya)</label>
                            <input type="text" name="no_identitas" required="required" class="form-control" style="height:45px">
                         </div>
                        <div class="form-group">
                            <input style="height:45px" type="text" class="col-sm-7" placeholder = "0" id="bayar"  onkeyup="format_num();">
                            <input style="height:45px" type="text" class="col-sm-1" value=">>" disabled="disabled">
                            <input style="height:45px" type="text" class="col-sm-4" id="kembali" value="0" disabled="disabled">
                     	</div>
                    </div> 
<SCRIPT LANGUAGE="JavaScript">
<!--
function format_num(id) {
		var fnf = document.getElementById("bayar");
		if (isNaN(fnf)) {
			fnf.addEventListener('keyup', function(evt){
				var n = parseInt(this.value.replace(/\D/g,''),10);
				fnf.value = n.toLocaleString();
			}, false);
		}
		
			var bayar = document.getElementById("bayar").value.replace(/,/g, '');
		   	var jenisangkutan = document.getElementById('jenisangkutan').value;
			var jmltiket = document.getElementById('jmltiket').value;
				
		   if (jenisangkutan == 1){
				var harga = document.getElementById('cbpenumpang').value;
		   } else {
				var harga = document.getElementById('cbkendaraan').value;
		   }
		   if (bayar > 0){
				var susuk = parseFloat(bayar) - (parseFloat(harga)*parseFloat(jmltiket));
				document.getElementById('kembali').value = susuk.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		   }else{
				document.getElementById('kembali').value = 0;
			}

    }
//-->
</SCRIPT>
                    <div class="modal-footer">
                        <div class="form-group">  
                            <label class="col-sm-2" for="aksi"></label>      
                                <div class="col-sm-10">
                                    <button type="submit" class="btn btn-success" style="width:80px"><i class='glyphicon glyphicon-ok' style="margin-right:5px;"></i> Beli</button>
                                </div>
                        </div>
                    </div>
                </form>
                </div>
        	<div class="col-sm-4" style="border-radius: 7px ; padding-top:20px; padding-bottom:20px; ">
                <div style="background-color:#3c8dbc; border-radius: 7px 7px 0px 0px; ">
                    <div style="padding:5px;color:#FFF; text-align:center">
                        <h3><?php echo $namakapal?></h3>
                     </div>
                </div> 
                <div class="callout callout-info" style="margin-bottom:0px">
                    <h4>Tipe Kapal : <?php echo $Jenis?></h4>
                    <h4>Kuota : <?php echo $Kuota_Order?></h4>
                    <h4>Sisa : <?php echo $Sisa?></h4>
                    
                </div> 
                <div clas="modal-body" style="padding:10px; margin-bottom:-20px;">
                    <ul class="list-group">
                        <li class="list-group-item">DARI : <?php echo $dari?></li>
                        <li class="list-group-item">TUJUAN : <?php echo $tujuan?></li>
                        <li class="list-group-item">TANGGAL : <?php echo $tanggal?></li>
                        <li class="list-group-item">WAKTU : <?php echo $Waktu?> Wita</li>
                    </ul>
                </div> 
                <div class="callout callout-info" style="margin-bottom:0px; min-height:60px;">  
                    <a data-toggle="modal" href="#modalInsert" data-id='<?php echo $id?>' class="open-Edit"><button type="submit" class="btn btn-info"><i class='glyphicon glyphicon-info-sign'></i> Info Harga Tiket</button></a>
                </div>
                <div style="background-color:#3c8dbc; border-radius: 0px 0px 7px 7px; min-height:10px; ">
                </div> 
            </div>
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
                            <div class="modal fade" id="modalInsert" tabindex="-1" role="dialog">
                                <div class="modal-dialog modal-lg">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Informasi Jadwal</h4>
                                        </div>
                                        <div class="modal-body" style="padding-left:50px; padding-right:50px;">
                                        
	          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>Jenis Angkutan /Penumpang</th>
                    <th>Harga</th>
                </tr>
            </thead>
            <tbody> 
            		<?php
				    include("config/connection.php");
              		$sql ="select tb_detil_angkutan_def.harga, tb_detil_angkutan_def.id, tb_angkutan.nama as angkutan 
							from tb_jadwal
							inner join tb_detil_angkutan_def on tb_jadwal.Id_Jadwal = tb_detil_angkutan_def.id_jadwal
							inner join tb_angkutan on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan 
							  order by tb_detil_angkutan_def.id_angkutan asc";
					$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
					mysql_close($test);
					
					while($row = mysql_fetch_object($hasil)){
						$id = $row->id;
						$harga = $row->harga;
						$angkutan = $row->angkutan;
						
			?>
            
            		<tr>
                        <td><?php echo $angkutan ?></td>
                        <td><?php echo number_format($harga)?></td>
                    </tr>
			<?php
					}
			?>
        	</tbody>
          </table> 
          
                                        </div> 
                                        <div class="modal-footer">
                                        	<button type="button" class="btn btn-warning" data-dismiss="modal">Tutup</button>
                                        </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>


    <script>
        $(document).on("click", ".open-Edit", function () {
            var Id = $(this).data('id');
            $.ajax({
                type: "get",
                url: "data-jadwal-proses.php?actget=5&id="+ Id,
                data: "id="+Id,
                success: function(data){
					        
                    $("#isi").html(data);
					
                    $("#modalInsert").modal('show');
                },
                error: function(){
                    alert("failure");
                }
            });
        });
        $(document).on("click", ".open-Delete", function () {
            var Id = $(this).data('id');
            //event.preventDefault();
            $('#idd').val(Id);
            $('#modalDelete').modal('show');
        });

    </script>
<script type="text/javascript">
            $('#timepicker2').timepicker({
                minuteStep: 1,
                template: 'modal',
                appendWidgetTo: 'body',
                showSeconds: true,
                showMeridian: false,
                defaultTime: false
            });
        </script>