<?php
//$count_spp_rep = "";
//$count_spp_rep = $this->session->flashdata('count_spp_rep');
function ctword($x) 
{
	$x = abs($x);
	$number = array("", "satu", "dua", "tiga", "empat", "lima",
	"enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
	$temp = "";

	if ($x <12) {
	$temp = " ". $number[$x];
	} else if ($x <20) {
	$temp = ctword($x - 10). " belas";
	} else if ($x <100) {
	$temp = ctword($x/10)." puluh". ctword($x % 10);
	} else if ($x <200) {
	$temp = " seratus" . ctword($x - 100);
	} else if ($x <1000) {
	$temp = ctword($x/100) . " ratus" . ctword($x % 100);
	} else if ($x <2000) {
	$temp = " seribu" . ctword($x - 1000);
	} else if ($x <1000000) {
	$temp = ctword($x/1000) . " ribu" . ctword($x % 1000);
	} else if ($x <1000000000) {
	$temp = ctword($x/1000000) . " juta" . ctword($x % 1000000);
	} else if ($x <1000000000000) {
	$temp = ctword($x/1000000000) . " milyar" . ctword(fmod($x,1000000000));
	} else if ($x <1000000000000000) {
	$temp = ctword($x/1000000000000) . " trilyun" . ctword(fmod($x,1000000000000));
	}
	return $temp;
}

function terbilang($x,$style=4,$strcomma=",") 
{
	if($x<0) {
	$result = "minus ". trim(ctword($x));
	} else {
	$arrnum=explode("$strcomma",$x);
	$arrcount=count($arrnum);
	if ($arrcount==1){
	$result = trim(ctword($x));
	}else if ($arrcount>1){
	$result = trim(ctword($arrnum[0])) . " koma " . trim(ctword($arrnum[1]));
	}
	}
	switch ($style) {
	case 1: //1=uppercase  dan
	$result = strtoupper($result);
	break;
	case 2: //2= lowercase
	$result = strtolower($result);
	break;
	case 3: //3= uppercase on first letter for each word
	$result = ucwords($result);
	break;
	default: //4= uppercase on first letter
	$result = ucfirst($result);
	break;
	}
	return $result;
}

class PDF extends FPDF2
{
	var $diserahkan;
	var $diterima;
	
    function diserahkan($diserahkan){
        $this->diserahkan=$diserahkan;
    }
	function diterima($diterima){
        $this->diterima=$diterima;
    }
	//Page header
	
	function Header()
	{
	    //Logo
		$this->Image('template/backend_default/img/logo_pesat.png',17,12,30);
		//Arial bold 15
		
		$this->SetFont('times','B',11);
		//Move to the right
		$this->SetX(75);
		$this->Cell(0,6,'LAPORAN TUNGGAKAN SISWA',0,1,1);
		$this->SetX(70);
		$this->Cell(0,6,'YAYASAN PESAT BIRRUL WALIDAIN',0,1,1);
		$this->SetX(83);
		$this->Cell(0,6,'SMP/SMA/SMK PESAT',0,1,1);
		//$this->Cell(0,8,'',0,1,1);
		/*
		$this->SetY(12);
		$this->SetX(120);
		$this->Cell(0,8,'Alamat :',0,1,1);
		$this->SetX(120);
		$this->Cell(0,8,'Jln. Poras No.7 Sindang Barang Loji Bogor',0,1,1);
		*/
		//$this->SetX(120);
		//$this->Cell(0,8,'Telpon.  (0251) 8627289',0,1,1);
		$this->SetFont('times','B',15);
		$this->Cell(0,0,'___________________________________________________________________',0,1,2);
		
		
		//Line break
		$this->Ln(15);
                
	}	
	
	function Footer() {
		/*
		global $diserahkan;
		global $diterima;
		//Position at 1.5 cm from bottom
		$this->SetY(-48);
		//Arial italic 8
		$this->SetFont('times','',10);
		//Page number
		$this->SetX(15);
		$this->Cell(0,15,'Jakarta, '.date('d F Y'),0,1);
		$this->SetX(15);
		$this->Cell(0,-5,'Yang Menyerahkan,',0,1);
		$this->SetX(15);
		$this->Cell(0,12,'',0,1);
		
		$this->SetX(15);
		$this->Cell(0,9,$this->diserahkan,0,1);
		//$this->SetX(10);
		//$this->Cell(0,0,'____________________________',0,1);
		$this->SetY(-48);
		$this->SetX(132);
		$this->Cell(0,25,'Yang Menerima,',0,1);
		$this->SetX(132);
		$this->Cell(0,10,'',0,1);
		$this->SetX(132);
		$this->Cell(0,-17,$this->diterima,0,1);
		//$this->SetX(140);
		//$this->Cell(0,0,'____________________________',0,1);
		*/
		$this->SetY(-23);
		$this->SetFont('times','B',15);
		$this->Cell(0,0,'___________________________________________________________________',0,1,2);
		$this->SetFont('times','',10);
		
		$this->SetX(75);
		$this->Cell(0,15,'Jln. Poras No.7 Sindang Barang Loji Bogor',0,1,1);
	}
}
 	
	//Instanciation of inherited class
	$pdf=new PDF();
	$pdf->SetFont('times','B',10);
	$pdf->AliasNbPages();
	$pdf->AddPage();
	
	
	$smk = $idsmk;
	$sis = $idsiswa;
	$get_id_siswa = $this->rep_sis->get_id_siswa($smk, $sis);
	$kelas_sis = $get_id_siswa->kelas;
	$nis = $get_id_siswa->nis;
	$get_smk = $this->rep_sis->getSMK($smk);
	//$this->SetY(132);
	$pdf->SetY(37);
	$pdf->Cell(0,5,'Nama',0,1);	
	$pdf->SetY(37);
	$pdf->SetX(30);
	$pdf->Cell(0,5,':',0,1);	
	$pdf->SetY(37.5);
	$pdf->SetX(32);
	$pdf->Cell(0,4,$get_id_siswa->nama,0,1);
	
	$pdf->Cell(0,8,'NIS',0,1);	
	$pdf->SetY(45);
	$pdf->SetX(30);
	$pdf->Cell(0,0,':',0,1);	
	//$pdf->SetY(35);
	$pdf->SetX(32);
	$pdf->Cell(0,0.2,$nis,0,1);
	
	
	$pdf->Cell(0,11.7,'Sekolah',0,1);	
	$pdf->SetY(51);
	$pdf->SetX(30);
	$pdf->Cell(0,0,':',0,1);	
	//$pdf->SetY(35);
	$pdf->SetX(32);
	$pdf->Cell(0,0,$get_smk->name,0,1);
	
	$bulan = array("July","August","September","October","November","December","January","February","March","April","May","June");
		$now = new \DateTime('now');
	   	$month = $now->format('m');
	   	$year = $now->format('Y');
		
		$curr_bulan = $month - 6;
		if($curr_bulan <= 0){
			$curr_bulan = $month + 6;
		}
		
		
				
		
		$thn_ajaran_sis = $this->rep_sis->get_thn_ajaran($sis);
		$thn_ajaran_sis_count = $this->rep_sis->get_jum_thn_ajaran($sis);
		
		
		$tem_c_thn=1;
		$const=0;
		$const_inc=0;
		$total_all_cost=0;
		foreach($thn_ajaran_sis as $thn){
			$spp_rep = $this->rep_sis->get_spp_rep($sis, $thn['tahun_ajaran']);	
			$thn_ajaran=$this->rep_sis->get_tahun_ajaran();
			$pdf->SetFont('times','B',12);
			if($const_inc>=1){
				$pdf->SetY($const+10);
			}else{
				$pdf->SetY(60);
			}
			
			$const_inc=$const_inc+1;
			$pdf->Cell(0,5,'Tunggakan Tahun Ajaran : '.$thn['tahun_ajaran'],0,1);
			$pdf->SetFont('times','U',10);
			$pdf->Ln(3);
			$pdf->Cell(0,5,'Tunggakan SPP (Perbulan : Rp. '. number_format($spp_rep->biaya,2,",",".").') :',0,1);
			
			$pdf->SetFont('times','',10);
			$count_spp_rep='';
			$temp_c=0;
			if($thn['tahun_ajaran']==$thn_ajaran){
				for($i=1;$i<=$curr_bulan;$i++){
					if($i==1){
						if((empty($spp_rep->July))||($spp_rep->July=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."July";
								$temp_c=1;
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}else{
								$count_spp_rep=$count_spp_rep.", July";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==2){
						if((empty($spp_rep->August))||($spp_rep->August=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."August";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", August";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==3){
						if((empty($spp_rep->September))||($spp_rep->September=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."September";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", September";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==4){
						if((empty($spp_rep->October))||($spp_rep->October=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."October";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", October";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==5){
						if((empty($spp_rep->November))||($spp_rep->November=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."November";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", November";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==6){
						if((empty($spp_rep->December))||($spp_rep->December=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."December";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", December";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==7){
						if((empty($spp_rep->January))||($spp_rep->January=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."January";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", January";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==8){
						if((empty($spp_rep->February))||($spp_rep->February=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."February";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", February";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==9){
						if((empty($spp_rep->March))||($spp_rep->March=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."March";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", March";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==10){
						if((empty($spp_rep->April))||($spp_rep->April=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."April";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", April";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==11){
						if((empty($spp_rep->May))||($spp_rep->May=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."May";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", May";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==12){
						if((empty($spp_rep->June))||($spp_rep->June=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."June";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", June";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}
				}
			}else{
				for($i=1;$i<=12;$i++){
						
					if($i==1){
						if((empty($spp_rep->July))||($spp_rep->July=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."July";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", July";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==2){
						if((empty($spp_rep->August))||($spp_rep->August=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."August";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", August";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==3){
						if((empty($spp_rep->September))||($spp_rep->September=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."September";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", September";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==4){
						if((empty($spp_rep->October))||($spp_rep->October=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."October";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", October";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==5){
						if((empty($spp_rep->November))||($spp_rep->November=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."November";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", November";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==6){
						if((empty($spp_rep->December))||($spp_rep->December=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."December";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", December";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==7){
						if((empty($spp_rep->January))||($spp_rep->January=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."January";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", January";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==8){
						if((empty($spp_rep->February))||($spp_rep->February=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."February";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", February";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==9){
						if((empty($spp_rep->March))||($spp_rep->March=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."March";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", March";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==10){
						if((empty($spp_rep->April))||($spp_rep->April=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."April";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", April";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==11){
						if((empty($spp_rep->May))||($spp_rep->May=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."May";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", May";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}else if($i==12){
						if((empty($spp_rep->June))||($spp_rep->June=='')){
							if($temp_c==0){
								$count_spp_rep=$count_spp_rep."June";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
								$temp_c=1;
							}else{
								$count_spp_rep=$count_spp_rep.", June";
								$total_all_cost=$total_all_cost+$spp_rep->biaya;
							}
						}
					}	
				}	
			}
			
			$pdf->Cell(0,5,$count_spp_rep,0,1);
			$pdf->Ln(3);
			$pdf->SetFont('times','U',10);
			$pdf->Cell(0,5,'Biaya Siswa :',0,1);
			$pdf->SetFont('times','',10);
			$gtotal_maps = $this->rep_sis->get_total_map_biaya_siswa($sis, $thn['tahun_ajaran']);
			foreach($gtotal_maps as $gtotal_map){
				
				if($gtotal_map['dana_opsional']==1){
					if(($gtotal_map['periode'])<=($curr_bulan)){
						$gtrans 	= $this->rep_sis->get_total_trans_opsi($sis, $gtotal_map['id'], $gtotal_map['tahun_ajaran']);
						if((empty($gtrans))||($gtrans==NULL)){
							$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'Telah Dibayarkan Sebesar Rp.0.-',0,1);
						}else{
							$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'Telah Dibayarkan Sebesar Rp. '.number_format($gtrans->total,2,",","."),0,1);
						}
					}else{
						$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Belum Ditagihkan',0,1);
								$total_all_cost=$total_all_cost;
					}
					
					
				}else{
					$gtrans 	= $this->rep_sis->get_total_trans($sis, $gtotal_map['id'], $gtotal_map['tahun_ajaran']);
				if((empty($gtrans))||($gtrans==NULL)){
					
					if(($get_id_siswa->kelas)==($gtotal_map['kelas'])){
						if($gtotal_map['tahun_ajaran']==$thn_ajaran){
							if(($gtotal_map['periode'])<=($curr_bulan)){
								//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$gtotal_map['total'].'</font></b></td></tr>';
								//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								//$pdf->Cell(20,0,$gtotal_map['total'],0,1);
								
								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Rp. '.number_format($gtotal_map['total'],2,",","."),0,1);
								$total_all_cost=$total_all_cost+$gtotal_map['total'];
							}else{
								//$html .= '<tr><td><b><font color="#F87217">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': Belum Ditagihkan </font></b></td></tr>';
								//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								//$pdf->Cell(20,0,'Belum Ditagihkan',0,1);

								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Belum Ditagihkan',0,1);
								$total_all_cost=$total_all_cost;
							}
						}else{
							//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$gtotal_map['total'].'</font></b></td></tr>';
							//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							//$pdf->Cell(20,0,$gtotal_map['total'],0,1);
							

							$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'Rp. '.number_format($gtotal_map['total'],2,",","."),0,1);
							$total_all_cost=$total_all_cost+$gtotal_map['total'];
						}
					}else if(($get_id_siswa->kelas)>($gtotal_map['kelas'])){
						//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$gtotal_map['total'].'</font></b></td></tr>';
						//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
						//$pdf->Cell(20,0,$gtotal_map['total'],0,1);
						
						$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'Rp. '.number_format($gtotal_map['total'],2,",","."),0,1);
							
							$total_all_cost=$total_all_cost+$gtotal_map['total'];
					}else{
						//$html .= '<tr><td><b><font color="#F87217">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': Belum Ditagihkan </font></b></td></tr>';
						//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
						//$pdf->Cell(20,0,'Belum Ditagihkan',0,1);
						
						$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'Belum Ditagihkan',0,1);
							$total_all_cost=$total_all_cost;
					}
				}else{
					
					if(empty($gtrans->total)||$gtrans->total==NULL){
						$min_trans = $gtotal_map['total'];
					}else{
						$min_trans = $gtotal_map['total']-$gtrans->total;
					}
					if($kelas_sis==$gtotal_map['kelas']){
						if($gtotal_map['tahun_ajaran']==$thn_ajaran){
							if(($gtotal_map['periode'])<=($curr_bulan)){
								if($min_trans<=0){
									//$html .= '<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': LUNAS </b></td></tr>';
									//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
									//$pdf->Cell(20,0,'LUNAS',0,1);
									
									
									$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							$pdf->SetX(70);
							$pdf->Cell(0,-5,':',0,1);
							$pdf->SetX(75);
							$pdf->Cell(0,5,'LUNAS',0,1);
							$total_all_cost=$total_all_cost;
								}else{
									//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$min_trans.' </font></b></td></tr>';
									//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
									//$pdf->Cell(20,0,$min_trans,0,1);
									
									$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
									$pdf->SetX(70);
									$pdf->Cell(0,-5,':',0,1);
									$pdf->SetX(75);
									$pdf->Cell(0,5,'Rp. '.number_format($min_trans,2,",","."),0,1);
									$total_all_cost=$total_all_cost+$min_trans;
								}
							}else{
								//$html .= '<tr><td><b><font color="#F87217">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': Belum Ditagihkan </font></b></td></tr>';
								//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								//$pdf->Cell(20,0,'Belum Ditagihkan',0,1);
								
								
								
								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Belum Ditagihkan',0,1);
								$total_all_cost=$total_all_cost;
							}
						}else{
							if($min_trans<=0){
								//$html .= '<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': LUNAS </b></td></tr>';
								//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								//$pdf->Cell(20,0,'LUNAS',0,1);
								
								
								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'LUNAS',0,1);
								$total_all_cost=$total_all_cost;
							}else{
								//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$min_trans.' </font></b></td></tr>';
								//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								//$pdf->Cell(20,0,$min_trans,0,1);
								
								
								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Rp. '.number_format($min_trans,2,",","."),0,1);
								$total_all_cost=$total_all_cost+$min_trans;
							}
						}
					}else if(($get_id_siswa->kelas)>($gtotal_map['kelas'])){
						if($min_trans<=0){
							//$html .= '<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': LUNAS </b></td></tr>';
							//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							//$pdf->Cell(20,0,'LUNAS',0,1);
							
							
								$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'LUNAS',0,1);
								$total_all_cost=$total_all_cost;
						}else{
							//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$min_trans.' </font></b></td></tr>';
							//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
							//$pdf->Cell(20,0,$min_trans,0,1);
						
							$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
								$pdf->SetX(70);
								$pdf->Cell(0,-5,':',0,1);
								$pdf->SetX(75);
								$pdf->Cell(0,5,'Rp. '.number_format($min_trans,2,",","."),0,1);
								
								$total_all_cost=$total_all_cost+$min_trans;
						}
					}else{
						//$html .= '<tr><td><b><font color="#F87217">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': Belum Ditagihkan </font></b></td></tr>';
						//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
						//$pdf->Cell(20,0,'Belum Ditagihkan',0,1);
				
						$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
						$pdf->SetX(70);
						$pdf->Cell(0,-5,':',0,1);
						$pdf->SetX(75);
						$pdf->Cell(0,5,'Belum Ditagihkan',0,1);
						$total_all_cost=$total_all_cost;
					}
					
					
				}
				}
				
			}
			$tem_c_thn=$tem_c_thn+1;
			$const=$pdf->GetY();
		}
		$pdf->Ln(8);
		$pdf->SetFont('times','B',12);
		$pdf->Cell(0,5,'DSP',0,1);
		$pdf->SetFont('times','',10);
		$gtotal_maps = $this->rep_sis->get_total_map_cicilan_siswa($sis, $thn['tahun_ajaran']);
		foreach($gtotal_maps as $gtotal_map){
			$gtrans 	= $this->rep_sis->get_total_trans_cicilan($sis, $gtotal_map['id']);
			//print_r($gtrans->total);die();
			if(empty($gtrans)||$gtrans==NULL||$gtrans==0){
				$min_cicilan = $gtotal_map['total'];
			}else{
				
				$min_cicilan = $gtotal_map['total']-$gtrans;
			}
				
			if($min_cicilan<=0){
				//$html .= '<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': LUNAS</b></td></tr>';
				//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
				//$pdf->Cell(20,0,'LUNAS',0,1);
				
				$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
				$pdf->SetX(70);
				$pdf->Cell(0,-5,':',0,1);
				$pdf->SetX(75);
				$pdf->Cell(0,5,'LUNAS',0,1);
				$total_all_cost=$total_all_cost;
			}else{
				//$html .= '<tr><td><b><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;- '.$gtotal_map['jenis_pembayaran'].': '.$min_cicilan.'</font></b></td></tr>';	
				//$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
				//$pdf->Cell(20,0,$min_cicilan,0,1);
				$pdf->Cell(0,5,$gtotal_map['jenis_pembayaran'],0,1);
				$pdf->SetX(70);
				$pdf->Cell(0,-5,':',0,1);
				$pdf->SetX(75);
				$pdf->Cell(0,5, 'Rp. '.number_format($min_cicilan,2,",","."),0,1);
				
				
				$total_all_cost=$total_all_cost+$min_cicilan;
			}
			
		}
	$pdf->SetFont('times','B',12);
	$pdf->Ln(8);
	$pdf->Cell(0,5,"TOTAL TUNGGAKAN",0,1);
	$pdf->SetX(70);
	$pdf->Cell(0,-5,':',0,1);
	$pdf->SetX(75);
	$pdf->Cell(0,5,'Rp. '.number_format($total_all_cost,2,",","."),0,1);
	
	$pdf->Output();
	
	?>