<?php
/* $Id: index.php 693 2014-10-26 23:18:08Z daintree $*/
error_reporting(E_ALL & ~E_NOTICE);
$PageSecurity=0;

include('includes/session.inc');
$Title=_('ERP Home');
include('includes/newheader.php');

?>

		
  					
	<script src="angular/angular.min.js"></script>  
        
 
     
     
		

   
  
 									
									<?php
									
		
    
if (isset($_GET['rosterid'])) {
		$_SESSION['rosterid'] = stripslashes($_GET['rosterid']);
	}
	$rosterid = $_SESSION['rosterid'];


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



		
	
				$SQL = "SELECT rostering.rosterid,
											
											rostering.id,
											guardforceclient.debtorno,
											guardforceclient.patrollocation,
											guardforceclient.sectors,
											guardforceclient.account_number,
											guardforceclient.department,
										    
											rostering.status,
											calendar_management.start_date,
											calendar_management.end_date
											
		                            FROM rostering 
									inner join guardforceclient on guardforceclient.clientid = rostering.clientid
									inner join calendar_management on calendar_management.id = rostering.id
		                            WHERE rosterid = '" . $rosterid."' 
									
									";

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

	
	$startdate= date("d-m-Y", strtotime($myrow50['start_date']));
	$enddate= date("d-m-Y", strtotime($myrow50['end_date']));
	$date = date('d-m-Y');


$SQLdepart = "SELECT departmentname
											
		                            FROM department
		                            WHERE departmentid ='" . $myrow50['department']."' ";
	$resultdepart=DB_query($SQLdepart);
	
$myrowdepart=DB_fetch_array($resultdepart);




	$SQLsectors = "SELECT name,supervisor_details_for_rosterprintheaders
											
		                            FROM sectors
		                            WHERE id ='" . $myrow50['sectors']."' ";
	$resultQ=DB_query($SQLsectors);
	
	$myrow200=DB_fetch_array($resultQ);

	$SQLdebtors = "SELECT 
											
											name
											
		                            FROM debtorsmaster
		                            WHERE debtorno ='" . $myrow50['debtorno']."' ";
	$resultR=DB_query($SQLdebtors);
	
	
	$myrow300=DB_fetch_array($resultR);
	

$sqlcom = "SELECT 
					controlroom_ph
				FROM companies
				WHERE coycode=1";

	$ErrMsg =  _('The company preferences could not be retrieved because');
	$resultcom = DB_query($sqlcom,$ErrMsg);


	$myrowcom = DB_fetch_array($resultcom);
	
	
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
	
	
	$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 );
  		$objPHPExcel->getActiveSheet()->setCellValue('F5', $empty );
  $objPHPExcel->getActiveSheet()->setCellValue('B6', $empty );
  $objPHPExcel->getActiveSheet()->setCellValue('B7', $empty );
	
	//delete other cells in ranges
	
	




	$cellcount = 10;	
while ($cellcount < 38 ) {
	
		
	
		
		
	
		
	    $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);
		$objPHPExcel->getActiveSheet()->setCellValue('V'.$cellcount, $empty);
		$objPHPExcel->getActiveSheet()->setCellValue('W'.$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', $printdate);
		$objPHPExcel->getActiveSheet()->setCellValue('B3', $myrow300['name']);
		$objPHPExcel->getActiveSheet()->setCellValue('F3', $myrow50['patrollocation']);
		$objPHPExcel->getActiveSheet()->setCellValue('B4', $myrow50['account_number']);
		$objPHPExcel->getActiveSheet()->setCellValue('F4', $myrowdepart['departmentname']);
		$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,
				  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;
	
//while ($rowCount < $num) {
	$cellcount = 10;	
	
	while ($myrow3=DB_fetch_array($AccountsResult)) {
		
		
		
	
		 $employee = $myrow3['employeeid'].'-'.$myrow3['first_name'];
	    
		 $objPHPExcel->getActiveSheet()->setCellValue('A'.$cellcount, $employee);
		
      			if ($myrow3['mon_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['mon_absent']);
			}
		
		
       if (round($myrow3['mon_total']) > 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_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $mon);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount, round($myrow3['mon_total']));
		
		 
		}
		
		if ($myrow3['tues_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['tues_absent']);
			}
	   if (round($myrow3['tues_total']) > 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_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount, $tues);
		$objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount, round($myrow3['tues_total']));
		
		 
		}
		
if ($myrow3['wed_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['wed_absent']);
			}

		if (round($myrow3['wed_total']) > 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_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount, $wed);
		$objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount, round($myrow3['wed_total']));
		
		 
		}
		if ($myrow3['thurs_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['thurs_absent']);
			}

		if (round($myrow3['thurs_total']) > 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_total']).'hrs';
			
		 $objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount, $thurs);
		$objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount, round($myrow3['thurs_total']));
		
		 
		}
		if ($myrow3['fri_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['fri_absent']);
			}
       
		if (round($myrow3['fri_total']) > 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_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount, $fri);
		$objPHPExcel->getActiveSheet()->setCellValue('K'.$cellcount, round($myrow3['fri_total']));
		
		 
		}
		if ($myrow3['sat_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['sat_absent']);
			}
		if (round($myrow3['sat_total']) > 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_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('L'.$cellcount, $sat);
		$objPHPExcel->getActiveSheet()->setCellValue('M'.$cellcount, round($myrow3['sat_total']));
		
		 
		}
		if ($myrow3['sun_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['sun_absent']);
			}
		if (round($myrow3['sun_total']) > 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_total']).'hrs';
			
		 $objPHPExcel->getActiveSheet()->setCellValue('N'.$cellcount, $sun);
		$objPHPExcel->getActiveSheet()->setCellValue('O'.$cellcount, round($myrow3['sun_total']));
		
		 
		}

		
		if ($myrow3['mon2_absent'] !=='None' ){
				 $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $myrow3['mon2_absent']);
			}
		   if (round($myrow3['mon2_total']) > 0.0){
			$mon2timein = date("g:i a", strtotime($myrow3['mon2time_in']));
			$mon2timeout = date("g:i a", strtotime($myrow3['mon2time_out']));
			$mon2 = $mo2timein.'-'.$mon2timeout.'-'.round($myrow3['mon2_total']).'hrs';
		 $objPHPExcel->getActiveSheet()->setCellValue('P'.$cellcount, $mon2);
		$objPHPExcel->getActiveSheet()->setCellValue('Q'.$cellcount, round($myrow3['mon2_total']));
		
		 
		}

		$objPHPExcel->getActiveSheet()->setCellValue('R'.$cellcount, round($myrow3['remarks']));
		 $objPHPExcel->getActiveSheet()->setCellValue('T'.$cellcount, round($myrow3['total_hrs']));

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

		$objPHPExcel->getActiveSheet()->setCellValue('V'.$cellcount, round($myrow3['time_half_hours']));
		$objPHPExcel->getActiveSheet()->setCellValue('W'.$cellcount, round($myrow3['double_hours']));



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

		
		
		$cellcount+=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);
		
			
	
	
	
//echo 'Quotation Created Successfully'. $jobno.'!';





		
  
 	echo '</div >';
	?>
		<p><a href="guardforceclient.php" class="btn btn-danger" role="button">Return to Patrol Locations</a></p>				

					

						<!--End::Section-->
					</div>
				</div>
			</div>
					
					

						<!--end:: Widgets/Stats-->

						<!--Begin::Section-->
						

		<!-- end::Quick Sidebar -->

		<!-- begin::Scroll Top -->
		<div id="m_scroll_top" class="m-scroll-top">
			<i class="la la-arrow-up"></i>
		</div>

		<!-- end::Scroll Top -->

		<!-- begin::Quick Nav -->
		

		<!-- begin::Quick Nav -->
<script src="includes/vendors/owl.carousel/dist/owl.carousel.js" type="text/javascript"></script>

		<!--end::Page Scripts -->
	</body>

	<!-- end::Body -->
</html>
 
      
<?php



/*The module link codes are hard coded in a switch statement below to determine the options to show for each tab */
include('includes/MainMenuLinksArray.php');

if (isset($SupplierLogin) AND $SupplierLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=1">' . _('View or Amend outstanding offers') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=2">' . _('Create a new offer') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=3">' . _('View any open tenders without an offer') . '</a></p>
			</td>
			</tr>
		</table>';
	include('includes/footer.inc');
	exit;
} elseif (isset($CustomerLogin) AND $CustomerLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/CustomerInquiry.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Account Status') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectOrderItems.php?NewOrder=Yes">' . _('Place An Order') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectCompletedOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Order Status') . '</a></p>
			</td>
			</tr>
		</table>';

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

if (isset($_GET['Application'])){ /*This is sent by this page (to itself) when the user clicks on a tab */
	$_SESSION['Module'] = $_GET['Application'];
}








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

function GetRptLinks($GroupID) {
/*
This function retrieves the reports given a certain group id as defined in /reports/admin/defaults.php
in the acssociative array $ReportGroups[]. It will fetch the reports belonging solely to the group
specified to create a list of links for insertion into a table to choose a report. Two table sections will
be generated, one for standard reports and the other for custom reports.
*/
	global $db, $RootPath, $ReportList;
	require_once('reportwriter/languages/en_US/reports.php');
	require_once('reportwriter/admin/defaults.php');
	$GroupID=$ReportList[$GroupID];
	$Title= array(_('Custom Reports'), _('Standard Reports and Forms'));

	$sql= "SELECT id,
				reporttype,
				defaultreport,
				groupname,
				reportname
			FROM reports
			ORDER BY groupname,
					reportname";
	$Result=DB_query($sql,'','',false,true);
	$ReportList = '';
	while ($Temp = DB_fetch_array($Result)) $ReportList[] = $Temp;

	$RptLinks = '';
	for ($Def=1; $Def>=0; $Def--) {
        $RptLinks .= '<li class="menu_group_headers">';
        $RptLinks .= '<b>' .  $Title[$Def] . '</b>';
        $RptLinks .= '</li>';
		$NoEntries = true;
		if ($ReportList) { // then there are reports to show, show by grouping
			foreach ($ReportList as $Report) {
				if ($Report['groupname']==$GroupID AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/ReportMaker.php?action=go&amp;reportid=' . $Report['id'] . '">' . _($Report['reportname']) . '</a></p>';
					$RptLinks .= '</li>';
					$NoEntries = false;
				}
			}
			// now fetch the form groups that are a part of this group (List after reports)
			$NoForms = true;
			foreach ($ReportList as $Report) {
				$Group=explode(':',$Report['groupname']); // break into main group and form group array
				if ($NoForms AND $Group[0]==$GroupID AND $Report['reporttype']=='frm' AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/folders.gif" width="16" height="13" alt="" />&nbsp;';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/FormMaker.php?id=' . $Report['groupname'] . '"></p>';
					$RptLinks .= $FormGroups[$Report['groupname']] . '</a>';
					$RptLinks .= '</li>';
					$NoForms = false;
					$NoEntries = false;
				}
			}
		}
		if ($NoEntries) $RptLinks .= '<li class="menu_group_item">' . _('There are no reports to show!') . '</li>';
	}
	return $RptLinks;
}
	
?>
<!-- Modal HTML embedded directly into document -->
<div id="ex1" class="modal">
  <p>Thanks for clicking. That felt good.</p>
  <a href="#" rel="modal:close">Close</a>
</div>


<!-- Modal -->
 <div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-lg">
      <div class="modal-content">
       <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <h4 class="modal-title" id="myModalLabel"> API CODE </h4>
       </div>
       <div class="modal-body" id="getCode" style="overflow-x: scroll;">
       
          
          
       </div>
    </div>
   </div>
 </div>
<script>
jQuery(document).ready(function($){
	
	
   }); 
	
	

	
	
		
		

	
	
</script>


<script type="text/javascript">
jQuery(document).on("ready xcrudafterrequest",function(){
    
});
</script>