<?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_transaksi.php";
	
	$DataTransaksi = new DataTransaksi;
	$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');
		});
		$('.context').click(function(e){
			var kode = $(this).attr('id');
			var noTrx = $(this).attr('noTrx');
			var nopendaftaran = $(this).attr('nopendaftaran');
			
			$('#kodekunci').val(kode);
			$('#noTrx').val(noTrx);
			$('#nopendaftaran').val(nopendaftaran);
			$("#menuklik").modal('show');
		});
		$("#Nama").click(function(){
			$("#myModal").modal('show');
		});
		$("#batal").click(function(){
			$('#form1').hide();
			$('#NPM').val() = '';
		});
		$("#AddTrans").click(function(){
			$("#myModal2").modal('show');
		});

		$('#cetak').click(function(){
			var kode = $('#kodekunci').val();
			window.location=''+base+'cetak-pendaftaran/'+ kode +'';
		});

		$('#cetak2').click(function(){
			var kode = $('#kodekunci').val();
			var noTrx = $('#noTrx').val();
			window.location=''+base+'cetak-daftar-ulang/'+ kode +'/'+ noTrx +'';
		});

		$('#delete').click(function(){
			var noTrx = $('#noTrx').val();
			var nopendaftaran = $('#nopendaftaran').val();
			if (confirm("Anda yakin menghapus data ini?")){
				window.location=''+base+'query-delete-pendaftaran/'+ noTrx +'/'+ nopendaftaran +'';	
			}
		});
		$('#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{
					$.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>')
								$('#simpan').hide();

								}else {
								$('.peringatan').html('<div id="warning"><div role="alert"></div></div>')
								$('#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>
   Data Pendaftaran
  </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 
							$operator = $_POST['operator'];
							list($idOperator, $NamaOperator) = explode('-', $operator);

							$kegiatan = $_POST['kegiatan'];
							$kegiatan1 = $kegiatan;	
							$jurusan = $_POST['jurusan'];
							$cetakjurusan = $jurusan;
							$tglawal = $_POST['tglawal'];
							$tglawal = 	substr($tglawal, 0, 10);
							$tglakhir = $_POST['tglakhir'];
							$tglakhir = substr($tglakhir, 0, 10);
							
								if ($idOperator == ""){
									$NamaOperator = "Semua Operator";	
								}

								if ($jurusan == "" ){
									$cetakjurusan = 'Semua';
									}					
								
								if ($kegiatan == ""){
									$kegiatan = 'Pendaftaran Mahasiswa';
									$kegiatan1 = 'Pendaftaran Mahasiswa';
									}								
								
								if ($tglawal == "") {
									$tglawal = date('Y-m-d');
								}

								if ($tglakhir == "") {
									$tglakhir = date('Y-m-d');
								}
								
								$haritglAwal = substr($tglawal, 8, 2);
								$bulantglAwal = substr($tglawal, 5, 2);
								$tahuntglAwal = substr($tglawal, 0, 4);
								$cetaktglAwal = $haritglAwal."-".$bulantglAwal."-".$tahuntglAwal; 
								
								$haritglAkhir = substr($tglakhir, 8, 2);
								$bulantglAkhir = substr($tglakhir, 5, 2);
								$tahuntglAkhir = substr($tglakhir, 0, 4);
								$cetaktglAkhir = $haritglAkhir."-".$bulantglAkhir."-".$tahuntglAkhir; 

									echo "<H3 style='margin-bottom:15px;'>Kegiatan : ".$kegiatan."</h3>";
									echo "<H5 style='margin-bottom:15px;'>Jurusan : ".$cetakjurusan."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Tanggal Awal : ".$cetaktglAwal."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Tanggal Akhir : ".$cetaktglAkhir."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Operator : ".$NamaOperator."</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>Setting</button>
                        </div>
                    </div >	 
                       <div class="table-responsive" style="margin-top:30px;">
                          <table  class="table table-striped">
                             <thead>
                                <tr>
                                    <th>NO Transaksi</th>
                                    <th>Nama Mahasiswa</th>
                                    <th>No Pendaftaran</th>
                                    <th>Jurusan</th>
                                    <th>Jumlah Bayar</th>
                                    <th>NPM</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
								$total = 0;
								$jumlahtotal = 0;
								$b = 0;
								$JumlahData = $DataMahasiswa->get_all_trans_total('',$a,'jumlah', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
                                if ($JumlahData<=0){
                                    echo "<tr class='odd gradeX'>";
                                    echo "<td>No Data</td>";
                                    echo "<td></td>";
                                    echo "<td></td>";
									echo "<td></td>";
									echo "<td></td>";
                                    echo "</tr>";	
                                }else{
                                    
									for ($a=1;$a<=$JumlahData;$a++){
										$no = $DataMahasiswa->get_all_trans_total('NoTRX',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
                                        $tglTRX = $DataMahasiswa->get_all_trans_total('tgInput',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$NPM = $DataMahasiswa->get_all_trans_total('noPendaftaran',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
                                        $jumlah = $DataMahasiswa->get_all_trans_total('total',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$NamaMhs = $DataMahasiswa->get_all_trans_total('Nama',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$kegiatan = $DataMahasiswa->get_all_trans_total('Des',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$Jurusan = $DataMahasiswa->get_all_trans_total('Jurusan',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$NPM2 = $DataMahasiswa->get_all_trans_total('NPM',$a,'', $tglawal, $tglakhir, $kegiatan1, $jurusan, $idOperator);
										$jumlahtotal = $jumlahtotal + $jumlah;
										$b	= $b + 1;
										
										if ($kegiatan1 == 'Pendaftaran Mahasiswa'){
											$kunci = $NPM;	
										}else{
											$kunci = $NPM2;	
											$NoPendaftaran = $NPM;
										}
										
                                        echo "<tr id='".$kunci."' noTrx = '".$no."' nopendaftaran = '".$NoPendaftaran."' class='odd gradeX context'>";
                                        echo "<td>".$no."</td>";
                                        echo "<td>".$NamaMhs."</td>";
                                        echo "<td>".$NPM."</td>";
										echo "<td>".$Jurusan."</td>";
                                        echo "<td>".number_format($jumlah)."</td>";
										echo "<td>".$NPM2."</td>";
                                        echo "</tr>";
                                    }
                                }
                            ?>
                            </tbody>
                          </table>
          			</div>
                    <div class="col-sm-7" >
                            <?php
                                date_default_timezone_set('UTC');
                            ?>
                            <h4>Total</h4>
                            <h4>Jumlah Mahasiswa : <?php echo $b?></h4>

                    </div>
                    <div class="col-sm-5">
                        <div align="right"><h1><div id="totaltrans"><?php echo "Rp".number_format($jumlahtotal) ?></div></h1></div>
                               <?php 
							   	if ($kegiatan == "Pendaftaran Mahasiswa"){
							   ?>   
                                  <form action="<?php echo $base?>tabel-pendaftaran.php" method="post" name="cmb" style="float:right" id="cmb" target="_blank">
                                            <input type="hidden" name="tglawal" value="<?php echo $tglawal?>" />
                                            <input type="hidden" name="tglakhir" value="<?php echo $tglakhir?>" />
                                        	<input type="hidden" name="kegiatan" value="<?php echo $kegiatan?>">
                                            <input type="hidden" name="jurusan" value="<?php echo $jurusan?>">
                                        	<input type="hidden" name="operator" value="<?php echo $idOperator?>">
                                        <button type="submit" class="btn btn-primary" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon-print"></i> Export Excel</button>
                                 </form>   
                               <?php }else{?>
                                  <form action="<?php echo $base?>tabel-daftar-ulang.php" method="post" name="cmb" style="float:right" id="cmb" target="_blank">
                                            <input type="hidden" name="tglawal" value="<?php echo $tglawal?>" />
                                            <input type="hidden" name="tglakhir" value="<?php echo $tglakhir?>" />
                                        	<input type="hidden" name="kegiatan" value="<?php echo $kegiatan?>">
                                            <input type="hidden" name="jurusan" value="<?php echo $jurusan?>">
                                        	<input type="hidden" name="operator" value="<?php echo $idOperator?>">
                                        <button type="submit" class="btn btn-primary" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon-print"></i> Export Excel</button>
                                 </form>   
								<?php } ?>                               
                               

                    </div>
				</div>
             </div> 
        	 
         </div>
    </div>
</section>
          <div id="menuklik" class="modal fade" role="dialog">
          	<div class="modal-dialog modal-sm">
                <div class="modal-content">
                	<div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h5 class="modal-title">Aksi</h5>
                    </div>
                  	<div class="modal-body">
                        <input type="hidden" value="" id="kodekunci">
                        <input type="hidden" value="" id="noTrx">
                        <input type="hidden" value="" id="nopendaftaran">
                        <div align="center">
                        <?php if ($kegiatan1 == 'Pendaftaran Mahasiswa'){?>
                        <p><button type="button" class="btn btn-primary" id="cetak"><i class='glyphicon glyphicon-print'></i>Cetak</button></p>
                        <?php }else{ ?>
                        <p><button type="button" class="btn btn-primary" id="cetak2"><i class='glyphicon glyphicon-print'></i>Cetak</button></p>
                       	<?php } ?>
                        <p><button type="button" class="btn btn-primary" id="delete"><i class='glyphicon glyphicon-delete'></i>Batalkan</button></p>
                        </div>
                        
                     </div>
                </div>
            </div>
          </div>

    	
<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</h4>
      </div>
      <div class="modal-body">
          <form action="<?php echo $base?>data-pendaftaran-total" method="post" name="cmb" style="margin-bottom:35px;" id="cmb">
            <div class="form-group">
                <label class="control-label">Kegiatan</label>
                <select class="form-control" name="kegiatan">
                <?php 
                    if ($kegiatan != "") {
                        echo "<option value='".$kegiatan."'>".$kegiatan."</option>";
                    }
                ?>
                    <option value="Pendaftaran Mahasiswa">Pendaftaran Mahasiswa</option>
                    <option value="Pendaftaran Ulang">Pendaftaran Ulang</option>

                </select>
			</div>

              <div class="form-group">
                <label class="control-label">Tanggal Awal</label>
                <div class="input-group date form_date" data-date="" data-date-format="dd-mm-yyyy" data-link-field="tglspk">
                    <input required="required" class="form-control" type="text" value="<?php echo $cetaktglAwal?>"  readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                    <input type="hidden" id="tglspk" name="tglawal" value="<?php echo $tglawal?>" />
                    <script type="text/javascript">
                        $('.form_date').datetimepicker({
                            language:  'id',
                            weekStart: 1,
                            todayBtn:  1,
                            autoclose: 1,
                            todayHighlight: 1,
                            startView: 2,
                            minView: 2,
                            forceParse: 0
                        });
                    </script>  
                </div>
              </div>
              <div class="form-group">
                <label class="control-label">Tanggal Akhir</label>
                <div class="input-group date form_date" data-date="" data-date-format="dd-mm-yyyy" data-link-field="tglspk1">
                    <input required="required" class="form-control" type="text" value="<?php echo $cetaktglAkhir?>" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                    <input type="hidden" id="tglspk1" name="tglakhir" value="<?php echo $tglakhir?>" />
                    <script type="text/javascript">
                        $('.form_date').datetimepicker({
                            language:  'id',
                            weekStart: 1,
                            todayBtn:  1,
                            autoclose: 1,
                            todayHighlight: 1,
                            startView: 2,
                            minView: 2,
                            forceParse: 0
                        });
                    </script>  
                </div>
              </div>
            <div class="form-group">
                <label class="control-label">Jurusan</label>
                <select class="form-control" name="jurusan">
                <?php 
                    if ($jurusan != "") {
                        echo "<option value='".$jurusan."'>".$cetakjurusan."</option>";
                    }
                        echo "<option value=''>Semua</option>";	
                ?>
                    <option value="IESP">IESP</option>
                    <option value="AKUNTANSI">AKUNTANSI</option>
                    <option value="MANAJEMEN">MANAJEMEN</option>

                </select>
			</div>
            <div class="form-group">
                <label class="control-label">Operator</label>
                <select class="form-control" name="operator" >
                <?php 
                    if ($idOperator != "") {
                        echo "<option value='".$idOperator."-".$NamaOperator."'>".$NamaOperator."</option>";
                    }
					echo "<option value='-Semua Operator'>Semua Operator</option>";
				?>
    
                        <?php 
							include "php_class/class_operator.php";
							$DataOperator = new dataOperator;
							
                            $JumlahData = $DataOperator->get_operator_for_transaksi('', $a,'jumlah');	
                                for ($a=1;$a<=$JumlahData;$a++){
                                $idOperator = $DataOperator->get_operator_for_transaksi('kodeOperator',$a,'');
                                $NamaOperator = $DataOperator->get_operator_for_transaksi('namaOperator', $a, '');
                            echo "<option value=".$idOperator."-".$NamaOperator.">".$NamaOperator."</option>";
                            }
                        ?>
                </select>
			</div>

                <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();
		});
	});

