<?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;
	$Nama = $DataTemplate->get_template_single_by_id('NamaTRX', $id);
	$Biaya = $DataTemplate->get_template_single_by_id('Biaya', $id);
?>
<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);?>;
		$("#Nama").click(function(){
			$("#myModal").modal('show');
		});
		$("#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-grup/'+ kode +'';	
			}
		});
		$('#NPM').keyup(function(e){
	  		if(e.keyCode == 13){
				var npm = $('#NPM').val();
				var action = '3';
				if (npm==''){
					$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">NPM Masih Kosong!</div></div>')			
				}else{
					$.ajax({
						type:"POST",
						data: "index=" + npm + "&action=" + action,
						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]);
								$('.peringatan').html('<div id="warning"><div role="alert"></div></div>')
							}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>
   Tambah Transaksi
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>"><i class="fa fa-dashboard"></i> Home</a></li>
    <li><a href="<?php echo $base?>data-transaksi">Data  Grup Transaksi</a></li>
    <li class="active">Tambah Data Grup Transaksi</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" >
                        </div>
                        <div class="col-sm-5">
		                 <a style="float:right; margin-bottom:35px;" class="btn btn-primary" href="<?php echo $base?>add-grup-detil">
                            <i class="glyphicon glyphicon-plus-sign" ></i>
                            Tambah Transaksi
                          </a>
                        </div>
                    </div>	 
                       <div class="table-responsive">
                          <table  class="table table-striped">
                             <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Nama</th>
                                    <th>Biaya</th>
                                    <th>Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
									if(!session_id()) session_start();
									$ids = session_id();
									$total = 0;
								$JumlahData = $datagrup->get_temp('',$a,'jumlah', $ids);
                                if ($JumlahData<=0){
                                    echo "<tr class='odd gradeX'>";
                                    echo "<td>No Data</td>";
                                    echo "<td></td>";
                                    echo "<td></td>";
                                    echo "<td></td>";
                                    echo "</tr>";	
                                }else{
                                    
									for ($a=1;$a<=$JumlahData;$a++){
										$no = $datagrup->get_temp('id', $a, '', $ids);
                                        $id = $datagrup->get_temp('idTemplate',$a,'', $ids);
                                        $namaTrx = $datagrup->get_temp('Nama',$a,'', $ids);
                                        $Biaya = $datagrup->get_temp('Biaya',$a,'', $ids);
										$total = $total + $Biaya;
                                        echo "<tr id='".$id."' class='odd gradeX context'>";
                                        echo "<td>".$a."</td>";
                                        echo "<td>".$namaTrx."</td>";
                                        echo "<td>".number_format($Biaya)."</td>";
										echo "<td class='center'>
											  <button class='btn btn-default delete btn-xs' ids='".$no."'><i class='glyphicon glyphicon-remove'></i> </button>
											  </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>

                        <form method="post" action="<?php echo $base?>query-add-grup">
                            <input type="hidden" name="nn" id="nn">
                             <div class="form-group">
                                <label class="control-label">Nama Grup</label>
                                <input type="text" class="form-control" placeholder="nama grup" name="nama">
                             </div>
                             <div class="form-group">
                            <button type="submit" class="btn btn-primary" id="simpan"> <i class="glyphicon glyphicon-floppy-saved"></i> Simpan</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">Daftar Mahasiswa</h4>
      </div>
      <div class="modal-body">
      	<div class="table-responsive">
          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>NPM</th>
                    <th>Nama</th>
                    <th>Jurusan</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
            <?php
            	$JumlahData = $DataMahasiswa->get_mahasiswa_all('',$a,'jumlah');
				if ($JumlahData<=0){
					echo "<tr class='odd gradeX'>";
					echo "<td>No Data</td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "</tr>";	
				}else{
					for ($a=1;$a<=$JumlahData;$a++){
						$id = $DataMahasiswa->get_mahasiswa_all('id',$a,'');
						$NPM = $DataMahasiswa->get_mahasiswa_all('NPM',$a,'');
						$Nama = $DataMahasiswa->get_mahasiswa_all('Nama',$a,'');
						$Jurusan = $DataMahasiswa->get_mahasiswa_all('Jurusan',$a,'');
						$Alamat = $DataMahasiswa->get_mahasiswa_all('Alamat',$a,'');
						$telp = $DataMahasiswa->get_mahasiswa_all('NoTelp',$a,'');
						$isAktif = $DataMahasiswa->get_mahasiswa_all('isAktif',$a,'');
						
						if ($isAktif=='1'){
							$Status = 'Aktif';
						}else{
							$Status ='Non Aktif';
						}
						echo "<tr ids='".$id."-".$NPM."-".$Nama."-".$Jurusan."-".$Alamat."/".$telp."' class='odd gradeX context pilih'>";
						echo "<td>".$NPM."</td>";
						echo "<td>".$Nama."</td>";
						echo "<td>".$Jurusan."</td>";
						echo "<td>".$Status."</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("-");	
				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>
<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="myModal2" 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 Mahasiswa</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 Template</th>
                    <th>Nama</th>
                    <th>Biaya</th>
                </tr>
            </thead>
            <tbody>
            <?php
            	$JumlahData = $DataTemplate->get_template_all('',$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 = $DataTemplate->get_template_all('NoID',$a,'');
						$namaTrx = $DataTemplate->get_template_all('NamaTRX',$a,'');
						$Biaya = $DataTemplate->get_template_all('Biaya',$a,'');
						echo "<tr id='".$id."' class='odd gradeX context cek'>";
						echo "<td>".$id."</td>";
						echo "<td>".$namaTrx."</td>";
						echo "<td>".$Biaya."</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(){
		$('.cek').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);
			$('#Nama').val(nama);
			$('#alamat').val(alamat);
			$('#jurusan').val(jurusan);
			$('#myModal').modal('hide')
			$('#Nama').focus();
		});
	});
</script>
   