<?php

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


include("config.inc.php");
include("Functions_Purchase.php");
include("Forms_DataGrid_stocktake.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");


if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$querylog="select ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

 
$querylog="SELECT ifNull(Login_FastPrint,0) As Login_FastPrint, 0 as login_outconfirm  from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";		 
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}
 
$querylistuserdir ="SELECT  FI_stocktake as loginaccess, FI_stocktake_App As FI_Insert  from ".$_SESSION['dbLabel'].".listuserdir where usercode='".$_SESSION['useraccount']."' 	";		
 
$resultlog=mysql_query($querylistuserdir ,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

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

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From stocktakeSetup Table
$queryAdjustSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout, ifNull(CurrencyBase,1) As SetupCurrencyBase, Warehouse_code As SetupDftWareHouse,Barcode,
					ifnull(stocktake_doubleunit,0) as stocktake_doubleunit, ifnull(ShowSellingPrice,0) as ShowSellingPrice, ifnull(HeatNo_Required,0) as HeatNo_Required,
					ifnull(stocktake_loadCharging,0) as stocktake_loadCharging, ifnull(defaultproject, null) as txtProjectCode1
					From stocktakeSetup ";
					// echo "<BR>".$queryAdjustSetup;
$resultAdjustSetup=mysql_query($queryAdjustSetup,$connection) or die(mysql_error());
while($rowAdjustSetup=mysql_fetch_array($resultAdjustSetup)){
	extract($rowAdjustSetup);
}

//Read From Module Table
$querymodule=" Select 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_SerialNo,0) As Module_SerialNo, ifNull(Module_IsInvoice,0) As Module_IsInvoice, ifNull(Module_PostToJournal,0) As Module_PostToJournal, ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ifNull(Module_ExpireDate,0) As Module_ExpireDate, ifNull(Module_Unit1Method,0) As Module_Unit1Method, ".
			 " ifNull(Module_ImportExcell,0) As Module_ImportExcell, ifNull(module_allowexpiry,0) As module_allowexpiry ,ifNull(Module_Heatno,0) As Module_Heatno,".
			 " ifNull(Module_sizes, 0) as Module_sizes, ifNull(Module_Color, 0) as Module_Color, ifNull(module_outconfirm, 0) as module_outconfirm ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}
 
$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

$querydivtype="Select DivisionTypes_Name From DivisionTypes Where Upper(DivisionTypes_Forms) Like '%AD%' And ifNull(DivisionTypes_Master,0) = 1 Order By DivisionTypes_Name";
$resultdivtype=mysql_query($querydivtype,$connection) or die(mysql_error());


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


if (empty($mainaction))	$mainaction = 'insert';

$message = ereg_replace("'"," ",$message);

 

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" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<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('adj-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('adj-nextcell'); 
		
		
		
	});
	
	
</script>


<script type="text/javascript" language="javascript">
function getAccount(index){
	
	if (document.getElementById('txtInvDebit')){
		var InvDEBITaccount = 'InvDEBITaccount['+index+']';
		document.getElementById(InvDEBITaccount).value = document.getElementById('txtInvDebit').value;
	}
	
}
function showlistHeatNo(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vHeatNoCode = encodeURIComponent(document.getElementById('stocktakedt_heatno['+PIndex+']').value);
	
	window.open('List_HeatNo.php?frm=5&index='+PIndex+'&PHeatNoCode='+vHeatNoCode,'List_HeatNo','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}


function loadfromrequest(){

	var str1 = 'Form_stocktakeLoadRequest.php';

		

		var result = 1;
		if (result == 1) {
			win = window.open(str1,'Form_ConfirmedstocktakeRequestSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=850,height=580,top=100,left=20');		
			win.creator = self;
			win.focus();		
		}
	
}
function itemTransfer(){
	win = window.open('Form_stocktakeTransferSerialNbr.php','Form_stocktakeTransferSerialNbr', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=850,height=580,top=100,left=20');		
			win.creator = self;
			win.focus();
}
function CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost){
  
    x = document.adjustment;
	
	var AdjDate     = x.txtDate.value;
	var AdjCurr     = x.txtCurr.value;
	var AdjProject  = x.txtProjectCode.value;
	var AdjCostCenter = x.txtCostCentCode.value;
	
	
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	
	if (AdjDate=='' )
	{
		alert("Date Column is mandatory!");
		x.txtDate.focus();
		return 0;
	}
	else if (AdjCurr=='' )
	{
		x.txtCurr.value = "$base1"; 
	}
	else if (AdjProject=='' && ModuleRestProj==1 && ModuleProj==1)
	{
		alert("Project is mandatory!");
		x.txtProjectCode.focus();
		return 0;
	}
	else if (AdjCostCenter=='' && ModuleRestCost==1 && ModuleCost==1 && document.getElementById('txtCostCentCode').type == 'text')
	{
		alert("CostCenter is mandatory!");
		x.txtCostCentCode.focus();
		return 0;
	}
	
			
	
	else
	return 1 ;	
}

function CheckFieldsDt(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo,AdjustType){
  
    x = document.adjustment;
	
	var AdjDtItem 	   = document.getElementById('itemcode['+PIndex+']').value;
	var AdjDtWarehouse = document.getElementById('warehousecode['+PIndex+']').value;
	var AdjDtQty       = document.getElementById('adjdtquantity['+PIndex+']').value;
	var AdjDtQty2	   = document.getElementById('unit2qty['+PIndex+']').value;
	var AdjDtPrice     = document.getElementById('costprice['+PIndex+']').value;
	
	var AdjDtExpireDate = document.getElementById('expiredate['+PIndex+']').value;
	var AdjDtBatchNo    = document.getElementById('batchno['+PIndex+']').value;
	var AdjDtHeatNo    = document.getElementById('stocktakedt_heatno['+PIndex+']').value;
	
	var vmode = x.actionmode.value;
 	
	if (AdjDtPrice == '')   AdjDtPrice = 0;
	if (AdjDtQty2 == '')    AdjDtQty2 = 0;
	if (AdjDtQty == '')     AdjDtQty = 0;
	
	AdjDtQty     = parseFloat(AdjDtQty);	
	
	
	if (AdjDtItem=='')
	{
		alert("Item is mandatory!");
		document.getElementById('itemcode['+PIndex+']').focus();
		return 0;
	}	
	else if (AdjDtWarehouse=='')
	{
		alert("Warehouse is mandatory!");
		document.getElementById('warehousecode['+PIndex+']').focus();
		return 0;
	}
	else if (AdjDtQty*1 != AdjDtQty/1 || AdjDtQty == 0  ) {
		alert('Quantity ('+AdjDtQty+') should be NUMERIC and NOT Zero. ');
		document.getElementById('adjdtquantity['+PIndex+']').focus();
		return 0;
	}
	else if (AdjDtQty < 0 && AdjustType == 'I') {
		alert('Quantity ('+AdjDtQty+') should be a POSITIVE value. ');
		document.getElementById('adjdtquantity['+PIndex+']').focus();
		return 0;
	}
	else if ((AdjDtPrice*1 != AdjDtPrice/1 || AdjDtPrice < 0) ) {
		alert('Cost Price should be a NUMERIC and POSITIVE value');
		document.getElementById('costprice['+PIndex+']').focus();
		return 0;
	}
	else if ((AdjDtQty2 != '' && AdjDtQty2*1 != AdjDtQty2/1) ) {
		alert('Item Qty2 should be a NUMERIC value.');
		document.getElementById('unit2qty['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && AdjDtExpireDate == '' ) {
		alert('Item Expire Date is mandatory.');
		document.getElementById('expiredate['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && AdjDtBatchNo == '' ) {
		alert('Item Batch No is mandatory.');
		document.getElementById('batchno['+PIndex+']').focus();
		return 0;
	} 
	 
	
	else
	return 1 ;	
}


function ClearPage(){
	x = document.adjustment;
	 
	
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		x.mainaction.value='insert';
		x.actionmode.value='';
		x.action='Form_stocktake.php';
		x.submit();
	}	
}

function ClearPage1(){
	x = document.adjustment;
	var msg = x.message.value; 
	
	ClearForm('All');
	
	x.mainaction.value='insert';
	x.actionmode.value='';
	x.message.value=msg;
	x.action='Form_stocktake.php';
	x.submit();
}

 

function CancelRecord(){
	x = document.adjustment;
	var vmode   = x.mainaction.value;
	var vmode1  = x.actionmode.value;
	var AdjId   = x.txtAdjId.value;
 		
	if (confirm ( "Are you sure you want to Delete current pending stocktake permenantly?"))
	{
		x.action="Form_stocktake_Actions.php?mode=cancel&mainmode=&SAdjId="+AdjId;
		x.submit();
	}
    
}


function PostChanges(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.adjustment;
	var vAdjId  = x.txtAdjId.value;
	var vMainMode = x.mainaction.value; 
	
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	
	if (x.txtAdjCountDetail.value == 0 || x.txtAdjCountDetail.value == '') {
		alert('Save not allowed. Please add at least one item.');
	}
	 
	else
	{
		if (result == 1) {
			if (confirm ( "Are you sure you want to Save current stocktake?"))
			{
				//Save Grid Before Posting	
				var vModRec  = document.getElementById('ModRec_G1').value;
				if (vModRec != "") {
					var Obj = document.getElementById('CurRec'+vModRec);
					Obj.style.backgroundColor='#F13A3A';
					alert("Please Submit changes before.");
					
				} else {
					if (document.getElementById('btnPost'))
						x.btnPost.disabled = true;
					if (document.getElementById('btnCancel'))
						x.btnCancel.disabled = true;	
					if (document.getElementById('btnClear'))
						x.btnClear.disabled = true;
					if (document.getElementById('btnAddItem'))
						x.btnAddItem.disabled = true;
					if (document.getElementById('btnAddSerial'))
						x.btnAddSerial.disabled = true;	
					
					x.actionmode.value='post';
					x.action="Form_stocktake_Actions.php?mode=post&mainmode="+vMainMode+"&SAdjId="+vAdjId;
					x.submit();
				}	
			}
		}	
	}
}

function downloadExcel(){
	var str = "Exp_ImportExcelDownload.php?transType=AD";
	window.open(str,'Import Excel Download');
}

function ImportExcel(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	
	x = document.adjustment;
	var vAdjId  = x.txtAdjId.value;
	var vMainMode = x.mainaction.value; 
	
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	
		
	var vMode = 'importexcel';
	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&AdjustType='+x.AdjustType.value+
					'&SAdjId='+x.txtAdjId.value+
					'&PAdjId='+x.txtAdjId.value+
					'&PAdjDate='+x.txtDate.value+
					'&PAdjCurr='+x.txtCurr.value+
					'&PAdjEntryType='+x.txtEntryType.value+
					'&PAdjIsInvoice='+x.txtAdjIsInvoice.value+
					'&PAdjInvDebit='+x.txtInvDebit.value+
					'&PAdjInvCredit='+x.txtInvCredit.value+
					'&PAdjProjectCode='+x.txtProjectCode.value+
					'&PAdjCostCentCode='+x.txtCostCentCode.value+
					'&PAdjRequestBy='+encodeURIComponent(x.txtRequestBy.value)+
					'&PAdjRemark='+encodeURIComponent(x.txtRemark.value);
					
						
	if (result == 1) {
		x.action="Form_stocktake_Actions.php?"+the_data;
		x.submit();		
	}
	
}
	
function DeleteAdjDt(AdjDtId, ItemPackCode, ItemCode) {
	x = document.adjustment;
	var vAdjId  = x.txtAdjId.value;
	var vMainMode = x.mainaction.value; 
	var vDelMsg = '';
	
	
	if (ItemPackCode != '')
	   vDelMsg = "Are you sure you want to Delete Pack Item "+ItemPackCode+" ?";
	else  
	   vDelMsg = "Are you sure you want to Delete Item "+ItemCode+" ?";
	   
	if (confirm ( vDelMsg ))
	{
		x.action="Form_stocktake_Actions.php?mode=deletedt&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDtId="+AdjDtId;
		x.submit();
	}

}

function UpdateAdjDt(AdjDtId) {
    x = document.adjustment;
	var vAdjId   = x.txtAdjId.value;
	var vAdjDate = x.txtDate.value;
	var vAdjCurr = x.txtCurr.value; 
		
	var vMainMode = x.mainaction.value;
	
	win = window.open('Form_stocktakeDetail.php?mainaction='+vMainMode+'&actionmode=&PAdjId='+vAdjId+'&PAdjDate='+vAdjDate+'&PAdjCurr='+vAdjCurr+'&PAdjDtId='+AdjDtId, 'Form_stocktakeDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=720,height=350,top=100');	
	win.creator = self;
	win.focus();		

}

 
function AddDivision(){
	x = document.adjustment;
	
	var vMainMode      = x.mainaction.value;
	var vAdjId    	   = x.txtAdjId.value;
	var vAdjDivId      = x.txtAdjDivID.value;
	var vDivisionId    = x.txtDivisionID.value;
	var vDivisionCode  = x.txtDivisionCode.value;
	
	if (vAdjId == "") {
		alert("Please add an item first.!");
	}
	else if (vDivisionCode == "") {
		alert("Division code is mandatory.!");
		x.txtDivisionCode.focus();
	}
	else {
		if (vAdjDivId == '')	vMode = 'adddivision';	
		else vMode = 'editdivision';
		
		x.action="Form_stocktake_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDivId="+vAdjDivId;
		x.submit();
	
	}
}

function EditDivision(AdjDivId, DivisionId, DivisionType, DivisionCode) {
	x = document.adjustment;
	
	x.txtAdjDivID.value     = AdjDivId;
	x.txtDivisionID.value   = DivisionId;
	x.txtDivisionCode.value = DivisionCode;
	x.txtDivType.value      = DivisionType;
	
	x.submit();
	
}

function DeleteDivision(AdjDivId, DivisionType, DivisionCode) {
	x = document.adjustment;
	
	var vMainMode = x.mainaction.value;
	var vAdjId    = x.txtAdjId.value;
	var vDelMsg   = "Are you sure you want to Delete "+DivisionType+" ("+DivisionCode+") ?";
	   
	if (confirm ( vDelMsg ))
	{
		x.action="Form_stocktake_Actions.php?mode=deletedivision&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDivId="+AdjDivId;
		x.submit();
	}

}

function ClearDivision() {
	x = document.adjustment;
	
	x.txtAdjDivID.value = '';
	x.txtDivisionID.value = '';
	x.txtDivisionCode.value = '';
	x.txtDivType.value = '';
	
	x.submit();

}

function ShowDivisions(AdjDtId) {
	x = document.adjustment;
	var vAdjId   = x.txtAdjId.value; 
		
	var vMainMode = x.mainaction.value;
	
	win = window.open('Form_stocktakeDtDivisions.php?mainaction='+vMainMode+'&actionmode=&PAdjId='+vAdjId+'&PAdjDtId='+AdjDtId, 'Form_stocktakeDtDivisions', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=560,height=330,top=100');	
	win.creator = self;
	win.focus();

}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.adjustment;
	var vmode = x.actionmode.value;
	
	if (Option == 'All') {
		
		x.txtAdjId.value='';
		x.txtRef.value='';
		x.txtDate.value='';
		x.txtJvRef.value='';
		x.txtJvFolio.value=''; 
		x.txtRemark.value='';
		x.txtCurr.value='';
		x.txtProjectCode.value='';
		x.txtCostCentCode.value=''; 
		  
		
		x.message.value=''; 
		x.txtAdjCountDetail.value='';
		
		x.actionmode.value = '';
		x.mainaction.value = '';
	} 
}

function AddItems(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.adjustment;
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);

	var vAdjId         = x.txtAdjId.value;
	var vAdjDate       = x.txtDate.value;
	var vAdjRemark     = x.txtRemark.value;
	var vAdjCurr       = x.txtCurr.value; 
	var vAdjProjectCode  = x.txtProjectCode.value;
	var vAdjCostCentCode = x.txtCostCentCode.value;
	//var vAdjProjectCode  = '';
	//var vAdjCostCentCode = '';	  
		
	
	var vMainMode = x.mainaction.value;
	
	vAdjRemark 	  = vAdjRemark.replace('&','%26'); 
	
	vAdjRemark 	  = vAdjRemark.replace('#','%23'); 
	
	if (result == 1) {
		win = window.open('Form_stocktakeDetail.php?mainaction='+vMainMode+'&actionmode=&PAdjId='+vAdjId+'&PAdjDate='+vAdjDate+
		                  '&PAdjCurr='+vAdjCurr+'&PAdjProjectCode='+vAdjProjectCode+'&PAdjCostCentCode='+vAdjCostCentCode+
						  '&PAdjIsInvoice='+vAdjIsInvoice+'&PAdjInvDebit='+vAdjInvDebit+'&PAdjInvCredit='+vAdjInvCredit+
						  '&PAdjEntryType='+vAdjEntryType+'&PAdjRequestBy='+vAdjRequestBy+'&PAdjRemark='+vAdjRemark	, 
						  'Form_stocktakeDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=720,height=350,top=100');		
		win.creator = self;
		win.focus();		
	}	
	
    
}

function AddSerials(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.adjustment;
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);

	var vAdjId         = x.txtAdjId.value;
	var vAdjDate       = x.txtDate.value;
	var vAdjRemark     = x.txtRemark.value;
	var vAdjCurr       = x.txtCurr.value;
	var vAdjRequestBy  = x.txtRequestBy.value;
	var vAdjIsInvoice  = x.txtAdjIsInvoice.value;
	var vAdjInvDebit   = x.txtInvDebit.value;
	var vAdjInvCredit  = x.txtInvCredit.value;
	var vAdjProjectCode  = x.txtProjectCode.value;
	var vAdjCostCentCode = x.txtCostCentCode.value;
	//var vAdjProjectCode  = '';
	//var vAdjCostCentCode = '';	 
	var vAdjEntryType	 = x.txtEntryType.value;
		
	
	var vMainMode = x.mainaction.value;
	
	vAdjRemark 	  = vAdjRemark.replace('&','%26');
	vAdjRequestBy = vAdjRequestBy.replace('&','%26');
	
	vAdjRemark 	  = vAdjRemark.replace('#','%23');
	vAdjRequestBy = vAdjRequestBy.replace('#','%23');
	
	if (result == 1) {
		win = window.open('Form_stocktakeAddSerial.php?mainaction='+vMainMode+'&actionmode=&PAdjId='+vAdjId+
		                  '&PAdjDate='+vAdjDate+'&PAdjCurr='+vAdjCurr+'&PAdjProjectCode='+vAdjProjectCode+'&PAdjCostCentCode='+vAdjCostCentCode+
						  '&PAdjIsInvoice='+vAdjIsInvoice+'&PAdjInvDebit='+vAdjInvDebit+'&PAdjInvCredit='+vAdjInvCredit+
						  '&PAdjEntryType='+vAdjEntryType+'&PAdjRequestBy='+vAdjRequestBy+'&PAdjRemark='+vAdjRemark	, 
						  'Form_stocktakeAddSerial', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=780,height=400,top=100');		
		win.creator = self;
		win.focus();		
	}

}


function DeleteRecordGrid(filepath,formname,transid,AdjDtId,index,dftorderby,orderby,morelines,startrange,perpage,direction) {
	x = document.adjustment;
	var vAdjId    = x.txtAdjId.value;
	var vAdjCurr  = x.txtCurr.value;
	var vAdjDate  = x.txtDate.value;
	var vMainMode = x.mainaction.value;
	var vDelMsg = 'Are you sure you want to delete this record?';

	
	if (confirm ( vDelMsg ))
	{
		var xmlhttp = getXMLHttpRequest();	
		$("#Loader").addClass("ajaxsaving");
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = $.parseJSON(xmlhttp.responseText);
					
				var msg = data[0].message;
					
				if (msg != "") {
					$("#Loader").removeClass("ajaxsaving");
					alert(decodeURIComponent(msg));
				} else { 
					$("#Loader").removeClass("ajaxsaving");
					ReloadGrid(filepath,formname,transid,'datagrid',index,dftorderby,'DEL',orderby,morelines,startrange,perpage,0,direction);			
					// ReloadGridDt(filepath,'ADJ-TOT','TOTALS','totals',transid,-1);
				}
			}
		}

		xmlhttp.open("GET","Form_stocktake_Actions.php?mode=deletedt&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDtId="+AdjDtId+"&txtCurr="+vAdjCurr+"&txtDate="+vAdjDate);
		xmlhttp.send();
	}	

}


function SubmitRecordGrid(PIndex,filepath,formname,transid,dftorderby,orderby,morelines,startrange,perpage,direction,ModuleRestProj,ModuleRestCost,ModuleProj,ModuleCost,ModuleExpireDate,ModuleSerialNo) 
{
	
	x = document.adjustment;

	 	//alert('invalid item code ');exit;
	//txtItemCode
	var itemcode  = document.getElementById('itemcode['+PIndex+']').value;
	var notallowedtoadditemduetocostcenter = false;
	 
	
	$.get( "Get_AutocompleteQuery.php?tablename=items&term="+itemcode, function( data ) {
		//  used to restrice user to add an item that belong to another cost center  , nb: will only fire  in case user have access to only specific cost center in loginstk NB cost center filtered in Get_AutocompleteQuery tablename:items
       
 if (parseInt(data.length) == parseInt(0) )
 {
	 alert('not allowed to add this item!');
		document.getElementById('itemcode['+PIndex+']').focus();
 }
	  
	
		
	var ItemExpire     = document.getElementById('itemexpire['+PIndex+']').value;
	var ItemWithSerial = document.getElementById('itemwithserial['+PIndex+']').value;
	
	var result = 1;
	result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	if (result == 1) {
		result = CheckFieldsDt(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo);
	}
	
	var AdjDtId   = document.getElementById('adjdtid['+PIndex+']').value;
	if (AdjDtId == '') vMode = 'submitrecord-ajax';	
	else vMode = 'editdt-ajax';	
	
	var txtloadToChanging = 0;
	if(document.getElementById('chkloadchanging')){
	if(document.getElementById('chkloadchanging').checked)
		txtloadToChanging = 1;
	}
	var txtClientCode = '';
	if(document.getElementById('client_code'))
	txtClientCode  = document.getElementById('client_code').value;
	
	var txtAdjDivision  = '';
	if(document.getElementById('txtdivision'))
	txtAdjDivision = document.getElementById('txtdivision').value;
	
	let varManual = ''; 
	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&SAdjId='+x.txtAdjId.value+'&PAdjId='+x.txtAdjId.value+
					'&PAdjDate='+x.txtDate.value+'&PAdjCurr='+x.txtCurr.value+
 					'&PAdjProjectCode='+encodeURIComponent(x.txtProjectCode.value)+'&PAdjCostCentCode='+encodeURIComponent(x.txtCostCentCode.value)+
					'&PAdjRemark='+encodeURIComponent(x.txtRemark.value)+
					'&SAdjDtId='+document.getElementById('adjdtid['+PIndex+']').value+
					'&lstWarehouse='+document.getElementById('warehousecode['+PIndex+']').value+
					'&txtItemCode='+encodeURIComponent(document.getElementById('itemcode['+PIndex+']').value)+
					'&txtAdjDtQty='+document.getElementById('adjdtquantity['+PIndex+']').value+
					'&txtExistDtQty='+document.getElementById('existingqty['+PIndex+']').value+
					'&txtDiffDtQty='+document.getElementById('Diffqty['+PIndex+']').value+
 					'&txtAdjDtPrice='+document.getElementById('costprice['+PIndex+']').value+
 					'&txtProjectCodeDt='+document.getElementById('projectcodedt['+PIndex+']').value+
 					'&txtCostCentCodeDt='+document.getElementById('costcentcodedt['+PIndex+']').value+
 					'&txtManualNo='+varManual;
		
	
	if (result == 1) {
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
  
		$("#Loader").addClass("ajaxsaving");
		//$('#datagrid :input').attr('disabled', true);
		
		var SubBtnID = 'imgSubmit['+PIndex+']';
		if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = true;
		
		if(xmlhttp) {
			//xmlhttp.open("POST", "Form_stocktake_Actions.php", true);
		
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var data = $.parseJSON(xmlhttp.responseText);
					
					var msg = data[0].message;
					
					if (msg != "") {
						$("#Loader").removeClass("ajaxsaving");
						if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = false;
						alert(decodeURIComponent(msg));
					} else {	
						if (transid == ""){
							transid = data[0].transid;
							
							x.txtAdjId.value = transid;
							x.submit();
						} 
							
						var index = parseInt(PIndex) + 1;
						var nextcell = 'itemcode['+index+']';
						
						createCookie('adj-nextcell',nextcell);
						
					ReloadGrid(filepath,formname,transid,'datagrid',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							MoveNextRecord(nextcell);
							// ReloadGridDt(filepath,'ADJ-TOT','TOTALS','totals',transid,-1);
							// document.getElementById('ModRec_G1').value = "";
						});
					
						
					}
				}
			}
			
			// adds  a header to tell the PHP script to recognize the data as is sent via POST
			//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlhttp.send(the_data);
			
			xmlhttp.open("GET","Form_stocktake_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}
	    
	   	});
}

function SubmitItemBarcode(ModuleRestProj,ModuleRestCost,ModuleProj,ModuleCost) {
	x = document.adjustment;
	
	var vMode = 'submitbarcode'; 
	var transid = x.txtAdjId.value;
	
	var result = 1;
	result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	if (result == 1) {
		if (x.txtItemBarcode.value=='')
		{
			result = 0;
			alert("Barcode is mandatory!");
			x.txtItemBarcode.focus();
		}
		else if (x.txtItemWarehouse.value=='')
		{
			result = 0;
			alert("Item warehouse is mandatory!");
			x.txtItemWarehouse.focus();
		}
	}

					
	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+ 
					'&SAdjId='+x.txtAdjId.value+
					'&PAdjId='+x.txtAdjId.value+
					'&PAdjDate='+x.txtDate.value+  
					'&PAdjProjectCode='+x.txtProjectCode.value+
					'&PAdjCostCentCode='+x.txtCostCentCode.value+ 
					'&PAdjRemark='+encodeURIComponent(x.txtRemark.value)+
					'&lstWarehouse='+x.txtItemWarehouse.value+
					'&txtItemBarcode='+x.txtItemBarcode.value+
					'&txtAdjDtQty='+x.txtItemQty.value;
		
	
	if (result == 1) { 
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
  
		$("#Loader").addClass("ajaxsaving");
		//$('#datagrid :input').attr('disabled', true);
		
		var SubBtnID = 'btnSubmitBar';
		  if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = true;
		
		
		if(xmlhttp) {
			
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var data = $.parseJSON(xmlhttp.responseText);
					
					var msg = data[0].message;
					
					if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = false;
					
					if (msg != "") {
						$("#Loader").removeClass("ajaxsaving");
						alert(decodeURIComponent(msg));
					} else {	
						if (transid == ""){
							transid = data[0].transid;
							
							x.txtItemBarcode.value='';
							x.txtAdjId.value = transid;
							x.submit();
						} 
							
						 ReloadGrid('Forms_DataGrid_stocktake.php','ADJ',transid,'datagrid',0,'','ADD','stocktakeDt.stocktakeDt_ID',1,0,'',0,'',function() {
							 // ReloadGridDt('Forms_DataGrid.php','ADJ-TOT','TOTALS','totals',transid,-1);
							 x.txtItemBarcode.value='';
							 x.txtItemBarcode.focus();
						  });
						
						// ReloadGrid(filepath,formname,transid,'datagrid',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							// MoveNextRecord(nextcell);
							// // ReloadGridDt(filepath,'ADJ-TOT','TOTALS','totals',transid,-1);
							// // document.getElementById('ModRec_G1').value = "";
						// });
						
					}
				}
			}
					
			xmlhttp.open("GET","Form_stocktake_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}

}

function SetIsInvoice() {
	x = document.adjustment;
	
	if (x.ChkIsInvoice.checked) x.txtAdjIsInvoice.value = 1;
	else x.txtAdjIsInvoice.value = 0;

}

 

function SearchForRef(){
    //ClearForm('All');
    x = document.adjustment; 
    win = window.open('Form_stocktakeSearch.php', 'Form_stocktakeSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=750,height=450,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}

function SearchForPending(){
    //ClearForm('All');
    x = document.adjustment; 
    win = window.open('Form_stocktakeSearchPending.php', 'Form_stocktakeSearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=960,height=560,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}

function SelectType() {
	x = document.adjustment;
	x.submit();
}


function Printstocktake(AdjId, AdjRef) {
	var str = '';
	var vPrtSer = 0;
	
	if (confirm ( "Do you want to Print current record with reference "+AdjRef+" ?"))
	{
		 
		str = 'Form_stocktakePreview.php?stocktakeId='+AdjId+'&PrtSer='+vPrtSer;
		window.open(str);
		window.location.href = "Form_stocktake.php";

	}
}

function PrintBarcode(AdjId, AdjRef, temp){
	var c = confirm("Do you want to print the items' barcode ?");
	if(c){
		var str = "Rep_ItemBarcodeList2.php?AdjId="+AdjId+"&temp="+temp;
		window.open(str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	}
}

function showlistDivision(str) {
	x = document.adjustment;
	
	vDivisionType = x.txtDivType.value;
	
	if (vDivisionType == "") {
		alert("Division Type is mandatory.!");
		x.txtDivType.focus();
	} else {
		window.open('List_FrmDivisions.php?frm=2&item='+str+'&divtype='+vDivisionType,'Divisions','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,width=700,height=450,left=100,top=20');
	}
	
}



function showlistLedgers(str, index){
	if(index == ''){
	if (str == 1) 
		vLedgerCode = encodeURIComponent(document.getElementById('txtInvDebit').value);
	else 
		vLedgerCode = encodeURIComponent(document.getElementById('txtInvCredit').value);
	} else 	vLedgerCode = encodeURIComponent(document.getElementById('InvDEBITaccount['+index+']').value);
	window.open('Form_stocktake_ListLedgers.php?item='+str+'&frm=1&index='+index+'&PRef='+vLedgerCode,'mywindow','width=650,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistLedgersName(str){
	if (str == 1) 
		vLedgerName = encodeURIComponent(document.getElementById('txtInvDebitName').value);
	else 
		vLedgerName = encodeURIComponent(document.getElementById('txtInvCreditName').value);
		
	window.open('Form_stocktake_ListLedgers.php?item='+str+'&frm=1&PRef='+vLedgerName,'mywindow','width=650,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistProject(str){

	vProjectCode = encodeURIComponent(document.getElementById('txtProjectCode').value);
	window.open('List_SorProject.php?frm=8&item='+str+'&PProject_Code='+vProjectCode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

	vCostcentCode = encodeURIComponent(document.getElementById('txtCostCentCode').value);
	window.open('List_SorCostcenter.php?frm=8&item='+str+'&PCostcent_Code='+vCostcentCode,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function showlistProjectDt(str,PIndex){
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	vProjectCode = encodeURIComponent(document.getElementById('projectcodedt['+PIndex+']').value);
	
	window.open('List_SorProject.php?frm=25&index='+PIndex+'&item='+str+'&PProject_Code='+vProjectCode,'List_SorProject','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}

function showlistCostcenterDt(str,PIndex){
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	vCostcentCode = encodeURIComponent(document.getElementById('costcentcodedt['+PIndex+']').value);
	
	window.open('List_SorCostcenter.php?frm=25&index='+PIndex+'&item='+str+'&PCostcent_Code='+vCostcentCode,'List_SorCostcenter','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}


function showlistItems(str,PIndex){
	var vDate, vItemCode, vCurrCode;
	x = document.adjustment;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('itemcode['+PIndex+']').value);
	vCurrCode  = x.txtCurr.value;
	
	window.open('List_SorItems.php?frm=7&index='+PIndex+'&PItem_Code='+vItemCode+'&ItemType=All&CurrCode='+vCurrCode+'&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistItems1(str){
	x = document.adjustment;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('itemcode1').value);
	
	window.open('List_SorItems.php?frm=23&PItem_Code='+vItemCode+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}


function showlistItemsDesc(str,PIndex){
	var vDate, vItemCode;
	x = document.adjustment;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemDesc  = encodeURIComponent(document.getElementById('itemdescription['+PIndex+']').value);
	
	window.open('List_SorItems.php?frm=7&index='+PIndex+'&PItem_Description='+vItemDesc+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistWarehouse(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	/* if(type=='shelf') {
		if(encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value) == '') {
			alert('Please Select a Warehouse!');
			return 0;
		}
	} */
	var vWarehouseCode = encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value);
	/* if(type=='warehouse')
	var vWarehouseCode = encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value);
	else var vWarehouseCode = encodeURIComponent(document.getElementById('locationcode['+PIndex+']').value);
	pwh=encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value); */
		
	//window.open('List_SorWarehouse.php?frm=2&index='+PIndex+'&PWarehouse_Code='+vWarehouseCode+'&warehouse_type='+type+'&parentWh='+pwh,'List_SorWarehouse','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
	window.open('List_SorWarehouse.php?frm=2&index='+PIndex+'&PWarehouse_Code='+vWarehouseCode,'List_SorWarehouse','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistWarehouse1() {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vWarehouseCode = encodeURIComponent(document.getElementById('txtItemWarehouse').value);
	
	window.open('List_SorWarehouse.php?frm=5&PWarehouse_Code='+vWarehouseCode,'List_SorWarehouse','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistBatchNo(str,PIndex) {
	x = document.adjustment;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 580) / 2;
	
	vItemCode = encodeURIComponent(document.getElementById('itemcode['+PIndex+']').value);
	vWarehouseCode = encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value);
	
	window.open('List_BatchNo.php?frm=10&index='+PIndex+'&PItem_Code='+vItemCode+'&PWarehouseCode='+vWarehouseCode,'List_BatchNo','width=580,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}
function showlistExpDate(str,PIndex){
	x = document.adjustment;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 580) / 2;
	
	vItemCode = encodeURIComponent(document.getElementById('itemcode['+PIndex+']').value);
	vWarehouseCode = encodeURIComponent(document.getElementById('warehousecode['+PIndex+']').value);
	
	window.open('List_ExpireDate.php?frm=1&index='+PIndex+'&PItem_Code='+vItemCode+'&PWarehouseCode='+vWarehouseCode,'List_ExpireDate','width=580,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);

}
function CalcAdjDtTotal(option,dec,PIndex) {
	x = document.adjustment;
	var vmode = x.actionmode.value;
	 
	var Qty      = document.getElementById('adjdtquantity['+PIndex+']').value;
	var Price    = document.getElementById('costprice['+PIndex+']').value;
	
	
	if (Qty == '') 		Qty = 0;
	if (Price == '') 	Price = 0;
	
	Qty      = parseFloat(Qty);
	Price    = parseFloat(Price);
	
	//if (Qty > 0 && Price >= 0) {
	   document.getElementById('adjdttotal['+PIndex+']').value = roundNumber((Qty*Price),dec);
	//}  
	
}
 
function CalcDiff(PIndex) { 
	x = document.adjustment;
	var Qty  = document.getElementById('adjdtquantity['+PIndex+']').value;
	var QtyExist  = document.getElementById('existingqty['+PIndex+']').value;
	if( Qty > QtyExist){
		alert("Reading Qty should be greater than existing Qty !");
		return 0;
	}
	else
	document.getElementById('Diffqty['+PIndex+']').value = QtyExist-Qty;
}
function CalcQty2(ModuleUnit1Method,Option,PIndex) { 
	x = document.adjustment;
	var Qty  = document.getElementById('adjdtquantity['+PIndex+']').value; 
	var Qty2 = document.getElementById('unit2qty['+PIndex+']').value;
	var UnitCoef = document.getElementById('itemunitcoef['+PIndex+']').value;
	
	if (Qty == '')  Qty = 0;
	if (Qty2 == '') Qty2 = 0;
	
	if(ModuleUnit1Method == 1) {
		if (Qty != 0 && Option == 1 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('unit2qty['+PIndex+']').value = Qty*UnitCoef;
		}	
		else if (Qty == 0 && Option == 1 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('unit2qty['+PIndex+']').value = '';
		}
	}
	//Case Modify Qty and Qty2 Should Be Empty
	else if(ModuleUnit1Method == 0 && Option == 1 && Qty2 == 0) {
		if (Qty != 0 && UnitCoef != 0 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('unit2qty['+PIndex+']').value = Qty/UnitCoef;
		}	
		else if (Qty == 0 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('unit2qty['+PIndex+']').value = '';
		}
	}
	//Case Modify Qty2 Get Qty
	else if(ModuleUnit1Method == 0 && Option == 2) {
		if (Qty2 != 0 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('adjdtquantity['+PIndex+']').value = Qty2*UnitCoef;
		}	
		else if (Qty2 == 0 && document.getElementById('unit2qty['+PIndex+']').type == 'text') {
			document.getElementById('adjdtquantity['+PIndex+']').value = '';
		}
	}
}

function ShowSlidingDiv(PDivID) {
	$(PDivID).slideToggle();
}

function Barcodekd(e)
{ 
	x=document.adjustment;
    var intKey = (window.Event) ? e.which : e.keyCode;
			
    if (intKey == 13) { //enter key
        x.btnSubmitBar.click();
		return false;
    }
	
    return true;
}

function changeQty2(vuniteQty,index){
	var vUnit2 = document.getElementById("itemunit2["+index+"]").value;
	
	if(vUnit2 == '') vUnit2 =0;
	if(vuniteQty == '') vuniteQty=0;
	document.getElementById("adjdtquantity["+index+"]").value = vuniteQty/vUnit2;
	var newqty = document.getElementById("adjdtquantity["+index+"]").value;
	if(document.getElementById("adjdttotal["+index+"]"))
	 document.getElementById("adjdttotal["+index+"]").value = parseFloat(newqty)*parseFloat(document.getElementById("costprice["+index+"]").value);
	
	
}

function showlistClient(str){
	var vdate, vcode;
	vdate=document.adjustment.txtDate.value;
	vcode=encodeURIComponent(document.adjustment.client_code.value);
	vname=encodeURIComponent(document.adjustment.client_name.value);
  
	window.open('List_SorClient.php?frm=10&item='+str+'&PLedger_name='+vname+'&PLedger_number='+vcode+'&TransDate='+vdate,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function setLoadChanging(){
	if(document.getElementById('chkloadchanging').checked){
		document.getElementById('chkloadchanging').value=1;
		document.getElementById('client_code').disabled=false;
		document.getElementById('client_name').disabled=false;
		document.getElementById('txtdivision').disabled=false;
		
	} else {
		document.getElementById('chkloadchanging').value=0;
		document.getElementById('client_code').disabled=true;
		document.getElementById('client_name').disabled=true;
		document.getElementById('txtdivision').disabled=true;
	}
}

function showlistUsers(str){
	window.open('list_users.php?frm='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>stocktake</title>


<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>

</head>
<body>
<form name='adjustment' method='post' enctype='multipart/form-data'>
<input type='hidden' name='HideMenu' value='$HideMenu'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='txtAdjId' value='$txtAdjId'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>
HERE;

$querydflwh="select default_warehouse_code as defaultwarehouse from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_warehouse_code != '' ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}



//Get Default Project from stocktakesetup
$querydflproject="select defaultproject as defaultprojectstocktakesetup from stocktakesetup ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}




	
//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}


 if (empty($defaultproject))
 {
	 $defaultproject =  $defaultprojectstocktakesetup;
 }



	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

	
if ((empty($txtProjectCode)) && $Module_Project == 1)
	$txtProjectCode = $defaultproject;
if ((empty($txtCostCentCode)) && $Module_CostCenter == 1)
	$txtCostCentCode = $defaultcostcent;	
if (empty($txtCurr)) {
	if ($SetupCurrencyBase == 1) $txtCurr = $base1;
	else $txtCurr = $base2;	
}	
if (empty($txtDate))	
	$txtDate = displayToday();
if (empty($txtAdjIsInvoice))
	$txtAdjIsInvoice = 0;
if (empty($txtUser))
	$txtUser = $_SESSION['useraccount'];	
	
	
if (empty($txtItemWarehouse)) {
	if (!empty($SetupDftWareHouse))
		$txtItemWarehouse = $SetupDftWareHouse;
	else	
		$txtItemWarehouse = $defaultwarehouse;
}

if (empty($txtItemQty)) $txtItemQty = 1;
	

// if ($txtEntryType != '') {
// 	$query  = " Select DebitAccount, CreditAccount, Ledger.Ledger_Name As DebitName, Ledger1.Ledger_Name As CreditName ".
// 			  " From stocktakeTypes ".
// 			  " Left Join Ledger on Ledger.Ledger_Number = stocktakeTypes.DebitAccount ".
// 			  " Left Join Ledger As Ledger1 on Ledger1.Ledger_Number = stocktakeTypes.CreditAccount ".
// 			  " Where Upper(stocktakeType_Code) = Upper('".$txtEntryType."')";
// 	$result = selectData($connection, $query);
	
// 	if ($AdjustType == 'O' && $result[1] != '') {
// 		$txtAdjIsInvoice  = 1;
// 		$txtInvDebit 	  = $result[0];
// 		$txtInvDebitName  = $result[2];
// 	}
// 	else if ($AdjustType == 'I' && $result[0] != '') {
// 		$txtAdjIsInvoice  = 1;
// 		$txtInvCredit 	  = $result[1];
// 		$txtInvCreditName = $result[3];
// 	}	
// }

 if ($actionmode != "cancel" && $txtAdjId != '') {
	// Read From Temp Tables For Selected Record				 
	$query = " Select stocktake_ID, stocktake_Reference, Date_Format(stocktake_Date,'%d/%m/%Y') As stocktake_Date, ".
	         " stocktake_Remak, stocktake.Project_Code, stocktake.Costcent_code,    ".
			 " stocktake.Currency_Code, ". 
			 " stocktake.User_Account ". 
			 " From Temp_stocktake As stocktake ".
	         " Where stocktake_ID = '".$txtAdjId."' ";  
 			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtAdjId      = $rows[0];
	$txtRef        = $rows[1];
	$txtDate       = $rows[2];
	$txtRemark     = $rows[3];
	$txtProjectCode   = $rows[4];
	$txtCostCentCode  = $rows[5];
	$txtCurr     	    = $rows[6];
	$txtUser  = $rows[7];
	
	$query = " Select Count(*) FROM Temp_stocktakeDt ".
			 " WHERE stocktake_id = ".$txtAdjId;
	$result = selectData($connection, $query);
	$txtAdjCountDetail = $result[0];
	if($txtAdjCountDetail == '') $txtAdjCountDetail = 0;
	
}

if(!isset($txtProjectCode) || $txtProjectCode == ''){
	 $txtProjectCode = $txtProjectCode1;
}



//$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'>";
if ($HideMenu != 1) 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'>Stock Take</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
//if ($FI_Insert == 1)
//	echo"<input type='button' id='btnAddItem' name='btnAddItem' value='Add Item'  onclick='AddItems($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter)' $style title='Add Item'>";

// if ($FI_Insert == 1 && $AdjustType == 'O' && $Module_SerialNo == 1)	
// 	echo" <button type='button' id='btnAddSerial' name='btnAddSerial' onclick='AddSerials($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;' title='Add Serial No'><span><span>Add Serials</span></span></button>";
	
				
	
	
	echo" <button type='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";
				
if ($txtAdjId != '')
	echo" <button type='button' id='btnCancel' name='btnCancel' onclick='CancelRecord();return false;' title='Cancel Changes'><span><span>Cancel</span></span></button>";
	
	
if ($txtAdjId != '')
	echo" <button type='button' id='btnPost' name='btnPost' onclick='PostChanges($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;' title='Save Changes'><span><span>Save</span></span></button>";


if ($txtAdjId != ''){
	//if($Module_sizes == 1 && $Module_Color == 1){
	echo" <button type='button' id='btnPost' name='btnPost' onclick=\"PrintBarcode($txtAdjId, '','1');return false;\" title='Save Changes'><span><span>Print Barcodes</span></span></button>";
	//}
}
if ($txtAdjId == '')
	echo" <button type='button' id='btnSearch' name='btnSearch' onclick='SearchForRef();return false;' title='Search By Reference'><span><span>Search</span></span></button>";


if ($txtAdjId == '')
	echo" <button type='button' id='btnPending' name='btnPending' onclick='SearchForPending();return false;' title='Pending stocktakes'><span><span>Pending</span></span></button>";

	
	// echo" <button type='button' id='btntransfer' name='btntransfer' onclick='itemTransfer();return false;' title='Item Transfer'><span><span>Item Transfer</span></span></button>";
	
// if ($Module_ImportExcell == 1) {
// 	echo"</td><td>";
// 	echo"<table border=0><tr>
// 			<td align='center' valign='middle'>
// 				<img src='./img/xls-icon.png' height='20px' width='22px' title='Download Excel Sheet' style='cursor: pointer;' onclick=\"downloadExcel();\">
// 				<button type='button' id='btnImport' name='btnImport' onclick=\"ImportExcel($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;\" title='Import From Excel'><span><span>Import Excel</span></span></button>
// 				<input type='file' name='excelfile' id='excelfile' style='width:200px;' accept='file/xls'>
// 			</td>
// 		</tr></table>";	
// }
		
echo"	</td></tr></table>";
echo"</td></tr>";				

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";	
print <<<HERE
	
		<table border="0" cellpadding="0" cellspacing="1" style='table-layout:fixed'>
		  <col width=80>
		  <col width=70>
		  <col width=55>
		  <col width=110>
		  <col width=40>
		  <col width=65>
		  <col width=50>
		  <col width=60>
		  <col width=85>
		  <col width=200>
		  <col width=70>
		  <col width=200>

		<tr bgcolor="#F7F7F7" >
          <td valign="center" align='left' ><span class="style1">Reference&nbsp;<span class="style16">*</span></span></td>
		  <td><font face='Verdana' size='2'><b>&nbsp;$txtRef</b></font>
			<input type='hidden' name='txtAdjCountDetail' value='$txtAdjCountDetail' >
 			<input type="hidden" name="txtRef" value="$txtRef" ></td>
		  <td align="left"><span class="style1">Date&nbsp;<span class="style16">*</span></span></td>
		  <td><input type='text' name='txtDate' value='$txtDate' maxlength='10'  style='width:80px;' >
		                   <A HREF="#" onClick="displayCalendar(document.adjustment.txtDate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A>
		 
   	      </td>
						   
HERE;

// if ($Module_PostToJournal == 1) {						   
// 	echo" <td align='left'><span class='style1'>Folio</span></td>	
// 		  <td><font face='Verdana' size='2'><b>&nbsp;$txtJvFolio</b></font></td>
// 		  <td align='left'><span class='style1'>JV Ref.</span></td>	
// 		  <td><font face='Verdana' size='2'><b>&nbsp;$txtJvRef</b></font></td>";
// } else 	{
	echo" <td align='left' colspan='4'>&nbsp;</td>";
// }

// if ($FI_ShowCostPrice == 1) {
// 	echo"     <td align='left' ><span class='style1'>Currency&nbsp;<span class='style16'>*</span></span></td>";
// 	echo"     <td ><span class='style1'><select name='txtCurr' id='txtCurr' style='width:80px;'>";
// 			  echo"<option></option>";
// 			  while($curf=mysql_fetch_row($resultcurrency)){
// 			  echo"<option ";
// 				if ($txtCurr==$curf[0])
// 					echo " selected ";
// 				echo" value='$curf[0]'>$curf[0] </option>";
// 			  }
// 			  echo"</select></span></td>";	
// } else {
	echo"     <td align='left' colspan='2'><input type='hidden' name='txtCurr' id='txtCurr' value='$txtCurr'></td>";
// }	

$Parameters = array();
$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['FI_ShowCostPrice'] 		= $FI_ShowCostPrice;
$Parameters['DecimalBase']  			= $DecimalBase;
$Parameters['DecimalBase1'] 			= $DecimalBase1;
$Parameters['DecimalBase2'] 			= $DecimalBase2;
$Parameters['Base1'] 					= $base1;
$Parameters['Base2'] 					= $base2;

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

$Parameters['txtDate'] 		   			= $txtDate;
$Parameters['txtCurrCode']     			= $txtCurr;
$Parameters['AdjustType']     			= $AdjustType;
$Parameters['Module_Heatno'] 			= $Module_Heatno;
$Parameters['module_locationstocktake'] = $module_locationstocktake;
$Parameters['module_allowexpiry'] 		= $module_allowexpiry;
$Parameters['ShowSellingPrice'] 		= $ShowSellingPrice;
$Parameters['Module_IsInvoice'] 		= $Module_IsInvoice;

$_SESSION['gadj_parameters']  			= $Parameters;


echo"	  <td rowspan='5' colspan='2' valign='top'>";

echo"	<div id='totals' style='width:270px; margin-top:3px; float:right;'>";
	// ShowstocktakeTotals($connection,$txtAdjId,$_SESSION['gadj_parameters'],$_SESSION['gadj_arrayaccess']);
echo"	</div>"; 

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



echo"   <tr bgcolor='#F7F7F7' >
		  <td align='left' ><span class='style1'>Remark</span></td><td colspan='7' > <span class='style1'>
		  <input type='text' name='txtRemark' value='".htmlspecialchars($txtRemark, ENT_QUOTES)."'  style='width:387px;' maxlength='100' ></td>";

// $querycashtype=" select user_account,user_account from userrequest ";
// $resultcashtype=mysql_query($querycashtype,$connection) or die(mysql_error());
// $numrow = mysql_num_rows($resultcashtype);		  
		  
// echo"	  <td align='left' ><span class='style1'>Request By</span></td><td><span class='style1'>";
// if ($numrow > 0){
// 	echo "<select name='txtRequestBy' id='txtRequestBy'  style='width:130px;'>";
// 	echo "<option value='' ".($rw[0] == ''?'selected':'')."></option>";
// 	while ($rw = mysql_fetch_array($resultcashtype)){
// 		echo "<option value='$rw[0]' ".($rw[0] == $txtRequestBy?'selected':'').">$rw[1]</option>";		
// 	}
// 	echo "</select>";
// } else
// echo "<input type='text' name='txtRequestBy' id='txtRequestBy' value='".htmlspecialchars($txtRequestBy, ENT_QUOTES)."'  style='width:130px;' maxlength='100' >
// 	<img src='img/btnopen.jpg' title=' Select User ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistUsers('6');\"  />";
// echo "</td>";
echo"   </tr>";		  


echo"   <tr bgcolor='#F7F7F7'>";

if ($Module_Project == 1) {
	echo" <td align='left' ><span class='style1'>Project&nbsp;<span class='style16'>*</span></span></td>
	      <td align='left' colspan='2'> <span class='style1'>
		    <input type='text' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' style='width:100px;' maxlength='20' onchange=\"CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeH');\" /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' id='lstProjectCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='3'><input type='hidden' name='txtProjectCode' id='txtProjectCode' value='' /></td>";

}			

if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1) {		  
	echo" <td align='right' ><span class='style1'>Costcenter&nbsp;<span class='style16'>*</span></span></td>		
		  <td align='left' colspan='5'><span class='style1'>
		    <input type='text' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' style='width:149px;' maxlength='20' onchange=\"CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeH');\" /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' id='lstCostCentCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='5'><input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='' /></td>";

}
			
echo"     <td align='left' ><span class='style1'>User</span><font face='Verdana' size='2'><b>&nbsp;&nbsp;&nbsp;$txtUser</b></font></td>";
echo"   </tr>";

echo"   <tr bgcolor='#F7F7F7'>";

// if ($Module_IsInvoice == 1) {
// 	echo"   <td align='left' valign='top' colspan='8' rowspan='3'><table border='0' cellpading='0' cellspacing='0' style='table-layout:fixed'>
// 			<col width=50>
// 			<col width=500>";

// 	echo"	<tr><td colspan='2'>
// 				<input type='hidden' name='txtAdjIsInvoice' value='$txtAdjIsInvoice' >
// 				<input type='checkbox' name='ChkIsInvoice' id='ChkIsInvoice' value='1' onClick='SetIsInvoice();' ";
// 				if($txtAdjIsInvoice==1 ) echo "checked  />"; else echo " />"; 
// 				echo "<span class='style1'>Is Invoice</span>";
// 	echo"   </td></tr>";				
// 	echo"   <tr><td><span class='style1'>Inv D </span></td><td><span class='style1'><label>";
// 	echo"       <input type='text'   name='txtInvDebit' id='txtInvDebit' value='$txtInvDebit' style='width:93px;' maxlength='10'  onchange=\"CheckLookup('chkcodeexists','ledgers','ledger_number',this.value,'lstLedgerCodeD'); \" />
// 				<input type='text'   name='txtInvDebitName' id='txtInvDebitName' value='$txtInvDebitName' style='width:320px;'  onchange=\"CheckLookup('chkcodeexists','ledgers','ledger_name',this.value,'lstLedgerNameD');\" />
// 				</label></span>
// 				<label><img src='img/btnopen.jpg' title=' Select Ledger ' id='lstLedgerCodeD' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('1','');\" /></label>
// 				<label><img src='img/btnopen.jpg' title='Select Ledger' id='lstLedgerNameD' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistLedgersName(1);' style='display:none;' /></label>
// 			</td></tr>";
	
// 	echo"   <tr><td><span class='style1'>Inv C </span></td><td><span class='style1'><label>";
// 	echo"       <input type='text'   name='txtInvCredit' id='txtInvCredit' value='$txtInvCredit' style='width:93px;' maxlength='10' onchange=\"CheckLookup('chkcodeexists','ledgers','ledger_number',this.value,'lstLedgerCodeC'); \" />
// 				<input type='text'   name='txtInvCreditName' id='txtInvCreditName' value='$txtInvCreditName' style='width:320px;' onchange=\"CheckLookup('chkcodeexists','ledgers','ledger_name',this.value,'lstLedgerNameC');\" />
// 				</label></span>
// 				<label><img src='img/btnopen.jpg' title=' Select Ledger ' id='lstLedgerCodeC' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('2',''); \" /></label>
// 				<label><img src='img/btnopen.jpg' title='Select Ledger' id='lstLedgerNameC' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistLedgersName(2);' style='display:none;' /></label>
// 			</td></tr>";
// 	echo" </table></td>";
// } else {
	// echo"	<td colspan='8'>
	// 			<input type='hidden' name='txtAdjIsInvoice' value='$txtAdjIsInvoice' >
	// 			<input type='hidden' name='txtInvDebit'  value='$txtInvDebit' >
	// 			<input type='hidden' name='txtInvDebitName'  value='$txtInvDebitName' >
	// 			<input type='hidden' name='txtInvCredit'  value='$txtInvCredit' >
	// 			<input type='hidden' name='txtInvCreditName'  value='$txtInvCreditName' >
	// 		</td>";
// }



// echo"     <td align='left' ><span class='style1'>Entry Type</span></td>";
// echo"     <td ><span class='style1'><select name='txtEntryType' id='txtEntryType' style='width:130px;' onchange='SelectType();'>";
// 		  while($adjtype=mysql_fetch_row($resulttypes)){
// 			echo"<option ";
// 			if ((strtoupper($txtEntryType)==strtoupper($adjtype[0])) || ($txtEntryType=='' && $adjtype[3] == 1))
// 				echo " selected ";
// 		    echo" value='".strtoupper($adjtype[0])."'>$adjtype[0] </option>";
// 		  }
	  
// echo"	  </select></span></td>";

echo"   <td>&nbsp;</td>";
echo"	</tr>";
// echo "<tr><td><span class='style1'>Manual No</span></td><td><input type='text' name='txtManualNo' id='txtManualNo' value='".htmlspecialchars($txtManualNo, ENT_QUOTES)."' style='width:130px;' maxlength=45></td></tr>";
if ($Module_IsInvoice == 1) {
	echo"   <tr bgcolor='#F7F7F7' >
			  <td align='left' colspan='2'><span class='style1'>&nbsp;</span></td>";
	echo"   </tr>";	

	echo"   <tr bgcolor='#F7F7F7' >
			  <td align='left' colspan='2'><span class='style1'>&nbsp;</span></td>";
	echo"   </tr>";	
}


// if ($Barcode==1) {
if (1==1) {
echo"   <tr bgcolor='#F7F7F7' height='30px;'>
			<td align='left' colspan='10'>
			<span class='style1'>Item Code</span>
				<input type='text' name='itemcode1' id='itemcode1' value='' style='width:130px;' maxlength='20' />
				<label><span><img src='img/btnopen.jpg' title='Select Item' id='lstItemCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems1(1); ' style='vertical-align:bottom;'/></span></label>

				<span class='style1'>Barcode</span>
				<input type='text' name='txtItemBarcode' id='txtItemBarcode' value='' style='width:130px;' maxlength='20' onkeydown='return Barcodekd(event);'/>
				<span class='style1'>Qty&nbsp;</span>
				<input type='text' name='txtItemQty' value='$txtItemQty' style='width:70px;' maxlength='10'/>
				<span class='style1'>Warehouse</span>
				<input type='text' name='txtItemWarehouse' id='txtItemWarehouse' value='".htmlspecialchars($txtItemWarehouse, ENT_QUOTES)."' style='width:70px;' maxlength='15'/>
				<label><span><img src='img/openlist.png' title='Select Warehouse' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouse1();' style='vertical-align:bottom;'/></span></label>
				<button type='button' id='btnSubmitBar' name='btnSubmitBar' onclick='SubmitItemBarcode($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;' title='Submit'><span><span>Submit</span></span></button>
			</td>	
		</tr>";
}
if($stocktake_loadCharging == 1 && $AdjustType == 'O' && $Module_IsInvoice == 1){
if($chkloadchanging == '') $chkloadchanging = 0;

if($chkloadchanging == 0) $disabled = 'disabled';	
else if($chkloadchanging == 0) $disabled = '';	

echo" <tr bgcolor='#F7F7F7'>
		  <td align='left' ><span class='style1'>Client</span></td>";
echo"     <td colspan='7' ><span class='style1'>";
echo"     <label>

           <input type='text'   name='client_code' id='client_code' value='$client_code' style='width:95px;' maxlength='10' $disabled />           
		   <input type='text'   name='client_name' id='client_name' value='$client_name' style='width:285px;' $disabled />
		   <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Client ' id='lstClientCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistClient(1); '  /> </span></label>
		   </label>
          </span>
          </td>";
echo "  <td align='left' ><span class='style1'>Division</span></td>
		<td> <input type='text'   name='txtdivision' id='txtdivision' value='$txtdivision' style='width:100px;'  $disabled /></td>";		  
echo "<td colspan='2'><input type='checkbox' name='chkloadchanging' id='chkloadchanging' value='$chkloadchanging' onclick=\"setLoadChanging();\"".($chkloadchanging == 1?'checked':'')."><span class='style1'>Load to Changing</span></td>";		
echo "</tr>";		  
} else {
	echo "<input type='hidden' name='client_name' id='client_name' value='$client_name' ><input type='hidden' name='txtdivision' id='txtdivision' value='$txtdivision' >
		  <input type='hidden' name='chkloadchanging' id='chkloadchanging' value='$chkloadchanging' >";
}
/*
echo"		<option value='stocktake'"; if ($txtEntryType == 'stocktake' || $txtEntryType == '') echo 'selected'; echo" >stocktake</option>";
echo"		<option value='PRODUCTION'"; if ($txtEntryType == 'PRODUCTION') echo 'selected'; echo" >Production</option>";
echo"		<option value='DIESEL'"; if ($txtEntryType == 'DIESEL') echo 'selected'; echo" >Diesel</option>";
echo"		<option value='PR'"; if ($txtEntryType == 'PR') echo 'selected'; echo" >PR</option>";
echo"		<option value='MGT ALLOWANCE'"; if ($txtEntryType == 'MGT ALLOWANCE') echo 'selected'; echo" >MGT Allowance</option>";
echo"		<option value='STAFF ALLOWANCE'"; if ($txtEntryType == 'STAFF ALLOWANCE') echo 'selected'; echo" >Staff Allowance</option>";
echo"		<option value='DAMAGE'"; if ($txtEntryType == 'DAMAGE') echo 'selected'; echo" >Damage</option>";
*/

  /*
echo"<tr bgcolor='#F7F7F7'>";
echo"	<td align='left' ><span class='style1'>Divisions</span></td>";
echo"	<td align='left' colspan='7'> <span class='style1'>
		<span class='style1'><select name='txtDivType' id='txtDivType' style='width:100px;'>";
		echo"<option></option>";
		while($divtype=mysql_fetch_row($resultdivtype)){
			echo"<option ";
			if ($txtDivType==$divtype[0])
				echo " selected ";
			echo" value='$divtype[0]'>$divtype[0] </option>";
		}
echo"	</select></span>";
echo"	<input type='hidden' name='txtAdjDivID' id='txtAdjDivID' value='$txtAdjDivID'> ";
echo"	<input type='hidden' name='txtDivisionID' id='txtDivisionID' value='$txtDivisionID'> ";
echo"	<input type='text' name='txtDivisionCode' id='txtDivisionCode' value='$txtDivisionCode' style='width:150px;' maxlength='15' readonly /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Division ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistDivision(1); '/></span></label>";
echo"	<input type='button' id='btnAddDivision' name='btnAddDivision' value='Submit'  onclick=\"AddDivision();\" $style title='Add Division'>";
echo"	<input type='button' id='btnClearDivision' name='btnClearDivision' value='Clear'  onclick=\"ClearDivision();\" $style title='Clear Division'>";
echo"   </td>";
	
echo"   <td align='left' colspan='4'>&nbsp;</td>";
echo"</tr>";

if ($txtAdjId != '' ) {
	$sub_query = " Select stocktakeDivisions_Id, stocktakeDivisions.Divisions_Id, DivisionTypes_Name, Divisions_Code, Divisions_Name  ".
				 " From Temp_stocktakeDivisions As stocktakeDivisions ".
				 " Inner Join Divisions on stocktakeDivisions.Divisions_Id = Divisions.Divisions_Id ".
				 " Inner Join DivisionTypes on Divisions.DivisionTypes_Id = DivisionTypes.DivisionTypes_Id ".
				 " Where stocktakeDivisions.stocktake_Id = '".$txtAdjId."' ";
	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());	
	$sub_totalrows = mysql_num_rows($sub_result);
	//echo $sub_query;
	
	if ($sub_totalrows > 0) {
		
		echo"<tr bgcolor='#F7F7F7'>";
		echo"	<td align='left' colspan='8'>";
		echo"	<table border='0' style='table-layout:fixed'>
				  <col width=20>
				  <col width=20>
				  <col width=100>
				  <col width=130>
				  <col width=250>";
		echo"		<tr>";
		echo"  			<td bgcolor='#F7F7F7' align='left' colspan='3'><span class='style27'>&nbsp;</span></td>";
		echo"  			<td bgcolor='#F7F7F7' align='left'><span class='style27'>Code</span></td>";
		echo"  			<td bgcolor='#F7F7F7' align='left'><span class='style27'>Name</span></td>";		  
		echo"		</tr>";
		
		while($sub_rows=mysql_fetch_array($sub_result)){
			$ct+=1;

			if($ct%2==0)
				$Color="style='background-color:".$grid_color1."'";
			else			
				$Color="style='background-color:".$grid_color2."'";	
						
					
			echo "<tr ".$Color." >";
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"EditDivision('".$sub_rows[0]."','".$sub_rows[1]."','".htmlentities($sub_rows[2])."','".htmlentities($sub_rows[3])."')\" title='Edit Record'  ></span></td>";
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeleteDivision('".$sub_rows[0]."','".htmlentities($sub_rows[2])."','".htmlentities($sub_rows[3])."')\" title='Delete Record'  ></span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[2]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[3]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[4]."</span></td>";
			echo "</tr>";
									
		}
		
		echo"	</table></td>";
		echo"   <td align='left' colspan='4'>&nbsp;</td>";
		echo"</tr>";

	}	
}			  
	*/	  

	
/*	
echo"   <tr><td colspan='12' valign='top' align='left'>";
echo"	<div style='overflow:scroll; height:180px; width:990px;' >";
echo"     <table border='0' style='table-layout:fixed'>
          <col width=20>
		  <col width=20>
		  <col width=20>";
		  
if ($Module_DoubleUnit == 1) {		  
	echo" <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=80>
		  <col width=80>
		  <col width=60>
		  <col width=70>
		  <col width=60>
		  <col width=70>
		  <col width=55>
		  <col width=90>
		  <col width=110>";
		  
	if ($Module_ProjectDt == 1)	
		echo"<col width=100>";
	if ($Module_CostCenterDt == 1)
		echo"<col width=100>";
	if ($Module_ExpireDate == 1) {
		echo"<col width=80>";
		echo"<col width=80>";
	}	  
} else {
	echo" <col width=120>
		  <col width=120>
		  <col width=110>
		  <col width=105>
		  <col width=70>
		  <col width=60>
		  <col width=60>
		  <col width=60>
		  <col width=90>
		  <col width=110>";
		  
	if ($Module_ProjectDt == 1)	
		echo"<col width=100>";
	if ($Module_CostCenterDt == 1)
		echo"<col width=100>";
	if ($Module_ExpireDate == 1) {
		echo"<col width=80>";
		echo"<col width=80>";
	}
}		  

		echo"<tr height='25'>";
		echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code Packed</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='left' colspan='2'><span class='style27'>Description</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>WH</span></td>";
		
		//if ($Module_DoubleUnit == 1)
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit1</span></td>";
			
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Qty</span></td>";
		
		if ($Module_DoubleUnit == 1) {
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit2</span></td>";
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit2 Qty</span></td>";
		 }
		 
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>S/N Bal</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Cost Price</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Total</span></td>";
		
		if ($Module_ProjectDt == 1)	
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Project</span></td>";
		if ($Module_CostCenterDt == 1)
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>CostCenter</span></td>";
		if ($Module_ExpireDate == 1) {
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Batch No</span></td>";
			echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Expire Date</span></td>";
		}
		echo"</tr>";


		  
		if ($txtAdjId != '' ) {
		
			//Checking For Difference Btw Qty and Count SerialNo
		    $QtySerNoCheck = 0;
			echo '<script type="text/javascript" language="javascript">';
			echo ' x = document.adjustment; ';
  			echo ' x.QtySerNo.value=0; ';
			echo '</script>';
			
			$querydt = " Select stocktakeDt.stocktakeDt_ID, stocktakeDt.Item_CodePacked, stocktakeDt.Item_code, Item_Description, stocktakeDt.Warehouse_Code, ".
					   " stocktakeDt_Quantity, Round(stocktakeDt_Price, ".$DecimalBase."), stocktakeDt_PriceBase1, stocktakeDt_PriceBase2, ".
					   " Round((ifNull(stocktakeDt_Quantity,0)*ifNull(stocktakeDt_Price,0)), ".$DecimalBase.") As TotalAmount, ".
					   " Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, ifNull(item_withserialno,0) As ItemWithSerialNo, ".
					   " stocktakeDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc,  ".
					   " Date_Format(stocktakeDt.stocktakeDt_ExpireDate,'%d-%m-%Y') As ExpireDate, stocktakeDt.stocktakeDt_BatchNo, stocktakeDt.Project_code, stocktakeDt.CostCent_Code ".
					   " From Temp_stocktakeDt As stocktakeDt Left Join Items on stocktakeDt.Item_code = Items.Item_code ".
					   " Left Join Temp_Purchasesserialno on stocktakeDt.stocktakeDt_ID = Temp_Purchasesserialno.PurchaseDt_ID ".
					   " And Temp_Purchasesserialno.Journal_Type = stocktakeDt.Journal_Type ".
					   " Where stocktakeDt.stocktake_ID = ".$txtAdjId.
					   " Group By  stocktakeDt.stocktakeDt_ID ".
					   " Order By stocktakeDt.stocktakeDt_ID Desc ";
			//echo $querydt;
			$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
			while($rowsdt=mysql_fetch_array($resultdt)){
			    $ct+=1;

				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
					
				
				echo "<tr ".$Color." >";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[11] == 1 && $Module_SerialNo == 1) 
					echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$rowsdt[0]."','".htmlentities($rowsdt[2])."',$rowsdt[5],'".htmlentities($rowsdt[4])."')\" title='Add Serial Nos'  ></span></td>";
				else
					echo "	<td align='center' valign='center'>&nbsp;</td>";
					
				echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateAdjDt('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
				echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeleteAdjDt('".$rowsdt[0]."','".htmlentities($rowsdt[1])."','".htmlentities($rowsdt[2])."')\" title='Delete Record'  ></span></td>";
				
				/*if ($Module_DivisionsDt == 1) {
					echo "	<td align='center' valign='center'><span class='style15'><img src='img/details.gif'  onMouseOver=\"style.cursor='hand'\" onclick=ShowDivisions('".$rowsdt[0]."') title='Show Divisions'  ></span></td>";
				} else {
					echo "	<td align='center' valign='center'>&nbsp;</td>";
				}	*/
			/*
				echo "	<td align='left'><span class='style15'>".$rowsdt[1]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$rowsdt[2]."</span></td>";
				echo "	<td align='left' colspan='2'><span class='style15'>".$rowsdt[3]."</span></td>";
				
				
				echo "	<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
				
				//if ($Module_DoubleUnit == 1)
					echo "	<td align='left'><span class='style15'>".$rowsdt[14]."</span></td>";
				
				// if Total Quantity Differs From Total SerialNos
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ((Abs($rowsdt[5]) != $rowsdt[10] && $rowsdt[11] == 1 && $Module_SerialNo == 1) || ($rowsdt[5] == 0 && $rowsdt[11] == 1 && $Module_SerialNo == 1)) {
				    if ($QtySerNoCheck == 0) {
						$QtySerNoCheck = 1;
						
						echo '<script type="text/javascript" language="javascript">';
						echo ' x = document.adjustment; ';
						echo ' x.QtySerNo.value=1; ';
						echo '</script>';
					}					
						
					echo "	<td align='right' style='background-color:#FF0000' ><span class='style28' style='text-decoration:underline;'>".$rowsdt[5]."</span></td>";
				} else	
					echo "	<td align='right'><span class='style15'>".$rowsdt[5]."</span></td>";
					
				if ($Module_DoubleUnit == 1) { 
					echo "	<td align='left'><span class='style15'>".$rowsdt[13]."</span></td>";	
					echo "	<td align='right'><span class='style15'>".$rowsdt[12]."</span></td>";	
				}	
					
				echo "	<td align='right'><span class='style15'>".$rowsdt[10]."</span></td>";	
				echo "	<td align='right'><span class='style15'>".number_format($rowsdt[6], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($rowsdt[9], $DecimalBase)."</span></td>";
				
				if ($Module_ProjectDt == 1)	
					echo "	<td align='left'><span class='style15'>".$rowsdt[17]."</span></td>";
				if ($Module_CostCenterDt == 1)
					echo "	<td align='left'><span class='style15'>".$rowsdt[18]."</span></td>";
				if ($Module_ExpireDate == 1) {
					echo "	<td align='left'><span class='style15'>".$rowsdt[16]."</span></td>";
					echo "	<td align='left'><span class='style15'>".$rowsdt[15]."</span></td>";
				}
				
				echo "</tr>";
						
			
			}
			
			
		}
echo "</table></div>";

echo"   </td></tr>";
*/
/*
echo"   <tr bgcolor='#D8D8D8' height='30'><td colspan='12' align='center'>";

if ($FI_Insert == 1)
	echo"<input type='button' id='btnAddItem' name='btnAddItem' value='Add Item'  onclick='AddItems($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter)' $style title='Add Item'>";

if ($FI_Insert == 1 && $AdjustType == 'O' && $Module_SerialNo == 1)	
	echo"<input type='button' id='btnAddSerial' name='btnAddSerial' value='Add Serials'  onclick='AddSerials($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter)' $style title='Add Serial No'>";
				
echo"   <input type='button' id='btnClear' name='btnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";
				
if ($txtAdjId != '')
	echo"   <input type='button' name='btnCancel' id='btnCancel' value='Cancel' onclick='CancelRecord();' $style title='Cancel Changes'>";
	
if ($txtAdjId != '')
	echo"   <input type='button' name='btnPost' id='btnPost' value='Save' onclick='PostChanges($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);' $style	title='Save Changes' />";

if ($txtAdjId == '')
	echo"   <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForRef();' $style title='Search By Reference' />";

if ($txtAdjId == '')
	echo"   <input name='btnPending' type='button' id='btnPending' value='Pending' onclick='SearchForPending();' $style title='Pending stocktakes'  />";

if ($FI_Insert == 1)
	echo"   <input name='btnLoading' type='button' id='btnLoading' value='Load From Request' onclick='loadfromrequest();' $style title='Loading Request'  />";	
	
		
echo"   </td></tr>";*/	


echo"   <tr bgcolor='#ffffff'><td colspan='12' valign='top'>";
echo"	<div id='datagrid' class='grid' style='width:1090px;' >";

//Show Items Grid
ShowstocktakeDtGrid($connection,'ADJ',$txtAdjId,$_SESSION['gadj_parameters'],$_SESSION['gadj_arrayaccess'],'stocktakeDt.stocktakeDt_ID');

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

echo"   </table></td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo" </table>  ";//end of last table menu
	
if ($actionmode == "post" && $PrAdjId != '') {
	echo '<script type="text/javascript" language="javascript">';
	
	if ($Login_FastPrint == 1) 
		echo ' Printstocktake(\''.$PrAdjId.'\', \''.$PrAdjRef.'\'); ';
		//if($Module_ProjectDt == 1 && $Module_CostCenterDt == 1){
	?>
	PrintBarcode('<?php echo $PrAdjId; ?>', '<?php echo $PrAdjId; ?>', '0');
	<?php
	//}
	echo ' ClearPage1(); ';
	echo '</script>';

}

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

HERE;

?>