<?php
// The function header by sending raw excel
header("Content-type: application/vnd-ms-excel");
 
// Defines the name of the export file "codelution-export.xls"
header("Content-Disposition: attachment; filename=data-transaksi.xls");
 
// Add data table
?>
<?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;
	$idOperator = $_POST['operator'];
	
	$ids = $_POST['idkg'];	
	$program = $_POST['program'];
	$tahun = $_POST['tahun'];
	$jurusan = $_POST['jurusan'];
	$semeter = $_POST['semester'];
	$tglawal = $_POST['tglawal'];
	$tglawal = 	substr($tglawal, 0, 10);
	$tglakhir = $_POST['tglakhir'];
	$tglakhir = substr($tglakhir, 0, 10);

		
		if ($ids == ""){
			$NamaGrup = "Semua Kegiatan";
		}else{
			$NamaGrup = $datagrup->get_grup_single_by_id('Des', $ids);
		}
		
		if ($program == '122') {
			$program1 = 'Non Reguler';	
		} else if ($program == '121'){
			$program1 = 'Reguler';
			$program = '121';	
		} else {
			$program1 = 'Semua';
			$program = '';
			}						
		
		if ($tahun == '1314') {
			$tahun1 = '2013/2014';	
		} else if ($tahun == '1415') {
			$tahun1 = '2014/2015';
		} else if ($tahun == '1516') {
			$tahun1 = '2015/2016';	
		} else {
			$tahun1 = '2016/2017';
			$tahun = '1617';
		}
		
		if ($semeter == '1') {
			$semeter1 = 'Ganjil';	
		} else {
			$semeter = '2';
			$semeter1 = 'Genap';	
		}
		
		if ($tglawal == "") {
			$tglawal = date('2015-02-02');
		}

		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; 

?>


                          <table  border="1">
                             <thead>
                                <tr>
                                    <th>NO Transaksi</th>
                                    <th>Tanggal</th>
                                    <th>Nama Mahasiswa</th>
                                    <th>NPM</th>
                                    <th>Kegiatan</th>
                                    <th>Jumlah Bayar</th>
                                    <th>Operator</th>
                                    <th>Alamat/No Hp</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
								$total = 0;
								$jumlahtotal = 0;
								
								$JumlahData = $DataTransaksi->get_all_trans_total('',$a,'jumlah', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
                                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 "<td></td>";
                                    echo "</tr>";	
                                }else{
                                    
									for ($a=1;$a<=$JumlahData;$a++){
										$no = $DataTransaksi->get_all_trans_total('NoTRX',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
                                        $tglTRX = $DataTransaksi->get_all_trans_total('TglInput',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										$NPM = $DataTransaksi->get_all_trans_total('NPM',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
                                        $jumlah = $DataTransaksi->get_all_trans_total('TotalBayar',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										$NamaMhs = $DataTransaksi->get_all_trans_total('Nama',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										$kegiatan = $DataTransaksi->get_all_trans_total('Des',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										$operator = $DataTransaksi->get_all_trans_total('namaOperator',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										$alamat = $DataTransaksi->get_all_trans_total('alamat',$a,'', $tglawal, $tglakhir, $program, $tahun, $semeter, $ids, $idOperator, $jurusan);
										
										$jumlahtotal = $jumlahtotal + $jumlah;

                                        echo "<tr id='".$no."' class='odd gradeX context'>";
                                        echo "<td>".$no."</td>";
										echo "<td>".$tglTRX."</td>";
                                        echo "<td>".$NamaMhs."</td>";
                                        echo "<td>".$NPM."</td>";
										echo "<td>".$kegiatan."</td>";
                                        echo "<td>".number_format($jumlah)."</td>";
										echo "<td>".$operator."</td>";
										echo "<td>'".$alamat."</td>";
                                        echo "</tr>";
                                    }
                                }
                            ?>
                            </tbody>
                       </table>
