<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
include('includes/session.inc');
$Title = _('All Print Roster for GFS');
include('includes/SQL_CommonFunctions.inc');
 
include('includes/header.inc');
if (isset($_GET['id'])) {
		$_SESSION['id'] = stripslashes($_GET['id']);
	}
	$id = $_SESSION['id'];


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



		
	

				$SQL = "SELECT rosterid,
											
											id,
											sectors,
											patrol_location,
											account_number,
											department,
											status
		                            FROM rostering
		                            WHERE id = '" . $id."' 
									
									";

$result=DB_query($SQL);
	
	while ($myrow50=DB_fetch_array($result)){


$SQLcalendar = "SELECT *
											
		                            FROM calendar_management
		                            WHERE id ='" . $myrow50['id']."' ";
	$resultcalendar=DB_query($SQLcalendar);
	
$myrow51=DB_fetch_array($resultcalendar);

	
	$startdate= date("d-m-Y H:m:s", strtotime($myrow51['start_date']));
	$enddate= date("d-m-Y H:m:s", strtotime($myrow51['end_date']));
	$date = date('d-m-Y H:i:s');
	
	$SQLpatrol = "SELECT 
											patrollocation,
											debtorno,
											account_number
											
		                            FROM guardforceclient
		                            WHERE clientid ='" . $myrow50['patrol_location']."' ";
	$resultP=DB_query($SQLpatrol);
	
		$myrow100=DB_fetch_array($resultP);
	$SQLsectors = "SELECT 
											
											name
											
		                            FROM sectors
		                            WHERE id ='" . $myrow50['sectors']."' ";
	$resultQ=DB_query($SQLsectors);
	
	$myrow200=DB_fetch_array($resultQ);
	$SQLdebtors = "SELECT 
											
											name
											
		                            FROM debtorsmaster
		                            WHERE debtorno ='" . $myrow100['debtorno']."' ";
	$resultR=DB_query($SQLdebtors);
	
	
	$myrow300=DB_fetch_array($resultR);
	
	
$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', _('Roster') );
$pdf->addInfo('Subject', _('Roster') );
$FontSize = 12;
	
$line_height = 12;// Recoeommended: $line_height = $x * $FontSize.
	$headinggap = 6;	
		include('includes/PDFRosterheader.inc');

  $topheading = $YPos + 35;
 $SQL = "SELECT rosteringtimesheet.*,
  				
                  employeemaster.first_name,
				  employeemaster.last_name
				  
				  
				FROM rosteringtimesheet INNER JOIN employeemaster
				ON rosteringtimesheet.employeeid = employeemaster.employeeid 
				WHERE rosteringtimesheet.rosterid='" . $rosterid."'
				";

  
  			

	$AccountsResult = DB_query($SQL);

	

$num= DB_num_rows($AccountsResult);


$rowCount= 0;
	$cellcount = 0;	
	$cellcount2 = 6;
$montotalhours = 0;	
		$tuestotalhours = 0; 	$wedtotalhours = 0;		$thurstotalhours = 0;	$fritotalhours = 0; 	$sattotalhours = 0;
	 	$suntotalhours = 0; 	$mon2totalhours = 0; $totalhours = 0;$totalnormal = 0; $totaltimehalf = 0 ; $totaldouble = 0;
while ($rowCount < $num) {
	


   
	while ($myrow3=DB_fetch_array($AccountsResult)) {
		
		
		
				
				  $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/PDFRosterheader.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.
 $employee = $myrow3['first_name'].'-'.$myrow3['employeeid'];
		$LeftOvers = $pdf->addTextWrap(20, $YPos+12-$cellcount2,200,$FontSize,$employee,'left');
		
		
	
	
		if (round($myrow3['mon_hrs']) > 0.0){
			
			$montimein = date("g:i a", strtotime($myrow3['montime_in']));
			$montimeout = date("g:i a", strtotime($myrow3['montime_out']));
			$mon = $montimein.'-'.$montimeout.'-'.round($myrow3['mon_hrs']).'hrs';
			$LeftOvers = $pdf->addTextWrap(143, $YPos+12 - $cellcount,200,$FontSize,$mon,'left');
		}
		
		if (round($myrow3['mon_hrs2']) > 0.0){
			
		
		 $montimein1 = date("g:i a", strtotime($myrow3['montime_in1']));
			$montimeout1 = date("g:i a", strtotime($myrow3['montime_out1']));
			$mon1 = $montimein1.'-'.$montimeout1.'-'.round($myrow3['mon_hrs2']).'hrs';
		$FontSize = 6;
				$LeftOvers = $pdf->addTextWrap(143, $YPos+12-$cellcount2,200,$FontSize,$mon1,'left');
		
		}
		if (round($myrow3['tues_hrs']) > 0.0){
		
		$tuestimein = date("g:i a", strtotime($myrow3['tuestime_in']));
			$tuestimeout = date("g:i a", strtotime($myrow3['tuestime_out']));
			$tues = $tuestimein.'-'.$tuestimeout.'-'.round($myrow3['tues_hrs']).'hrs';
			
			
			$LeftOvers = $pdf->addTextWrap(220, $YPos+12 - $cellcount,200,$FontSize,$tues,'left');
				
		}
		if (round($myrow3['tues_hrs2']) > 0.0){
			
		
		 $tuestimein1 = date("g:i a", strtotime($myrow3['tuestime_in1']));
			$tuestimeout1 = date("g:i a", strtotime($myrow3['tuestime_out1']));
			$tues1 = $tuestimein1.'-'.$tuestimeout1.'-'.round($myrow3['tues_hrs2']).'hrs';
		$FontSize = 6;
			
				$LeftOvers = $pdf->addTextWrap(220, $YPos+12-$cellcount2,200,$FontSize,$tues1,'left');
		
		}

		if (round($myrow3['wed_hrs']) > 0.0){
			$wedtimein = date("g:i a", strtotime($myrow3['wedtime_in']));
			$wedtimeout = date("g:i a", strtotime($myrow3['wedtime_out']));
			$wed = $wedtimein.'-'.$wedtimeout.'-'.round($myrow3['wed_hrs']).'hrs';
			
			
			$LeftOvers = $pdf->addTextWrap(305, $YPos+12 - $cellcount,200,$FontSize,$wed,'left');
		
		 
		}
		if (round($myrow3['wed_hrs2']) > 0.0){
			
		
			
			$wedtimein1 = date("g:i a", strtotime($myrow3['wedtime_in1']));
			$wedtimeout1 = date("g:i a", strtotime($myrow3['wedtime_out1']));
			$wed1 = $wedtimein1.'-'.$wedtimeout1.'-'.round($myrow3['wed_hrs2']).'hrs';
		
			
				$LeftOvers = $pdf->addTextWrap(305, $YPos+12-$cellcount2,200,$FontSize,$wed1,'left');
		
			
		}

		if (round($myrow3['thurs_hrs']) > 0.0){
				$thurstimein = date("g:i a", strtotime($myrow3['thurstime_in']));
			$thurstimeout = date("g:i a", strtotime($myrow3['thurstime_out']));
			$thurs = $thurstimein.'-'.$thurstimeout.'-'.round($myrow3['thurs_hrs']).'hrs';
			
			
			$LeftOvers = $pdf->addTextWrap(383, $YPos+12 - $cellcount,200,$FontSize,$thurs,'left');
				
		   
		 
		}
		if (round($myrow3['thurs_hrs2']) > 0.0){
			
		
		 	
			$thurstimein1 = date("g:i a", strtotime($myrow3['thurstime_in1']));
			$thurstimeout1 = date("g:i a", strtotime($myrow3['thurstime_out1']));
			$thurs1 = $thurstimein1.'-'.$thurstimeout1.'-'.round($myrow3['thurs_hrs2']).'hrs';
		
				$LeftOvers = $pdf->addTextWrap(383, $YPos+12-$cellcount2,200,$FontSize,$thurs1,'left');
		   
		
		}
       if (round($myrow3['fri_hrs']) > 0.0){
			$fritimein = date("g:i a", strtotime($myrow3['fritime_in']));
			$fritimeout = date("g:i a", strtotime($myrow3['fritime_out']));
			$fri = $fritimein.'-'.$fritimeout.'-'.round($myrow3['fri_hrs']).'hrs';
			
			$LeftOvers = $pdf->addTextWrap(461, $YPos+12 - $cellcount,200,$FontSize,$fri,'left');
				
		
		}
		if (round($myrow3['fri_hrs2']) > 0.0){
			
		
			$fritimein1 = date("g:i a", strtotime($myrow3['fritime_in1']));
			$fritimeout1 = date("g:i a", strtotime($myrow3['fritime_out1']));
			$fri1 = $fritimein1.'-'.$fritimeout1.'-'.round($myrow3['fri_hrs2']).'hrs';
		
				$LeftOvers = $pdf->addTextWrap(461, $YPos+12-$cellcount2,200,$FontSize,$fri1,'left');
		
		
		}
		if (round($myrow3['sat_hrs']) > 0.0){
			$sattimein = date("g:i a", strtotime($myrow3['sattime_in']));
			$sattimeout = date("g:i a", strtotime($myrow3['sattime_out']));
			$sat = $sattimein.'-'.$sattimeout.'-'.round($myrow3['sat_hrs']).'hrs';
			
			$LeftOvers = $pdf->addTextWrap(535, $YPos+12 - $cellcount,200,$FontSize,$sat,'left');
					
		 
		}
		if (round($myrow3['sat_hrs2']) > 0.0){
			
		
		
			
			$sattimein1 = date("g:i a", strtotime($myrow3['sattime_in1']));
			$sattimeout1 = date("g:i a", strtotime($myrow3['sattime_out2']));
			$sat1 = $sattimein1.'-'.$sattimeout1.'-'.round($myrow3['sat_hrs2']).'hrs';
		
				$LeftOvers = $pdf->addTextWrap(535, $YPos+12-$cellcount2,200,$FontSize,$sat1,'left');
		}
		if (round($myrow3['sun_hrs']) > 0.0){
			$sunttimein = date("g:i a", strtotime($myrow3['sunttime_in']));
			$sunttimeout = date("g:i a", strtotime($myrow3['sunttime_out']));
			$sunt = $sunttimein.'-'.$sunttimeout.'-'.round($myrow3['sun_hrs']).'hrs';
			
			
			$LeftOvers = $pdf->addTextWrap(609, $YPos+12 - $cellcount,200,$FontSize,$sunt,'left');
				
		 
		}

		if (round($myrow3['sun_hrs2']) > 0.0){
			
		
			
			$suntimein1 = date("g:i a", strtotime($myrow3['suntime_in1']));
			$suntimeout1 = date("g:i a", strtotime($myrow3['suntime_out2']));
			$sun1 = $suntimein1.'-'.$suntimeout1.'-'.round($myrow3['sun_hrs2']).'hrs';
		
				$LeftOvers = $pdf->addTextWrap(609, $YPos+12-$cellcount2,200,$FontSize,$sun1,'left');
		
		}
		if (round($myrow3['mon2_hrs']) > 0.0){
			$mon2timein = date("g:i a", strtotime($myrow3['mon2time_in']));
			$mon2timeout = date("g:i a", strtotime($myrow3['mon2time_out']));
			$mon2 = $mon2timein.'-'.$mon2timeout.'-'.round($myrow3['mon2_hrs']).'hrs';
			
			
	
			$LeftOvers = $pdf->addTextWrap(684, $YPos+12 - $cellcount,200,$FontSize,$mon2,'left');
		 
		}
		
	//tallies
		
		$LeftOvers = $pdf->addTextWrap(756, $YPos+12 - $cellcount,200,$FontSize,$myrow3['total_hrs'],'left');
		
			$LeftOvers = $pdf->addTextWrap(776, $YPos+12 - $cellcount,200,$FontSize,$myrow3['normal_hours'],'left');
			$LeftOvers = $pdf->addTextWrap(796, $YPos+12 - $cellcount,200,$FontSize,$myrow3['time_half_hours'],'left');
			$LeftOvers = $pdf->addTextWrap(816, $YPos+12 - $cellcount,200,$FontSize,$myrow3['double_hours'],'left');
		
	
		
		$monday   = $myrow3['mon_hrs2'] + $myrow3['mon_hrs'];
		$montotalhours +=$monday;
		
		$tuesday   = $myrow3['tues_hrs2'] + $myrow3['tues_hrs'];
		$tuestotalhours +=$tuesday;
		
		$wednesday   = $myrow3['wed_hrs2'] + $myrow3['wed_hrs'];
		$wedtotalhours +=$wedday;
		
		$thursday   = $myrow3['thurs_hrs2'] + $myrow3['thurs_hrs'];
		$thurstotalhours +=$thursday;
		
		$friday   = $myrow3['fri_hrs2'] + $myrow3['fri_hrs'];
		$fritotalhours +=$friday;
		
		$satday   = $myrow3['sat_hrs2'] + $myrow3['sat_hrs'];
		$sattotalhours +=$satday;
		
		$sunday   = $myrow3['sunhrs2'] + $myrow3['sun_hrs'];
		$suntotalhours +=$sunday;
		$monday2   = $myrow3['mon2_hrs'];
		$mon2totalhours +=$monday2;
		
		$totalhours += $myrow3['total_hrs'];
		$totalnormal +=$myrow3['normal_hours'];
		$totaltimehalf +=$myrow3['time_half_hours'];
		$totaldouble +=$myrow3['double_hours'];
		
		$cellcount = $cellcount + 6;
		$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/PDFRosterheader.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/PDFRosterheader.inc');
	} //end if need a new page headed up

				
				
				
				
		}	
	$rowCount++;
}


//total
		
		$pdf->addTextWrap(60, $Bottom_Margin+(3*$line_height+10),200,$FontSize,"TOTAL",'left');
         
$pdf->addTextWrap(145, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$montotalhours,'left');
$pdf->addTextWrap(220, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$tuestotalhours,'left');
$pdf->addTextWrap(303, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$wedtotalhours,'left');
$pdf->addTextWrap(383, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$thurstotalhours,'left');
$pdf->addTextWrap(462, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$fritotalhours,'left');
$pdf->addTextWrap(536, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$sattotalhours,'left');
$pdf->addTextWrap(610, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$suntotalhours,'left');
$pdf->addTextWrap(684, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$mon2totalhours,'left');

$pdf->addTextWrap(758, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$totalhours,'left');
$pdf->addTextWrap(778, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$totalnormal,'left');
$pdf->addTextWrap(798, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$totaltimehalf,'left');
$pdf->addTextWrap(818, $Bottom_Margin+(3*$line_height+10),200,$FontSize,$totaldouble,'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(218, $topheading,218,$Bottom_Margin+(3*$line_height));
$pdf->line(300, $topheading,300,$Bottom_Margin+(3*$line_height));
$pdf->line(380, $topheading,380,$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));
$pdf->line(775, $topheading,775,$Bottom_Margin+(3*$line_height));
$pdf->line(795, $topheading,795,$Bottom_Margin+(3*$line_height));
$pdf->line(815, $topheading,815,$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->addTextWrap(60, $Bottom_Margin+(2*$line_height),200,$FontSize,"Supervisor Signature:",'left');
$pdf->addTextWrap(160, $Bottom_Margin+(2*$line_height),200,$FontSize,"_________________",'left');

	$pdf->addTextWrap(280, $Bottom_Margin+(2*$line_height),200,$FontSize,"Manager Signature:",'left');
$pdf->addTextWrap(380, $Bottom_Margin+(2*$line_height),200,$FontSize,"_________________",'left');
	$grand = locale_number_format($grandtotal,2);

$pdf->addTextWrap(480, $Bottom_Margin+(2*$line_height),200,$FontSize,"Date Signed:",'left');
$pdf->addTextWrap(550, $Bottom_Margin+(2*$line_height),200,$FontSize,"_________________",'left');
	$grand = locale_number_format($grandtotal,2);

			$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/PDFRosterheader.inc');
		}
		$LeftOvers = $pdf->addTextWrap(40, $YPos, $Width2, $FontSize, $LeftOvers);
	}


	
	
	
	
	

ob_end_clean();
	 //its not an email just print the invoice to PDF
		$pdf->OutputD('AllGFSRoster_' . $id. '.pdf');

		
		
	
	$pdf->__destruct();
		
			
	}
			
		
			
		
		
		
			    
		
	
//echo 'Quotation Created Successfully'. $jobno.'!';




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

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

?>

