<?php
session_start();
//header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_Invoicing_DataGrid.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");

print <<<HERE
<html>
<head>
<title>List of Pending Invoicing</title>
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
<script>
function deleteTempInvoicingHeader(headerinvoicing_id){
	if(confirm("Are you sure?")){
		var str = "List_HeaderInvoicing_Actions.php?actionmode=deletetemp&headerinvoicing_id="+headerinvoicing_id;
		var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			
			 document.getElementById('list_invoicing').innerHTML = data[0];
			 }
      };
       xhttp.open("GET", str, true);
       xhttp.send();
	}
}
function viewDetails(headerinvoicing_id){
    
	var str = "List_HeaderInvoicing_Actions.php?actionmode=displaytempdetails&headerinvoicing_id="+headerinvoicing_id;
	var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 document.getElementById('list_invoicing_'+headerinvoicing_id).innerHTML = data[0];
			 $("#list_invoicing_"+headerinvoicing_id).toggle("medium");
			 }
      };
       xhttp.open("GET", str, true);
       xhttp.send();
	

	
		
}
function searchInvoicing(){
	var search_id   = document.getElementById('search_id').value;
	var search_date = document.getElementById('search_date').value;
    var str = "List_HeaderInvoicing_Actions.php?actionmode=searchtempinvociing&search_id="+search_id+"&search_date="+search_date;
    var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 document.getElementById('list_invoicing').innerHTML = data[0];
    }
      };
       xhttp.open("GET", str, true);
       xhttp.send();			 
}
function editTempInvoicingHeader(headerinvoicing_id){
	var str = "List_HeaderInvoicing_Actions.php?actionmode=edittempinvoicingheader&headerinvoicing_id="+headerinvoicing_id;
	//alert(str);exit;
	var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 //alert(data[0]);exit;
			 opener.document.getElementById('id_no').innerHTML = data[0];
			 opener.document.getElementById('Invoicing_Main_Date').value = data[1];
			 opener.document.getElementById('list_invoicing').innerHTML = data[2];
			 opener.document.getElementById('actionmode').value = "edit";
			 opener.document.getElementById('headerinvoicing_id').value = data[0];
			 window.close();
	     }
      };
       xhttp.open("GET", str, true);
       xhttp.send();
}
</script>
<script src="jquery.min.js"></script>
</head>
<body>
HERE;
echo "<div style='text-align: center; font-family: Arial; font-size: 18px; font-weight:bold; padding: 5px; background: #016a84; color: #FFFFFF'>
List of Pending Invoicing
</div>";
$curr_date = date("d/m/Y");
echo "<div style='background: #dddddd; font-family: Arial; padding: 5px'>
<table width=100% style='border-collapse: collapse'>
<tr>
<td style='font-size: 16px; font-weight: bold; padding: 5px;'>ID #</td>
<td><input type='number' name='search_id' id='search_id' placeholder='ID #' style='padding: 5px;' /></td>
<td style='font-size: 16px; font-weight: bold; padding: 5px;'>Date</td>
<td><input type='text' name='search_date' id='search_date' placeholder='Date' style='padding: 5px;' value='$curr_date' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('search_date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td><button class='button' onclick=\"searchInvoicing()\"><span><span>Search</span></span></button></td>
</tr>
</table>
</div>";
echo "<div id='list_invoicing'>";
drawListTempInvoicing($connection);
echo"</div>";
print <<<HERE
</body>
</html>
HERE;
?>