<?php

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


include("config.inc.php");
include("Functions_Sales.php");
//include("Forms_DataGrid.php");
include("Forms_DataGrid_DeliveryStatus.php");
$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

//$d = ShowReportDate($connection);
/* $querylog="SELECT ifnull(deliverystatus_level,0) deliverystatus_level from ".$_SESSION['dbLabel'].".users where User_account='".$_SESSION['useraccount']."' 	";

	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	} */

$querylog="SELECT FI_DeliveryStatus as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error()); 
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
if (empty($deliverystatus_dateto)) $deliverystatus_dateto = displayToday();

//Read From Module Table
$querymodule=" Select ifNull(Module_Delivery,0) As Module_Delivery, ifNull(Module_DirectStock,0) As Module_DirectStock, ".
		     " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
             " ifNull(Module_PrintWaybill,0) As Module_PrintWaybill, ifNull(Module_PostToJournal,0) As Module_PostToJournal From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}
	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
 
  
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(Client_ValidateProject,0) as Client_ValidateProject, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Delivery,0) As Module_Delivery, ".
             " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
             " ifNull(module_DeliveryWithSorder,0) As Module_DeliveryWithSorder, ifNull(Module_DirectStock,0) As Module_DirectStock, ".
			 " ifNull(Module_PrintWaybill,0) As Module_PrintWaybill, ifNull(Module_ShowBalance,0) As Module_ShowBalance,	".
			 " ifNull(Module_SerialNo,0) As Module_SerialNo, ifNull(Module_PostToJournal,0) As Module_PostToJournal, ".
			 " ifNull(Module_ReferenceByProject,0) As Module_ReferenceByProject, ifNull(Module_CreditLimitByProj,0) As Module_CreditLimitByProj, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_ExpireDate,0) As Module_ExpireDate, ".
			 " ifNull(Module_Pack,0) As Module_Pack, ifNull(Module_Unit1Method,0) As Module_Unit1Method,  ".
			 " ifNull(Module_DeliveryClosingQty,0) As Module_DeliveryClosingQty, ifNull(Module_ChangeInvoiceItems,0) As Module_ChangeInvoiceItems, ".
			 " ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity, ifNull(Module_VehicleWeight,0) As Module_VehicleWeight, ".	
			 " ifNull(Module_LoadSoldItems,0) as Module_LoadSoldItems ".
			 " ,ifNull(Module_ImportExcell,0) As Module_ImportExcell ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From SalesSetup Table
$querySalesSetup=" Select SalesTTC, ClientCur, Warehouse As SetupDftWareHouse, ifNull(ExportTransportToJV,0) As ExportTransportToJV, ".
				 " ifNull(ExportBonusToJV,0) As ExportBonusToJV, ifNull(Sale_MaxExceedQty,0) As Sale_MaxExceedQty, ifNull(ShowCostCentLayout,0) As ShowCostCentLayout From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}

$querydflwh="select warehouse_code as defaultwarehouse from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and ifNull(default_warehouse,0) = 1 ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}

$query_checkStatus="select FI_DeliveryStatusFrom as statusfrom, FI_DeliveryStatusTo as statusto from ".$HTTP_SESSION_VARS['dbLabel'].".login 
				where user_account='".$HTTP_SESSION_VARS['useraccount']."'"; 
$res_checkstatus=mysql_query($query_checkStatus,$connection) or die(mysql_error());
$row_checkstatus = mysql_fetch_row($res_checkstatus);
$statusfrom = $row_checkstatus[0]; 
$statusto = $row_checkstatus[1];

$Parameters = array();
$Parameters['FI_SalesCheckSalesman'] = $FI_SalesCheckSalesman;
$Parameters['FI_DeliverySalesPrice'] = $FI_DeliverySalesPrice;
$Parameters['Login_NegativeQty'] = $Login_NegativeQty;
$Parameters['Login_ModifySellingPrice'] = $Login_ModifySellingPrice;
$Parameters['Login_ModifyDiscount'] = $Login_ModifyDiscount;
$Parameters['Login_MinAllowCostPer'] = $Login_MinAllowCostPer;
$Parameters['Login_MaxAllowCostPer'] = $Login_MaxAllowCostPer;
$Parameters['Module_Delivery'] = $Module_Delivery;
$Parameters['Module_NegativeQuantity'] = $Module_NegativeQuantity;
$Parameters['Module_Unit1Method'] = $Module_Unit1Method;
$Parameters['Module_Pack'] = $Module_Pack;
$Parameters['Module_DoubleUnit'] = $Module_DoubleUnit;
$Parameters['Module_Project'] = $Module_Project;
$Parameters['Module_CostCenter'] = $Module_CostCenter;
$Parameters['Module_ProjectDt'] = $Module_ProjectDt;
$Parameters['Module_CostCenterDt'] = $Module_CostCenterDt;
$Parameters['Module_RestrictProjCost'] = $Module_RestrictProjCost;
$Parameters['Module_RestrictCost'] = $Module_RestrictCost;
$Parameters['ShowCostCentLayout'] = $ShowCostCentLayout;
$Parameters['Module_SerialNo'] = $Module_SerialNo;
$Parameters['Module_ExpireDate'] = $Module_ExpireDate;
$Parameters['Module_DeliveryClosingQty'] = $Module_DeliveryClosingQty;
$Parameters['Module_DeliveryWithSorder'] = $Module_DeliveryWithSorder;
$Parameters['Sale_MaxExceedQty'] = $Sale_MaxExceedQty;
$Parameters['SalesTTC'] = $SalesTTC;
$Parameters['DecimalBase'] = $DecimalBase;
$Parameters['Setup_VatPercentage'] = $Setup_VatPercentage;
$Parameters['Module_AdditionalTaxes'] = $Module_AdditionalTaxes;
$Parameters['ExportTransportToJV'] = $ExportTransportToJV;
$Parameters['ExportBonusToJV'] = $ExportBonusToJV;
$Parameters['VatApplied'] = $VatApplied;
$Parameters['AllowModifyVAT'] = $AllowModifyVAT;

$Parameters['SetupDftWareHouse'] = $SetupDftWareHouse;
$Parameters['defaultwarehouse']  = $defaultwarehouse;

$Parameters['txtDate'] 		   = $txtDate;
$Parameters['txtClientCode']   = $txtClientCode;
$Parameters['txtClientDetail'] = $txtClientDetail;
$Parameters['txtCurrCode']     = $txtCurr;
$Parameters['Base1']    	   = $base1;
$Parameters['Base2']    	   = $base2;
$Parameters['useraccount']    	   =  $_SESSION['username'];


$Parameters['dbLabel']    	   =  $HTTP_SESSION_VARS['dbLabel'];
$Parameters['useraccount1']    	   =  $HTTP_SESSION_VARS['useraccount'];
$Parameters['Module_CostCenterParent']    	   =  $Module_CostCenterParent;
$Parameters['Module_ProjectParent']    	   =  $Module_ProjectParent;



$_SESSION['gdl_parameters']  = $Parameters;
if(isset($_POST['btnPrint'])){
	$_POST['deliverystatus_datefrom'] = $dateFrom;
	$_POST['deliverystatus_dateto'] = $dateTo; 
}

print <<<HERE
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<script type="text/javascript" language="javascript">


</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delivery Status</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;
}
.style1 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.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;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmit');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		
		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
		//Set Cursor Position After Page Reload
		var NextElement = readCookie('dl-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('dl-nextcell');
		
		
		
	});
	

function showrelationtodt(id){

	 
	 
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 
				
					var data = xmlhttp.responseText.split("[BRK]");
					
					document.getElementById('deliverydtgrid').innerHTML=data[0];
					document.getElementById('DeliveryStatusGrid').innerHTML=data[1];
					document.getElementById('deliverylotgrid').innerHTML=data[2];
					
				}
		}
  }

		xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?actionmode=showdeliverydt&delivery_id="+id);
		xmlhttp.send();
 	

}

function showrelationtolot(id,qty){

	 
	 document.deliverystatus.deliverydt_quantity.value=qty;
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 
				
					
					
					document.getElementById('deliverylotgrid').innerHTML=xmlhttp.responseText;
					
					
				}
		}
  }

		xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?actionmode=showdeliverydtlot&deliverydt_id="+id+"&qty="+qty);
		xmlhttp.send();
 	

}













function returncolor(vobj,vtextname,vcolorname){

 

if (document.getElementById(vtextname).value=='')
	{
		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
	}	
else {
var prevobj = document.getElementById(vtextname).value;
document.getElementById(prevobj).style.backgroundColor = document.getElementById(vcolorname).value;

		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
}	
vobj.style.backgroundColor='#B8EDFF';
}


function submitstatus(vrec){


var deliverystatus_id = 'deliverystatus_id['+vrec+']';
var deliverystatus_date = 'deliverystatus_date'+vrec+'';
var status_id = 'status_id['+vrec+']';
var remark = 'remark['+vrec+']';
var username = 'username['+vrec+']';


var value1 = document.getElementById(deliverystatus_id).value;
var value2 = document.getElementById(deliverystatus_date).value;
var value3 = document.getElementById(status_id).value;
var value4 = document.getElementById(remark).value; alert(value4);
var value5 = document.getElementById(username).value;
var value6 = document.getElementById('delivery_id').value;

 

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('DeliveryStatusGrid').innerHTML=xmlhttp.responseText;
						$(document).ready(function() {
							$(function() {
									$('.roundeddate_attendcostcent').datepick({showTrigger: '#calImg'});
									});
									});	
					
				}
		}
  }
xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?value1="+value1+"&value2="+value2+"&value3="+value3+"&value4="+value4+"&value5="+value5+"&value6="+value6+"&actionmode=submitstatus",true);
xmlhttp.send();
  

}

function deletelot(vid){

	 var value4 = document.getElementById('deliverydt_id').value;
	
if (confirm ( "Are you sure you want to Delete Currenct Record?")){
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
				
					
					document.getElementById('deliverylotgrid').innerHTML=xmlhttp.responseText;
					
					
				 
				}
		}
  }

xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?vid="+vid+"&value4="+value4+"&actionmode=deletelot",true);
xmlhttp.send();

}
}

function SearchKeyword(vers){


var keyword = document.deliverystatus.keyword.value;
var keywordlot = document.deliverystatus.keywordlot.value;
var status = document.deliverystatus.status.value;


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
				
					
					document.getElementById('deliverygrid').innerHTML=xmlhttp.responseText;
					document.getElementById('DeliveryStatusGrid').innerHTML='';
					document.getElementById('deliverydtgrid').innerHTML='';
					document.getElementById('deliverylotgrid').innerHTML='';
					
					
				 
				}
		}
  }

xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?vers="+vers+"&actionmode=search&keyword="+keyword+"&keywordlot="+keywordlot+"&status="+status,true);
xmlhttp.send();


}
function returnStatus() {
	var valStatus = document.getElementById('notstatus').value;
	return valStatus;
}

function PrintPreview(vers){
x=document.deliverystatus; 

var valStatus = returnStatus();
if(valStatus == -1) { alert("status Not Selected!"); return;}
x.target="_blank";
x.action = 'Rep_DeliveryStatus.php?val='+valStatus;
x.submit();


}
/*
function submitlot(vrec){


var lotnumber_id = 'lotnumber_id['+vrec+']';
var lotnumber_qty = 'lotnumber_qty['+vrec+']';
var lotnumber_number = 'lotnumber_number['+vrec+']';


var value1 = document.getElementById(lotnumber_id).value;
var value2 = document.getElementById(lotnumber_qty).value;
var value3 = document.getElementById(lotnumber_number).value;


var value4 = document.getElementById('deliverydt_id').value;

 
var last = document.deliverystatus.numberofrecords.value; 

 var xx;
 var sumof = 0;
 for (i = 0; i <= last; i++)
{
		xx = 'lotnumber_qty'+'['+i+']';
		sumof = sumof + parseFloat(document.getElementById(xx).value);				
}
 
if(sumof > document.deliverystatus.deliverydt_quantity.value){
 alert('can not save chack quantity');
return; 
}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('deliverylotgrid').innerHTML=xmlhttp.responseText;
					 
					
				}
		}
  }
xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?value1="+value1+"&value2="+value2+"&value3="+value3+"&value4="+value4+"&actionmode=submitlot",true);
xmlhttp.send();
  

}
*/

function showwindow(lotnum,itemcode){

	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	

	
	window.open('Form_ProductionGrid.php?lotnum='+lotnum+'&itemcode='+itemcode,'ProductionGrid','width=950,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);



}
function submitlot(vrec){

var last = 9;

var value0 = document.getElementById('lotnumber_id[0]').value;
var value00 = document.getElementById('lotnumber_qty[0]').value;
var value000 = document.getElementById('lotnumber_number[0]').value;

var value1 = document.getElementById('lotnumber_id[1]').value;
var value11 = document.getElementById('lotnumber_qty[1]').value;
var value111 = document.getElementById('lotnumber_number[1]').value;

var value2 = document.getElementById('lotnumber_id[2]').value;
var value22 = document.getElementById('lotnumber_qty[2]').value;
var value222 = document.getElementById('lotnumber_number[2]').value;

var value3 = document.getElementById('lotnumber_id[3]').value;
var value33 = document.getElementById('lotnumber_qty[3]').value;
var value333 = document.getElementById('lotnumber_number[3]').value;

var value4 = document.getElementById('lotnumber_id[4]').value;
var value44 = document.getElementById('lotnumber_qty[4]').value;
var value444 = document.getElementById('lotnumber_number[4]').value;

var value5 = document.getElementById('lotnumber_id[5]').value;
var value55 = document.getElementById('lotnumber_qty[5]').value;
var value555 = document.getElementById('lotnumber_number[5]').value;

var value6 = document.getElementById('lotnumber_id[6]').value;
var value66 = document.getElementById('lotnumber_qty[6]').value;
var value666 = document.getElementById('lotnumber_number[6]').value;

var value7 = document.getElementById('lotnumber_id[7]').value;
var value77 = document.getElementById('lotnumber_qty[7]').value;
var value777 = document.getElementById('lotnumber_number[7]').value;

var value8 = document.getElementById('lotnumber_id[8]').value;
var value88 = document.getElementById('lotnumber_qty[8]').value;
var value888 = document.getElementById('lotnumber_number[8]').value;

var value9 = document.getElementById('lotnumber_id[9]').value;
var value99 = document.getElementById('lotnumber_qty[9]').value;
var value999 = document.getElementById('lotnumber_number[9]').value;


var value10 = document.getElementById('deliverydt_id').value;


 
 
//var last = document.deliverystatus.numberofrecords.value; 


 var xx;
 var yy;
 var zz;
 var sumof = 0;
 for (i = 0; i <= last; i++)
{
		xx = 'lotnumber_qty'+'['+i+']';
		zz = 'lotnumber_number'+'['+i+']';
if(document.getElementById(zz).value=='' && parseFloat(document.getElementById(xx).value) > 0){
document.getElementById(zz).focus();
return;
}
		yy = parseFloat(document.getElementById(xx).value);
		if (isNaN(yy)) 
			yy =  0;
		sumof = sumof + yy;				
}
 
if(sumof != document.deliverystatus.deliverydt_quantity.value){
 alert('Unable to save Plz:check quantity');
return; 
}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('deliverylotgrid').innerHTML=xmlhttp.responseText;
				}
		}
  }
  
xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?value0="+value0
										+"&value00="+value00
										+"&value000="+value000
										+"&value1="+value1
										+"&value11="+value11
										+"&value111="+value111
										+"&value2="+value2
										+"&value22="+value22
										+"&value222="+value222
										+"&value3="+value3
										+"&value33="+value33
										+"&value333="+value333
										+"&value4="+value4
										+"&value44="+value44
										+"&value444="+value444
										+"&value5="+value5
										+"&value55="+value55
										+"&value555="+value555
										+"&value6="+value6
										+"&value66="+value66
										+"&value666="+value666
										+"&value7="+value7
										+"&value77="+value77
										+"&value777="+value777
										+"&value8="+value8
										+"&value88="+value88
										+"&value888="+value888
										+"&value9="+value9
										+"&value99="+value99
										+"&value999="+value999
										+"&value10="+value10
										+"&actionmode=submitlot",true);
xmlhttp.send();
  

}
function submitnhmsremark(deliveryid,statusid){
	
	var delremark = document.getElementById("remark"+statusid).value;
	var deldate = document.getElementById("deliverystatus_date"+statusid).value;
	
 	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					var d =xmlhttp.responseText; //alert(d);
				}
		}
  }
  statusid = statusid+1;
xmlhttp.open("GET","Form_DeliveryStatus_Actions.php?delivery_id="+deliveryid+"&status_id="+statusid+"&deldate="+deldate+"&delremark="+delremark+"&mode=updateRemark");
xmlhttp.send(); 

}
</script>
</head>
<body >
<form name='deliverystatus' method='post'>

<input type=hidden name='mainmode' value='$mainmode'>
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='txtSalesmanCode' value='$txtSalesmanCode'>
HERE;

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Delivery Status</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  
//echo"<tr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id='btnPrint' name='btnPrint' onclick='PrintPreview(3); return false;' title='Print'><span><span>Print</span></span></button></tr>";
echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
		<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' align=left height='34' width='590px'>";
				
echo"<table width=100% border=0><tr><td width=180 align=left>";
echo"<i><b>Search&nbsp;(Invoice)</i></b>:<input type='text' name='keyword' value='$keyword' onKeyUp='SearchKeyword(1)' >";

echo"</td>
<td align=left>";
echo"<div><i><b>Search&nbsp;(Lot#)</i></b>:<input type='text' name='keywordlot' value='$keywordlot' onKeyUp='SearchKeyword(2)' >";
 
			

			if($vers=='') $vers=3;
			//if($status=='') $status=1;
			
			echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select id='status' onchange='SearchKeyword(3)' name='status[$i]'>";
			$query="select id,name from deliverystatus_setup where 1=1 ";
			//if($statusfrom != '') $query=$query." and deliverystatus_level >= ($statusfrom-1) ";
			//if($statusto != '') $query=$query." and deliverystatus_level <= $statusto ";
			$query=$query." order by deliverystatus_level"; 
			$resultstatus=mysql_query($query,$connection) or die(mysql_error());
			
		//$curf=mysql_fetch_row($resultstatus); $status=$curf[0];
		echo"<option value=''></option> ";
				while($curf=mysql_fetch_row($resultstatus)){
				echo"<option ";
					if ($status==$curf[0] )
						echo " selected ";
					echo" value='$curf[0]'>$curf[1] </option>";
					}
			 
			echo"</select>";
			echo"</div>";
			echo "</td>";	
			
echo"</tr></table>";
echo"</td>	";

				

echo"<td align='left'><table><tr>";
echo"<td><button type='button' id='btnPrint' name='btnPrint' onclick='PrintPreview(3); return false;' title='Print'><span><span>Print</span></span></button>";
	
	
	echo "</td>";
	//added
	echo"<td><select id='notstatus' onchange='returnStatus()' name='status[$i]'>";
	$query="select id,name from deliverystatus_setup where deliverystatus_level != 1 order by deliverystatus_level ";
			
	$resultstatus=mysql_query($query,$connection) or die(mysql_error());
	echo"<option value=''></option> ";
	while($curf=mysql_fetch_row($resultstatus)){
	echo"<option ";
		if ($status==$curf[0] )
			echo " selected ";
			echo" value='$curf[0]'>Not $curf[1] </option>";
		}
			 
	echo"</select></td>"; 
    
	
	echo"</tr><tr>";
	/* echo "<td valign='center' align='right' ><span class='style1'>From &nbsp;</span>";
	echo"<input type='text'  class='roundeddate_attendcostcent'  style='width:70px' name='deliverystatus_datefrom' id='deliverystatus_datefrom'   value='' readonly>";
	echo"&nbsp;<a href='#' onClick=\"displayCalendar(document.deliverystatus.deliverystatus_datefrom,'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A>";
		echo"</td>"; */
	echo "<td valign='center' align='right'><span class='style1'>Salesman Code: </span>";
	echo "<select name='txtSalesmanCode' id='txtSalesmanCode'>";
	echo "<option value=''></option>";
	$q1 = "select ledger_number, ledger_name from Salesmen order by ledger_name";
	$res1 =mysql_query($q1,$connection);
	while($r1 = mysql_fetch_row($res1)){
		echo "<option value='$r1[0]'>$r1[1]</option>";
	}
	echo "</select></td>";
		echo"<td valign='center' align='right' ><span class='style1'>To Date &nbsp;</span>";
	echo"<input type='text'  class='roundeddate_attendcostcent'  style='width:70px' name='deliverystatus_dateto' id='deliverystatus_dateto'   value='$deliverystatus_dateto' readonly>";
	echo"&nbsp;<a href='#' onClick=\"displayCalendar(document.deliverystatus.deliverystatus_dateto,'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A>";
		echo"</td></tr></table></td>";
	echo "</tr>";
echo"	</table>";
echo"</td></tr>";
//echo"<tr><td id='content-body' colspan=3></td></tr>";				

echo"<tr><td id='content-body'>";				
echo"<table border='0'  align='center' valign='top'  class='tablecontent' >
	<col width=500>
	<col width=400>";
echo"<tr><td>";
echo"	<div style='overflow:scroll; height:250px; width:550px;' id='deliverygrid'>"; 
	ShowDelivery(-1,$keywordlot,$vers,$status,$connection,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess']); 
	
echo"	</div>";
echo"</td>";


echo"<td align=right>";
echo"	<div style='overflow:scroll; height:250px; width:500px;' id='DeliveryStatusGrid' >";
Show_Delivery_DeliveryStatus($delivery_id,$connection,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess'], $_SESSION['username']);
echo"	</div>";
echo"</td>";
echo"</tr>";


echo"<tr><td>";
echo"	<div style='overflow:scroll; height:250px; width:550px;' id='deliverydtgrid'  >";
	ShowDeliveryDt(-1,$connection,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess']);
echo"	</div>";
echo"</td>";

echo"<td align=left>";
echo"	<div style='overflow:scroll; height:250px; width:390px;' id='deliverylotgrid'>";
	Show_Delivery_DeliveryLot($deliverydt_id,$connection,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess'], $_SESSION['username']);
echo"	</div>";
echo"</td>";
echo"</tr>";

echo" </table></td></tr>";

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu



print <<<HERE
</form>
</body>

HERE;

?>
