<?php
/* include("../../../TaquaLB/Ajax/CGI/PHP/config.php"); //the configuration object (connection parameters)
include("../../PHP/getinfo.php");//hold basic functions to perform some common database operations or request*/
 //the caller or script that include it should also include the config and getinfo
 //simpaydate=29/01/2019&simbatch=8&simstudy=5&simfac=4&simdept=1&simprog=1&simlvl=1&simstate=3&simgender=M&simstatus=S&simmodeentry=1&simpaypol=1-2&PayID=2
 
	

	$RegNo = isset($_REQUEST["RegNo"]) ? $_REQUEST["RegNo"] : '';

	//get the student payment info by the itemno from order_tb
	if(trim($RegNo) !== ''){
		/*ID 	ItemNo 	TransNum 	ItemName 	ItemDescr 	Amt 	Currency 	RegNo 	Sem 	Lvl 	ItemID 	Paid 	RegDate 	Ses*/
	
	//$StuddbPre = StudPreByPayID($PayID,$RegID);
	//$StuddbPre = (isset($_GET['pre']))?$_GET['pre']:"p";
	/*if((int)$PayID == 3){
	$StuddbPre = "p";	
	}*/
	//echo "$RegNo,'',$StuddbPre,$RegID";
	$StudD = GetBasicInfo($RegNo,"",'');
	
	if(!is_array($StudD)){
		//$StudD = GetBasicInfo($RegNo,"","p",$RegID);
		$StudD = $dbo->SelectFirstRow("pstudentinfo_tb","*, CONCAT(SurName,' ',FirstName,' ',OtherNames) as Name","RegNo='".$dbo->SqlSafe($RegNo)."' OR JambNo='".$dbo->SqlSafe($RegNo)."'",MYSQLI_ASSOC);
		$studpref = "p";
		
	// $studpref = "";
		if(!is_array($StudD)){
	//try getting Details from payee_tb
	$StudD = $dbo->SelectFirstRow("payee_tb","","PayeeID='$RegNo' LIMIT 1");
	if(is_array($StudD)){
		$studpref = "g";
		$otherdet = $StudD['OtherDet'];
			if(trim($otherdet) != ""){
				$otherdet = json_decode($otherdet,true);
				$StudD = array_merge($StudD,$otherdet);
			}
	}

	}
	} 
 }
//print_r()


//ModeOfEntry
$name = "";
if(is_array($StudD)){
	$name = $StudD['Name'];
	//add other det to array
	if(trim($StudD['OtherDet']) != ""){
		$StudD = array_merge($StudD,json_decode($StudD['OtherDet'],true));
	}
}


$school = GetSchool();
$schoolType = SchoolType($school['Type']);
//$thirdPPayIDarr = array("ETRANZACT"=>"PAYEE ID","REMITA"=>"RRR");
//$thirdPPayID = isset($thirdPPayIDarr[$school["PayThirdParty"]])?$thirdPPayIDarr[$school["PayThirdParty"]]:"REFERENCE NO.";

//$pdf->mpdf->showImageErrors = true;
//genearte pdf slip
$pdf->Banner("Wallet History",array("LogoSize"=>"100px*100px","WaterMark"=>$school['Abbr']),$school);

$pdf->Panel();
 $pdf->InfoBox(4,"text-transform:uppercase");
 $pdf->InfoTitle("PAYMENT DETAILS");
 $pdf->Info("full name:",$name);
 $pdf->Info("Registration Number:",$RegNo);
//  $pdf->Info("$thirdPPayID:",$transNo);
//  $pdf->Info("Payment Type:",$payType);
 /*if(!isset($order['PayScope']) || $order['PayScope'] != "w"){ //if not wallet payment
 $pdf->Info("Payment Policy:",$payPol);
 } else{
	$pdf->Info("Description:",$payDescr);	 
 } */
 
$LevelName = LevelName(StudLevel($RegNo),$StudD['StudyID']);
$Class = StudClass($RegNo);
 $pdf->Info("Class:","$LevelName"."({$Class['Name']})");
 $dts = new DateTime();
$dts = $dts->format(" (D, F Y | h:i A)");
 $pdf->Info("Date:",$dts);

 $pdf->_InfoBox();
$pdf->_Panel();

//get all wallet transactions
$walTrans = $dbo->Select("wallet_tb","","RegNo='$RegNo' ORDER BY ID DESC");
$bal = NULL;
if(is_array($walTrans) && $walTrans[1] > 0){
	$pdf->Table("");
$pdf->TableHead(array("Date","CREDIT","DEBIT","BALANCE", "REMARK"));
while($indwal = $walTrans[0]->fetch_assoc()){
	$bal = is_null($bal)?$indwal['Balance']:$bal;
	$pdf->TableRow(array(date_format(date_create($indwal['TransDate']),"d, M Y | h:i A"),$indwal['Flow'] == 0?number_format($indwal['Amt'], 2, '.', ','):'',$indwal['Flow'] == 1?number_format($indwal['Amt'], 2, '.', ','):'',number_format($indwal['Balance'], 2, '.', ','),$indwal['TransDetails']));
	
}

// $pdf->TableRow(array('15, Dec 2022','','12,000','0.00',"School Fee Payment"));
				

 $pdf->Dump('<tr>
     <th colspan="3" style="font-weight: bolder; text-align:right"><strong>Balance as at '.$dts.'</strong></td><th colspan="2" style="text-align:left">'.number_format($bal, 2, '.', ',').'</th>
   </tr>'); 
$pdf->_Table();
}else{
	$pdf->Dump('<div style="text-align:center"><h2>No Transaction Yet</h2></div>');
}



  
   
   
   /* if(strtolower($school["PayThirdParty"]) == "remita"){
     $html .= '<img src="'.$pdf->BaseConfigPath.'UserImages/App/Images/logo.png" alt="REMITA LOGO" width="300" />';
   }else{
	  $html .= '<span style="padding-bottom:30px"> Sterling Bank | UBA | FCMB | Zennith Bank | Enterprise Bank | Eco Bank | Diamond Bank | Union Bank | Unity Bank | WEMA | First Bank | GTB | Skye Bank | Keystone Bank | Access Bank</span><hr />'; 
   } */
//    $html .= "</p><hr />";
$FooterNote = "Wallet History";
$pdf->FooterNote($FooterNote,$html);
 /* if($Channel == "OFFLINE"){
	 $pdf->Dump('<div style="page-break-after: always;"></div>');
	
	 $baseurl = "../../";
	 $OrderID = $order['ID'];
	 $Waterm = $pstatus;
	 include $baseurl."cportal/Reports/Payment/offlinereceipt.php";
   } */

$pdf->Finish();
?>