<?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";
	
	$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');
		});

		$("#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');
			if (confirm("Anda yakin menghapus transaksi ini?")){
				window.location=''+base+'query-delete-temp/'+ 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 + "&tahun=" + tahun + "&semester=" + semester + "&grup=" + idgrup ,
						url:"<?php echo $base?>cek-npm.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]);
								status = pecah[5];
								statuskelas = pecah[6];
								
								if (statuskelas == "tidak") {
									$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Kelas dengan NPM yang diinput tidak sesuai!</div></div>')
								$('#simpan').hide();
								} else if (status == "ada") {
									$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Mahasiswa ini sudah melakukan pembayaran untuk transaksi ini!</div></div>')
								$('#alamat').hide();	
								$('#lblAlamat').hide();
								$('#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="box box-info">
                <div class="box-body">
					<div class="row">
                        <div class="col-sm-7" >
							<?php 
								$ids = $_SESSION["id"];	
								$program = $_SESSION["program"];
								$tahun = $_SESSION["tahun"];
								$semeter = $_SESSION["semester"];
								
								if ($ids == ""){
									if ($xcode == ""){
										$ids = 'G0004';
									}else {
										$ids = $xcode;
									}
								}
								
								if ($program == '122') {
									$program1 = 'R. Sore -Eksekutif';	
								} else {
									$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 < 3){
												$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 ($semeter == '1') {
									$semeter1 = 'Ganjil';	
								} else {
									if ($semeter == ''){
										$bulansmst = date('m');
										$bulansmst = substr($bulansmst, 1, 1); 
										if ($bulansmst > 8 and $bulansmst < 13){
											$semeter = '1';
											$semeter1 = 'Ganjil';	
										}else if ($bulansmst < 3){
											$semeter = '1';
											$semeter1 = 'Ganjil';	
										}else{
											$semeter = '2';
											$semeter1 = 'Genap';	
										}
									}else{
										$semeter = '2';
										$semeter1 = 'Genap';	
									}
								}
								
								
								
								$NamaGrup = $datagrup->get_grup_single_by_id('Des', $ids);
								if ($ids != "") {
									echo "<H3 style='margin-bottom:15px;'>Kegiatan : ".$NamaGrup."</h3>";
									echo "<H5 style='margin-bottom:15px;'>Kelas : ".$program1."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Tahun Akademin: ".$tahun1."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Semester : ".$semeter1."</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 >	 
                       <div class="table-responsive" style="margin-top:30px;">
                          <table  class="table table-striped">
                             <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Nama</th>
                                    <th>Biaya</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
								$total = 0;
								$JumlahData = $datagrup->get_detil('',$a,'jumlah', $ids);
                                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++){
										$no = $datagrup->get_detil('id', $a, '', $ids);
                                        $id = $datagrup->get_detil('idTemplate',$a,'', $ids);
                                        $namaTrx = $datagrup->get_detil('NamaTRX',$a,'', $ids);
                                        $BiayaReguler = $datagrup->get_detil('BiayaReguler',$a,'', $ids);
                                        $BiayaNonReguler = $datagrup->get_detil('BiayaNonReguler',$a,'', $ids);
										
										if ($program == '121') {
											$BiayaTrx = $BiayaReguler;	
										} else {
											$BiayaTrx = $BiayaNonReguler;
											}
										$total = $total + $BiayaTrx;

                                        echo "<tr id='".$id."' class='odd gradeX context'>";
                                        echo "<td>".$a."</td>";
                                        echo "<td>".$namaTrx."</td>";
                                        echo "<td>".number_format($BiayaTrx)."</td>";
                                        echo "</tr>";
                                    }
                                }
                            ?>
                            </tbody>
                          </table>
          			</div>
                    <div class="col-sm-7" >
                            <?php
                                date_default_timezone_set('UTC');
                            ?>
                            <h4>Total</h4>
                    </div>
                    <div class="col-sm-5">
                        <div align="right"><h1><div id="totaltrans"><?php echo "Rp".number_format($total) ?></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-grup" style="display:none" id="form1">
                            <input type="hidden" name="idMhs" id="kodeMhs">
                            <input type="hidden" name="nn" id="nn">
                            <input type="hidden" name="nmmhs" id="Nama3">
                            <input type="hidden" name="tahun" value="<?php echo $tahun?>" id="tahun">
                            <input type="hidden" name="semester" value="<?php echo $semeter?>" id="semester">
                            <input type="hidden" name="program" value="<?php echo $program?>" id="program">
                            <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?>query-add-setting" method="post" name="cmb" style="margin-bottom:35px;" id="cmb">
            <select class="form-control" name="idkg" style="margin-bottom:20px;">
            <?php 
				if ($ids != "") {
                	echo "<option value='".$ids."'>".$NamaGrup."</option>";
				}else{
					echo "<option value=''>-Pilih Kegiatan-</option>";	
				}
			?>

                    <?php 
                        $JumlahData = $datagrup->get_grup_all('',$a,'jumlah');	
                            for ($a=1;$a<=$JumlahData;$a++){
                            $id = $datagrup->get_grup_all('idGrup',$a,'');
                            $Nama = $datagrup->get_grup_all('Des', $a, '');
                        echo "<option value=".$id.">".$Nama."</option>";
                        }
                    ?>
            </select>

            <select class="form-control" name="program"  style="margin-bottom: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">R. Sore Eksekutif</option>
            </select>
            <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 ($semeter != "") {
                	echo "<option value='".$semeter."'>".$semeter1."</option>";
				}else{
					echo "<option value=''>-Pilih Semester-</option>";	
				}
			?>
                <option value="1">Ganjil</option>
                <option value="2">Genap</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();
		});
	});
