<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Sales.php");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$message 	= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   

$txtDateFrom = $_POST["txtDateFrom"]; if ($txtDateFrom == ""){$txtDateFrom = $_GET["txtDateFrom"];}   



print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">


<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/calendar/jquery.datetimepicker.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datetimepicker.js"></script>

<script type="text/javascript" language="javascript">
	$(document).on('click', '#txtDateFrom', function() {
			$('#txtDateFrom').datetimepicker({
				timepicker:false,
				formatDate:'Y/m/d',
				scrollMonth:false
			});
		});
</script>
		
<script type="text/javascript" language="javascript">

function LoadForm() 
{ 
	x=document.form1;
	x.txtDateFrom.focus();
}

function CloseForm() {
	self.close();
}


function SubmitRecord() {
	x = document.form1;
	
	if (confirm ( "Are you sure you want to Close cashregister?" ))
	{
		if (document.getElementById('btnClosing'))
			x.btnClosing.disabled = true;
				
		x.action="Form_Retail_Actions.php?mode=closingcashreg";
		x.submit();
		
		document.getElementById("mainDiv").style.display="block";
		document.getElementById("imgDiv").style.display="block";
		MakeCursorHourglass();
	}   
	
}

function PrintForm() {
	var x = document.form1;
	var DateFrom = x.txtDateFrom.value;
	
	var str = 'Form_RetailSummary.php?PDateFrom='+DateFrom;
	window.open(str, 'Form_RetailSummary', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
	
}
	

function MakeCursorHourglass()
{
    document.body.style.cursor = "wait";
}

function kd(e)
{ 
	x=document.form1;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	 
	// Block browser short cuts     
	//F1, F3, F4  key
	if (intKey == 112 || intKey == 114 || intKey == 115 ) {
		if(e.preventDefault) // non-IE browsers         
			e.preventDefault();     
		else  // IE Only  
		{
			e.keyCode=0;  
			e.returnValue = false; 
			
		}	
	}

	
    if (intKey == 113) { //F2 key
		x.btnClosing.click();
		return false;
	}
	else if (intKey == 114) { //F3 key
		x.btnPrint.click();
		return false;
	}
	else if (intKey == 27) { //ESC key
		x.btnClose.click();
		return false;
	}
	
	
    return true;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Closing CashRegister</title>
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 12px;
	color: #999999;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

div#mainDiv, div#imgDiv {
	font-size: 12px; 
    font-weight:bold; 
	color: #FF0000 ;
	text-align: center; 
	margin-top:10px;
	display:none;
}
 button {
  padding: 0 0 0 0;
  margin: 0 3px 0 3px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  outline: none;
  white-space: nowrap;
  overflow: visible;
  height: 22px; 
  font-family: 11px Arial, sans-serif;
  font-size: 13px;
  color: #000000;
  background: none;
  font-weight: bold;

}
</style>

</head>
<body onLoad='LoadForm();' onkeydown='return kd(event);'>
<form name='form1' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
		
HERE;
	
if ($print != 1) {	
	$sub_query  = " Select date_format(CashRegisterClosing_Date,'%Y/%m/%d %H:%i:%s') As ClosingDate From cashregisterclosing ".
				  " Where Upper(CashRegister_Name) = Upper('".$_SESSION['cashregister']."') ".
				  " Order By CashRegisterClosing_Date Desc Limit 1";
	$sub_result = selectData($connection, $sub_query);
	//echo $sub_query;

	$txtDateFrom = $sub_result[0];
	//if (empty($txtDateFrom))	$txtDateFrom = $sub_result[0];
	//if (empty($txtDateFrom))	$txtDateFrom = displayToday();
}
	
//$style= "style=' width:75px; height:22px; background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

	  #<a href=\"#\" onClick=\"displayCalendar(document.form1.txtDateFrom,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></a>

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='330px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:330px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'></span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  	  
echo"   <table border='0' cellpadding='1' align='center' valign='center' >
          <col width=100>
		  <col width=230>
		   <tr bgcolor='#F7F7F7' height='20'>	
			 <td colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
		   </tr>
		
		  <tr bgcolor='#F7F7F7' height='30'>
             <td valign='center' align='left' ><span class='style4'>Date From</span></td> 
			 <td align='left' >
			 <input type='text' name='txtDateFrom' id='txtDateFrom' value='$txtDateFrom' maxlength='10' style='background-color: #000000; color:#00FF00; text-align:right; font-size:16px; font-weight:bold; width:160px; height:27px;' class='date' >
			 </td>
		  </tr>	

		  
		  <tr bgcolor='#F7F7F7' height='50'>
             <td valign='center' align='left' colspan='2'>&nbsp;</td> 
		  </tr>	 	
			 
		  <tr bgcolor='#F7F7F7' height='30'>
		     <td colspan='2' align='center' bgcolor=#D8D8D8>
			 <button type='button' id='btnClosing' name='btnClosing'    onclick='SubmitRecord();return false;'   title='Ok'><span><span>F2:Closing</span></span></button>
			 <button type='button' id='btnPrint' name='btnPrint'    onclick='PrintForm();return false;'   title='Print'><span><span>F3:Print</span></span></button>
			 <button type='button' id='btnClose' name='btnClose'    onclick='CloseForm();return false;'   title='Close'><span><span>Esc:Exit</span></span></button>
			 
			 </td>
			 
		  </tr>
        </table>";
 echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
	echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr>";	
echo "<div id='mainDiv' >Working, please wait ...</div>";	
echo "<div id='imgDiv'><p><image src='img/ajax-loader.gif' id='loader-img' /></p></div>";

if ($message != '') {
	echo '<script type="text/javascript" language="javascript">
			x=document.form1; 
			var vMsg  = x.message.value;
			
			alert(vMsg); 
			
			x.message.value="";
			x.action="Form_Retail_Closing.php";
			x.submit(); 
	</script>';

}
else if ($print == 1) {
	echo '<script type="text/javascript" language="javascript">';
	echo ' var x=document.form1; x.action="Form_Retail_Closing.php"; x.submit(); ';
	echo ' PrintForm(); ';
	echo ' PrintForm(); ';
	echo '</script>';

}	

print <<<HERE


</form>
</body>

HERE;



?>