<?php

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


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

//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Pack,0) As Module_Pack, ".
			 " 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_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_PRequestConfirm,0) As Module_PRequestConfirm, ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_Unit1Method,0) As Module_Unit1Method ".
			 ", ifnull(Module_PurchaseRequestPrice,0) as Module_PurchaseRequestPrice, ifNull(Module_Heatno,0) As Module_Heatno ".
			 " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}
					
$querylog="select * 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);
}

$AdjustType = 'O';

	$querylog="SELECT FI_OUTREQUEST as loginaccess, FI_OutappRequest As FI_Insert, ifNull(Login_FastPrintRequest,0) As Login_FastPrint 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);
}

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 AdjustmentSetup Table
$queryAdjustSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout From AdjustmentSetup ";
$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 ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querytypes="select AdjustmentType_Code, DebitAccount, CreditAccount, AdjustmentType_Default from AdjustmentTypes order by AdjustmentType_Code";
$resulttypes=mysql_query($querytypes,$connection) or die(mysql_error());

$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"];}   


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

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

$querydflwh="select warehouse_code as defaultwarehouse from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and ifNull(default_warehouse,0) = 1 ";

$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}


$_SESSION['prqstdefaultcostcent'] = $defaultcostcent;
$_SESSION['prqstdefaultwarehouse'] = $defaultwarehouse;
$_SESSION['prqstdefaultproject'] = $defaultproject;



 $FormTitle = 'STOCK OUT REQUEST';  

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">
<script type="text/javascript" language="javascript">



function CheckFields(ModuleRestProj, ModuleRestCost){
  
    x = document.adjustmentrequest;
	
	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=='' )
	{
		alert("Currency Column is mandatory!");
		x.txtCurr.focus();
		return 0;
	}*/
	else if (AdjProject=='' && ModuleRestProj==1)
	{
		alert("Project is mandatory!");
		x.txtProjectCode.focus();
		return 0;
	}
	else if (AdjCostCenter=='' && ModuleRestCost==1 && document.getElementById('txtCostCentCode').type == 'text')
	{
		alert("CostCenter is mandatory!");
		x.txtCostCentCode.focus();
		return 0;
	}
	
			
	
	else
	return 1 ;	
}


function showlistCostcenter(vtype,vtext1,vwidth,vheight,item){
  	var text1value = document.getElementById(vtext1).value;
	
	if (item=='')
		item = 2;
	win = window.open('List_Costcenter.php?PCostcent_Code='+text1value+'&item='+item+'&vtype='+vtype+'&vtext1='+vtext1
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	

	
}




function setcostcentercode(val,vfield1,btnname){

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]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						
						//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

				}
		}
  }

xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?vcostcentercode="+val+"&actionmode=checkcostcentercode",true);
xmlhttp.send();

}
function setprojectcode(val,vfield1,btnname){

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]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						

				}
		}
  }

xmlhttp.open("GET","Form_PurchaseRequest_Actions.php?vprojectcode="+val+"&actionmode=checkprojectcode",true);
xmlhttp.send();

}


function setitemcode(val,vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,vgridname,btnname,btnname1,codedesc, index){

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]");
					var resp = data[1];
					
					if (resp==0)
						{
							if (codedesc==1)
								document.getElementById(btnname).click();
							else	
								document.getElementById(btnname1).click();
						}
						else
							{	
								if (codedesc==1){
									document.getElementById(vfield2).value = resp;
									if(document.getElementById('txtcostpriceDt['+index+']'))
									document.getElementById('txtcostpriceDt['+index+']').value = data[2];
								}
								else	
									document.getElementById(vfield1).value = resp;
							}	
						//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

				}
		}
  }

  if (codedesc==1){
	var vDate = document.adjustmentrequest.txtDate.value; 
	xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?vitemcode="+val+"&codedesc="+codedesc+"&actionmode=checkitemcode&vDate="+vDate,true);
  }
else	
  if (codedesc==2)
	xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?vitemdesc="+val+"&codedesc="+codedesc+"&actionmode=checkitemcode",true);  
  
  
xmlhttp.send();

}


function showsearchpage1(vtype,vtext1,vtext2,vtext3,vtext4,vtext5,vtext6,vwidth,vheight){

	
	
	
		var text2value = document.getElementById(vtext2).value;
		
		
	win = window.open('List_PurItems.php?PItem_Code=&PItem_Description='+text2value+'&item=6&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vtext3='+vtext3
						+'&vtext4='+vtext4+'&vtext5='+vtext5+'&vtext6='+vtext6
						+'&text1value=', 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}
	
	
	
function dokeytransferrequest(e,obj,rowindx,columnslist,vbutname){





	//if (e.ctrlKey == false)
	//return;
	var vindx = rowindx;
	if (!e) { var e = window.Events;}
    var intKey = (window.Events) ? e.which : e.keyCode;


	var columnsarray=new Array();
	columnsarray = columnslist.split(",");
	var firstcell = columnsarray[0];
	var lastcell  = columnsarray[columnsarray.length-1];
	var arrayname = obj.id.split("[");

	if (( ((intKey == 37) || (intKey == 39)) && e.ctrlKey )  ||  (intKey == 13))
	{
		var cindx = columnsarray.indexOf(arrayname[0]);
		
		if (intKey == 37) { //left key
			var nextindx = Number(cindx) - 1;
		}
		if (intKey == 13 || intKey == 39) { //right key
			var nextindx = Number(cindx) + 1;
		}


		var nextitem = columnsarray[nextindx] + '[' + rowindx + ']' ;

		
		if (document.getElementById(nextitem)) {
			var nextobj = document.getElementById(nextitem);
			nextobj.focus();
			if(nextobj.type!='select-one')
			nextobj.select();
		}
		else { 
			var nextrow  = rowindx + 1;
			var nextcell = firstcell + '[' +  nextrow + ']';
				
			var imgname = 'imgSubmit' + vbutname + '[' +  rowindx + ']';
			
			document.getElementById(imgname).click();
			
			if (document.getElementById(nextcell) ) {
				document.getElementById(nextcell).focus();
				if(document.getElementById(nextcell).type!='select-one')
				document.getElementById(nextcell).select();
			}	
					
		}	
	}
	else if ( ((intKey == 38) || (intKey == 40)) && e.ctrlKey) {
		
		if (intKey == 38) 
			rowindx = rowindx - 1;
		if (intKey == 40) 
			rowindx = rowindx + 1;
			
		var nextitem =  arrayname[0] + '[' + rowindx + ']';
		if (document.getElementById(nextitem)) {
			var nextobj = document.getElementById(nextitem);
			nextobj.focus();
			if(nextobj.type!='select-one')
			nextobj.select();
		}	
	}

}

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

function ClearPage1(){
	x = document.adjustmentrequest;
	var msg = x.message.value;
	var vAdjustType = x.AdjustType.value;
	
	ClearForm('All');
	
	x.mainaction.value='insert';
	x.actionmode.value='';
	x.message.value=msg;
	x.action='Form_AdjustmentRequest.php?AdjustType='+vAdjustType;
	x.submit();
}

function CancelRecord(){
	x = document.adjustmentrequest;
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	var vAdjId = x.txtAdjId.value;
	var vAdjustType = x.AdjustType.value;
	
	if (confirm ( "Are you sure you want to Delete current pending adjustment permenantly?"))
	{
		ClearForm('All');
		x.txtAdjId.value = vAdjId;
		x.mainaction.value='insert';
		x.actionmode.value='cancel';
		x.action='Form_AdjustmentRequest.php?AdjustType='+vAdjustType;
		x.submit();
	}
    
}



function PostChanges(ModuleRestProj, ModuleRestCost) {
	x = document.adjustmentrequest;
	var vAdjId  = x.txtAdjId.value;
	var vMainMode = x.mainaction.value;
	var vAdjustType = x.AdjustType.value;
	
	var result = CheckFields(ModuleRestProj, ModuleRestCost);
	
	if (result == 1) {
		if (confirm ( "Are you sure you want to Save current adjustment request?"))
		{
			x.btnPost.disabled = true;
			x.btnCancel.disabled = true;
			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_AdjustmentRequest_Actions.php?AdjustType='+vAdjustType+'&mode=post&mainmode="+vMainMode+"&SAdjId="+vAdjId;
			x.submit();
		}
	}
}
	
function DeleteAdjDt(AdjDtId, ItemPackCode, ItemCode) {
	x = document.adjustmentrequest;
	var vAdjId  = x.txtAdjId.value;
	var vMainMode = x.mainaction.value;
	var vAdjustType = x.AdjustType.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_AdjustmentRequest_Actions.php?AdjustType='+vAdjustType+'&mode=deletedt&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDtId="+AdjDtId;
		x.submit();
	}

}

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

}


function AddSerialNo(AdjDtId, ItemCode, AdjDtQty, WhCode) {
	x = document.adjustmentrequest;
	var vAdjId 		= x.txtAdjId.value;
	var vAdjustType = x.AdjustType.value;
	
	WhCode = WhCode.replace('&','%26');
	WhCode = WhCode.replace('#','%23');
	
	XPos = (screen.availHeight - 450) / 2;
	YPos = (screen.availWidth - 550) / 2;
    win = window.open('Form_AdjustmentRequestSerialNo.php?AdjustType='+vAdjustType+'&SRAdjDtId='+AdjDtId+'&SRAdjId='+vAdjId, 'Form_AdjustmentRequestSerialNo', 'titlebar=no,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no, width=550,height=450,left='+YPos+',top='+XPos);
	//win.creator = self;
	//win.focus();		
	
}

function AddDivision(){
	x = document.adjustmentrequest;
	
	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_AdjustmentRequest_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDivId="+vAdjDivId;
		x.submit();
	
	}
}

function EditDivision(AdjDivId, DivisionId, DivisionType, DivisionCode) {
	x = document.adjustmentrequest;
	
	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.adjustmentrequest;
	
	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_AdjustmentRequest_Actions.php?mode=deletedivision&mainmode="+vMainMode+"&SAdjId="+vAdjId+"&SAdjDivId="+AdjDivId;
		x.submit();
	}

}

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

}

function ShowDivisions(AdjDtId) {
	x = document.adjustmentrequest;
	var vAdjId   = x.txtAdjId.value;
	var vAdjustType = x.AdjustType.value;
		
	var vMainMode = x.mainaction.value;
	
	win = window.open('Form_AdjustmentRequestDtDivisions.php?AdjustType='+vAdjustType+'&mainaction='+vMainMode+'&actionmode=&PAdjId='+vAdjId+'&PAdjDtId='+AdjDtId, 'Form_AdjustmentDtDivisions', '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.adjustmentrequest;
	var vmode = x.actionmode.value;
	
	if (Option == 'All') {
		
		x.txtAdjId.value='';
		x.txtRef.value='';
		x.txtDate.value='';
		
		
		x.txtRequestBy.value='';
		x.txtAdjIsInvoice.value=0;
		x.txtInvDebit.value='';
		x.txtInvCredit.value='';
		x.txtInvDebitName.value='';
		x.txtInvCreditName.value='';
		x.txtRemark.value='';

		x.txtProjectCode.value='';
		x.txtCostCentCode.value='';
		x.txtEntryType.value='';
		
		
		
		x.message.value='';
		
	
		x.actionmode.value = '';
		x.mainaction.value = '';
	} 
}

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

	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 vAdjustType      = x.AdjustType.value;
	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_AdjustmentRequestDetail.php?AdjustType='+vAdjustType+'&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_AdjustmentRequestDetail', '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) {
	x = document.adjustmentrequest;
	var result = CheckFields(ModuleRestProj, ModuleRestCost);

	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 vAdjustType      = x.AdjustType.value;
	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_AdjustmentRequestAddSerial.php?AdjustType='+vAdjustType+'&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_AdjustmentRequestAddSerial', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=780,height=400,top=100');		
		win.creator = self;
		win.focus();		
	}

}

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

}




function SearchForRef(){
    //ClearForm('All');
    x = document.adjustmentrequest;
	var vAdjustType = x.AdjustType.value;
    win = window.open('Form_AdjustmentRequestSearch.php?AdjustType='+vAdjustType, 'Form_AdjustmentRequestSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=680,height=480,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}

function SearchForPending(){
    //ClearForm('All');
    x = document.adjustmentrequest;
	var vAdjustType = x.AdjustType.value;
    win = window.open('Form_AdjustmentRequestSearchPending.php?AdjustType='+vAdjustType, 'Form_AdjustmentRequestSearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=960,height=580,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}

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


function PrintAdjustment(AdjId, AdjRef) {
	var str = '';
	var vPrtSer = 0;
	
	if (confirm ( "Do you want to Print current record with reference "+AdjRef+" ?"))
	{
				
		str = 'Form_AdjustmentRequestPreview.php?AdjustmentRequestId='+AdjId+'&PrtSer='+vPrtSer;
		window.open(str);
	}	
}


function showlistDivision(str) {
	x = document.adjustmentrequest;
	
	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 showlistProject(vtype,vtext1,vwidth,vheight,item){
  	var text1value = document.getElementById(vtext1).value;
	if (item=='')
		item = 2;
	win = window.open('List_Project.php?PProject_Code='+text1value+'&item='+item+'&vtype='+vtype+'&vtext1='+vtext1
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	

	
}
function showlistWarehouse(str,wrh){

var text1value = document.getElementById(wrh).value;

  window.open('List_TrsWarehouseGrid.php?item='+str+'&Warehouse='+wrh+'&PLedger_number='+text1value,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function setwarehousecode(val,vfield1,btnname){

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]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						
						//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

				}
		}
  }

xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?vwarehousecode="+val+"&mode=checkwarehousecode",true);
xmlhttp.send();

}



function changeqty2(vnum,vitemunit,moduleunit1,indx){

itemunit = 'Item_Unit[' + indx + ']';
itemunit =document.getElementById(itemunit).value;
var txtAdjDtQty2 = 'txtAdjDtQty2[' + indx + ']';


var txtAdjDtQty = 'txtAdjDtQty[' + indx + ']';




if (vnum==1)
	{ 
if (document.getElementById(txtAdjDtQty2))	
if (document.getElementById(txtAdjDtQty2).value!='')
return;
		
			if (moduleunit1==1 && itemunit !='')
					{
					var itemqty = document.getElementById(txtAdjDtQty).value;
					var xx = Number(itemqty) * Number(itemunit);
				
				if(document.getElementById(txtAdjDtQty2))
					document.getElementById(txtAdjDtQty2).value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{
							var itemqty = document.getElementById(txtAdjDtQty).value;
							var xx = Number(itemqty) / Number(itemunit);
							
							if(document.getElementById(txtAdjDtQty2))
							document.getElementById(txtAdjDtQty2).value = xx;
						}
				}
	}
else {

if (document.getElementById(txtAdjDtQty).value!='')
return;
			if (moduleunit1==1 && itemunit !='')
					{
					if (document.getElementById(txtAdjDtQty2))
					var itemqty = document.getElementById(txtAdjDtQty2).value;
					
					var xx = Number(itemqty) / Number(itemunit);

					document.getElementById(txtAdjDtQty).value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{	if (document.getElementById(txtAdjDtQty2))
							var itemqty = document.getElementById(txtAdjDtQty2).value;
							
							if (itemqty == '')
								itemqty = 0;
								
							var xx = Number(itemqty) * Number(itemunit);
							document.getElementById(txtAdjDtQty).value = xx;
						}
				}
	}

}


function calcTotal(vprice,vqty,indx){


var vprice = document.getElementById(vprice).value;


var vqty = document.getElementById(vqty).value;

var vamount = 'amount['+indx+']';

if (vprice=='')
	vprice = 0;
	
if (vqty=='')
	vqty = 0;
	
document.getElementById(vamount).value  = parseInt(vprice) * parseInt(vqty);


}


function FillData(prjct,cst){

var x =  document.adjustmentrequest;
if (document.getElementById(prjct).value == '')
	document.getElementById(prjct).value =  x.txtProjectCode.value;
	
if (document.getElementById(cst).value == '')	
	document.getElementById(cst).value = x.txtCostCentCode.value;

}

function showsearchpage(vtype,vtext1,vtext2,vtext3,vtext4,vtext5,vtext6,vwidth,vheight){

	var text1value = document.getElementById(vtext1).value;
	
	if (document.getElementById(vtext2))
		var text2value = document.getElementById(vtext2).value;
else
		var text2value = '';
		
		
	win = window.open('List_PurItems.php?PItem_Code='+text1value+'&PItem_Description=&item=6&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vtext3='+vtext3
						+'&vtext4='+vtext4+'&vtext5='+vtext5+'&vtext6='+vtext6
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}
	
function showlistCostcenter(vtype,vtext1,vwidth,vheight,item){
  	var text1value = document.getElementById(vtext1).value;
	
	if (item=='')
		item = 2;
	win = window.open('List_Costcenter.php?PCostcent_Code='+text1value+'&item='+item+'&vtype='+vtype+'&vtext1='+vtext1
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	

	
}

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_Adjustment_ListLedgers.php?item='+str+'&frm=3&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 roundNumber(num, dec) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  newnumber = parseFloat(newnumber); 
  
  return newnumber;
}

function formatNumber(num, dec) { // Arguments: number to format, number of decimal places
	return num.toFixed(dec);
}



function submitAdjustReqDt(txtAdjDtId,txtAdjId,vrec,vmode,VPurchaseTTC,FIPurchaseCategory,filepath){


var txtAdjDtId = txtAdjDtId;

	if (vmode=='i')
			{		 
				var vactionmode = 'submitrecord';
				var actionmoded = 'i';
			}	
	else 	{
				var vactionmode = 'editdt';	
				var actionmoded = 'e';
			}
						

var txtItemCode = 'txtItemCode['+vrec+']';
var lstWarehouse = 'lstWarehouse['+vrec+']';
var txtAdjDtQty = 'txtAdjDtQty['+vrec+']';
var txtItemUnit1 = 'txtItemUnit1['+vrec+']';
var txtAdjDtQty2 = 'txtAdjDtQty2['+vrec+']';
var txtItemUnit2 = 'txtItemUnit2['+vrec+']';
var Item_Unit = 'Item_Unit['+vrec+']';
var txtAdjDtBatchNo = 'txtAdjDtBatchNo['+vrec+']';
var txtProjectCodeDt = 'txtProjectCodeDt['+vrec+']';
var txtCostCentCodeDt = 'txtCostCentCodeDt['+vrec+']';
var txtAdjDtExpireDate = 'txtAdjDtExpireDate['+vrec+']';
var txtAdjDtInvDebitAcc = 'InvDEBITaccount['+vrec+']';

var txtcostpriceDt = 'txtcostpriceDt['+vrec+']';
var txtheatnoDt = 'txtAdjDtHeatNo['+vrec+']';

if (document.getElementById(txtAdjDtQty).value=='')
	document.getElementById(txtAdjDtQty).value = '0';
	
	//if(vAdjustType=='O')
		document.getElementById(txtAdjDtQty).value = Math.abs(document.getElementById(txtAdjDtQty).value) * -1;
		
var value1 = encodeURIComponent(document.getElementById(txtItemCode).value);
var value2 = document.getElementById(lstWarehouse).value;
var value3 = document.getElementById(txtAdjDtQty).value;
var value4 = document.getElementById(txtItemUnit1).value;
if(document.getElementById(txtAdjDtQty2))
	var value5 = document.getElementById(txtAdjDtQty2).value;
else	
	var value5 = 0;
if(document.getElementById(txtItemUnit2))	
var value6 = document.getElementById(txtItemUnit2).value;
else	
	var value6 = 0;
var value7 = document.getElementById(Item_Unit).value;
var value8 = document.getElementById(txtAdjDtBatchNo).value;
var value9 = document.getElementById(txtProjectCodeDt).value;
var value10 = document.getElementById(txtCostCentCodeDt).value;
var value11 = document.getElementById(txtAdjDtExpireDate).value;

//if (PreqId=='')
		var x =  document.adjustmentrequest;
		var value12 = x.txtAdjId.value;
		var value13 = x.txtDate.value;
		var value14 = x.txtRemark.value;
		var value15 = x.txtRequestBy.value;
		var value16 = x.txtProjectCode.value;
		var value17 = x.txtCostCentCode.value;
		var value18 = x.txtEntryType.value;
		
if(document.getElementById(txtcostpriceDt))
	var value19 = document.getElementById(txtcostpriceDt).value;
else	
	var value19 = 0;		


if (value13=='')
{
			alert("Date is mandatory!");
			x.txtDate.focus();
			return 0;
}

var value20 = document.getElementById(txtheatnoDt).value;
var value21 = document.getElementById(txtAdjDtInvDebitAcc).value;

var value22 = document.getElementById('txtStockRef').value;
	
if (document.getElementById(txtItemCode).value=='')
{
			alert("Item is mandatory!");
			document.getElementById(txtItemCode).focus();
return 0;
}

if (document.getElementById(txtAdjDtQty).value=='')
{
			alert("Quantity is mandatory!");
			document.getElementById(txtAdjDtQty).focus();
return 0;
}


var txtAdjId = document.getElementById('txtAdjId').value;
//$("#Loader").addClass("ajaxsaving");

	var SubBtnID = 'imgSubmitPTransReqDt['+vrec+']';
	var SubBtnObj = document.getElementById(SubBtnID);
	$(SubBtnObj).unbind('click');
	$(SubBtnObj).removeAttr("onclick");	

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('testdatagrid').innerHTML = data[0];
						
					
					if (vmode=='i')
						{  
					
							var data = xmlhttp.responseText.split("[BRK]");
							
							document.getElementById('txtAdjId').value = data[1];
							//document.getElementById('testdatagrid').innerHTML = data[0];
							
							
					
						
						document.adjustmentrequest.actionmode.value='edit';
					
						if (txtAdjId==''){				
								document.adjustmentrequest.action='Form_AdjustmentRequest.php';				
								document.adjustmentrequest.submit();
								
										}
										else {
										
										ReloadGrid(filepath,'ADR',txtAdjId,'datagrid','','','ADD','','','','',0,'',function() {
											var focusedvrec = parseInt(vrec) + 1;
											var focused = 'txtItemCode['+focusedvrec+']';
											document.getElementById(focused).focus();
										});
										$("#Loader").removeClass("ajaxloading");
										//ReloadGridDt(filepath,'TRQ-totals','totalsdatagrid','totalsdatagrid',txtAdjId,-1);
										//$("#Loader").removeClass("ajaxsaving");
										
										}
					
						}	
					else {
					
							//document.getElementById('testdatagrid').innerHTML =  xmlhttp.responseText;
							  xmlhttp.responseText;
							  
						 
							ReloadGrid(filepath,'ADR',txtAdjId,'datagrid','','','ADD','','','','',0,'',function() {
											var focusedvrec = parseInt(vrec) + 1;
											var focused = 'txtItemCode['+focusedvrec+']';
											document.getElementById(focused).focus();
										});
						$("#Loader").removeClass("ajaxloading");	
										
						
						}						
				
				}
		}
  }


xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?mode="+vactionmode+"&value1="+value1+"&value2="+value2+"&value3="+value3+"&value4="+value4+"&value5="+value5+"&value6="+value6
					+"&value7="+value7+"&value8="+value8+"&value9="+value9+"&value10="+value10+"&value11="+value11+"&value12="+value12+"&value13="+value13+"&value14="+value14+"&value15="+value15
					+"&value16="+value16+"&value17="+value17+"&value18="+value18+"&AdjDtInvDebitAcc="+value21+"&txtAdjDtId="+txtAdjDtId+"&SAdjDtId="+txtAdjDtId+"&SAdjId="+txtAdjId
					+"&txtAdjId="+txtAdjId+"&value19="+value19+"&txtAdjDtHeatNo="+value20+"&txtStockRef="+value22+"&actionmode="+vactionmode+"&actionmoded="+actionmoded,true);

xmlhttp.send();

    
}


function deletetrequestsdt(txtAdjId,txtAdjDtId, ItemPackCode, ItemCode,filepath){


var x =  document.transferrequest;
			
		
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 ))
	{
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('testdatagrid').innerHTML = xmlhttp.responseText;
							var data = xmlhttp.responseText.split('[BRK]');
							//document.getElementById('testdatagrid').innerHTML = data[0];
								
							ReloadGrid(filepath,'ADR',txtAdjId,'datagrid','','','ADD','','','','',0,'',function() {
								document.getElementById('SelectedRec').value='';		});
							$("#Loader").removeClass("ajaxloading");
														
				}
		}
  }

xmlhttp.open("GET","Form_AdjustmentRequest_Actions.php?txtAdjId="+txtAdjId+"&mode=deletedt&SAdjDtId="+txtAdjDtId+"&adjustmentrequest_id="+txtAdjDtId
				,true);
xmlhttp.send();

}
}


function clearprequestdt(vrec,VPurchaseTTC,Module_DoubleUnit){


var txtItemCode = 'txtItemCode['+vrec+']';
var lstWarehouse = 'lstWarehouse['+vrec+']';
var txtAdjDtQty = 'txtAdjDtQty['+vrec+']';
var txtItemUnit1 = 'txtItemUnit1['+vrec+']';
var txtAdjDtQty2 = 'txtAdjDtQty2['+vrec+']';
var txtItemUnit2 = 'txtItemUnit2['+vrec+']';
var Item_Unit = 'Item_Unit['+vrec+']';
var txtAdjDtBatchNo = 'txtAdjDtBatchNo['+vrec+']';
var txtProjectCodeDt = 'txtProjectCodeDt['+vrec+']';
var txtCostCentCodeDt = 'txtCostCentCodeDt['+vrec+']';
var txtAdjDtExpireDate = 'txtAdjDtExpireDate['+vrec+']';
var txtItemDesc = 'txtItemDesc['+vrec+']';



document.getElementById(txtItemCode).value='';
document.getElementById(lstWarehouse).value='';
document.getElementById(txtAdjDtQty).value='';
document.getElementById(txtItemUnit1).value='';
document.getElementById(txtAdjDtQty2).value='';
document.getElementById(txtItemUnit2).value='';
document.getElementById(Item_Unit).value='';
document.getElementById(txtAdjDtBatchNo).value='';
document.getElementById(txtCostCentCodeDt).value='';
document.getElementById(txtAdjDtExpireDate).value='';
document.getElementById(txtProjectCodeDt).value='';
document.getElementById(txtItemDesc).value='';

}

function CalcAdjDtTotal(option,dec,PIndex) {
	var x = document.adjustmentrequest;
	var vmode = x.actionmode.value;
	var pricedt = 'txtcostpriceDt['+PIndex+']'; 
		
	var Qty      = document.getElementById('txtAdjDtQty['+PIndex+']').value; 
	var Price    = document.getElementById(pricedt).value;
	
	
	if (Qty == '') 		Qty = 0;
	if (Price == '') 	Price = 0;
	
	Qty      = parseFloat(Qty);
	Price    = parseFloat(Price);
	
	//if (Qty > 0 && Price >= 0) {
	   document.getElementById('txtAdjDtTotal['+PIndex+']').value = roundNumber((Qty*Price),dec);
	//}  
	
}

function showlistHeatNo(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vHeatNoCode = encodeURIComponent(document.getElementById('txtAdjDtHeatNo['+PIndex+']').value);
	
	window.open('List_HeatNo.php?frm=15&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 showlistItems(PIndex){
	var vDate, vItemCode;
	x = document.adjustmentrequest;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('txtItemCode['+PIndex+']').value);
	
	window.open('List_SorItems.php?frm=21&index='+PIndex+'&PItem_Code='+vItemCode+'&ItemType=All&CurrCode=&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 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>Adjustment</title>
<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>
<link rel="stylesheet" href="tabsClass/tabber.css" type="text/css" />



<script type="text/javascript" language="javascript">
	
	
	$(document).ready(function() { 
		
	if (document.getElementById('txtItemCode[1]'))
		document.getElementById('txtItemCode[1]').focus();
		
	
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmitPTransReqDt');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		
		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
	
	});
	
	
</script>


<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>


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



	$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});	

	});
	
	
</script>

<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body>
<form name='adjustmentrequest' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='AdjustType' value='$AdjustType' size='200'>
HERE;

	
//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);
}
	
//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))
	$txtCurr = $base1;
if (empty($txtDate))	
	$txtDate = displayToday();
if (empty($txtAdjIsInvoice))
	$txtAdjIsInvoice = 0;
if (empty($txtUser))
	$txtUser = $_SESSION['useraccount'];	
	

		
if ($actionmode != "cancel" && $txtAdjId != '') {
	// Read From Temp Tables For Selected Record				 
	$query = " Select AdjustmentRequest_ID, AdjustmentRequest_Reference, Date_Format(AdjustmentRequest_Date,'%d/%m/%Y') As AdjustmentRequest_Date, ".
	         " AdjustmentRequest_Remak, AdjustmentRequest.Project_Code, AdjustmentRequest.Costcent_code, AdjustmentRequest_RequestBy,  ".
			 " ifNull(AdjustmentRequest_isInvoice,0), InvDebitAccount, InvCreditAccount, AdjustmentRequest.Currency_Code, ".
			 " Round(AdjustmentRequest_Amount, ".$DecimalBase.") As AdjustmentRequestAmount, ".
			 " Round(AdjustmentRequest_AmountBase1, ".$DecimalBase1.") As AdjustmentRequestAmountBase1, ".
			 " Round(AdjustmentRequest_AmountBase2, ".$DecimalBase2.") As AdjustmentRequestAmountBase2, ".
			 " NULL, NULL, AdjustmentRequest.User_Account, NULL, NULL, AdjustmentRequest.Entry_Type, AdjustmentRequest_SockReference ".
			 " From Temp_AdjustmentRequest As AdjustmentRequest ".	 
	         " Where AdjustmentRequest_ID = '".$txtAdjId."' ".
			 " And AdjustmentRequest_EntryType = '".$AdjustType."'";
			 
			 
			 
	//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];
	$txtRequestBy 	  = $rows[6];
	$txtAdjIsInvoice  = $rows[7];
	$txtEntryType	  = $rows[19];
	
	$txtCurr     	    = $rows[10];
	$txtAdjAmount       = number_format($rows[11], $DecimalBase);
	$txtAdjAmountBase1  = number_format($rows[12], $DecimalBase);
	$txtAdjAmountBase2  = number_format($rows[13], $DecimalBase);
	
	
	$txtUser  		= $rows[16];
	$txtStockRef  	= $rows[20];
	
	
	$query = " Select Count(*) FROM Temp_AdjustmentRequestDt ".
			 " WHERE AdjustmentRequest_id = ".$txtAdjId;
	$result = selectData($connection, $query);
	$txtAdjCountDetail = $result[0];
	if($txtAdjCountDetail == '') $txtAdjCountDetail = 0;
	
}



//Search/Cancel Mode	
if ($actionmode == "cancel" && $txtAdjId != '') {
	
		
	// Delete From Temp Tables Already Filled By Search
	
	
	
	$query = " DELETE FROM Temp_AdjustmentRequestDt ".
			 " WHERE AdjustmentRequest_id = ".$txtAdjId;
			 //" AND Logged_Code = '".$_SESSION['useraccount']."' ";
	if (!updateData($connection, $query, true))
      $message  = mysql_error(); 
	  
	  
	$query = " DELETE FROM Temp_AdjustmentRequest ".
			 " WHERE AdjustmentRequest_id = ".$txtAdjId;
			 //" AND Logged_Code = '".$_SESSION['useraccount']."' ";
	if (!updateData($connection, $query, true))
      $message  = mysql_error();   

	$txtAdjId = '';
}






//$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'>$FormTitle</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'>";

	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' name='btnCancel' id='btnCancel' value='Cancel' onclick='CancelRecord();return false;' title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
echo"   <button type='button' name='btnPost' id='btnPost'  ";//post
		if (($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit')
			echo " disabled ";
		echo" onclick='PostChanges($Module_RestrictProjCost, $Module_RestrictCost);return false;' title='Save Changes'><span><span>Save</span></span></button>";

echo"   <button name='btnSearch' type='button' id='btnSearch'  onclick='SearchForRef();return false;' title='Search By Reference' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
		    echo " disabled ";
		echo "  ><span><span>Search</span></span></button>";
				
echo"   <button name='btnPending' type='button' id='btnPending'  onclick='SearchForPending();return false;'  title='Pending Adjustments' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
		    echo " disabled ";
		echo " ><span><span>Pending</span></span></button>";	
		
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" style='table-layout:fixed' >
		  <col width=80>
		  <col width=70>
		  <col width=50>
		  <col width=110>
		  <col width=40>
		  <col width=65>
		  <col width=50>
		  <col width=60>
		  <col width=85>
		  <col width=140>
		  <col width=70>
		  <col width=150>

		<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='txtAdjId'  id='txtAdjId' value='$txtAdjId' >
			<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.adjustmentrequest.txtDate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A>
			  
   	      </td>
						   
HERE;


	echo" <td align='left' colspan='6'>&nbsp;</td>";



echo"     <td align='left' ></td>";
echo"     <td ></td>";	
		  

echo"   </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:385px;' maxlength='100' ></td>";

echo"	  <td align='left' ><span class='style1'>Request By</span></td><td><span class='style1'>
		  <input type='text' name='txtRequestBy' id='txtRequestBy' value='".htmlspecialchars($txtRequestBy, ENT_QUOTES)."'  style='width:110px;' maxlength='100' >
		  <img src='img/btnopen.jpg' title=' Select User ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistUsers('6');\"  />
		  </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"   </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'  $PreviewButtons  id='txtProjectCode' value='".htmlentities($txtProjectCode)."'   onchange=setprojectcode(this.value,'txtProjectCode','transfromprojectimg')  size='10' maxlength='15' /></span>
		    <label><span class='style1'><img src='img/scroll-down-1.png' title=' Select Project '  id='transfromprojectimg' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistProject('project','txtProjectCode','800','500',3)\"  $PreviewButtons/></span></label>
			</td>";
} else {
	echo" <td align='left' colspan='3'><input type='hidden' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' /></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='4'><span class='style1'>
		     <input type='text' $PreviewButtons name='txtCostCentCode'  id='txtCostCentCode' value='".htmlentities($txtCostCentCode)."' size='17' maxlength='15' onchange=setcostcentercode(this.value,'txtCostCentCode','imgcostcenterbtnheader') /></span>
		    <label><span class='style1'><image src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtnheader' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  
			onclick=\"showlistCostcenter('costcenter','txtCostCentCode','800','500',3) \"  $PreviewButtons/></span></label></td>";
} else {
	echo" <td align='left' colspan='5'><input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' /></td>";

}
			
echo"     <td align='left' ><span class='style1'>User</span></td>
		  <td > <font face='Verdana' size='2'><b>&nbsp;$txtUser</b></font></td>
		  <td align='left' ><span class='style1'>Stock Out Ref.</span></td>
		  <td ><input type='text' name='txtStockRef' id='txtStockRef' value = '$txtStockRef' style='width:130px;'></td> ";
echo"   </tr>";

echo"   <tr bgcolor='#F7F7F7' height='35px'>
		  <td align='left' valign='top' colspan='12' rowspan='2'><table border='0' cellpading='0' cellspacing='0' style='table-layout:fixed'>
			<col width=50>
			<col width=500>";

		
if ($Module_IsInvoice == 1) {
	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'  readonly />
				<input type='text'   name='txtInvDebitName' id='txtInvDebitName' value='$txtInvDebitName' style='width:320px;'  readonly />
				</label></span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Ledger ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('1','');\" /> </span></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' readonly />
				<input type='text'   name='txtInvCreditName' id='txtInvCreditName' value='$txtInvCreditName' style='width:320px;' readonly />
				</label></span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Ledger ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('2','');\" /> </span></label>
			</td></tr>";
	
} else {
	echo"	<tr><td colspan='2'>
				<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></tr>";				
}

echo"	  </table></td>";
//echo"     <td align='left' colspan='2'>&nbsp;</td>";

echo"	</tr>";

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

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

				
echo"   <input type='button' id='btnClear' name='btnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";
				
echo"   <input type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
		if ($actionmode=='cancel' || ($actionmode=='' && $mainaction!='edit'))
			echo " disabled ";
		echo" onclick='CancelRecord();' $style title='Cancel Changes'>";
				
echo"   <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
		if (($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit')
			echo " disabled ";
		echo" onclick='PostChanges();' $style	title='Save Changes' />";

echo"   <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForRef();' $style title='Search By Reference' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
		    echo " disabled ";
		echo " />";
				
echo"   <input name='btnPending' type='button' id='btnPending' value='Pending' onclick='SearchForPending();' $style title='Pending Adjustments' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
		    echo " disabled ";
		echo " />";				

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




echo"   <tr ><td colspan='9' valign='top'>";
echo"	<div id='main' >";
echo"	<div id='Loader' class=''><div></div></div>";
echo"	<div id='datagrid' class='' style='overflow:scroll;width:1100px;' >";

//Show Items Grid


ShowAdjustmentRequestDtGrid($connection,'ADR',$txtAdjId,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$DecimalBase,$Module_DoubleUnit,$Module_ProjectDt,$Module_CostCenterDt,$Module_Unit1Method,$Module_Pack, $Module_Heatno, $Module_IsInvoice);

echo"	  </div>"; 
echo"   </td></tr>"; 
		
	echo"   <tr><td colspan='9' valign='top'>";

echo"	<div id='testdatagrid' class='' style='width:1090px;' >";


echo"	  </div>"; 
echo"	  </div>"; 

echo"   </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 ' PrintAdjustment(\''.$PrAdjId.'\', \''.$PrAdjRef.'\'); ';
		
	echo ' ClearPage1(); ';
	echo '</script>';

}

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

HERE;

?>