<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
include('includes/session.inc');
$Title = _('Print Timesheet for GFS');
include('includes/SQL_CommonFunctions.inc');
include ('includes/htmlMimeMail.php');

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
//include('includes/header.inc');
if (isset($_GET['id'])) {
		$_SESSION['id'] = stripslashes($_GET['id']);
	}
	$id = $_SESSION['id'];


$printdate = date("d-m-Y");

$sqlcount = "select count(*) as totalcount from payrun_details where id = '" . $id."' ";

		$resultc=DB_query($sqlcount);
	$myrowc=DB_fetch_array($resultc);
			$totalcount = $myrowc['totalcount'];

		//		echo $totalcount ;
	 //its not an email just print the invoice to PDF
	//	$pdf->OutputD('PaySlip-Period_' . $id. '.pdf');

//get all emails in array
// Define temporary CSV file
$tempFile = "BulkEmailPayslipReport-ID-".$id.".csv";

// Open the file for writing
$file = fopen($tempFile, "w");
 fputcsv($file, ["ID", "Name", "Email","Status"]);
	

		$SQL = "SELECT  payrun_details.*,
								employeemaster.tin,
								employeemaster.fnpf,
								employeemaster.first_name,
								employeemaster.middle_name,
								employeemaster.last_name,
								employeemaster.job_role,
								employeemaster.ytd_income_tax_withheld,
								employeemaster.ytd_srt_tax_withheld,
								employeemaster.ytd_ecal_tax_withheld,
								employeemaster.ytd_gross
									
		                            FROM payrun_details 
									INNER JOIN employeemaster
									on payrun_details.employeeid = employeemaster.employeeid
									
		                            WHERE payrun_details.id = '" . $id."' 
									AND emailed = '0'
									
									";

$result=DB_query($SQL);



	while ($myrow50=DB_fetch_array($result)){

			
$PaperSize = 'A4_Landscape';// PDFStarter.php: $Page_Width=842; $Page_Height=595; $Top_Margin=30; $Bottom_Margin=30; $Left_Margin=40; $Right_Margin=30;
include('includes/PDFStarter.php');
$pdf->addInfo('Title', _('payslip') );
$pdf->addInfo('Subject', _('payslip') );
$FontSize = 12;
	
$line_height = 12;// Recoeommended: $line_height = $x * $FontSize.
	$headinggap = 6;	
	$testcount =0;
		
$SQLcalendar = "SELECT *
											
		                            FROM calendar_management
		                            WHERE id ='" . $myrow50['id']."' ";
	$resultcalendar=DB_query($SQLcalendar);
	
$myrow51=DB_fetch_array($resultcalendar);

$SQLemployee = "SELECT *
											
		                            FROM employeemaster
		                            WHERE employeeid ='" . $myrow50['employeeid']."' ";
	$resultemployee=DB_query($SQLemployee);
	
$myrowemployee=DB_fetch_array($resultemployee);

$baserate= $myrow50['base_wage'];
	$employeeemail = $myrowemployee['email_address'];
	$startdate= date("d-m-Y", strtotime($myrow51['start_date']));
	$enddate= date("d-m-Y", strtotime($myrow51['end_date']));
	$date = date('d-m-Y');
	$employee = $myrow50['employeeid'];
			$fullname = $myrow50['full_name'];
$manage= $myrowemployee['management'];
		
$SQLdepart = "SELECT departmentname
											
		                            FROM department
		                            WHERE departmentid ='" . $myrow50['department']."' ";
	$resultdepart=DB_query($SQLdepart);
	
$myrowdepart=DB_fetch_array($resultdepart);

	//	$totaldeductions = ($myrow50['payrun_details.fnpf'] + $myrow50['fixed_deductions'] + $myrow50['other_deductions']);

		include('includes/PDFpayslipheader.inc');

  $topheading = $YPos + 35;
		
		
		//timesheet
 

$rowCount= 0;
	$cellcount = 0;	
	$cellcount2 = 6;
$totalhours = 0;	
		
//while ($rowCount <= $num) {
	  

		

	
	
	//timesheet
		
		if ($myrow50['normal_pay'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Timesheet",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Normal Pay",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,$myrow50['normal_hours'] ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,$baserate,'left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['normal_pay'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
			// timehalf
		if ($myrow50['timehalf_amount'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Timesheet",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Time and half",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,$myrow50['timehalf_hours'] ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,($baserate * 1.5),'left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['timehalf_amount'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}		
				
			if ($myrow50['double_amount'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Timesheet",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Double Pay",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,$myrow50['double_hours'] ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,($baserate * 2),'left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['double_amount'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}	
		if ($myrow50['public_holiday_amount'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Timesheet",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Public Holiday ",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,$myrow50['public_holiday_hours'],'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,$baserate,'left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['public_holiday_amount'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['premium'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Premium",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Premium Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['premium'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}	
		
		if ($myrow50['stay_away'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"stay away",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"stay away Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['stay_away'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['call_out_allowances'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"callout",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Call Out Allowances",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,' ' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'nonfnpf','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['call_out_allowances'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['sick_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"sickleave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Sick Leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['sick_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['bl_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"bleave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Bereavement Leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['bl_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['annual_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"AL-leave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Annual leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['annual_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		
		if ($myrow50['paternity_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"P-leave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Paternity leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['paternity_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['maternity_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"M-leave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Maternity leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['maternity_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['family_care_leave'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"fm-leave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Family Care Leave Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['family_care_leave'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['other_allowances_fnpf'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"allowances",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Other Allowances(Fnpf deductable) Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['other_allowances_fnpf'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['other_allowances_nonfnpf'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"AL-leave",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Other Allowances (fnpf not deductable) Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['other_allowances_nonfnpf'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		if ($myrow50['meal_allowance'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"meal",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Meal Allowance Gross Value",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,$myrow50['meal_allowance'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
	if ($myrow50['fixed_deductions'] > 0){
	
			
			//get data from extra table
			
			$SQLextra = "SELECT payrun_details_extra.fixeddeduction_id,payrun_details_extra.name, 
								payrun_details_extra.ref_no,
								payrun_details_extra.amount
		                            FROM payrun_details_extra
								
									
		                            WHERE payrun_details_extra.payid = '" . $myrow50['payid']."' 
									
									";

$resultextra=DB_query($SQLextra);
			
			while ($myrow50extra=DB_fetch_array($resultextra)){
				
				
				//get balance
					$SQLbalance= "SELECT  fixeddeductions.balance_left,fixeddeductions.total_amount_to_deduct,fixed_deduction_codecategory.name
									
		                            FROM fixeddeductions
									INNER JOIN fixed_deduction_codecategory
									on fixeddeductions.name = fixed_deduction_codecategory.id
		                            WHERE fixeddeductions.id = '" . $myrow50extra['fixeddeduction_id']."'
									
									";

$resultbalance=DB_query($SQLbalance);
				$myrowbalance=DB_fetch_array($resultbalance);
			
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Fixed Deductions",'left');
		
		
	
	
	if ($myrowbalance['balance_left'] <='0.00'){
		
		$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,$myrowbalance['name'].' ref: '.$myrow50extra['ref_no'],'left');
	}else{
		
		$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,400,$FontSize,$myrowbalance['name'].' ref: '.$myrow50extra['ref_no'].' Total Amount: '.$myrowbalance['total_amount_to_deduct'].' Balance: '.$myrowbalance['balance_left'],'left');
		
		
	}
	
		
			
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,-$myrow50extra['amount'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
			
			
		}

	if ($myrow50['employee_fnpf'] > 0){
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"fnpf",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"fnpf",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,-$myrow50['employee_fnpf'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
	}
		
		if ($myrow50['income_tax_to_withhold'] > 0){
	
				  $ListCount ++;
				

		$YPos -= $line_height;// Increment a line down for the next line item.
				
      
		if ((mb_strlen($myrow1['narrative']) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($myrow1['narrative']) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finsih off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
		} //end if need a new page headed up

			
								//$myrow6 = DB_fetch_array($result6) ;
				
				
				//write to pdf
				
				//$total = $myrow7979['quantity'] * $myrow3['materialcost'] ;
			    
			 
			  // $grandtotal += $total;
				
				//$costprice = locale_number_format($myrow3['materialcost'],2);
				
				//$roundtotal= locale_number_format($total,2);

	
			
			$FontSize = 7;// Font size for the line item.

		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount,200,$FontSize,"Tax",'left');
		
		
	
	
	
	
		
			$LeftOvers = $pdf->addTextWrap(150, $YPos+12 - $cellcount,200,$FontSize,"Income Tax",'left');
		
			
		
		
			
			$LeftOvers = $pdf->addTextWrap(470, $YPos+12 - $cellcount,200,$FontSize,'' ,'left');
				
		   
			
			$LeftOvers = $pdf->addTextWrap(550, $YPos+12 - $cellcount,200,$FontSize,'','left');
				
			
			$LeftOvers = $pdf->addTextWrap(630, $YPos+12 - $cellcount,200,$FontSize," ",'left');
					
			$LeftOvers = $pdf->addTextWrap(700, $YPos+12 - $cellcount,200,$FontSize,-$myrow50['income_tax_to_withhold'] ,'left');
				
		 
		

		
		
	
		
		$LeftOvers = $pdf->addTextWrap(780, $YPos+12 - $cellcount,200,$FontSize,$myrowdepart['departmentname'],'left');
		
			
		
	
		
		//$totalamount   = $myrow3['amount'] ;
		//$totalhours +=$totalamount;
		
		
		$cellcount = $cellcount * 0.5;
		$cellcount2 = $cellcount2 + 6;
		
		
			
			
			// Prints salesorderdetails.narrative:
		$FontSize2 = $FontSize*0.8;// Font size to print salesorderdetails.narrative.
		$Width2 = $Page_Width-$Right_Margin-145;// Width to print salesorderdetails.narrative.
		$LeftOvers = trim($myrow1['narrative']);
		//**********
		$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
		$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
		$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
			
			while (mb_strlen($LeftOvers) > 1) {
			$YPos -= $FontSize2;
			if ($YPos < ($Bottom_Margin)) {// Begins new page.
				include ('includes/PDFpayslipheader.inc');
			}
			$LeftOvers = $pdf->addTextWrap(145, $YPos, $Width2, $FontSize2, $LeftOvers);
		}
			
			if ((mb_strlen($quoteterms) >200 AND $YPos-$line_height <= 75)
			OR (mb_strlen($quoteterms) >1 AND $YPos-$line_height <= 62)
			OR $YPos-$line_height <= 50){
		/* We reached the end of the page so finish off the page and start a newy */
			include ('includes/PDFpayslipheader.inc');
	 //end if need a new page headed up
			}
			
		}
		
	//$rowCount++;
//}


//total
		
		$pdf->addTextWrap(60, $Bottom_Margin+(3*$line_height+10),200,$FontSize,"NETPAY",'left');

$pdf->addTextWrap(700, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$myrow50['net_pay'],'left');
		/* Print a column vertical line  with enough space for the footer */
			/* draw the vertical column lines to 4 lines shy of the bottom to leave space for invoice footer info ie totals etc */
			//the first part is the horizontal path, second is from top 
$pdf->line(143, $topheading,143,$Bottom_Margin+(3*$line_height));

$pdf->line(459, $topheading,459,$Bottom_Margin+(3*$line_height));
$pdf->line(533, $topheading,533,$Bottom_Margin+(3*$line_height));
$pdf->line(607, $topheading,607,$Bottom_Margin+(3*$line_height));
$pdf->line(681, $topheading,681,$Bottom_Margin+(3*$line_height));
//tallies columns
$pdf->line(755, $topheading,755,$Bottom_Margin+(3*$line_height));

		$FontSize = 10;
		

	$pdf->line($Page_Width-$Right_Margin-810, $Bottom_Margin+(3*$line_height),$Page_Width-$Right_Margin,$Bottom_Margin+(3*$line_height));		$pdf->line($Page_Width-$Right_Margin-810, $Bottom_Margin+(3*$line_height+20),$Page_Width-$Right_Margin,$Bottom_Margin+(3*$line_height+20));
	$pdf->SetFont('Helvetica', 'B', 12,' ' , 'false');
	$pdf->addTextWrap(60, $Bottom_Margin+(2*$line_height),200,$FontSize,"Method of Payment:",'left');
			$pdf->SetFont('Helvetica', '', 12,' ' , 'false');
$pdf->addTextWrap(160, $Bottom_Margin+(2*$line_height),200,$FontSize,$myrow50['method_of_payment'],'left');
	$pdf->SetFont('Helvetica', 'B', 12,' ' , 'false');
	$pdf->addTextWrap(250, $Bottom_Margin+(2*$line_height),200,$FontSize,"Bank:",'left');
			$pdf->SetFont('Helvetica', '', 12,' ' , 'false');
$pdf->addTextWrap(300, $Bottom_Margin+(2*$line_height),200,$FontSize,$myrow50['bank_name'],'left');
	//$grand = locale_number_format($grandtotal,2);
			$pdf->SetFont('Helvetica', 'B', 12,' ' , 'false');

$pdf->addTextWrap(380, $Bottom_Margin+(2*$line_height),200,$FontSize,"Bank Account Name:",'left');
			$pdf->SetFont('Helvetica', '', 12,' ' , 'false');
		
		
		
	if (isset($myrow50['bank_account_name']))	{
		$pdf->addTextWrap(480, $Bottom_Margin+(2*$line_height),200,$FontSize,$myrow50['bank_account_name'],'left');
			$pdf->SetFont('Helvetica', 'B', 10,' ' , 'false');	
		
		
		
	}else{
		
	$pdf->addTextWrap(480, $Bottom_Margin+(2*$line_height),200,$FontSize,$myrowemployee['first_name'].' '.$myrowemployee['last_name'],'left');
			$pdf->SetFont('Helvetica', 'B', 10,' ' , 'false');
	}	
			
			

		$pdf->addTextWrap(600, $Bottom_Margin+(2*$line_height),200,$FontSize,"Bank Account Number:",'left');
			$pdf->SetFont('Helvetica', '', 12,' ' , 'false');
$pdf->addTextWrap(720, $Bottom_Margin+(2*$line_height),200,$FontSize,$myrow50['bank_account_number'],'left');
	//$grand = locale_number_format($grandtotal,2);
	$pdf->addTextWrap(380, $Bottom_Margin+($line_height-1),200,9,"Powered by E-Business",'left');
			$DisplayFreight = 0;
			
			
			
	$YPos -= $line_height;
	/*rule off for total */
		//	$pdf->line($Page_Width-$Right_Margin-222, $YPos+7,$Page_Width-$Right_Margin,$YPos+7);
$YPos -= $FontSize;
	//$LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-90-655, $YPos, 655, $FontSize, _('GRAND TOTAL'), 'right');
	//$LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-90, $YPos, 90, $FontSize, _('$').$grand, 'right');
	$YPos -= $FontSize;





	// Print salesorders.comments:
	$YPos -= $FontSize*3;
	//$pdf->addText($XPos+550, $YPos+$FontSize, $FontSize, _('Supervision Signiture By:'));
    //$pdf->addText($XPos+650, $YPos+$FontSize, $FontSize, $received_by);
//$pdf->line($Page_Width-$Right_Margin-222, $YPos+$FontSize*-1,$Page_Width-$Right_Margin,$YPos+$FontSize*-1);

//
	//$pdf->addText($XPos+550, $YPos+$FontSize*-2, $FontSize, _('Authorized By:'));
   // $pdf->addText($XPos+650, $YPos+$FontSize*-2, $FontSize, $authorized_by);
//$pdf->line($Page_Width-$Right_Margin-222, $YPos+$FontSize*-3.5,$Page_Width-$Right_Margin,$YPos+$FontSize*-3.5);

	//$pdf->addText($XPos, $YPos+$FontSize-45, $FontSize, _('Comments').':');
	$Width2 = $Page_Width-$Right_Margin-120;// Width to print salesorders.comments.
$LeftOvers =	$pdf->addText($XPos, $YPos+$FontSize-55, $FontSize, $narrative);
	//$LeftOvers = trim($quoteterms);
	//**********
	$LeftOvers = str_replace('\n', ' ', $LeftOvers);// Replaces line feed character.
	$LeftOvers = str_replace('\r', '', $LeftOvers);// Delete carriage return character
	$LeftOvers = str_replace('\t', '', $LeftOvers);// Delete tabulator character
	//**********
	while(mb_strlen($LeftOvers) > 1) {
		$YPos -= $FontSize;
		if ($YPos < ($Bottom_Margin)) {// Begins new page.
			include ('includes/PDFpayslipheader.inc');
		}
		$LeftOvers = $pdf->addTextWrap(40, $YPos, $Width2, $FontSize, $LeftOvers);
	}
		
		
$FileName = $_SESSION['reports_dir'] . '/' . $_SESSION['DatabaseName'] . '_Payslip-Payid' . $payid .'.pdf';
	ob_end_clean();	
$pdf->Output($FileName,'F');
		
		//process email
//include ('includes/processemail.inc');
		if ($employeeemail !== ''){
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp-relay.sendinblue.com';
$mail->SMTPAuth = true;
$mail->Username = 'sachinebusiness@gmail.com'; //paste one generated by Mailtrap
$mail->Password = 'R5kyxwrJnWSLH4fh'; //paste one generated by Mailtrap
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
		//Recipients
		$mail->ClearAddresses();
		
   // $mail->setFrom('erp@ebusinescloudservers.com', 'E-Business ERP');
		  $mail->setFrom('wormald@ebusinescloudservers.com', 'Wormald Fire & Security');
		
		  $email = explode(',', $employeeemail);
                for ($i = 0; $i < count($email); $i++) {
                    $mail->addAddress($email[$i], 'recipient '); 
                }
  //  $mail->addAddress($employeeemail);     //Add a recipient
    //$mail->addAddress('ellen@example.com');               //Name is optional
  //  $mail->addReplyTo('info@example.com', 'Information');
 //   $mail->addCC('cc@example.com');
  //  $mail->addBCC('bcc@example.com');

    //Attachments
   // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    $mail->addAttachment($FileName, 'Payslipweek' .$enddate .'.pdf');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    
			if ($manage == '0'){
		$mail->Subject = 'Payslip Week Ending-'.$enddate;}

if ($manage == '1'){
		$mail->Subject = 'Payslip Month -'.$enddate;}
		
	//$mail->Subject = 'Here is the subject';
    $mail->Body    = 'Please find attached Payslips From Evergreen Int(Fiji) Ltd Trading as Wormald Fire & Security and Guardforce Fiji. Autogenerated from E-Business ERP 2.0 Platform. Please do not reply to this email';
  //  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

   $resultsending= $mail->send();
    if(!$resultsending) {
    // There was an error
   echo " There is error at this user. Please go fix the email at user:".$employee." Email:-".$employeeemail;
		echo "<br>";
		fputcsv($file, [$employee, $fullname, $employeeemail,"Email Sending Failed"]);
		
} else {
    echo "EmployeeID-".$employee."-sent";
		echo "<br>";
		
	 fputcsv($file, [$employee, $fullname, $employeeemail,"Email Sending Success"]);
		
		
}
		
		

			
	
		}
		
			unlink($FileName); //delete the temporary file
	
	

        $pdf->__destruct();
		//	echo $employeeemail;
		//echo "<br>";
		
		
		//update payrun table to esnure employee is emailed.
		
		$sql1="UPDATE payrun_details SET
				emailed='1'
				where employeeid = '" . $myrow50['employeeid']."'
				";

	$ErrMsg = _('The emailed cannot be updated.');
	$DbgMsg = _('The SQL failed to update is ');
	$result1=DB_query($sql1, $ErrMsg, $DbgMsg);
	
	} //end while



		
		
	
//	include ('includes/htmlMimeMail.php');


	$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp-relay.sendinblue.com';
$mail->SMTPAuth = true;
$mail->Username = 'sachinebusiness@gmail.com'; //paste one generated by Mailtrap
$mail->Password = 'R5kyxwrJnWSLH4fh'; //paste one generated by Mailtrap
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
		//Recipients
		$mail->ClearAddresses();
		
   // $mail->setFrom('erp@ebusinescloudservers.com', 'E-Business ERP');
		  $mail->setFrom('wormald@ebusinescloudservers.com', 'Wormald Fire & Security');

		
		
                    //$mail->addAddress('msharukh@wormaldfj.com', 'recipient '); 
   $mail->addAddress('jprasad@wormaldfj.com', 'recipient '); 
                   $mail->addAddress('ravneet.c@wormaldfj.com', 'recipient '); 
   $mail->addCC('rdeo@wormaldfj.com', 'recipient '); 
   $mail->addCC('msharukh@wormaldfj.com', 'recipient '); 
  //  $mail->addAddress($employeeemail);     //Add a recipient
    //$mail->addAddress('ellen@example.com');               //Name is optional
  //  $mail->addReplyTo('info@example.com', 'Information');
 //   $mail->addCC('cc@example.com');
  //  $mail->addBCC('bcc@example.com');

    //Attachments
   // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
     $mail->addAttachment($tempFile);

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    
	
		$mail->Subject = 'Bulk Email Report for ID - '.$id;
		
	//$mail->Subject = 'Here is the subject';
    $mail->Body    = 'Please find attached csv file bulk email report for sending payslips to staffs. Autogenerated from E-Business ERP 2.0 Platform. Please do not reply to this email';
  //  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
   // echo 'Message has been sent';
	
	
				
		
		
	// Delete the temporary CSV file
unlink($tempFile);
		
	
//echo 'Quotation Created Successfully'. $jobno.'!';

?>

<button id="erp" class="success">Go Back To Payrol Pay Run Main Page</button>
<?php


//echo 'Quotation Created Successfully'. $jobno.'!';
echo '</div>';
echo '</div>';

//include('includes/footer.inc'); 

?>


<script>$(document).ready(function() {
 $('#erp').click(function() {
      // Redirect to the desired page (e.g., page2.html)
     // window.location.href = 'page2.html';
	  window.history.back();
    });
		
		

} );
	
	</script>

