<?php require_once("includes/initialize.php");
require_once("phpqrcode/qrlib.php");
if (!$session->is_logged_in()) {
    redirect_to("index.php");
}
$user_data = Userdata::find_by_id($session->user_id);
$biodata = Biodata::find_by_id($user_data->formno, $user_data->email);
  $id=$session->user_id;


echo $biodata->formno."<br>";
echo   $biodata->email;
$transact_feedback = Schoolfees::findschoolfees($user_data->formno, $user_data->email);

 echo $transact_feedback->formno."<br>";
 echo  $transact_feedback->email;
//}else
if (!$transact_feedback){
redirect_to ("http://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php");
}else { 
    $transact_feedback1 = Schoolfees::authenticate($user_data->formno, $user_data->email);

echo $transact_feedback1->formno."rieieiieiei"."<br>";
 echo  $transact_feedback1->email;
 echo $biodata->courses."zjdjjdjdsdsfjkhjjki"."<br>";
$dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);

$alldp = DEPARTMENTCLASS::find_all($dp->faculty);


$totamount = 0;
foreach ($alldp as $aldp) {
   echo  $faculty = $aldp->faculty;
}
$pay_cat = '';
if ($faculty == 'Engineering' or $faculty == 'Applied Sciences' or $faculty == 'Environmental Studies') {
    $pay_cat = 'science';
} elseif ($faculty == 'Management Sciences') {
    $pay_cat = 'nonscience';
}
$level = $biodata->programme;
$level = $level . " " . "I";
echo "<br>".$level;
//$pay_settings = Pay_settings::authenticate(1,$level,$pay_cat);
//$total_sc_fees=0;
$adm_type = (substr($user_data->formno, 0, 2));
if (($adm_type == 'PU') or ($adm_type == 'FT')) {
            $adm_type = 'regular';

        } elseif ($adm_type == 'DP') {

            $adm_type = 'dailypt';
        }
$count = 0;
echo "<br>".$adm_type."<br>";
//$total_sc_fees = 0;
echo "<br>".$level ." ". $pay_cat ." ". $adm_type."<br>";
$total = Pay_settings::find_sch_fees(3, $level, $pay_cat, $adm_type);


//echo $pay_settings->amount;
foreach ($total as $fees) {
   echo  "<br>".$totamount = $totamount + $fees->amount;
}
date_default_timezone_set('Africa/Lagos');
//echo $transact_feedback1->amount."khkhk";
//echo $totamount.'00';
//echo $transact_feedback1->amount;
//echo $totamount.'.00';

//echo $user_data->formno ." ". $user_data->email."".$transact_feedback1->responsecode;
if ($totamount.'.00' == $transact_feedback1->amount && $transact_feedback1->responsecode=='00'){
    //echo $transact_feedback->txt_ref;
$output = $transact_feedback1->txt_ref.'- '.$transact_feedback1->formno.' '.$transact_feedback1->surname .' '.$transact_feedback1->othernames.'  School Fees: PAID';

QRcode::png($output,$transact_feedback1->formno.'.png');

//A4 width: 219mm
//default margin : 10mm each side
//writable horizontal : 219 - (10*2)=189mm
if ($user_data->std_process_id == 3){
 
 		 $user_level = $user_data->std_process_id + 1;
 	
		 Userdata::update($id, $user_level);
		 
}
//echo $id." ". $user_level;
class PDF extends FPDF
{

    function Header()
    {

        $this->SetFont('Arial', 'B', 16);

        $this->Cell(12);
        $this->Image('images/icon.png', 10, 13, 22, 22);
        $this->Cell(189, 5, 'OSUN STATE COLLEGE OF TECHNOLOGY, ESA OKE.', 0, 1, 'C');
        $this->Ln(1);
        $this->SetFont('Arial', 'B', 12);
        $this->Cell(189, 5, 'P.M.B 1011, ESA-OKE, OSUN STATE.', 0, 1, 'C');
        $this->Ln(19);
//$this->Cell(189,1,'',0,1);
//$this->Cell(189,5,'',0,1);

        $this->SetTextColor(255, 255, 255);
        $this->SetFillColor(0, 0, 0);
        $this->SetFont('Courier', 'B', 14);

        $this->Cell(189, 5, 'School Fees Payment Receipt', 1, 1, 'C', true);


        $this->Cell(189, 5, "", 0, 1);

    }

    function Footer()
    {
        $this->Cell(189, 30, '', 0, 1);//end of line
        $this->Cell(189, 5, '', 0, 1);//end of line
        $this->Cell(189, 5, '', 0, 1);//end of line
        $this->Cell(189, 2, '', 0, 1);//end of line
        $this->SetTextColor(255, 255, 255);
        $this->SetFillColor(0, 0, 0);
        $this->SetFont('Courier', 'B', 7);
        $this->Cell(189, 5, 'Directorate of ICT, ESA OKE. ' . date('Y', time()) . ' All Rights Reserved.', 1, 1, 'C', true);

    }

    function Footer2()
    {
        $this->SetFont('Arial', '', 8);
        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 1, 'C');
    }

}


$pdf = new PDF('p', 'mm', 'A4');

$pdf->AddPage();


$pdf->Image('images/img2.png', 60, 55, 100, 100);
$pdf->Cell(189, 5, '', 0, 1);

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

$pdf->Cell(30, 5, 'Form no: ', 0, 0);
$pdf->Cell(40, 5, strtoupper($transact_feedback1->formno), 0, 0);

$pdf->Cell(50, 5, '', 0, 0);//end of line

//$pdf->Cell(80 ,5,'',0,0);
$pdf->Cell(20, 5, 'Date: ', 0);
//date("jS \of F, Y", strtotime($ftranzact->verified_date));
$pdf->Cell(49, 5, date('d/m/Y h:i a',strtotime($transact_feedback1->datetime)), 0, 1);//end of line


$pdf->Cell(30, 5, 'Department: ', 0, 0);
$pdf->Cell(159, 5, strtoupper($transact_feedback1->department), 0, 1);//end of line

//$pdf->Cell(50, 5, '', 0, 0);//end of line


//$pdf->Cell(120, 5,'',0,0);
//$pdf->Cell(20, 5, 'Level: ', 0);
//$pdf->Cell(49, 5, strtoupper($level), 0, 1);//end of line

$pdf->Cell(30, 5, 'Phone: ', 0, 0);
$pdf->Cell(90, 5, $transact_feedback1->phone, 0, 0);
$pdf->Cell(20, 5, 'Level: ', 0);
$pdf->Cell(49, 5, strtoupper($level), 0, 1);//end


//make a dummy empty cell as a vertical spacer
$pdf->Cell(189, 5, '', 0, 1);//end of line


$pdf->Cell(189, 5, 'FULLNAME: ' . strtoupper($transact_feedback1->surname . ' ' . $transact_feedback1->othernames), 0, 1, 'C');
$pdf->Cell(189, 3, '', 0, 1);


$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(10, 5, '', 0, 0);

$pdf->Cell(10, 5, 'S/N', 1, 0, 'C');
$pdf->Cell(90, 5, 'Description', 1, 0, 'C');
$pdf->Cell(25, 5, '', 1, 0);
$pdf->Cell(34, 5, 'Amount', 1, 0, 'C');//end of line
$pdf->Cell(20, 5, '', 0, 1);

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

//Numbers are right-aligned so we give 'R' after new line parameter
$count = 0;

foreach ($total as $fees) {
    //$totamount=$totamount + $fees->amount;
    //}
    $pdf->Cell(10, 5, '', 0, 0);

    $pdf->Cell(10, 5, $count += 1, 1, 0);

    $pdf->Cell(90, 5, $fees->fees_description, 1, 0);
    $pdf->Cell(25, 5, '', 1, 0);
    $pdf->Cell(34, 5, $fees->amount, 1, 0, 'R');
    $pdf->Cell(20, 5, '', 0, 1);
}
//end of line

/*$pdf->Cell(20 ,5,'',0,0);
$pdf->Cell(90 ,5,'Additional charges',1,0);
$pdf->Cell(25  ,5,'',1,0);
$pdf->Cell(34 ,5,'0.00',1,1,'R');
$pdf->Cell(20 ,5,'',0,0);*/

//end of line
/*$pay_settings->charge_interswitch + $pay_settings->charge_omoluabi*/

$pdf->Cell(120, 5, '', 0, 0);
$pdf->Cell(25, 5, 'Total Due', 1, 0);
$pdf->Cell(4, 5, 'N', 1, 0);
$pdf->Cell(20, 5, $totamount, 1, 1, 'R');//end of line

/*$pay_settings->amount+$pay_settings->charge_interswitch + $pay_settings->charge_omoluabi*/

// $pdf->image($transact_feedback1->formno.'.png',185,15,25,25,'png');
$pdf->image($biodata->formno.'.png',95,155,30,30,'png');


$pdf->Output();
}
} 
?>