<?php


function getQtyBudget($perpage, $startrange, $connection) {
	if ($perpage == '') $perpage = 20;
	if ($startrange=='') $startrange = 0;
	
echo "<table bgcolor='#d3d3d3' width='1910px' border=0 cellpadding=0 cellspacing=0>";
echo "<col width=30px><col width=30px><col width=130px><col width=180px><col width=100px><col width=100px>
	<col width=85px><col width=85px><col width=85px> <col width=85px><col width=85px><col width=85px> <col width=85px><col width=85px><col width=85px> <col width=85px><col width=85px><col width=85px>
	<col width=160px><col width=160px>";
$bbottom = "border-bottom: 1px solid black";	
		
echo "<tr height='30px' >
			<td style='$bbottom;'></td><td style='$bbottom;'></td><td style='$bbottom;'><span class='style1'>Item Code</span></td><td style='$bbottom;'><span class='style1'>Budget Desc.</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>Start Date</span></td><td align='center' style='$bbottom;'><span class='style1'>End Date</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>January</span></td><td align='center' style='$bbottom;'><span class='style1'>February</span></td><td align='center' style='$bbottom;'><span class='style1'>March</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>April</span></td><td align='center' style='$bbottom;'><span class='style1'>May</span></td><td align='center' style='$bbottom;'><span class='style1'>June</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>July</span></td><td align='center' style='$bbottom;'><span class='style1'>August</span></td><td align='center' style='$bbottom;'><span class='style1'>September</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>October</span></td><td align='center' style='$bbottom;'><span class='style1'>November</span></td><td align='center' style='$bbottom;'><span class='style1'>December</span></td>
			<td align='center' style='$bbottom;'><span class='style1'>Project</span></td><td align='center' style='$bbottom;'><span class='style1'>Costcenter</span></td>
	</tr>";

	$query = "select budget_id, item_code, budget_desc, qty_month1 as jan, qty_month2 as feb, qty_month3 as mar, qty_month4 as apr, qty_month5 as may,
			qty_month6 as jun, qty_month7 as jul, qty_month8 as aug, qty_month9 as sep, qty_month10 as oct,
			qty_month11 as nov, qty_month12 as decm, project_code, costcent_code, date_format(sdate,'%d/%m/%Y') as sdate, date_format(edate,'%d/%m/%Y') as edate
			from qty_budget
			order by item_code, sdate, edate ";
	$res = mysql_query($query, $connection);
	$totalrows = mysql_num_rows($res);
	
	$query .= " limit ".$startrange.",".$perpage; 
	//echo $query;
	$res = mysql_query($query, $connection);
	$i = 0;
	while ($rw = mysql_fetch_array($res)){
		extract($rw);
		echo "<tr height='25px' >
				<td align='center'><img src='img/c_delete.png' height='14px' title='Delete Budget' onmouseover=\"style.cursor='hand';\" onclick=\"deleteBudget('$budget_id', '$i');\" ></td>
				<td align='center'><img src='img/confirm-1.png' title='Update Budget' onmouseover=\"style.cursor='hand';\" onclick=\"updateBudget('$budget_id', '$i');\" ></td>
				<td><input type='text' name='itemcode[$i]' id='itemcode[$i]' value='$item_code' style='width:105px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Item ' id='lstitem[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistitem('16','$i');\"  />
				</td>
				<td><input type='text' name='budgetdesc[$i]' id='budgetdesc[$i]' value='$budget_desc' style='width:175px;'></td>
				<td align='center'><input type='text' name='startdate$i' id='startdate[$i]' value='$sdate' style='width:70px;' readonly>
					<A HREF=\"#\" onClick=\"displayCalendar(document.qtybudget.startdate$i,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
				</td>
				<td align='center'><input type='text' name='enddate$i' id='enddate[$i]' value='$edate' style='width:70px;' readonly>
					<A HREF=\"#\" onClick=\"displayCalendar(document.qtybudget.enddate$i,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
				</td>	
				
				<td align='center'><input type='text' name='month1[$i]' id='month1[$i]' value='$jan' style='width:70px;'></td>
				<td align='center'><input type='text' name='month2[$i]' id='month2[$i]' value='$feb' style='width:70px;'></td>
				<td align='center'><input type='text' name='month3[$i]' id='month3[$i]' value='$mar' style='width:70px;'></td>
				
				<td align='center'><input type='text' name='month4[$i]' id='month4[$i]' value='$apr' style='width:70px;'></td>
				<td align='center'><input type='text' name='month5[$i]' id='month5[$i]' value='$may' style='width:70px;'></td>
				<td align='center'><input type='text' name='month6[$i]' id='month6[$i]' value='$jun' style='width:70px;'></td>
				
				<td align='center'><input type='text' name='month7[$i]' id='month7[$i]' value='$jul' style='width:70px;'></td>
				<td align='center'><input type='text' name='month8[$i]' id='month8[$i]' value='$aug' style='width:70px;'></td>
				<td align='center'><input type='text' name='month9[$i]' id='month9[$i]' value='$sep' style='width:70px;'></td>
				
				<td align='center'><input type='text' name='month10[$i]' id='month10[$i]' value='$oct' style='width:70px;'></td>
				<td align='center'><input type='text' name='month11[$i]' id='month11[$i]' value='$nov' style='width:70px;'></td>
				<td align='center'><input type='text' name='month12[$i]' id='month12[$i]' value='$decm' style='width:70px;'></td>
				
				<td align='center'><input type='text' name='projectcode[$i]' id='projectcode[$i]' value='$project_code' style='width:125px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Project ' id='lstProjectCodeH[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject('41', '$i');\"  /></span></label>
				</td>
				<td align='center'><input type='text' name='costcentcode[$i]' id='costcentcode[$i]' value='$costcent_code' style='width:125px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Costcenter ' id='lstCostcentCodeH[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistCostcenter('37','$i');\"  /></span></label>
				</td>
			</tr>";
		$i++;
	}
echo "<tr height='30px'><td colspan='3'></td>
		<td colspan='2'><span style='font-size: 11px; color: #000000; font-weight: bold;'>Result per page </span><select name='perpage' id='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>";
echo "</select></td><td colspan='1'>";
$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 colspan='14'>";

if ($startrange <= $totalrows){
		$startrange = $startrange + $perpage;
		if  ($startrange <= $totalrows)
			echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
	} else
		echo "&nbsp;";
	
echo "</td></tr>";	
echo"</table>";

}


function getBudget($base1, $base2, $Decimalbase1, $Decimalbase2, $perpage, $startrange, $connection) {
	$bbottom = "border-bottom: 1px solid black";
	
	if ($perpage == '') $perpage = 20;
	if ($startrange=='') $startrange = 0;
	
	echo "<table bgcolor='#d3d3d3' width='3400px' border=0 cellpadding=0 cellspacing=0>";
	echo "<tr height='30px'>
			<td style='$bbottom;width:30px;'><span class='style1'></span></td>
			<td style='$bbottom;width:30px;'><span class='style1'></span></td>
			<td style='$bbottom;width:140px;'><span class='style1'>Ledger Number</span></td>
			<td style='$bbottom;width:180px;'><span class='style1'>Description</span></td>
			<td style='$bbottom;width:110px;'><span class='style1'>Start Date</span></td>
			<td style='$bbottom;width:110px;'><span class='style1'>End Date</span></td>
			<td style='$bbottom;width:80px;'><span class='style1'>Cur</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Amount</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>$base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>$base2</span></td>
			<td style='$bbottom;width:120px;'><span class='style1'>Project</span></td>
			<td style='$bbottom;width:120px;'><span class='style1'>CostCenter</span></td>
			<td style='$bbottom;width:50px;'><span class='style1'>D/C</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jan $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Feb $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Mar $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Apr $base1</span></td>
			 
			<td style='$bbottom;width:90px;'><span class='style1'>May $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jun $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jul $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Augt $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Sep $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Oct $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Nov $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Dec $base1</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jan $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Feb $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Mar $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Apr $base2</span></td>
			 
			<td style='$bbottom;width:90px;'><span class='style1'>May $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jun $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Jul $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Aug $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Sep $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Oct $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Nov $base2</span></td>
			<td style='$bbottom;width:90px;'><span class='style1'>Dec $base2</span></td>
			
			
		</tr>";
	
	$query = "select budget_id, ledger_number, Budget_Description, currency, amount, base1 as amntB1, base2 as amntB2, project_code as projectCode, costCenter_code as costcentCode,Budget_DBCD,
				ifnull(Month1_base1,0) as Month1_base1, ifnull(Month2_base1,0) as Month2_base1, ifnull(Month3_base1,0) as Month3_base1,
				ifnull(Month4_base1,0) as Month4_base1, ifnull(Month5_base1,0) as Month5_base1, ifnull(Month6_base1,0) as Month6_base1,
				ifnull(Month7_base1,0) as Month7_base1, ifnull(Month8_base1,0) as Month8_base1, ifnull(Month9_base1,0) as Month9_base1,
				ifnull(Month10_base1,0) as Month10_base1, ifnull(Month11_base1,0) as Month11_base1, ifnull(Month12_base1,0) as Month12_base1,

				ifnull(Month1_base2,0) as Month1_base2, ifnull(Month2_base2,0) as Month2_base2, ifnull(Month3_base2,0) as Month3_base2,
				ifnull(Month4_base2,0) as Month4_base2, ifnull(Month5_base2,0) as Month5_base2, ifnull(Month6_base2,0) as Month6_base2,
				ifnull(Month7_base2,0) as Month7_base2, ifnull(Month8_base2,0) as Month8_base2, ifnull(Month9_base2,0) as Month9_base2,
				ifnull(Month10_base2,0) as Month10_base2, ifnull(Month11_base2,0) as Month11_base2, ifnull(Month12_base2,0) as Month12_base2,
				date_format(Budget_Sdate,'%d/%m/%Y') as startdate, date_format(Budget_Edate,'%d/%m/%Y') as enddate
				from budget
				order by ledger_number, Budget_Sdate, Budget_Edate ";
				
	$result = mysql_query($query, $connection);			
	$totalrows = mysql_num_rows($result);
	
	$query .= " limit ".$startrange.",".$perpage; 
	$result = mysql_query($query, $connection);	
	$i = 0;
	while ($rw = mysql_fetch_array($result)){
		extract($rw);
		echo "<tr height='25px' >
				<td align='center' style='width:30px;'><img src='img/c_delete.png' height='14px' title='Delete Budget' onmouseover=\"style.cursor='hand';\" onclick=\"deleteBudget('$budget_id', '$i');\" ></td>
				<td align='center' style='width:30px;'><img src='img/confirm-1.png' title='Update Budget' onmouseover=\"style.cursor='hand';\" onclick=\"updateBudget('$budget_id', '$i');\" ></td>
				<td style='width:140px;'><input type='text' name='ledgercode[$i]' id='ledgercode[$i]' value='$ledger_number' style='width:115px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Ledger ' id='lstLedger[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistledger('14','$i');\"  />
				</td>
				<td style='width:180px;'><input type='text' name='budgetDesc[$i]' id='budgetDesc[$i]' value='$Budget_Description' style='width:170px;'></td>
				<td style='width:110px;'><input type='text' name='startdate$i' id='startdate[$i]' value='$startdate' maxlength='10' style='width:80px;' readonly>
					<A HREF=\"#\" onClick=\"displayCalendar(document.budget.startdate$i,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
				</td>
				<td style='width:110px;'><input type='text' name='enddate$i' id='enddate[$i]' value='$enddate' maxlength='10' style='width:80px;' readonly>
					<A HREF=\"#\" onClick=\"displayCalendar(document.budget.enddate$i,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
				</td>
				
				<td style='width:80px;'><select name='budgetCur[$i]' id='budgetCur[$i]' style='width:70px;' onchange=\"setAmount('$base1', '$base2','$Decimalbase1','$Decimalbase2','$i');\">";
		$querycurrency="select Currency_code from currency order by currency_code";
		$resultcurrency=mysql_query($querycurrency,$connection);
		echo"	<option value=''></option>";
		while($curf=mysql_fetch_row($resultcurrency)){
			echo " <option value='$curf[0]' ".($currency == $curf[0]?'selected':'').">$curf[0]</option>";
		}
		echo "		</select>
				</td>							
				<td style='width:90px;'><input type='text' name='budgetAmnt[$i]' id='budgetAmnt[$i]' value='$amount' style='width:85px;' onkeyup=\"setAmount('$base1', '$base2','$Decimalbase1','$Decimalbase2','$i');\"></td>	
				<td style='width:90px;'><input type='text' name='budgetAmntB1[$i]' id='budgetAmntB1[$i]' value='$amntB1' style='width:85px;' readonly></td>	
				<td style='width:90px;'><input type='text' name='budgetAmntB2[$i]' id='budgetAmntB2[$i]' value='$amntB2' style='width:85px;' readonly></td>	
				
				<td style='width:120px;'><input type='text' name='projectcode[$i]' id='projectcode[$i]' value='$projectCode' style='width:85px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Project ' id='lstProjectCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject('41','$i');\"  /></span></label>
				</td>	
				<td style='width:120px;'><input type='text' name='costcentcode[$i]' id='costcentcode[$i]' value='$costcentCode' style='width:85px;'>
					<label><span class='style1'><img valign='bottom' src='img/btnopen.jpg' title=' Select Costcenter ' id='lstCostcentCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistCostcenter('37','$i');\"  /></span></label>
				</td>	
				<td style='width:50px;'><select name='budgetDBCD[$i]' id='budgetDBCD[$i]' style='width:45px'>
					<option value='' ".($Budget_DBCD == ''?'selected':'')."></option>
					<option value='D' ".($Budget_DBCD == 'D'?'selected':'')." >D</option>
					<option value='C' ".($Budget_DBCD == 'C'?'selected':'').">C</option>
				</select></td>
				
				<td style='width:90px;'><input type='text' name='mnth1B1[$i]' id='mnth1B1[$i]' value='$Month1_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth2B1[$i]' id='mnth2B1[$i]' value='$Month2_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth3B1[$i]' id='mnth3B1[$i]' value='$Month3_base1' style='width:85px;'></td>	
				
				<td style='width:90px;'><input type='text' name='mnth4B1[$i]' id='mnth4B1[$i]' value='$Month4_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth5B1[$i]' id='mnth5B1[$i]' value='$Month5_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth6B1[$i]' id='mnth6B1[$i]' value='$Month6_base1' style='width:85px;'></td>
				
				<td style='width:90px;'><input type='text' name='mnth7B1[$i]' id='mnth7B1[$i]' value='$Month7_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth8B1[$i]' id='mnth8B1[$i]' value='$Month8_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth9B1[$i]' id='mnth9B1[$i]' value='$Month9_base1' style='width:85px;'></td>
				
				<td style='width:90px;'><input type='text' name='mnth10B1[$i]' id='mnth10B1[$i]' value='$Month10_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth11B1[$i]' id='mnth11B1[$i]' value='$Month11_base1' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth12B1[$i]' id='mnth12B1[$i]' value='$Month12_base1' style='width:85px;'></td>
				
				<td style='width:90px;'><input type='text' name='mnth1B2[$i]' id='mnth1B2[$i]' value='$Month1_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth2B2[$i]' id='mnth2B2[$i]' value='$Month2_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth3B2[$i]' id='mnth3B2[$i]' value='$Month3_base2' style='width:85px;'></td>	
				
				<td style='width:90px;'><input type='text' name='mnth4B2[$i]' id='mnth4B2[$i]' value='$Month4_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth5B2[$i]' id='mnth5B2[$i]' value='$Month5_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth6B2[$i]' id='mnth6B2[$i]' value='$Month6_base2' style='width:85px;'></td>
				
				<td style='width:90px;'><input type='text' name='mnth7B2[$i]' id='mnth7B2[$i]' value='$Month7_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth8B2[$i]' id='mnth8B2[$i]' value='$Month8_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth9B2[$i]' id='mnth9B2[$i]' value='$Month9_base2' style='width:85px;'></td>
				
				<td style='width:90px;'><input type='text' name='mnth10B2[$i]' id='mnth10B2[$i]' value='$Month10_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth11B2[$i]' id='mnth11B2[$i]' value='$Month11_base2' style='width:85px;'></td>	
				<td style='width:90px;'><input type='text' name='mnth12B2[$i]' id='mnth12B2[$i]' value='$Month12_base2' style='width:85px;'></td>
				
				
			</tr>";
		
		$i++;
	}
	
	echo "<tr height='30px'><td colspan='3'></td>
		<td colspan='2'><span style='font-size: 11px; color: #000000; font-weight: bold;'>Result per page </span><select name='perpage' id='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>";
	echo "</select></td><td colspan='1'>";
	$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 colspan='14'>";

	if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
		
	echo "</td></tr>";	
	echo "</table>";
}




function getQtyBudgetDetails($bqId, $perpage, $startrange, $connection) {
	if ($perpage == '') $perpage = 20;
	if ($startrange=='') $startrange = 0;
	
echo "<table width='900px' border=0 cellpadding=0 cellspacing=0>";
echo "<col width=25px><col width=25px><col width=50px><col width=200px><col width=400px><col width=100px><col width=100px>";
$bbottom = "border-bottom: 1px solid black";	
$query = "select BQdt_Id, budget_qtydt.item_code as item_code, Item_UnitSalesDesc, item_description, qty
			 from budget_qtydt 
			 inner join items on items.item_code = budget_qtydt.item_code
			 inner join budget_qtyhd on budget_qtyhd.BQ_Id = budget_qtydt.BQ_Id
			 where budget_qtydt.BQ_Id = $bqId	
			 order by item_code "; //echo $query;
	$res = mysql_query($query, $connection);
	$totalrows = mysql_num_rows($res);
	
	$query .= " limit ".$startrange.",".$perpage; 
	
echo "<tr height='30px'><td colspan='2'></td>
		<td colspan='3'><span style='font-size: 11px; color: #000000; font-weight: bold;'>Result per page </span><select name='perpage' id='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>";
echo "</select></td><td colspan='1'>";
$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 "";

if ($startrange <= $totalrows){
		$startrange = $startrange + $perpage;
		if  ($startrange <= $totalrows)
			echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
	} else
		echo "&nbsp;";
	
echo "</td><td colspan='1'></td></tr>";	
		
echo "<tr height='30px' >
			<td colspan='2' style='$bbottom;'></td><td style='$bbottom;'></td>
			<td style='$bbottom;'><span class='style1'>Item Code</span></td>
			<td style='$bbottom;'><span class='style1'>Item Description</span></td>
			<td style='$bbottom;'><span class='style1'>Quantity</span></td>
			<td style='$bbottom;'><span class='style1'>Unit</span></td>		
	</tr>";

	$res = mysql_query($query, $connection);
	$i = 0;
	while ($rw = mysql_fetch_array($res)){
		extract($rw);
		
		echo "<tr height='20px' >
				<td align='center'><img src='img/c_delete.png' height='12px' title='Delete Budget' onmouseover=\"style.cursor='hand';\" onclick=\"deleteBudget('$BQdt_Id', '$i');\" ></td>
				<td align='center'><img src='img/confirm-1.png' height='14px' title='Submit Quantity' onmouseover=\"style.cursor='hand';\" onclick=\"submitQty('$BQdt_Id', '$i');\" ></td>
				<td align='center'><span class='details1'>".($i+1)."</span></td>
				<td><span class='details1'>$item_code</span></td>
				<td><span class='details1'>$item_description</span></td>
				<td><span class='details1'><input type='number' name='qty$BQdt_Id' id='qty$BQdt_Id' value='$qty' style='width:70px;height:12px;text-align: center;'></span></td>
				<td ><span class='details1'>$Item_UnitSalesDesc</span></td>
			</tr>";
		$i++;
	}

echo"</table>";

}




?>