<?php

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


include("config.inc.php");
include("function.inc.php");
include("Functions_Trans.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_OUTDel,0) As FI_Delete, ifNull(FI_OUTMod,0) As FI_Modify, ifNull(FI_Outapp,0) As FI_Insert, ".
			  " ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(ShowTransaction,0) As ShowTransaction 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);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
             " ifNull(Module_PostToJournal,0) As Module_PostToJournal From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


//Access Mode On Insert/Edit/Delete
$DelMode = 1;
$EditMode =1;
$PrevMode = 1;

$PrevHint = '';
$EditHint = '';
$DelHint = '';

$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);
}

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
			  
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
//echo $queryperiod;	

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
			  
			  
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);	


$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
			   
			  
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  



//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 ((!isset($PProjectCode)) && $Module_Project == 1)
	$PProjectCode = $defaultproject;
if ((!isset($PCostCentCode)) && $Module_CostCenter == 1)	
	$PCostCentCode = $defaultcostcent;	

if (empty($orderby)) $orderby = 1;
if (empty($searchby)) $searchby = 2;

if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
	
//if ($AdjustType == 'O')      { $FormTitle = 'Unconfirmed Stock Out';   }


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<title>Search $FormTitle</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.search.keyword.value='';
  document.search.PProjectCode.value='';
  document.search.PCostCentCode.value='';

  document.search.action='Form_ProductionConfirm.php';
  document.search.submit();

}

function SetNextPage(startrange,perpage){

	document.search.action='Form_ProductionConfirm.php?keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){

	document.search.action='Form_ProductionConfirm.php?keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}


function ConfirmRecord(PrdId, PrdRef, type){
	if (type=='1'){
		if (confirm ( "Are you sure you want to Confirm selected records?") )
			{
				document.search.action="Form_Production_Actions.php?mainmode=ConfirmAll";
				document.search.submit();
			}	
		
	} else {
		if (PrdId != '') {
			if (confirm ( "Are you sure you want to Confirm this record with reference = "+PrdRef+" ?") )
			{
				document.search.action="Form_Production_Actions.php?mainmode=ConfirmStockOut&SPrdId="+PrdId;
				document.search.submit();
			}
		}
	}
	
}

function ShowHideDetails(PrdId, Option, startrange) {
	
	vSlideDivId = '#displaydetails'+PrdId;
	$(vSlideDivId).slideToggle();
}



function SelectOrderBy()
{
  document.search.keyword.value='';

  document.search.action='Form_ProductionConfirm.php';
  document.search.submit();

}

function SelectSearchBy()
{	

  //document.search.keyword.value='';
  //document.search.action='Form_ProductionConfirm.php';
  document.search.submit();

}

function SubmitForm()
{	

  //document.search.keyword.value='';
  document.search.action='Form_ProductionConfirm.php?startrange=0';
  document.search.submit();

}

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

function showlistProject(str){

  window.open('List_SorProject.php?frm=6&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=6&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function RefreshPage()
{
   document.search.action='Form_ProductionConfirm.php?startrange=0';
  document.search.submit();

}

function SetFirstPage(startrange,perpage){
	document.search.action='Form_ProductionConfirm.php?startrange=0&perpage='+perpage;
	document.search.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='Form_ProductionConfirm.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function setConfirm(){
	var MasterCheckName, y;
	var x = document.search;
	var vSelectedRows = '*';
	
	var totrows = allrows.value;
	for (var i=1; i <= totrows; i++)
	{
		MasterCheckName = 'chkconfirm'+i;
		
		y = document.getElementById(MasterCheckName);
		if (y.checked)
			vSelectedRows = vSelectedRows + ',' + y.value;
		
	}
	
	x.prdids.value = vSelectedRows;
}
</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}

.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}

.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body  class='bodybackground'>
<form name='search' method='post' action=''>
<input type='hidden' name='AdjustType' value='$AdjustType'>
HERE;



$PRef = GetSQLValueString($keyword, 'text');

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;

			 
$querysearch=" Select Distinct productionhd.productionhd_ID, productionhd.productionhd_Reference, Date_Format(productionhd.productionhd_Date,'%d-%m-%Y') As productionhd_Date, ".
			 " productionhd.productionhd_Remark, Project.Project_Name As ProjectName, Costcent.Costcent_name As CostcentName, ".
			 " productionhd.Currency_code As CurrencyCode, Round(productionhd.ProductionHD_Total, ".$DecimalBase.") As ProductionHD_Total, ".
			 " ifNull(Temp_productionhd.productionhd_ID, -1) As TempproductionhdId, Journal.Journal_folio, Journal.Journal_refgovernment,productionhd.User_Account ".
			 " From productionhd ".
			 " Left Join Project on productionhd.Project_Code = Project.Project_Code ".
			 " Left Join Costcent on productionhd.Costcenter_Code = Costcent.Costcent_code ".
			 " Left Join Journal on productionhd.Journal_ID = Journal.Journal_ID ".
			 " Left Join Temp_productionhd on Temp_productionhd.productionhd_ID = productionhd.productionhd_ID ";  
			 
if ($projectexist >	0)
  $querysearch= $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on (($Module_ProjectParent=1 and productionhd.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and productionhd.project_code = Q1.project_code )) ";
							 
if ($costcentexist > 0)
  $querysearch= $querysearch." Inner join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (costcent_code is not null and costcent_code != '') ".
							 "			 ) Q2 on (($Module_CostCenterParent=1 and productionhd.Costcenter_Code like concat(Q2.Costcent_Code,'%')) or ($Module_CostCenterParent=0 and productionhd.Costcenter_Code = Q2.costcent_code )) ";

							 
$querysearch= $querysearch.											 
			 " Where (($searchby = 2 and productionhd.productionhd_Reference Like Concat(ifNull($PRef, productionhd.productionhd_Reference),'%')) Or ".
			 "        ($searchby = 1 and Date_Format(productionhd.productionhd_Date,'%Y-%m-%d') = ifNull(Date_Format($PRef,'%Y-%m-%d'), Date_Format(productionhd.productionhd_Date,'%Y-%m-%d'))) Or  ".
			 "        ($searchby = 5 and productionhd.productionhd_Remark Like Concat('%', ifNull($PRef, productionhd.productionhd_Remark),'%')) ) ".
			 " And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(productionhd.productionhd_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',productionhd.productionhd_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
             "                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(productionhd.productionhd_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ".
			 " and ifnull(productionhd.productionhd_confirm,0) = 0 ";
			 
if ($ShowTransaction != 1)
	$querysearch= $querysearch." And Upper(productionhd.User_Account) = Upper('".$_SESSION['useraccount']."') ";
			 
			 
if ($PProjectCode != '')
	$querysearch= $querysearch." And productionhd.project_code like concat('".$PProjectCode."','%') ";
if ($PCostCentCode != '')
	$querysearch= $querysearch." And productionhd.Costcenter_Code like concat('".$PCostCentCode."','%') ";				 
			 

if ($orderby == 1)
	$querysearch= $querysearch." Order By productionhd.productionhd_Date Desc, productionhd.productionhd_Reference Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By productionhd.productionhd_Reference Desc ";	
	
			 
//echo $querysearch;		exit;	 

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);

		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		

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

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
		 

echo"<table border='0' cellspacing='1'  style='table-layout:fixed'>
	  <col width=25>
	  <col width=20>
	  <col width=20>
	  <col width=70>
	  <col width=80>
	  <col width=50>
	  <col width=50>
	  <col width=180>
	  <col width=100>
	  <col width=100>
	  <col width=60>
	  <col width=100>
		     
	
	  <tr class='Search-header-bg'>";
	  
if ($Module_Project == 1) {
	echo" <td align='left' colspan='3'><span class='style4'>Project</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='PProjectCode' id='PProjectCode' value='$PProjectCode' style='width:120px;' maxlength='20' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='5'><input type='hidden' name='PProjectCode' id='PProjectCode' value='$PProjectCode' /></td>";

}			

if ($Module_CostCenter == 1) {		  
	echo" <td align='right' colspan='2'><span class='style4'>Costcenter &nbsp;</span></td>		
		  <td align='left' ><span class='style4'>
		    <input type='text' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' style='width:150px;' maxlength='20' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
			
} else {
	echo" <td align='left' colspan='3'><input type='hidden' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' /></td>";

}	  

echo" <td align='right' colspan='4'><span class='style4'>Order By</span>
	<span class='style4'><select name='orderby' id='orderby' value='$orderby' onchange='SelectOrderBy();'>";
	if ($orderby==1)
		$s11 = 'selected';
	else if ($orderby==2)
		$s12 = 'selected';
		
	echo"<option ".$s11." value='1'>Date</option>
		 <option ".$s12." value='2'>Reference</option>";		
	
echo "</select></td>";
  
echo" </tr>
	  <tr class='Search-header-bg'>	  
	    <td align='left' colspan='3'><span class='style4'>Search By</span></td>
		<td align='left' colspan='5'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' size='15' maxlength='30' onkeydown='return kd(event)'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		
			<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
		
			if ($searchby==1)		$s21 = 'selected';
			else if ($searchby==2)	$s22 = 'selected';
			else if ($searchby==5)	$s25 = 'selected';
				
			echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
				 <option ".$s22." value='2'>Reference</option>
				 <option ".$s25." value='5'>Remark</option>";
			echo"</select>";	
				 
echo"	<button type='button' id='btnSubmit' name='btnSubmit' onclick=\"SubmitForm(); return false;\" title='Find'><span><span>Find</span></span></button>
		<button type='button' id='btnCancel' name='btnCancel' onclick=\"clearform();return false;\" title='Cancel'><span><span>Cancel</span></span></button>
		<button type='button' id='btnConfirm' name='btnConfirm' onclick=\"ConfirmRecord('','', '1');return false;\" title='Find'><span><span>Confirm Selected</span></span></button>
			</td>";
echo" <td align='right' ></td>		
	  <td align='left' ></td>";		
			 


echo" </tr>
</table>
		</td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>"; 
echo" </tr>";

	  echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:1025px;'>
		<table width='100%' border=0>
		<tr>
			<td align='right' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage();\">";
              
			if ($perpage==20)
				$s20 = 'selected';
			else if ($perpage==30)
				$s30 = 'selected';
			else if ($perpage==40)
				$s40 = 'selected';
			else if ($perpage==50)
				$s50 = 'selected';

						
							
			echo'<option '.$s20.' value="20">20</option>
				 <option '.$s30.' value="30">30</option>
				 <option '.$s40.' value="40">40</option>
				 <option '.$s50.' value="50">50</option>
				 </select></span></td>
			<td  style="width:74px;border-right:1px solid #000000;text-align:right;">';
			
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
			}
			else
				echo "&nbsp;";
		
echo"		</td><td  align='left' style='width:74px;'>";
		
		
			if ($startrange <= $totalrows){
				$startrange1 = $startrange + $perpage;
				if  ($startrange1 < $totalrows){
					echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
				}
			} else
				echo "&nbsp;";
				
			
echo"		</td><td style='width:380px;'>&nbsp;</td>
		</tr>";
echo"	</table></td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>";
echo"</tr>";			


	
	echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		<td id='search-content2'>
			<div style='overflow:scroll;height:400px;width:870px;'>
			<table border='0'  cellpadding='0' cellspacing='1' style='width:1080px;'>
			  <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=70>
			  <col width=90>
			  <col width=300>
			  <col width=100>
			  <col width=100>
			  <col width=60>
			  <col width=120>
			  <col width=180>";

	 
	if($message!=''){
		echo"<tr class='Search-header-bg'>
				<td height='15' align='center' colspan='11' class='searchmessage'>".$message."</td>
			</tr>";
	}
	 
	echo" <tr class='Search-Label-bg'>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='left'><span class='style4'>Reference </span></td>
			<td  height='25' align='center'><span class='style4'>Date </span></td>";
			
				 
	echo"	<td  height='25' align='left'><span class='style4'>Remark</span></td>
			<td  height='25' align='center'><span class='style4'>Project</span></td>
			<td  height='25' align='center'><span class='style4'>CostCenter</span></td>
			<td  height='25' align='center'><span class='style4'>Currency</span></td>
			<td  height='25' align='center'><span class='style4'>Amount</span></td>
			<td  height='25' align='center'><span class='style4'>Request By</span></td>
		  </tr>";
		
$i=1;
while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	

	
	if ($TempproductionhdId != -1) $ConfirmMode = 0; else $ConfirmMode = 1;
	
	echo'<tr '.$Color.'>';

	//echo $productionhd_Reference;exit;
	
	if($ConfirmMode==1){
		$chkConfirm = "chkconfirm".$i;
		
		echo"<td align='center'><input type='checkbox' name='$chkConfirm' id='$chkConfirm' value='$productionhd_ID' onclick=\"setConfirm();\"></td>";
		echo'<td align="center"><span class="style5"><img src="img/confirmorder.png" onMouseOver="style.cursor=\'hand\'" onclick="ConfirmRecord('.$productionhd_ID.', \''.$productionhd_Reference.'\', \'2\');" title="Confirm Production"  style="width: 15px; height: 15px; "></span></td>';
	} else 
		echo'<td align="center">&nbsp;</td><td align="center">&nbsp;</td>';  
		
	echo'<td align="center"><span class="style5"><img src="img/details.gif" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails(\''.$productionhd_ID.'\', \''.'S'.'\',\''.$startrange.'\');" title="Show Details" style="width:15px; height:15px; "></span></td>';
	 
	echo'	<td align="left"><span class="style5">'.$productionhd_Reference.'</span></td>
			<td align="center"><span class="style5">'.$productionhd_Date.'</span></td>';
			
		
	echo'	<td align="left" style="padding-left:3px;"><span class="style5">'.$productionhd_Remark.'</span></td>
			<td align="left"><span class="style5">'.$ProjectName.'</span></td>
			<td align="left"><span class="style5">'.$CostcentName.'</span></td>
			<td align="center"><span class="style5">'.$CurrencyCode.'</span></td>
			<td align="right" style="padding-right:3px;"><span class="style5">'.number_format($ProductionHD_Total, $DecimalBase).'</span></td>
			<td align="center"><span class="style5">'.$User_Account.'</span></td>
		</tr>';
		
					 
	$sub_query = " Select productionfg.productionfg_ID, productionfg.Item_CodePacked, productionfg.Item_code, Item_Description, productionfg.Warehouse_Code, ".
				 " Item_UnitSalesDesc, productionfg_Quantity, Round(productionfg_Cost, ".$DecimalBase."), ".
				 " Round((ifNull(productionfg_Quantity,0)*ifNull(productionfg_Cost,0)), ".$DecimalBase.") As TotalAmount,'FG' ".
				 " From productionfg Left Join Items on productionfg.Item_code = Items.Item_code ".
				 " Where productionfg.productionhd_ID = ".$productionhd_ID;
				 
	$sub_query = $sub_query." Union ".	
                 " Select productionrm.productionrm_ID, productionrm.Item_CodePacked, productionrm.Item_code, Item_Description, productionrm.Warehouse_Code, ".
				 " Item_UnitSalesDesc, productionrm_Quantity, Round(productionrm_Cost, ".$DecimalBase."), ".
				 " Round((ifNull(productionrm_Quantity,0)*ifNull(productionrm_Cost,0)), ".$DecimalBase.") As TotalAmount,'RM' ".
				 " From productionrm Left Join Items on productionrm.Item_code = Items.Item_code ".
				 " Where productionrm.productionhd_ID = ".$productionhd_ID;	
				 
	//echo $sub_query;exit;			 

	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error($connection));	
	$sub_totalrows = mysql_num_rows($sub_result);
		
	if ($sub_totalrows > 0) {
		$SlideDivId = 'displaydetails'.$productionhd_ID;
			
		echo "<tr ".$Color.">";
		echo "<td colspan='14' valign='top' align='left'><div id='$SlideDivId' class='div-search-details' style='display:none; margin-left:80px;'>";
		echo "<table border='0' style='table-layout:fixed; width:840px;' cellpadding='0' cellspacing='1'>";
		echo "<tr><td width='40px'><span class='style4'>Type</span></td>
		          <td width='140px'><span class='style4'>Item Code</span></td>
				  <td width='240px'><span class='style4'>Description</span></td> 
				  <td width='100px'><span class='style4'>Warehouse</span></td> 
				  <td width='60px' align='center'><span class='style4'>Unit1</span></td>
				  <td width='80px' align='center'><span class='style4'>Qty</span></td>
				  <td width='100px' align='center'><span class='style4'>Price</span></td>
				  <td width='120px' align='center'><span class='style4'>Total</span></td>
			 </tr>";
		while($sub_rows=mysql_fetch_array($sub_result)){
			echo "<tr><td align='left' valign='top' class='style9'>".$sub_rows[9]."</td>
			          <td align='left' valign='top' class='style9'>".$sub_rows[2]."</td>
					  <td align='left' valign='top' class='style9'>".$sub_rows[3]."</td>
					  <td align='left' valign='top' class='style9'>".$sub_rows[4]."</td>
					  <td align='center' valign='top' class='style9'>".$sub_rows[5]."</td>
					  <td align='right' valign='top' class='style9'>".$sub_rows[6]."</td>
					  <td align='right' valign='top' class='style9'>".number_format($sub_rows[7],$DecimalBase)."</td>
					  <td align='right' valign='top' class='style9'>".number_format($sub_rows[8],$DecimalBase1)."</td>";
  			echo "</tr>";
				
		}
			
		echo "</table></div></td>";
		echo "</tr>";
	}	
	$i++;
}
							

			
echo"</table></div></td><td id='search-content3' style='width:31px;'>
		<input type='hidden' name='prdids' id='prdids' value=''>
		<input type='hidden' name='allrows' id='allrows' value='".($i-1)."'>
		</td></tr>";		
		
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:920px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:280px;'>&nbsp;</td><td align='right' style='width:74px;border-right:1px solid #000000;'>";
		
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";
				
		//$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			//$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='left'>";
		
		
		if ($startrange <= $totalrows){
			//$startrange = $startrange + $perpage;
			if  ($startrange1 < $totalrows){
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
				echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
			}	
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

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


          

		  

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

HERE;

?>