<?php
ob_start();

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
include('includes/session.inc');
$Title = _('FRCS EMS File');
include('includes/SQL_CommonFunctions.inc');
include('includes/newheader.php');

if (isset($_GET['id'])) {
		$_SESSION['id'] = stripslashes($_GET['id']);
	}
	$id = $_SESSION['id'];


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




$reasons = $_POST['reason'];

if (isset($_POST['reversal']) && ($_POST['reason'] == $reasons )){

//fetch data check which calendar ids does this month have
	
	
$SQL = "SELECT id
		                            FROM calendar_management WHERE period= '" .  $_POST['Period'] . "'
		                           
									 
									 ";

$result=DB_query($SQL);
	while ($myrow = DB_fetch_array($result)) {
		
		
$sql4 =  "SELECT 
	              
				   			 
							  SUM(IF( mon_gap = 0, timesheetsuvadetails.mon_total, 0)) AS montotal,
							  SUM(IF( mon_gap = 1, timesheetsuvadetails.mon_total, 0)) AS montotalgap,
							  SUM(IF( tues_gap = 0, timesheetsuvadetails.tues_total, 0)) AS tuestotal,
							  SUM(IF(tues_gap = 1, timesheetsuvadetails.tues_total, 0)) AS tuestotalgap,
							  SUM(IF( wed_gap = 0, timesheetsuvadetails.wed_total, 0)) AS wedtotal,
							  SUM(IF(wed_gap = 1, timesheetsuvadetails.wed_total, 0)) AS wedtotalgap,
							  SUM(IF( thurs_gap = 0, timesheetsuvadetails.thurs_total, 0)) AS thurstotal,
							  SUM(IF(thurs_gap = 1, timesheetsuvadetails.thurs_total, 0)) AS thurstotalgap,
							  SUM(IF( fri_gap = 0, timesheetsuvadetails.fri_total, 0)) AS fritotal,
							  SUM(IF(fri_gap = 1, timesheetsuvadetails.fri_total, 0)) AS fritotalgap,
							  SUM(IF( sat_gap = 0, timesheetsuvadetails.sat_total, 0)) AS sattotal,
							  SUM(IF(sat_gap = 1, timesheetsuvadetails.sat_total, 0)) AS sattotalgap,
							  SUM(IF( sun_gap = 0, timesheetsuvadetails.sun_total, 0)) AS suntotal,
							  SUM(IF(sun_gap = 1, timesheetsuvadetails.sun_total, 0)) AS suntotalgap,
							 
				             SUM(timesheetsuvadetails.total_hrs) as totalhours
				   
						 
			FROM payrun_details 
			where calendar_id = '" . $myrow[]."'
		    Group by employeeid
			Order by employeeid 
			";
	$ErrMsg = _('This customer could not be added    because');
			$result4 = DB_query($sql4,$ErrMsg);
		
			
			
		while ($myrow4 = DB_fetch_array($result4)) {
		
		
		
	}
	
	
	
	


	    
		echo "<br>";
	
     echo '<p class="page_title_text"><a href=westpac/payrol.txt download="DISDATA.PC1" >' . _('Successfully created the file. click here to download it');
	
}
else 
{
	
	
echo '<p> </p> <p></p><p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
		'/images/printer.png" title="' .// Icon image.
		_('Due date.  ') . '" /> ' .// Icon title.
		_('Please this process needs to be done by your manager') . '</p>';// Page title.
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
	echo '<div class="col-sm-12">';// div class=?
	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="table">';

$SQL = "SELECT period
		                            FROM calendar_management WHERE ems_status='0'
		                             group by period
									 
									 ";

$result=DB_query($SQL);


echo '<tr>
				<td>' . _('Period') . ':</td>
				<td><select tabindex="17" name="Period" required="required">';
		while ($myrow = DB_fetch_array($result)) {
			if ($_POST['Period']==$myrow['period']){
				echo '<option selected="selected" value="'. $myrow['period'] . '">' . $myrow['period'] . '</option>';
			} else {
				echo '<option value="'. $myrow['period'] . '">' . $myrow['period'] . '</option>';
			}
		} '</tr>';
echo '</td>';

echo '<input type="submit" name="reversal" value="' ._('Submit & Process') . '" />
		</div>
		';



echo '</div>';

echo '</div>';
}
				
		
	

	
//echo 'Quotation Created Successfully'. $jobno.'!';




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

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

?>

