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

include('includes/header.inc');
echo '<p> </p> <p></p><p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
		'/images/printer.png" title="' .// Icon image.
		_('Outstanding Approved Job Costing ') . '" /> ' .// Icon title.
		_('Choose below the GFS Roster to Print. Locked Rosters are not shown') . '</p>';// Page title.
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
	echo '<div class="col-sm-10">';// div class=?
	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="table">';

echo '<td>' . _('Select Roster to Print ') . ':</td>
							<td><select name="RosterPeriod">';
							
							$SQL = "SELECT rosterid,
											
											start_date,
				                            end_date,
											sectors,
											patrol_location,
											account_number,
											department,
											status
		                            FROM rostering
		                            WHERE status = 'approved'
									
									";

$result=DB_query($SQL);
//echo '<option value="0">0 - ' . _('None Available') . '</option>';
 echo '<option value="0">0 - ' . _('Print All') . '</option>';
while ($myrow=DB_fetch_array($result)){
	
	$SQLpatrol = "SELECT 
											patrollocation,
											debtorno,
											account_number
											
		                            FROM guardforceclient
		                            WHERE clientid ='" . $myrow['patrol_location']."' ";
	$resultP=DB_query($SQLpatrol);
	
	
	$SQLsectors = "SELECT 
											
											name
											
		                            FROM sectors
		                            WHERE id ='" . $myrow['sectors']."' ";
	$resultQ=DB_query($SQLsectors);
	
	
	
	
	while (($myrowP=DB_fetch_array($resultP)) && ($myrowQ=DB_fetch_array($resultQ))) {
		
		$SQLdebtors = "SELECT 
											
											name
											
		                            FROM debtorsmaster
		                            WHERE debtorno ='" . $myrowP['debtorno']."' ";
	$resultR=DB_query($SQLdebtors);
	
	while ($myrowR=DB_fetch_array($resultR)) {
		
	if (isset($_POST['RosterPeriod']) AND $_POST['RosterPeriod']==$myrow['rosterid']){
	    
		echo '<option selected="selected" value="' . $myrow['rosterid'] . '">' . $myrow['rosterid'] . ' - ' .$myrow['start_date'] . ' - ' .$myrow['end_date'] .' -' .$myrowQ['name'] .' -' .$myrowR['name'] .' -'  .$myrowP['patrollocation'] .' -' .$myrow['department'] . '-' .$myrow['status'] .'</option>';
	} else {
			echo '<option value="' . $myrow['rosterid'] . '">' . $myrow['rosterid'] . ' - ' .$myrow['start_date'] . ' - ' .$myrow['end_date'] .' -' .$myrowQ['name'] .' -' .$myrowR['name'] .' -'  .$myrowP['patrollocation'] .' -' .$myrow['department'] . '-' .$myrow['status'] .'</option>';
	}
	
	}
	}
}
echo '</select>';


echo '<br><input type="submit" name="PrintRoster" value="' ._('Print Roster(Excel)') . '" />
<input type="submit" name="PrintRosterPDF" value="' ._('Print Roster(PDF)') . '" />
		</div>
		';



echo '</div>';

echo '</div>';
$rosterid = $_POST['RosterPeriod'];

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


	if (isset($_POST['PrintRoster']) && ($_POST['RosterPeriod'] == 0)){


	echo ' <b><font style="color: red">all rosters will be printed. </font></b>';	
		
	}

elseif (isset($_POST['PrintRoster']) && ($_POST['RosterPeriod'] == $rosterid)){
		
	
	
	
if (PHP_SAPI == 'cli')
	die('This example should only be run from a Web Browser');

/** Include PHPExcel */
//include_once('Classes/PHPExcel.php');


include_once('Classes/PHPExcel/IOFactory.php');

$inputFileName = 'printing/rostergfs.xlsx';
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod);


/*check point*/

// Read the existing excel file
//$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(false);
$objPHPExcel = $objReader->load($inputFileName);

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
//$objPHPExcel->setActiveSheetIndex();

// Add months and till date information derived from above
//$objPHPExcel->getActiveSheet()->duplicateStyle($objPHPExcel-‌​>getActiveSheet()->g‌​etStyle('B2'), 'B3:B20');

	//header
	
			$SQL = "SELECT rosterid,
											
											start_date,
				                            end_date,
											sectors,
											patrol_location,
											account_number,
											department,
											status
		                            FROM rostering
		                            WHERE rosterid = '" . $rosterid."' 
									
									";

$result=DB_query($SQL);
	
	$myrow50=DB_fetch_array($result);
	
	
	
	$timenow = date('Y-m-d 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);
	
	//clear or empty needed cells first
	
	$empty = '';
	
	  $objPHPExcel->getActiveSheet()->setCellValue('B2', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('F2',  $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('L2', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('B3', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('F3', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('B4', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('F4', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('L4', $empty );
	    $objPHPExcel->getActiveSheet()->setCellValue('B5', $empty );
	
	//delete other cells in ranges
	
	




	$cellcount = 8;	
while ($cellcount < 36 ) {
	
		
	
		
		
	
		
	    $objPHPExcel->getActiveSheet()->setCellValue('A'.$cellcount, $empty);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $empty);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount, $empty);
		$objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('K'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('L'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('M'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('N'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('O'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('P'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('Q'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('R'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('S'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('T'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('U'.$cellcount, $empty);
	
		$cellcount++;
		
			
	
	
}

	
	
	
	//now write to this
	
        $objPHPExcel->getActiveSheet()->setCellValue('B2',  ConvertSQLDate($myrow50['start_date']));
		$objPHPExcel->getActiveSheet()->setCellValue('F2',  ConvertSQLDate($myrow50['end_date']));
		$objPHPExcel->getActiveSheet()->setCellValue('L2', $timenow);
		$objPHPExcel->getActiveSheet()->setCellValue('B3', $myrow300['name']);
		$objPHPExcel->getActiveSheet()->setCellValue('F3', $myrow100['patrollocation']);
		$objPHPExcel->getActiveSheet()->setCellValue('B4', $myrow100['account_number']);
		$objPHPExcel->getActiveSheet()->setCellValue('F4', $myrow50['department']);
		$objPHPExcel->getActiveSheet()->setCellValue('L4', $myrow50['rosterid']);
	    $objPHPExcel->getActiveSheet()->setCellValue('B5', $myrow200['name']);
	
	
	   
	
// Generate an updated excel file
// Redirect output to a client’s web browser (Excel2007)
	//employee schedules

  $SQL = "SELECT rosteringtimesheet.*,
  				
                  employeemaster.first_name
				  
				  
				FROM rosteringtimesheet INNER JOIN employeemaster
				ON rosteringtimesheet.employeeid = employeemaster.employeeid 
				WHERE rosteringtimesheet.rosterid='" . $myrow50['rosterid']."'
				";

  
  			

	$AccountsResult = DB_query($SQL);

	

//$num= DB_num_rows($AccountsResult);


//$rowCount= 0;
	
//while ($rowCount < $num) {
	$cellcount = 8;	
	$cellcount2 = 9;	
	while ($myrow3=DB_fetch_array($AccountsResult)) {
		
		
	
		 $employee = $myrow3['employeeid'].''.$myrow3['first_name'];
	    
		 $objPHPExcel->getActiveSheet()->setCellValue('A'.$cellcount, $employee);
		
       if (round($myrow3['mon_hrs']) > 0.0){
			$mon = $myrow3['montime_in'].'-'.$myrow3['montime_out'].'-'.round($myrow3['mon_hrs']).'h';
		 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $mon);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount, round($myrow3['mon_hrs']));
		
		 
		}
		if (round($myrow3['mon_hrs2']) > 0.0){
			
		
		 $mon1 = $myrow3['montime_in1'].'-'.$myrow3['montime_out1'].'-'.round($myrow3['mon_hrs2']).'h';
			 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount2, $mon1);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount2, round($myrow3['mon_hrs2']));
		
		}
		
	   if (round($myrow3['tues_hrs']) > 0.0){
			$tues = $myrow3['tuestime_in'].'-'.$myrow3['tuestime_out'].'-'.round($myrow3['tues_hrs']).'h';
		 $objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount, $tues);
		$objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount, round($myrow3['tues_hrs']));
		
		 
		}
		if (round($myrow3['tues_hrs2']) > 0.0){
			
		
		 $tues1 = $myrow3['tuestime_in1'].'-'.$myrow3['tuestime_out1'].'-'.round($myrow3['tues_hrs2']).'h';
			 $objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount2, $tues1);
		$objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount2, round($myrow3['tues_hrs2']));
		
		}


		if (round($myrow3['wed_hrs']) > 0.0){
			$wed = $myrow3['wedtime_in'].'-'.$myrow3['wedtime_out'].'-'.round($myrow3['wed_hrs']).'h';
		 $objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount, $wed);
		$objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount, round($myrow3['wed_hrs']));
		
		 
		}
		if (round($myrow3['wed_hrs2']) > 0.0){
			
		
		 $wed1 = $myrow3['wedtime_in1'].'-'.$myrow3['wedtime_out1'].'-'.round($myrow3['wed_hrs2']).'h';
			 $objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount2, $wed1);
		$objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount2, round($myrow3['wed_hrs2']));
		
		}

		if (round($myrow3['thurs_hrs']) > 0.0){
			$thurs = $myrow3['thurstime_in'].'-'.$myrow3['thurstime_out'].'-'.round($myrow3['thurs_hrs']).'h';
		 $objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount, $thurs);
		$objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount, round($myrow3['thurs_hrs']));
		
		 
		}
		if (round($myrow3['thurs_hrs2']) > 0.0){
			
		
		 $thurs1 = $myrow3['thurstime_in1'].'-'.$myrow3['thurstime_out1'].'-'.round($myrow3['thurs_hrs2']).'h';
			 $objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount2, $thurs1);
		$objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount2, round($myrow3['thurs_hrs2']));
		
		}
       
		if (round($myrow3['fri_hrs']) > 0.0){
			$fri = $myrow3['fritime_in'].'-'.$myrow3['fritime_out'].'-'.round($myrow3['fri_hrs']).'J';
		 $objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount, $fri);
		$objPHPExcel->getActiveSheet()->setCellValue('K'.$cellcount, round($myrow3['fri_hrs']));
		
		 
		}
		if (round($myrow3['fri_hrs2']) > 0.0){
			
		
		 $fri1 = $myrow3['fritime_in1'].'-'.$myrow3['fritime_out1'].'-'.round($myrow3['fri_hrs2']).'J';
			 $objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount2, $fri1);
		$objPHPExcel->getActiveSheet()->setCellValue('K'.$cellcount2, round($myrow3['fri_hrs2']));
		
		}

		if (round($myrow3['sat_hrs']) > 0.0){
			$sat = $myrow3['sattime_in'].'-'.$myrow3['sattime_out'].'-'.round($myrow3['sat_hrs']).'L';
		 $objPHPExcel->getActiveSheet()->setCellValue('L'.$cellcount, $sat);
		$objPHPExcel->getActiveSheet()->setCellValue('M'.$cellcount, round($myrow3['sat_hrs']));
		
		 
		}
		if (round($myrow3['sat_hrs2']) > 0.0){
			
		
		 $sat1 = $myrow3['sattime_in1'].'-'.$myrow3['sattime_out1'].'-'.round($myrow3['sat_hrs2']).'L';
			 $objPHPExcel->getActiveSheet()->setCellValue('L'.$cellcount2, $sat1);
		$objPHPExcel->getActiveSheet()->setCellValue('M'.$cellcount2, round($myrow3['sat_hrs2']));
		
		}

		if (round($myrow3['sun_hrs']) > 0.0){
			$sun = $myrow3['sunttime_in'].'-'.$myrow3['sunttime_out'].'-'.round($myrow3['sun_hrs']).'N';
		 $objPHPExcel->getActiveSheet()->setCellValue('N'.$cellcount, $sun);
		$objPHPExcel->getActiveSheet()->setCellValue('O'.$cellcount, round($myrow3['sun_hrs']));
		
		 
		}

		if (round($myrow3['sun_hrs2']) > 0.0){
			
		
		 $sun1 = $myrow3['suntime_in1'].'-'.$myrow3['suntime_out1'].'-'.round($myrow3['sun_hrs2']).'N';
			 $objPHPExcel->getActiveSheet()->setCellValue('N'.$cellcount2, $sun1);
		$objPHPExcel->getActiveSheet()->setCellValue('O'.$cellcount2, round($myrow3['sun_hrs2']));
		
		}

		if (round($myrow3['mon2_hrs']) > 0.0){
			$mon2 = $myrow3['mon2time_in'].'-'.$myrow3['mon2time_out'].'-'.round($myrow3['mon2_hrs']).'P';
		 $objPHPExcel->getActiveSheet()->setCellValue('P'.$cellcount, $mon2);
		$objPHPExcel->getActiveSheet()->setCellValue('Q'.$cellcount, round($myrow3['mon2_hrs']));
		
		 
		}
		if (round($myrow3['mon2_hrs2']) > 0.0){

			
		
		 $mon21 = $myrow3['mon2time_in1'].'-'.$myrow3['mon2time_out1'].'-'.round($myrow3['mon2_hrs2']).'P';
			 $objPHPExcel->getActiveSheet()->setCellValue('P'.$cellcount2, $mon21);
		$objPHPExcel->getActiveSheet()->setCellValue('Q'.$cellcount2, round($myrow3['mon2_hrs2']));
		
		}
       
		 $objPHPExcel->getActiveSheet()->setCellValue('R'.$cellcount2, round($myrow3['total_hrs']));

		$objPHPExcel->getActiveSheet()->setCellValue('S'.$cellcount2, round($myrow3['normal_hours']));

		$objPHPExcel->getActiveSheet()->setCellValue('T'.$cellcount2, round($myrow3['time_half_hours']));
		$objPHPExcel->getActiveSheet()->setCellValue('U'.$cellcount2, round($myrow3['double_hours']));



		$objPHPExcel->getActiveSheet()->setCellValue('U'.$cellcount2, round($myrow3['time_half_hours']));

		
		
		$cellcount+=2;
		$cellcount2+=2;

		
	}
		
		//$rowCount++;
	
	
//}
   
// Generate an updated excel file
// Redirect output to a client’s web browser (Excel2007)



//save the file to the server (Excel2007)

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


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save($inputFileName);
$objWriter->save($inputFileName);


    
    //<?php
	
echo '<br /><p></p><p></p> <p></p> <p></p> <p></p>  <p class="page_title_text"><a href="' . $inputFileName . '">' . _('File generated o.k. Click to view this  excel File ') . '</p>';




//echo $AccountCode;



$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
		
			
	
}
elseif (isset($_POST['PrintRosterPDF']) && ($_POST['RosterPeriod'] == $rosterid)){
	

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

$result=DB_query($SQL);
	
	$myrow50=DB_fetch_array($result);
	
	$startdate= date("d-m-Y H:m:s", strtotime($myrow50['start_date']));
	$enddate= date("d-m-Y H:m:s", strtotime($myrow50['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.
		
		include('includes/PDFRosterheader.inc');


 $SQL = "SELECT rosteringtimesheet.*,
  				
                  employeemaster.first_name,
				  employeemaster.last_name
				  
				  
				FROM rosteringtimesheet INNER JOIN employeemaster
				ON rosteringtimesheet.employeeid = employeemaster.employeeid 
				WHERE rosteringtimesheet.rosterid='" . $myrow50['rosterid']."'
				";

  
  			

	$AccountsResult = DB_query($SQL);

	

//$num= DB_num_rows($AccountsResult);


//$rowCount= 0;
	
//while ($rowCount < $num) {
	$montotalhours = 0;	
		$tuestotalhours = 0; 	$wedtotalhours = 0;		$thurstotalhours = 0;	$fritotalhours = 0; 	$sattotalhours = 0;
	 	$suntotalhours = 0; 	$mon2totalhours = 0;
	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['last_name'].'-'.$myrow3['employeeid'];
		$LeftOvers = $pdf->addText($Left_Margin, $YPos+$FontSize, $FontSize,$employee);
		
		if (round($myrow3['mon_hrs']) == 0.0){
			
			$mon = $myrow3['montime_in'].'-'.$myrow3['montime_out'];
		$LeftOvers = $pdf->addText(145, $YPos+$FontSize, $FontSize,$mon );
		
			
		
			
		}
	//	elseif (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->addText(145, $YPos+$FontSize, $FontSize,$mon );
	
		
		 
		//}
		
		elseif (round($myrow3['mon_hrs2']) == 0.0){
			
			
			$mon1 = $myrow3['montime_in1'].'-'.$myrow3['montime_out1'];
			$LeftOvers = $pdf->addText(145, $YPos+$FontSize+3,$FontSize,$mon1 );
		
		}
		elseif (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';
			
			 $LeftOvers = $pdf->addText(145, $YPos+$FontSize+3,FontSize,$mon1 );
		
		}
		
		

		$monday   = $myrow3['mon_hrs2'] + $myrow3['mon_hrs'];
		$montotalhours +=$monday;
		
		
		
		
	
		$LeftOvers = $pdf->addTextWrap(520, $YPos,85,$FontSize,$myrow7979['quantity'],'right');
		
				$LeftOvers = $pdf->addTextWrap(600, $YPos,85,$FontSize,$myrow7979['uom'],'right');
				$LeftOvers = $pdf->addTextWrap(650, $YPos,85,$FontSize,$costprice,'right');
		$LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-90, $YPos, 90, $FontSize, $roundtotal,'right');
			
			
			// 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/PDFStockRequestheader.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/PDFStockRequestheader.inc');
	} //end if need a new page headed up

				
				
				
				
		}	
		

		
			
		
		
		$FontSize = 10;
		

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


	
	


	
	

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

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




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

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

?>

