<?php

include("dbconnect.php");
require("pdf_gen/fpdf2.php");
require("word2.php");
class PDF extends FPDF {
function Footer(){
include("dbconnect.php");
require("fpdf1.php");
		$this->SetFont('Times', '', 9);  
		$this->SetTextColor(0,33,56);
		$this->Cell(0,30,'Licensed to '.$vjhvkbnl, 0, 0, 'C');

    }
function RotatedText($x, $y, $txt, $angle)
{
	//Text rotated around its origin
	$this->Rotate($angle,$x,$y);
	$this->Text($x,$y,$txt);
	$this->Rotate(0);
}
function Header() {


}

}




$pdf = new PDF();



$pdf->SetFont('Arial','',12);


include("dbconnect.php");
$rece1=@$_GET['receipt1'];
$rece2=@$_GET['receipt2'];
$sssql="SELECT * FROM `feepayments` WHERE `receiptno` BETWEEN '$rece1' AND '$rece2'";
$resu = mysqli_query($con,$sssql);
while($row1dsd = mysqli_fetch_array($resu)){
$rec=@$row1dsd['receiptno'];
$pdf->AddPage();
$sql1 = 'SELECT * FROM school_info';
$result1 = mysqli_query($con,$sql1);
$row1 = mysqli_fetch_array($result1);

        $data2='Address:'.$row1['address'].' '.$row1['city'];
		$data3='Mobile No: '.$row1['phone'];
		$data4='Email:'.$row1['email'];
		$data5=$row1['logo'];
		$data55=$row1['signature'];
		$dat=date('d-m-Y');
		$data6='Fees Receipt generated on date : '.$dat;
		$data7='__________________________________________________________________________';

		$dec=$row1['school_name'];
		$ttype=$row1['type'];
		
//$sql2 = '';
		$line_thickness=0.04;
		$line_thickness_thicker= 0.6;
		$line_thickness_thick= 0.2;
		$pdf->SetFont('Times','',11);
		$dat1=date('d-m-Y');
		$paydateqw=strtotime($dat1);
		$payyear=date("Y",$paydateqw);
		
        $w = $pdf->GetStringWidth($pdf->title)+150;

        $pdf->SetTextColor(0);

        //$pdf->SetLineWidth(0);
		$pdf->SetFont('Times','',6);
		$pdf->SetFillColor(976,245,458);
		$pdf->Rect(0, 0, 300, 500, 'F');
		$pdf->SetFillColor(200,120,400);
		$pdf->Rect(10, 37, 130, 18, 'F');
		$pdf->SetFont('Times','',10);
		
        $pdf->Image($data5,10,10,20,'L');
		$pdf->Image($data5,120,10,20,'R');
		
       $pdf->Cell($w,9,$pdf->title,0,0,'C');
	    $pdf->Ln(5);
		/*$pdf->SetLineWidth(0.4);
		$pdf->Line(5,5,143,5);
		$pdf->SetLineWidth(0.4);
		$pdf->Line(5,205,143,205);
		$pdf->SetLineWidth(0.4);
		$pdf->Line(5,5,1,205);*/
		$pdf->SetTextColor(0,0,255);
       $pdf->Cell(130,0,"MINISTRY OF EDUCATION" ,0 ,0 ,'C');
	   $pdf->Ln(5);
		$pdf->SetTextColor(0,0,255);
       $pdf->Cell(130,0,$dec ,0 ,0 ,'C');
	    $pdf->Ln(5);
		$pdf->SetTextColor(0,0,0);
	   $pdf->Cell(130,0,$data2 ,0 ,0 ,'C');
	    $pdf->Ln(5);
	   $pdf->Cell(130,0,$data3 ,0 ,0 ,'C');
	    $pdf->Ln(5);
	   $pdf->Cell(130,0,$data4 ,0 ,0 ,'C');
        $pdf->Ln(5);
		$pdf->SetLineWidth(0.2);
		$pdf->Line(10,37,140,37);
		$pdf->SetFont('Times','',10);
		
		$sqlqq47=mysqli_query($con,"select *,(SELECT mode FROM pmodes WHERE pmodes.id=feepayments.modeofpayment) AS modes,
        (SELECT bankname FROM banks WHERE banks.id=feepayments.bank) AS bankname,
        (SELECT fullname FROM finance_users WHERE finance_users.id=feepayments.user_id) AS users,(SELECT academicyear FROM academicyears WHERE academicyears.id=feepayments.years) AS academicy,(select periods from academicyearsperiods where academicyearsperiods.id=feepayments.periods) as period,(select form from forms where forms.id=feepayments.form_id) as form,(select stream from streams where streams.id=feepayments.stream_id) as stream,(SELECT CONCAT(fname,' ',sname,' ',tname) from students where students.adm_no=feepayments.adm_no) as studentname,(SELECT s_type from students where students.adm_no=feepayments.adm_no) as studenttype from  feepayments where `receiptno`='$rec'");
		$rowas414=mysqli_fetch_array($sqlqq47);
		$yeearactive=$rowas414['years'];
		$studenttype=$rowas414['studenttype'];
		$periods=$rowas414['periods'];
		$formsidds=$rowas414['form_id'];
		$admno=$rowas414['adm_no'];
		$pdf->Cell(25,0,'Admission No:' ,0 ,0 ,'L');
        $pdf->Cell(60,0,'#'.$rowas414['adm_no'] ,0 ,0 ,'L');
        $pdf->Cell(23,0,'Receipt No:' ,0 ,0 ,'L');
        $pdf->Cell(0,0,'#'.$rec ,0 ,0 ,'L');
        $pdf->Ln(5);
		$pdf->SetFont('Times','',10);
		$pdf->Cell(25,5,'Student Name:' ,0 ,0 ,'L');
        $pdf->Cell(60,5,$rowas414['studentname'] ,0 ,0 ,'L');
		$date=date_create($rowas414['created_at']);
        $pdf->Cell(23,5,'Receipt Date:' ,0 ,0 ,'L');
        $pdf->Cell(0,5,date_format($date,"Y/m/d") ,0 ,0 ,'L');
        $pdf->Ln(5);
		$pdf->SetFont('Arial','',8);
		$pdf->RotatedText(148,170,$rec,90.5);
		$pdf->RotatedText(148,150,number_format($rowas414['amount_paid'],2),90.5);
		$pdf->RotatedText(148,100,$dec,90.5);
		$pdf->SetFont('Times','',10);
		$pdf->Cell(20,5,'Class:' ,0 ,0 ,'L');
        $pdf->Cell(40,5,$ttype.$rowas414['form'].' '.$rowas414['stream'] ,0 ,0 ,'L');
        $pdf->Cell(10,5,'Term:' ,0 ,0 ,'L');
		$pdf->Cell(15,5,$rowas414['period'] ,0 ,0 ,'L');
		$pdf->Cell(15,5,'Time:' ,0 ,0 ,'L');
		$pdf->Cell(0,5,strtoupper(date_format($date,"H:i:sa")) ,0 ,0 ,'L');
        $pdf->Ln(5);
		$pdf->SetLineWidth(0.2);
		//$pdf->Line(10,57,140,57);
		$pdf->SetFont('Times','B',11);
	   $pdf->Cell(10,5,'' ,1 ,0 ,'L');
		$pdf->Cell(20,5,'Votehead' ,1 ,0 ,'L');
		$pdf->Cell(20,5, 'Term Fee',1 ,0 ,'R');
		$pdf->Cell(20,5, 'Year Fee',1 ,0 ,'R');
		$pdf->Cell(20,5, 'RPT AMT',1 ,0 ,'R');
		$pdf->Cell(20,5, 'T Paid',1 ,0 ,'R');
		$pdf->Cell(20,5, 'Balance',1 ,0 ,'R');
		$pdf->SetFont('Times','',10);
		$pdf->SetLineWidth(0.4);
		//$pdf->Line(10,62,140,62);
		$pdf->SetFont('Arial','',8);
		$pdf->Ln(5);		
		$totaltermnfee=0;
		$totalyearfee=0;
		$totalereceipt=0;
		$totalpaid=0;
		$totalbalance=0;
		$FFF=1;
		$erer=1;
		$sqlqq=mysqli_query($con,"select * from  voteheads where `academicyear`='$yeearactive' order by priority ASC");
		while($rowasasa=mysqli_fetch_array($sqlqq)){
		$FDFGGDFG=$rowasasa['id'];
		$FDFGGDFGnam=$rowasasa['votehead'];
		$voteheadiddd=$rowasasa['id']; 
		$sqlqq14=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where adm_no='$admno' and `academicyear`='$yeearactive' and academicperiod='{$periods}' and votehead='$voteheadiddd' and transaction_type='1'");
		$rowasasa14=mysqli_fetch_array($sqlqq14);
		$sqlqq141=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where adm_no='$admno' and `academicyear`='$yeearactive'  and votehead='$voteheadiddd' and transaction_type='1'");
		$rowasasa141=mysqli_fetch_array($sqlqq141);
		$sqlqq141s=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where adm_no='$admno' and `academicyear`='$yeearactive'  and votehead='$voteheadiddd' and transaction_type='2'");
		$rowasasa141s=mysqli_fetch_array($sqlqq141s);
		$sqlqq141s1=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where `transaction`='$rec'  and votehead='$voteheadiddd' and transaction_type='2'");
		$rowasasa141s1=mysqli_fetch_array($sqlqq141s1);
		$totaltermnfee=$totaltermnfee+$rowasasa14['amt'];
		$totalyearfee=$totalyearfee+$rowasasa141['amt'];
		$totalereceipt=$totalereceipt+$rowasasa141s1['amt'];
		$totalpaid=$totalpaid+$rowasasa141s['amt'];
		$balance=$rowasasa141['amt']-$rowasasa141s['amt'];
		$totalbalance=$totalbalance+$balance;
		$pdf->Cell(10,5,$FFF ,1 ,0 ,'L');
		$pdf->Cell(20,5,$FDFGGDFGnam ,1 ,0 ,'L');	
		$pdf->Cell(20,5, number_format($rowasasa14['amt'],2),1 ,0 ,'R');	
		$pdf->Cell(20,5, number_format($rowasasa141['amt'],2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($rowasasa141s1['amt'],2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($rowasasa141s['amt'],2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($balance,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$FFF++;
		}
		$pdf->SetFont('arial','B',9);
		$pdf->Cell(10,5,'' ,1 ,0 ,'L');
		$pdf->Cell(20,5,'Totals' ,1 ,0 ,'L');	
		$pdf->Cell(20,5, number_format($totaltermnfee,2),1 ,0 ,'R');	
		$pdf->Cell(20,5, number_format($totalyearfee,2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($totalereceipt,2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($totalpaid,2),1 ,0 ,'R');
		$pdf->Cell(20,5, number_format($totalbalance,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$sqll090=mysqli_query($con,"select orders from academicyearsperiods where id='$periods'");
		$rooowsasss=mysqli_fetch_array($sqll090);
		$oooerders=$rooowsasss['orders'];
		
		$sqlqq14yyyyyyy=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where adm_no='$admno' and `academicyear`='$yeearactive' and transaction_type='1' and academicperiod IN (SELECT id from academicyearsperiods where orders<='$oooerders' and academicyear='$yeearactive')");
		$rowasasa14yyy=mysqli_fetch_array($sqlqq14yyyyyyy);
		$totalbalancefee1=$rowasasa14yyy['amt'];
		
		$sqlqq14yyyyyyy1=mysqli_query($con,"select SUM(amount) as amt from  studentsfee where adm_no='$admno' and `academicyear`='$yeearactive' and transaction_type='2' and transaction<='$rec' and academicperiod IN (SELECT id from academicyearsperiods where orders<='$oooerders' and academicyear='$yeearactive')");
		$rowasasa14yyyy=mysqli_fetch_array($sqlqq14yyyyyyy1);
		$totalbalancefee2=$rowasasa14yyyy['amt'];
		$totalbalancefee=$totalbalancefee1-$totalbalancefee2;
		$pdf->SetFont('arial','',9);
		$pdf->Cell(76,5,' ' ,0 ,0 ,'L');
		$pdf->Cell(34,5,'Total Expected ' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($totalyearfee,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$ssqlfeeo=mysqli_query($con,"SELECT SUM(amount) AS amt FROM `overpayments` WHERE adm_no='$admno' and `academicyear`='$yeearactive' AND receipt_no<='$rec'"); 
        $rowasa75474=mysqli_fetch_array($ssqlfeeo);
		$amtoverpay=$rowasa75474['amt'];
		$totalpaid45=$amtoverpay+$totalpaid;
		$pdf->SetFont('Times','',9);
		$pdf->Cell(76,0,'Amount in word: ' ,0 ,0 ,'L');
		$pdf->SetFont('arial','',9);
		$pdf->Cell(34,5,'Total Fees Paid' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($totalpaid45,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$pdf->SetFont('Times','',9);
		$pdf->Cell(76,5,' #'.convert_number_to_words($rowas414['amount_paid']).' only.#' ,0 ,0 ,'L');
		$pdf->SetFont('arial','',9);
		$pdf->Cell(34,5,'Rec. Paid Amount' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($rowas414['amount_paid'],2),1 ,0 ,'R');
		$pdf->Ln(5);
		$pdf->Cell(76,5,' ' ,0 ,0 ,'L');
		$pdf->Cell(34,5,'Term Fee Balance' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($totalbalancefee,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$pdf->Cell(76,5,' ' ,0 ,0 ,'L');
		$pdf->Cell(34,5,'Year Fee Balance' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($totalbalance,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$pdf->Cell(76,5,' ' ,0 ,0 ,'L');
		$pdf->Cell(34,5,'Total Overpayment' ,1 ,0 ,'L');
		$pdf->Cell(20,5, number_format($amtoverpay,2),1 ,0 ,'R');
		$pdf->Ln(5);
		$pdf->Ln(5);
		$pdf->Cell(30,5,'Payment Mode:',1 ,0 ,'L');
		$pdf->Cell(30,5,$rowas414['modes'],1 ,0 ,'L');
		$pdf->Cell(20,5,'',0 ,0 ,'L');
		$pdf->Cell(0,5,'Bursar',0 ,0 ,'L');
		$pdf->Ln(5);
		$pdf->Cell(30,5,'Paid by:' ,1 ,0 ,'L');
		$pdf->Cell(30,5,$rowas414['paidby'],1 ,0 ,'L');
		$pdf->Ln(5);
		$pdf->Cell(30,5,'Served by:' ,1 ,0 ,'L');
		$pdf->Cell(30,5,$rowas414['users'],1 ,0 ,'L');
		$pdf->Cell(20,5,'',0 ,0 ,'L');
		$pdf->Image($data55,95,101+5*$FFF,30,'R');
		$pdf->Cell(0,5,'________________________',0 ,0 ,'L');
		$pdf->Ln(5);
		$pdf->Cell(30,5,'Bank :' ,1 ,0 ,'L');
		$pdf->Cell(30,5,$rowas414['bankname'],1 ,0 ,'L');
		$pdf->Ln(5);
		$dateposted=date_create($rowas414['datedeposited']);
		$pdf->Cell(30,5,'Date Deposited:',1 ,0 ,'L');
		$pdf->Cell(30,5,date_format($dateposted,"Y/m/d"),1 ,0 ,'L');
		$pdf->Ln(5);
		$pdf->Cell(30,5,'Bank Slip:' ,1 ,0 ,'L');
		$pdf->Cell(30,5,$rowas414['bankslipno'],1 ,0 ,'L');
		$pdf->Ln(5);
		$pdf->SetLineWidth(0.3);
		$pdf->Line(10,60+(5*$FFF),10,94+(5*$FFF));
		$pdf->Line(80,60+(5*$FFF),80,94+(5*$FFF));
		$pdf->Line(10,94+(5*$FFF),80,94+(5*$FFF));
		
		$pdf->SetLineWidth(0.3);
		$pdf->Line(71,95+(5*$FFF),71,125+(5*$FFF));
		$pdf->Line(71,95+(5*$FFF),140,95+(5*$FFF));
		$pdf->Line(140,95+(5*$FFF),140,125+(5*$FFF));
		$pdf->Line(71,125+(5*$FFF),140,125+(5*$FFF));

}
// call the table creation method
//$pdf->Cell(0,5,$data1 ,1 ,0 ,'L');
//$pdf->BuildTable($header,$data);
$pdf->Output();


?>