<?php
	include "php_class/class_mysql.php";
	include "php_class/class_template.php";
	include "php_class/class_mahasiswa.php";
	include "php_class/class_grup.php";
	include "php_class/class_semesterpendek.php";
	include "php_class/class_dosen.php";
	$DataDosen = new dataDosen;
	$datasp = new DataSemesterPendek;
	$datagrup = new DataGrup;
	$DataMahasiswa = new DataMahasiswa;
	$DataTemplate = new DataTemplate;

	$id = $xcode;
?>
<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>
	$(document).ready(function(){
	var base = <?php echo json_encode($base);?>;
		$("#setting").click(function(){
			$("#myModal").modal('show');
		});
		$("#matakuliah").click(function(){
			$("#myModalmk").modal('show');
		});
		$("#dosen").click(function(){
			$("#myModaldosen").modal('show');
		});

		$("#Nama").click(function(){
			$("#myModal").modal('show');
		});
		$("#batal").click(function(){
			$('#form1').hide();
			$('.peringatan').html('<div id="warning"><div role="alert"></div></div>')
			$('#NPM').val() = '';
		});
		$("#AddTrans").click(function(){
			$("#myModal2").modal('show');
		});
		$('.delete').click(function(){
			var kode = $(this).attr('ids');
			window.location=''+base+'query-delete-temp-matakuliah/'+ kode +'';	
		});
		$('#NPM').keyup(function(e){
	  		if(e.keyCode == 13){
				var npm = $('#NPM').val();
				var action = '3';
				var program = $('#program').val();
				var tahun = $('#tahun').val();
				var semester = $('#semester').val();
				var idgrup = $('#idgrup').val();
				if (npm==''){
					$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">NPM Masih Kosong!</div></div>')			
				}else{
					$('.peringatan').html('<div id="warning"><img src="img/ld.gif"></div>')			
					$.ajax({
						type:"POST",
						data: "index=" + npm + "&program=" + program  ,
						url:"<?php echo $base?>cek-sempek.php",     
						success: function(data){
							var tampung = data;
							if(tampung!=404){
								$('#form1').show();
								var pecah=tampung.split(":");
								$('#Nama2').val(pecah[0]);
								$('#jurusan').val(pecah[1]);
								$('#alamat').val(pecah[2]);
								$('#kodeMhs').val(pecah[3]);
								$('#nn').val(pecah[4]);
								$('#Nama3').val(pecah[0]);
								statuskelas = pecah[5];
								
								
								if (statuskelas == "tidak") {
									$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Program dengan NPM yang diinput tidak sesuai!</div></div>')
									$('#simpan').hide();
								}else{
								$('.peringatan').html('<div id="warning"><div role="alert"></div></div>')
								$('#alamat').show();	
								$('#lblAlamat').show();
								$('#simpan').show();
								$('#simpan').focus();
								}	
							}else{
								$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Mahasiswa dengan NPM ini tidak ditemukan!</div></div>')
								$('#NPM').focus();	
								}
						}
					});
				}
			} 
		});

	});
</script>
<section class="content-header">
  <h1>
   Transaksi
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>"><i class="fa fa-dashboard"></i> Home</a></li>
  </ol>
</section>
<section class="content">
 	<div class="row">
    	<div class="row">
        	<div class="col-md-12">
            </div>
        </div>
    	<div class="col-md-12">
                        <div class="peringatan2">
						<?php
							if($xcode == 'x'){							
						?>
							<div id="warning"><div class="alert alert-warning" role="alert">Mata kuliah ini sudah dimasukkan!</div></div>
                        <?php } ?>
                        </div>
        	 <div class="box box-info">
                <div class="box-body">
					<div class="row">
                        <div class="col-sm-7" >
							<?php 
								$ids = $_SESSION["id"];	
								$tahun = $_POST["tahun"];
								$jurusan = $_POST['jurusan'];
								$semester = $_POST['semester'];
								$program = $_POST['program'];

								if ($program != ''){
									$_SESSION['program'] = $program;	
								}else{
									$program = $_SESSION['program'];	
								}
								
								if ($program == '122') {
									$program1 = 'R. Malam - Eksekutif';	
								}elseif($program == '121'){
									$program1 = 'Reguler';
									$program = '121';	
								}					
								
								if ($tahun == ""){
										$bulansmst = date('m');
										$bulansmst = substr($bulansmst, 1, 1); 
										if ($bulansmst > 8 and $bulansmst < 13){
												$dp = date('y');
												$bk = $dp - 1;
												$tahun = $bk.$dp;	
										}else if ($bulansmst < 8){
												$dp = date('y');
												$bk = $dp - 1;
												$tahun = $bk.$dp;	
										}else{
												$dp = date('y');
												$bk = $dp + 1;
												$tahun = $dp.$bk;	
										}
								}
								$tahundp = substr($tahun, 0, 2);
								$tahunbk = substr($tahun, 2, 2);
								
								$tahun1 = '20'.$tahundp."/20".$tahunbk;
								
								if ($jurusan != ''){
									$_SESSION['jurusansempek'] = $jurusan;	
								}else{
									$jurusan = $_SESSION['jurusansempek'];	
								}
								
								if ($semester != ''){
									$_SESSION['semestersempek'] = $semester;	
								}else{
									$semester = $_SESSION['semestersempek'];	
								}
																
								if ($semester == '1') {
									$semester1 = 'Ganjil';	
								} elseif($semester == '2') {
									$semester1 = 'Genap';	
								}

							$datasp3 = new DataSemesterPendek;
							$biayareguler = $datasp3->get_biaya('biaya');
							$biayanonreguler = $datasp3->get_biaya('biayanonreguler');
							
							if ($program == '122'){
								$biayasks = $biayanonreguler;
								$operasional =  $datasp3->get_biaya('biayaoperasionalnonreguler');
							}elseif ($program == '121'){
								$biayasks = $biayareguler;
								$operasional =  $datasp3->get_biaya('biayaoperasionalreguler');
							}else {
								$biayasks = 'Silahkan pilih program!';	
							} 

									echo "<H3 style='margin-bottom:15px;'>Jurusan : ".$jurusan."</h3>";
									echo "<H5 style='margin-bottom:15px;'>Tahun Akademin: ".$tahun1."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Semester: ".$semester1."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Program: ".$program1."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Biaya per SKS: ".$biayasks."</h5>";
							?>
                        </div>
                        <div class="col-sm-5">
            <button type="submit" class="btn btn-primary" id="setting" style="margin-top:20px; float:right"> <i class="glyphicon glyphicon glyphicon glyphicon-edit" style="padding-right:4px;"></i>Pilih Kegiatan</button>
            			</div>
                        <div class="col-sm-7"></div>
                        <div class="col-sm-5">
                	<form method="post" action="<?php echo $base?>query-add-temp-matakuliah">
                    	<input type="hidden" name="idmatakuliah" id="idmatakuliah">
                        <input type="hidden" name="iddosen" id="iddosen">
                        <input type="hidden" name="sks" id="sks">
                        <input type="hidden" name="jurusan" value="<?php echo $jurusan?>">
                        <input type="hidden" name="kode" id="kode">
                        <input type="hidden" name="program" value="<?php echo $program?>" id="program">
                        <div class="form-group">
                            <label class="control-label">Mata Kuliah</label>
                            <input type="text" class="form-control" placeholder="pilih mata kuliah" name="matakuliah" id="matakuliah" required="required">
                         </div>
                        <div class="form-group">
                            <label class="control-label">Nama Dosen</label>
                            <input type="text" class="form-control" placeholder="pilih dosen" name="dosen" id="dosen" required="required">
                         </div>
                         <div class="form-group">
                            <button type="submit" class="btn btn-default"><i class='glyphicon glyphicon-ok'></i> Simpan</button>
                          </div>
                    </form>
                        </div>
                    </div >	 
                       <div class="table-responsive" style="margin-top:30px;">
                          <table  class="table table-striped">
                             <thead>
                                <tr>
                                    <th>Kode</th>
                                    <th>Mata Kuliah</th>
                                    <th>Nama Dosen</th>
                                    <th>Jurusan</th>
                                    <th>SKS</th>
                                    <th>Biaya</th>
                                    <th>Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
							if(!session_id()) session_start();
							$idss = session_id();
						
								$total = 0;
								$JumlahData = $datasp->get_temp('',$a,'jumlah', $idss);
                                if ($JumlahData<=0){
                                    echo "<tr class='odd gradeX'>";
                                    echo "<td>No Data</td>";
                                    echo "<td></td>";
                                    echo "</tr>";	
                                }else{
                                    
									for ($a=1;$a<=$JumlahData;$a++){
										$idtemp = $datasp->get_temp('idTemp',$a,'', $idss);
                                        $matakuliah = $datasp->get_temp('matakuliah',$a,'', $idss);
                                        $sks = $datasp->get_temp('sks',$a,'', $idss);
										$kode = $datasp->get_temp('kode',$a,'', $idss);
										$jurusan1 = $datasp->get_temp('jurusan',$a,'', $idss);
										$biaya = $datasp->get_temp('biaya',$a,'', $idss);
										$namadosen = $datasp->get_temp('namadosen',$a, '', $idss);
										$total = $total + $biaya;

                                        echo "<tr id='".$id."' class='odd gradeX context'>";
										echo "<td>".$kode."</td>";
										echo "<td>".$matakuliah."</td>";
										echo "<td>".$namadosen."</td>";
                                        echo "<td>".$jurusan1."</td>";
									    echo "<td>".$sks."</td>";
                                        echo "<td>".number_format($biaya)."</td>";
										echo "<td class='center'>
											  <button class='btn btn-default delete btn-xs' ids='".$idtemp."'><i class='glyphicon glyphicon-remove'></i> </button>
											  </td>";
                                        echo "</tr>";
                                    }
                                }
                            ?>
                            </tbody>
                          </table>
          			</div>
                    <div class="col-sm-7" >
                            <?php
								$datasp4 = new DataSemesterPendek;
                                $totalsks = $datasp4->get_temp_by_id_jml('jml', $idss);
								
								$totaloperasional = $totalsks*$operasional;
								echo "<h4>Biaya Operasional : Rp".number_format($totaloperasional)."</h4>";
								
								$grandtotal = $total+$totaloperasional;
                            ?>
                            <h4>Total</h4>
                    </div>
                    <div class="col-sm-5">
                        <div align="right"><h1><div id="totaltrans"><?php echo "Rp".number_format($grandtotal) ?></div></h1></div>
                    </div>
				</div>
             </div> 
        	 <div class="box">
                <div class="box-body">
                    <div class="row" style="margin-top:25px;">
                    </div>	 
                        <div class="peringatan">
                        </div>

                     <div class="form-group">
                        <label class="control-label">NPM</label>
                        <input type="text" name="npm" required="required" class="form-control"  placeholder="masukkan NPM kemudian tekan enter" id="NPM">
                     </div>

                        <form method="post" action="<?php echo $base?>query-add-transaksi-sempek" style="display:none" id="form1">
                            <input type="hidden" name="idMhs" id="kodeMhs">
                            <input type="hidden" name="nn" id="nn">
                            <input type="hidden" name="semester" value="<?php echo $semester?>">
                            <input type="hidden" name="nmmhs" id="Nama3">
                            <input type="hidden" name="tahun" value="<?php echo $tahun?>" id="tahun">
                            <input type="hidden" name="idgrup" value="<?php echo $ids?>" id="idgrup">
                             <div class="form-group">
                                <label class="control-label">Nama Mahasiswa</label>
                                <input type="text" class="form-control" placeholder="nama mahasiswa" name="Nama" id="Nama2" disabled="disabled">
                             </div>
                             <div class="form-group">
                                <label class="control-label">Jurusan / Prodi</label>
                                <input type="text" class="form-control" placeholder="jurusan / Prodi" name="jurusan" disabled id="jurusan">
                             </div>
                             <div class="form-group">
                                <label class="control-label" id="lblAlamat">Alamat / No. Telepon</label>
                                <input type="text" name="Alamat" required="required" class="form-control"  placeholder="alamat / no. telepon"   id="alamat">
                             </div>
                             <div class="form-group">
                            <button type="submit" class="btn btn-primary" id="simpan"> <i class="glyphicon glyphicon-floppy-saved"></i> Simpan</button>
                            <button type="button" class="btn btn-primary" id="batal"> <i class="glyphicon glyphicon-delete"></i> Batal</button>
                             </div>
                        </form>
                </div>
             </div>
         </div>
    </div>
</section>

    	
<link href="<?php echo $base?>plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="<?php echo $base?>plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function(){
	$("#example1").dataTable();
	
  });
</script>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Setting Transaksi</h4>
      </div>
      <div class="modal-body">
          <form action="<?php echo $base?>add-semester-pendek" method="post" name="cmb" style="margin-bottom:35px;" id="cmb">
            <div class="form-group">
                <label class="control-label">Jurusan</label>
                <select class="form-control" name="jurusan">
                <?php 
                    if ($jurusan != "") {
                        echo "<option value='".$jurusan."'>".$jurusan."</option>";
                    }
                ?>
                    <option value="IESP">IESP</option>
                    <option value="AKUNTANSI">AKUNTANSI</option>
                    <option value="MANAJEMEN">MANAJEMEN</option>

                </select>
			</div>

            <select class="form-control" name="tahun"  style="margin-top:20px;">
            <?php 
				if ($tahun != "") {
                	echo "<option value='".$tahun."'>".$tahun1."</option>";
				}else{
					echo "<option value=''>-Pilih Tahun Akademik-</option>";	
				}
			?>
                    <?php 
					
					
                        $JumlahData = $DataMahasiswa->get_all_angkatan('',$a,'jumlah');	
                            for ($a=1;$a<=$JumlahData;$a++){
                            $angkatan = $DataMahasiswa->get_all_angkatan('angkatan',$a,'');
							if ($angkatan == '08'){
								$upAngkatan = '09';
							}else{
                            	$upAngkatan = $angkatan + 1;
							}
							

							$tahun = $angkatan.$upAngkatan;
							$tahun1 = "20".$angkatan."/20".$upAngkatan;
                       		echo "<option value=".$tahun.">".$tahun1."</option>";

                        }
                    ?>
                    

            </select>
            <select class="form-control" name="semester" style="margin-top:20px;">
            <?php 
				if ($semester != "") {
                	echo "<option value='".$semester."'>".$semester1."</option>";
				}else{
					echo "<option value=''>-Pilih Semester-</option>";	
				}
			?>
                <option value="1">Ganjil</option>
                <option value="2">Genap</option>
            </select>
            <select class="form-control" name="program"  style="margin-bottom:20px; margin-top:20px;">
            <?php 
				if ($program1 != "") {
                	echo "<option value='".$program."'>".$program1."</option>";
				}else{
					echo "<option value=''>-Pilih Program-</option>";	
				}
			?>
                <option value="121">Reguler</option>
                <option value="122">Non Reguler</option>
            </select>
            <button type="submit" class="btn btn-primary" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon glyphicon-ok-circle"></i> OK</button>
         </form>   
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="closemodal" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<script>
	$(document).ready(function(){
		$('.pilih').click(function(){
			var kode = $(this).attr('ids');
			var pecah = kode.split("-");	
				kodeMhs = pecah[0];
				npm = pecah[1];
				nama = pecah[2];
				jurusan = pecah[3];
				alamat = pecah[4];
				
			$('#kodeMhs').val(kodeMhs);
			$('#NPM').val(npm);
			$('#nn').val(npm);
			$('#Nama').val(nama);
			$('#alamat').val(alamat);
			$('#jurusan').val(jurusan);
			$('#myModal').modal('hide')
			$('#Nama').focus();
		});
	});

</script>
<div id="myModalmk" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Daftar MataKuliah</h4>
      </div>
      <div class="modal-body">
            <div class="table-responsive">
              <table id="example1" class="table table-bordered table-striped table-hover">
                 <thead>
                    <tr>
                        <th>Id</th>
                        <th>Mata Kuliah</th>
                        <th>SKS</th>
                        <th>Kode</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                    $JumlahData = $datasp->get_mk_all('',$a,'jumlah', $jurusan);
                    if ($JumlahData<=0){
                        echo "<tr class='odd gradeX'>";
                        echo "<td>No Data</td>";
                        echo "<td></td>";
                        echo "<td></td>";
                        echo "</tr>";	
                    }else{
                        for ($a=1;$a<=$JumlahData;$a++){
                            $id = $datasp->get_mk_all('idmatakuliah',$a,'', $jurusan);
                            $matakuliah = $datasp->get_mk_all('matakuliah',$a,'', $jurusan);
                            $sks = $datasp->get_mk_all('sks',$a,'', $jurusan);
							$kode = $datasp->get_mk_all('kode',$a,'', $jurusan);
							
                            echo "<tr ids='".$id."-".$matakuliah."-".$sks."-".$kode."' class='odd gradeX context pilih'>";
                            echo "<td>".$id."</td>";
                            echo "<td>".$matakuliah."</td>";
                            echo "<td>".$sks."</td>";
							echo "<td>".$kode."</td>";
                            echo "</tr>";
                        }
                    }
                ?>
                </tbody>
              </table>
           </div>
	  </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="closemodal" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<script>
	$(document).ready(function(){
		$('.pilih').click(function(){
			var kode = $(this).attr('ids');
			var pecah = kode.split("-");	
				id = pecah[0];
				matakuliah = pecah[1];
				sks = pecah[2];
				kode = pecah[3];
				
			$('#idmatakuliah').val(id);
			$('#matakuliah').val(matakuliah);
			$('#sks').val(sks);
			$('#kode').val(kode);
			$('#myModalmk').modal('hide')
		});
	});
</script>


<link href="<?php echo $base?>plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="<?php echo $base?>plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function(){
	$("#example2").dataTable();
	
  });
</script>

<div id="myModaldosen" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Daftar Dosen</h4>
      </div>
      <div class="modal-body">
      	<div class="table-responsive">
          <table id="example2" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>No</th>
                    <th>Nama Dosen</th>
                    <th>NIK / NIP</th>
                </tr>
            </thead>
            <tbody>
            <?php
            	$JumlahData = $DataDosen->get_data_dosen('',$a,'jumlah');
				if ($JumlahData<=0){
					echo "<tr class='odd gradeX'>";
					echo "<td>No Data</td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "</tr>";	
				}else{
					for ($a=1;$a<=$JumlahData;$a++){
						$id = $DataDosen->get_data_dosen('Id',$a,'');
						$NIDN = $DataDosen->get_data_dosen('NIDN', $a, '');
						$Nama = $DataDosen->get_data_dosen('Nama',$a,'');
						$NIK = $DataDosen->get_data_dosen('NIP',$a,'');
						
						echo "<tr ids='".$id."-".$Nama."-".$NIK."' class='odd gradeX context pilih1'>";
						echo "<td>".$id."</td>";
						echo "<td>".$Nama."</td>";
						echo "<td>".$NIK."</td>";
						echo "</tr>";
					}
				}
			?>
        	</tbody>
          </table>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="closemodal" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<script>
	$(document).ready(function(){
		$('.pilih1').click(function(){
			var kode = $(this).attr('ids');
			var pecah = kode.split("-");	
				kodeDosen = pecah[0];
				bendahara = pecah[1];
				nip = pecah[2];
				
			$('#iddosen').val(kodeDosen);
			$('#dosen').val(bendahara);
			$('#myModaldosen').modal('hide')
		});
	});
</script>
