<?php


/*
function GetSQLValueString($theValue, $theType) 
{
  $theValue = trim($theValue);	
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "Null";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "Null";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "Null";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "Null";
      break;
  }
  return $theValue;
}
*/

function draw_fixedassetsamount($assets_id,$base1,$base2,$DecimalBase,$DecimalBase1,$DecimalBase2,$vatPerc, $connection) {
		
	$query = " select Assets_amount as assets_amount, Assets_amount1 as assets_amount1, Assets_amount2 as assets_amount2, temp_assets.Currency_code as CurCode,
				assets_vat, assets_price
				from temp_assets inner join ledger on ledger.ledger_number = temp_assets.ledger_number
				left join journal on journal.journal_id = temp_assets.journal_id
				where assets_id = '$assets_id' ";
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result)){
		extract($rows);
		}
		

		echo"<table border='0' cellspacing=0 width=100% ><col width=30%><col width=70%>";
		//echo'<tr><td align="center"><span class="style10">Amount</span></td>';
		//echo"<td><input type='text'  readonly id='assets_amount' name='assets_amount' value='".number_format($assets_amount,$DecimalBase)."' style='height:20;text-align:right' size=10></td>";

	echo"<tr><td align='center'><span class='style10'>Gross Total </span></td>
			<td><input type='text' readonly  id='assets_price' name='assets_price' value='".number_format($assets_price,$DecimalBase1)."'  style='height:20;text-align:right' size=10></td></tr>";
	echo"<tr><td align='center'><span class='style10'>VAT $vatPerc % </span></td>
			<td><input type='text' readonly  id='assets_vat' name='assets_vat' value='".number_format($assets_vat,$DecimalBase1)."'  style='height:20;text-align:right' size=10></td></tr>";			
		
	echo"<tr><td align='center'><span class='style10'>Net Total $CurCode </span></td>
			<td><input type='text' readonly  id='assets_amount' name='assets_amount' value='".number_format($assets_amount,$DecimalBase1)."'  style='height:20;text-align:right' size=10></td></tr>";	
	if ($CurCode != $base1)	
		echo"<tr><td align='center'><span class='style10'>Net Total $base1 </span></td>
			<td><input type='text' readonly  id='assets_amount1' name='assets_amount1' value='".number_format($assets_amount1,$DecimalBase1)."'  style='height:20;text-align:right' size=10></td></tr>";
	if ($CurCode != $base2)		
		echo"<tr><td align='center'><span class='style10'>Net Total $base2</span></td>
			<td><input type='text' readonly id='assets_amount2' name='assets_amount2' value='".number_format($assets_amount2,$DecimalBase2)."' style='height:20;text-align:right'  size=10></td></tr>";	
		echo"</table></td></tr>
		<tr>
			<td id='total-bottom' style='width:240px;height:12px;'></td>
		</tr></table>";
				
}

				
function draw_assetsdt($assets_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$actionbefore){

	$ClassI = 'grid_roundedtext2';
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	$columnsarray = array("ledger_number", "ledger_name", "currency_code", "assetsdt_description", "assetsdt_qty","assetsdt_unitPrice", "assetsdt_valuedate", "assetsdt_isvat");
	$columnslist = implode(',', $columnsarray);
	
		
		
	echo"<input type='hidden' name='headercurrency_code' id='headercurrency_code' value='$headercurrency_code'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'assetsdt_id';
		
		
	$query="select assetsdt_id, assets_id, temp_assetsdt.Ledger_number,ledger.ledger_name 
			, temp_assetsdt.Currency_code , assetsdt_description , assetsdt_amount, assetsdt_amount1, assetsdt_amount2
			, date_format(assetsdt_ValueDate,'%d/%m/%Y'),assetsDt_IsVat, ifnull(assetsdt_quantity,1), assetsdt_unitprice,temp_assetsdt.costcenter_code
			from temp_assetsdt inner join ledger on ledger.ledger_number = temp_assetsdt.ledger_number 
			where assets_id = '$assets_id'  order by $orderby $direction";
	//echo $query;	
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	//$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);
	$numRows = mysql_num_rows($result) ;
	$i=0;

	$queryjournal_distribution = "select  ifNull(journal_distribution,0) As journal_distribution from module";
	$sub_resultjournal_distribution = selectData($connection, $queryjournal_distribution);	
	$journal_distribution = $sub_resultjournal_distribution[0];

	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div id='assetsdtdiv' style='overflow:scroll;width:1080px;height:200px'>";
	echo"<table border='1' align='center'   class='grid_data' style='table-layout:fixed;font-size:10px;border:1px solid black;border-spacing:0;width:1195px;' cellpadding='0' cellspacing='1'>
		";
	echo"
		<col width=35>
		<col width=150>
		<col width=180>
		<col width=85>
		<col width=180>
		<col width=100>
		<col width=100>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=80>
		<col width=40>
		<col width=180>
		<col width=25>
		";	
		
				
		echo"<tr  height=10px >
			<th id='resizable1'  height='15' align='left'></span></th>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Account No. </th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Acc. Name </th>
			<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Currency </th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Description </th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Quantity </th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Unit Price </th>
			<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount </th>
			<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1 </th>
			<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2 </th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Value Date </th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Is Vat </th> 
			";
			if($journal_distribution == 1){
			echo"<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>distribution Code</th>";
			}
			echo"<th id='resizable1'  height='15' align='left'></span></th>
			</tr>";
		
		$i=0;
		$j=1;
		
		echo"
			
			<input type='hidden' name='selectedassetsdttr' id='selectedassetsdttr' value='$selectedassetsdttr'>
			<input type='hidden' name='selectedassetsdttrcolor' id='selectedassetsdttrcolor' value='$selectedassetsdttrcolor'>
			<input type='hidden' name='selectedassetsdt_id' id='selectedassetsdt_id' value='$selectedassetsdt_id'>
			<input type='hidden' name='lastinputrow' id='lastinputrow' value='$numRows'>
			
			";

			
	while($row=mysql_fetch_row($result)){
				
			if ($i%2==0)
			$bgcolor='#F5FAFF';
		else	
			$bgcolor='#FFFFFF';
			
			
			
			
			$onclick=" onclick='showrelationtoItemJour(\"$row[0]\",\"$row[4]\");' ";
			
		
			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'AssetsDt\')"';

				$assetsdt_id[$i] = $row[0];
				$ledger_number[$i] = $row[2];
				$ledger_name[$i] = $row[3];
				$currency_code[$i] = $row[4];
				$assetsdt_description[$i] = $row[5];
				$assetsdt_amount[$i] = $row[6];
				$assetsdt_amount1[$i] = $row[7];
				$assetsdt_amount2[$i] = $row[8];
				$assetsdt_valuedate[$i] = $row[9];
				$assetsdt_isvat[$i] = $row[10];
				$assetsdt_qty[$i] = $row[11];
				$assetsdt_unitPrice[$i] = $row[12];
				$txtCostCentCodeDt[$i] = $row[13];
				
				echo"<tr height='20px' id='assdt$i' onclick=\"returncolorassetsdt(this,'selectedassetsdttr','selectedassetsdttrcolor','$row[0]')\" style='background-color:$bgcolor'>";

			
							
				$recno = $i+1;
				$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
				
				echo"<td  align=center onclick=\"deleteassetsdt('$row[0]','$startrange','$perpage','$morelines'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   onchange=setaccountno(this.value,'ledger_number[$i]','ledger_name[$i]','assetsdt','assetsdtledgernumberimage[$i]')   name='ledger_number[$i]' id='ledger_number[$i]' value='".$ledger_number[$i]."' style='width:120px;' ></span>
						<img src='img/btnopen.jpg' width='15' height='20' id='assetsdtledgernumberimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('ledger_number','ledger_number[$i]','ledger_name[$i]','800','500');\">
						</td>";
				
					echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   readonly class='roundedtext_amortization_medium' name='ledger_name[$i]' id='ledger_name[$i]' value='".$ledger_name[$i]."' style='width:170px;'> </span></td>";					

				//echo"<td $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='currency_code[$i]' id='currency_code[$i]' value='".$currency_code[$i]."'> </span></td>";
				
				
				$querycurrency="select  currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
				
				if ($lastcurrency[$i]=='')
					$lastcurrency[$i] = $currency_code[$i];
				
				echo"<td align=center $onclick><span class='style4'>
				<input type='hidden' name='lastcurrency[$i]' id='lastcurrency[$i]' value='$lastcurrency[$i]'>
				<select   $KeyDown name='currency_code[$i]' id='currency_code[$i]' 	onchange=changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','currency','currency_code[$i]','lastcurrency[$i]')
					></span>";
					echo"	<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($currency_code[$i]==$curf[0])	echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"	</select></td>";	
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_description[$i]' id='assetsdt_description[$i]' value='".$assetsdt_description[$i]."' style='width:180px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_qty[$i]' id='assetsdt_qty[$i]' value='".$assetsdt_qty[$i]."' style='width:100px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_unitPrice[$i]' id='assetsdt_unitPrice[$i]' value='".$assetsdt_unitPrice[$i]."' style='width:100px;' onchange=\"calcTotal('$i');\"> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' style='text-align:right;color:#0000FF;width:110px;' name='assetsdt_amount[$i]' id='assetsdt_amount[$i]' value='".$assetsdt_amount[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount','currency_code[$i]','lastcurrency[$i]');\" readonly> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  style='text-align:right;color:#994E67;width:110px;' name='assetsdt_amount1[$i]' id='assetsdt_amount1[$i]' value='".$assetsdt_amount1[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount1','currency_code[$i]','lastcurrency[$i]')\" readonly> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  style='text-align:right;color:#4B6318;width:110px;' name='assetsdt_amount2[$i]' id='assetsdt_amount2[$i]' value='".$assetsdt_amount2[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount2','currency_code[$i]','lastcurrency[$i]')\" readonly> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown     name='assetsdt_valuedate[$i]' id='assetsdt_valuedate[$i]'  style='width:70px' class='".$ClassI." date'  value='".$assetsdt_valuedate[$i]."'> </span></td>";
				
				
				if($assetsdt_isvat[$i]==1)
					$chk = ' checked ';
				else	
					$chk = ' ';
					
				echo"<td $onclick><span class='style4'>
				<input   $KeyDown  type='checkbox' id='assetsdt_isvat[$i]' $chk name='assetsdt_isvat[$i]' value=''></td>";
				//echo"<td $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_vsmall'  name='assetsdt_isvat[$i]' id='assetsdt_isvat[$i]' value='".$assetsdt_isvat[$i]."'> </td>";
				if ($Module_CostCenterDt == 1 && $journal_distribution == 0 ) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$txtCostCentCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else if($journal_distribution == 1){
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$txtCostCentCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
					<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				}
				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitAssetsDt[$i]' title='Save' onclick=\"submitassetsdt('$assets_id','$i','e');\"></td>";
				echo"<input type='hidden'  name='assetsdt_id[$i]' id='assetsdt_id[$i]' value='".$assetsdt_id[$i]."' >";
				echo"</tr>";
				
				
				$i+=1;
			}
			
		$k=1;
			$morelines = 1;
			//echo $morelines;
			while ($k <= $morelines) {
				$recno = $i+1;
				if ($k==$morelines)
					$mode = 'i';
				else
					$mode = 'e';			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'AssetsDt\')"';

				echo"<tr  height='20px' >";
				echo"<td align=center><img src='img/undo.png' width=17 height=17 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearassetsdt('$i')\"></td>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    onchange=setaccountno(this.value,'ledger_number[$i]','ledger_name[$i]','assetsdt','assetsdtledgernumberimage[$i]')   class='roundedtext_amortization_small'  name='ledger_number[$i]' id='ledger_number[$i]' value='".$ledger_number[$i]."' style='width:120px;' ></span>
						<img src='img/btnopen.jpg' id='assetsdtledgernumberimage[$i]' width='15' height='20' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('ledger_number','ledger_number[$i]','ledger_name[$i]','800','500')\">
						</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   readonly class='roundedtext_amortization_medium' name='ledger_name[$i]' id='ledger_name[$i]' value='".$ledger_name[$i]."'  style='width:170px;'> </span></td>";					

				//echo"<td $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='currency_code[$i]' id='currency_code[$i]' value='".$currency_code[$i]."'> </span></td>";
				
				
				$querycurrency="select  currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
				
			if ($currency_code[$i]=='')
					$currency_code[$i] = $base1;
			
				
				echo"<td align=center $onclick>
				<input type='hidden' name='lastcurrency[$i]' id='lastcurrency[$i]' value='$lastcurrency[$i]'   style='width:80px;'>
				<span class='style4'><select   $KeyDown name='currency_code[$i]' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','currency','currency_code[$i]','lastcurrency[$i]')\" id='currency_code[$i]' ></span>";
					echo"	<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($currency_code[$i]==$curf[0])	echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"	</select></td>";	
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_description[$i]' id='assetsdt_description[$i]' value='".$assetsdt_description[$i]."' style='width:180px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_qty[$i]' id='assetsdt_qty[$i]' value='".$assetsdt_qty[$i]."' style='width:100px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='assetsdt_unitPrice[$i]' id='assetsdt_unitPrice[$i]' value='".$assetsdt_unitPrice[$i]."' style='width:100px;' onchange=\"calcTotal('$i');\"> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' style='text-align:right;color:#0000FF;width:110px;' name='assetsdt_amount[$i]' id='assetsdt_amount[$i]' value='".$assetsdt_amount[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount','currency_code[$i]','lastcurrency[$i]')\" readonly> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' style='text-align:right;color:#994E67;width:110px;' name='assetsdt_amount1[$i]'  id='assetsdt_amount1[$i]' value='".$assetsdt_amount1[$i]."'  onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount1','currency_code[$i]','lastcurrency[$i]')\" readonly> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' style='text-align:right;color:#4B6318;width:110px;' name='assetsdt_amount2[$i]'  id='assetsdt_amount2[$i]' value='".$assetsdt_amount2[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount2','currency_code[$i]','lastcurrency[$i]')\"  readonly> </span></td>";
				
				if ($assetsdt_valuedate[$i]=='')
					$assetsdt_valuedate[$i] = displayToday();
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown   name='assetsdt_valuedate[$i]' id='assetsdt_valuedate[$i]'  style='width:70px'  class='".$ClassI." date'     value='".$assetsdt_valuedate[$i]."'> </span></td>";
				//<input type='text'   $KeyDown   class='roundedtext_amortization'  name='assetsdt_isvat[$i]' id='assetsdt_isvat[$i]' value='".$assetsdt_isvat[$i]."'> 
				echo"<td $onclick><span class='style4'>
				<input   $KeyDown  type='checkbox' id='assetsdt_isvat[$i]' name='assetsdt_isvat[$i]' value=''></td>";
				if ($Module_CostCenterDt == 1 && $journal_distribution == 0 ) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$txtCostCentCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else if($journal_distribution == 1){
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$txtCostCentCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
					<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				}
				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitAssetsDt[$i]' title='Save' onclick=\"submitassetsdt('$assets_id','$i','i');\"></td>";
				echo"<input type='hidden'  name='assetsdt_id[$i]' id='assetsdt_id[$i]' value='".$assetsdt_id[$i]."' >";
				echo"</tr>";
			$i+=1;
			$k+=1;
			}	
		echo"		<input type='hidden' name='RecCount_G1' id='RecCount_G1' value='$i'>"; 	
		echo"</table></div>";
		

	

}



function draw_itemjour($assetsdt_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$defaultproject,$defaultcostcent){

	$ClassI = 'grid_roundedtext2';

	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	$columnsarray = array(
	"itemjour_location","itemjour_barcode","itemjour_code","itemjour_description","itemjour_prcnt"
	,"itemjourproject_code","projectproject_name","itemjourcostcent_code","itemjourcostcent_name","itemjour_amount","itemjour_amount1","itemjour_amount2"
	,"ledger_numberdebit","ledger_namedebit","ledger_numbercredit","ledger_namecredit","project_codecredit","project_namecredit"
	,"costcent_codecredit","costcent_namecredit"	,"itemjour_remark","itemjour_previousdate");

	$columnslist = implode(',', $columnsarray);
	
	$queryjournal_distribution = "select  ifNull(journal_distribution,0) As journal_distribution from module";
	$sub_resultjournal_distribution = selectData($connection, $queryjournal_distribution);	
	$journal_distribution = $sub_resultjournal_distribution[0];
		
	echo"
		
		<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'assetsdt_id';
		
		
	$query="select itemjour_location,itemjour_barcode,ItemJour_Code,ItemJour_Description,ItemJour_prcnt
					,temp_assetsitemjour.Project_Code,project.project_name,temp_assetsitemjour.Costcent_code,costcent.costcent_name as costcent_name
					,ItemJour_amount,ItemJour_amount1,ItemJour_amount2,temp_assetsitemjour.Ledger_Number,Ledger_NumberDebit
					,ledger.ledger_name as Ledger_NameDebit,Ledger_NumberCredit,ledgercredit.ledger_name as Ledger_NameCredit
					,Project_CodeCredit,projectcredit.project_name as  Project_NameCredit
					,CostCent_CodeCredit,costcentcredit.costcent_name as CostCent_NameCredit
					,ItemJour_Remark,date_format(ItemJour_PreviousDate,'%d-%m-%Y') as ItemJour_PreviousDate,autoincrement,temp_assetsitemjour.Currency_Code,temp_assetsitemjour.Costcent_code
					from temp_assetsitemjour left join project on project.project_code=temp_assetsitemjour.project_code
				left join project as projectcredit on projectcredit.project_code=temp_assetsitemjour.Project_CodeCredit
				left join costcent on costcent.costcent_code=temp_assetsitemjour.costcent_code
				left join costcent as costcentcredit on costcentcredit.costcent_code=temp_assetsitemjour.costcent_code
				left join ledger on ledger.ledger_number=temp_assetsitemjour.Ledger_NumberDebit
				left join ledger as ledgercredit on ledgercredit.ledger_number=temp_assetsitemjour.Ledger_NumberCredit
				where assetsdt_id = '$assetsdt_id'  order by $orderby $direction";
	//echo $query;
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='width:1150px;height:120px'>";
	echo"<table border='1' 	align='center'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:3400px;' cellpadding='0' cellspacing='1'>
		";
	echo"
		<col width=35>
		<col width=170>
		<col width=120>
		<col width=170>
		<col width=180>
		<col width=70>
		<col width=180>
		<col width=180>
		<col width=180>
		<col width=160>
		<col width=160>
		<col width=160>
		<col width=160>
		<col width=180>
		<col width=160>
		<col width=180>
		<col width=180>
		<col width=180>
		<col width=160>
		<col width=180>
		<col width=160>
		";
		if($journal_distribution == 1){
		echo"<col width=160>";
		}
		echo"<col width=160>
		<col width=160>
		<col width=25>
		";	
		
				
		echo"<tr  height=10px >
			<th id='resizable1'  height='15' align='left'></span></th>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Location</th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Barcode</th>
			<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Item Code</th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Item Description </th>
			<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Per.(%)</th>
			<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Code</th>
			<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Name</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcenter Code</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Name</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Number(Db)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Name(Db)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Number(Cr)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Name(Cr)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Code(Cr)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Name(Cr)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Code(Cr)</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Name(Cr)</th>";
			if($journal_distribution == 1){
			echo"<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>distribution Code</th>";
			}
			echo"<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Remark</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Previous Date</th>		
			<th id='resizable1'  height='15' align='left'></th>
			</tr>";
			
		$i=0;
		$j=1;
		echo"
		
			<input type='hidden' name='selectedtritemjour' id='selectedtritemjour' value='$selectedtritemjour'>
			<input type='hidden' name='selectedtrcoloritemjour' id='selectedtrcoloritemjour' value='$selectedtrcoloritemjour'>";

			
	while($row=mysql_fetch_row($result)){
				
			if ($i%2==0)
			$bgcolor='#F5FAFF';
		else	
			$bgcolor='#FFFFFF';
			
			
			
			
			//$onclick=" onclick='showrelationtoItemJour(\"$row[0]\")' ";
			
		
			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'jour\')"';
			
				echo"<tr height='15px' id='itmjour$i' onclick=\"returncoloritemjour(this,'selectedtritemjour','selectedtrcoloritemjour')\" style='background-color:$bgcolor'>";

				$itemjour_location[$i] = $row[0];
				$itemjour_barcode[$i] = $row[1];
				$itemjour_code[$i] = $row[2];
				$itemjour_description[$i] = $row[3];
				$itemjour_prcnt[$i] = $row[4];
				$itemjourproject_code[$i] = $row[5];
				$projectproject_name[$i] = $row[6];
				$itemjourcostcent_code[$i] = $row[7];
				$itemjourcostcent_name[$i] = $row[8];
				$itemjour_amount[$i] = $row[9];
				$itemjour_amount1[$i] = $row[10];
				$itemjour_amount2[$i] = $row[11];
				$itemjourledger_number[$i] = $row[12];
				$ledger_numberdebit[$i] = $row[13];
				$ledger_namedebit[$i] = $row[14];
				$ledger_numbercredit[$i] = $row[15];
				$ledger_namecredit[$i] = $row[16];
				$project_codecredit[$i] = $row[17];
				$project_namecredit[$i] = $row[18];
				$costcent_codecredit[$i] = $row[19];
				$costcent_namecredit[$i] = $row[20];
				$itemjour_remark[$i] = $row[21];
				$itemjour_previousdate[$i] = $row[22];
				$autoincrement[$i] = $row[23];
				$txtCostCentCodeDt1[$i] = $row[25];

							
				$recno = $i+1;
				$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
				
				echo"<td  align=center onclick=\"deleteitemjour('$autoincrement[$i]','$assetsdt_id','$startrange','$perpage','$morelines'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large'  name='itemjour_location[$i]' id='itemjour_location[$i]' value='".$itemjour_location[$i]."' style='width:140px;'></span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse ' id='lstWarehouseCode' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistWarehouse('1','$i');\" /> </span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium' name='itemjour_barcode[$i]' id='itemjour_barcode[$i]' value='".$itemjour_barcode[$i]."' style='width:115px;'> </span></td>";					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'   name='itemjour_code[$i]' id='itemjour_code[$i]' value='".$itemjour_code[$i]."' onchange=\"checkitemjour(this)\" style='width:135px;'> </span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Item ' id='lstItemCode' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistItems('1','$i'); \" /> </span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour_description[$i]' id='itemjour_description[$i]' value='".$itemjour_description[$i]."' style='width:175px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' style='width:50px;text-align:right' name='itemjour_prcnt[$i]' id='itemjour_prcnt[$i]' value='".$itemjour_prcnt[$i]."'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  style='text-align:left;width:140px;' onchange=setprojectcostcenter(this.value,'itemjourproject_code[$i]','projectproject_name[$i]','itemjour','itemjourprojectimg[$i]','project') name='itemjourproject_code[$i]' id='itemjourproject_code[$i]' value='".$itemjourproject_code[$i]."' > </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='itemjourprojectimg[$i]' onClick=\"showlistProject(2,'itemjourproject_code[$i]','projectproject_name[$i]');\"  /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  style='text-align:left;width:160px;' name='projectproject_name[$i]' id='projectproject_name[$i]' onchange=setprojectcostcenter(this.value,'itemjourcostcent_code[$i]','itemjourcostcent_name[$i]','itemjour','itemjourcostcenterimg[$i]','costcenter') value='".$projectproject_name[$i]."' > </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' name='itemjourcostcent_code[$i]' id='itemjourcostcent_code[$i]'  onchange=setprojectcostcenter(this.value,'itemjourcostcent_code[$i]','itemjourcostcent_name[$i]','itemjour','itemjourcostcenterimg[$i]','costcenter') value='".$itemjourcostcent_code[$i]."' style='width:140px;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  id='itemjourcostcenterimg[$i]' id='itemjourcostcenterimg[$i]' onClick=\"showlistCostcenter(2,'itemjourcostcent_code[$i]','itemjourcostcent_name[$i]');\" /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'  style='text-align:left;width:160px;' name='itemjourcostcent_name[$i]' id='itemjourcostcent_name[$i]' value='".$itemjourcostcent_name[$i]."' > </span></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount[$i]' id='itemjour_amount[$i]' value='".$itemjour_amount[$i]."' onchange=\"changeamounts(this,'itemjour_amount1[$i]','itemjour_amount2[$i]')\" style='width:155px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount1[$i]' id='itemjour_amount1[$i]' value='".$itemjour_amount1[$i]."' style='width:155px;' readonly> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount2[$i]' id='itemjour_amount2[$i]' value='".$itemjour_amount2[$i]."' style='width:155px;' readonly> </td>";


				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_numberdebit[$i]' id='ledger_numberdebit[$i]' value='".$ledger_numberdebit[$i]."' style='width:140px;'>
					<img src='img/btnopen.jpg' width='15' height='15' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('ledger_number','ledger_numberdebit[$i]','ledger_namedebit[$i]','800','500')\">
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_namedebit[$i]' id='ledger_namedebit[$i]' value='".$ledger_namedebit[$i]."' style='width:150px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_numbercredit[$i]' id='ledger_numbercredit[$i]' value='".$ledger_numbercredit[$i]."' style='width:140px;'> 
				<img src='img/btnopen.jpg' width='15' height='15' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('ledger_number','ledger_numbercredit[$i]','ledger_namecredit[$i]','800','500')\">
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_namecredit[$i]' id='ledger_namecredit[$i]' value='".$ledger_namecredit[$i]."' style='width:150px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_codecredit[$i]' id='project_codecredit[$i]' value='".$project_codecredit[$i]."' style='width:140px;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject(2,'project_codecredit[$i]','project_namecredit[$i]');\"  /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_namecredit[$i]' id='project_namecredit[$i]' value='".$project_namecredit[$i]."' style='width:150px;'> </td>";

				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='costcent_codecredit[$i]' id='costcent_codecredit[$i]' value='".$costcent_codecredit[$i]."' style='width:140px;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'costcent_codecredit[$i]','costcent_namecredit[$i]');\" /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='costcent_namecredit[$i]' id='costcent_namecredit[$i]' value='".$costcent_namecredit[$i]."' style='width:150px;'> </td>";
				// echo $journal_distribution;
				if ($Module_CostCenterDt == 1 && $journal_distribution == 0 ) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt1[$i]' id='costcentcodedt1[$i]' value='".$txtCostCentCodeDt1[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode1[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt1(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else if($journal_distribution == 1){
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt1[$i]' id='costcentcodedt1[$i]' value='".$txtCostCentCodeDt1[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode1[$i]');\" ".$KeyDown." /></span>
					<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt1(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				}
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_remark[$i]' id='itemjour_remark[$i]' value='".$itemjour_remark[$i]."' style='width:150px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='".$ClassI." date'   name='itemjour_previousdate[$i]' id='itemjour_previousdate[$i]'   value='".$itemjour_previousdate[$i]."' style='width:150px;' readonly></td>";
				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitjour[$i]' title='Save' onclick=\"submititemjour('$assetsdt_id','$i','e')\"></td>";
				echo"<input type='hidden'  name='autoincrement[$i]' id='autoincrement[$i]' value='".$autoincrement[$i]."' >";
				echo"</tr>";
				
				
				$i+=1;
			}
			
			
		$k=1;
			$morelines = 1;
		
			
			while ($k <= $morelines) {
			$recno = $i+1;
				if ($k==$morelines)
					$mode = 'i';
				else
					$mode = 'e';			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'jour\')"';
				

				echo"<tr  height='30px' >";
				
				echo"<td align=center><img src='img/undo.png' width=15 height=15 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearitemjour('$i')\"></td>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large'  name='itemjour_location[$i]' id='itemjour_location[$i]' value='".$itemjour_location[$i]."' style='width:140px;'></span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse ' id='lstWarehouseCode' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistWarehouse('1','$i');\" /> </span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium' name='itemjour_barcode[$i]' id='itemjour_barcode[$i]' value='".$itemjour_barcode[$i]."' style='width:115px;'> </span></td>";					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'   name='itemjour_code[$i]' id='itemjour_code[$i]' value='".$itemjour_code[$i]."' onchange=\"checkitemjour(this)\" style='width:125px;'> </span>
				<label><span class='style1'><img src='img/add.png' title='Add Item' id='aItemCode' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"addItem('1','$i'); \" />
										<img src='img/btnopen.jpg' title=' Select Item ' id='lstItemCode' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistItems('1','$i'); \" /> </span></label>
			</td>";
						
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour_description[$i]' id='itemjour_description[$i]' value='".$itemjour_description[$i]."' style='width:175px;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_small'  style='width:50px'    name='itemjour_prcnt[$i]' id='itemjour_prcnt[$i]' value='".$itemjour_prcnt[$i]."'> </span></td>";
				
				if($itemjourproject_code[$i])
					$itemjourproject_code[$i] = $defaultproject;
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'    name='itemjourproject_code[$i]'  onchange=setprojectcostcenter(this.value,'itemjourproject_code[$i]','projectproject_name[$i]','itemjour','itemjourprojectimg[$i]','project')  id='itemjourproject_code[$i]' value='".$itemjourproject_code[$i]."' style='width:140px;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='itemjourprojectimg[$i]' onClick=\"showlistProject(2,'itemjourproject_code[$i]','projectproject_name[$i]');\"  /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='projectproject_name[$i]' id='projectproject_name[$i]' value='".$projectproject_name[$i]."' style='width:160px;'> </span></td>";

				if($itemjourcostcent_code[$i])
					$itemjourcostcent_code[$i] = $defaultcostcent;
					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' name='itemjourcostcent_code[$i]'  onchange=setprojectcostcenter(this.value,'itemjourcostcent_code[$i]','itemjourcostcent_name[$i]','itemjour','itemjourcostcenterimg[$i]','costcenter')   id='itemjourcostcent_code[$i]' value='".$itemjourcostcent_code[$i]."' style='width:140px;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' id='itemjourcostcenterimg[$i]' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'itemjourcostcent_code[$i]','itemjourcostcent_name[$i]');\" /></span></label>
				</td>";
				echo"<td align='center' $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'    name='itemjourcostcent_name[$i]' id='itemjourcostcent_name[$i]' value='".$itemjourcostcent_name[$i]."' style='width:150px;'> </span></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount[$i]' id='itemjour_amount[$i]' value='".$itemjour_amount[$i]."' onchange=\"changeamounts(this,'itemjour_amount1[$i]','itemjour_amount2[$i]')\" style='width:155px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount1[$i]' id='itemjour_amount1[$i]' value='".$itemjour_amount1[$i]."' style='width:155px;' readonly> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_amount2[$i]' id='itemjour_amount2[$i]' value='".$itemjour_amount2[$i]."' style='width:155px;' readonly> </td>";


				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization' onchange=setaccountno(this.value,'ledger_numberdebit[$i]','ledger_namedebit[$i]','itemjour','itemjourledgernumberdebitimage[$i]') name='ledger_numberdebit[$i]' id='ledger_numberdebit[$i]' value='".$ledger_numberdebit[$i]."' style='width:140px;'>
					<img src='img/btnopen.jpg' width='15' height='15' onmouseover=\"style.cursor='pointer'\" id='itemjourledgernumberdebitimage[$i]' onclick=\"showsearchpage('ledger_number','ledger_numberdebit[$i]','ledger_namedebit[$i]','800','500')\">
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_namedebit[$i]' id='ledger_namedebit[$i]' value='".$ledger_namedebit[$i]."' style='width:150px;'> </td>";
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  onchange=setaccountno(this.value,'ledger_numbercredit[$i]','ledger_namecredit[$i]','itemjour','itemjourledgernumbercreditimage[$i]') name='ledger_numbercredit[$i]' id='ledger_numbercredit[$i]' value='".$ledger_numbercredit[$i]."' style='width:140px;'> 
				<img src='img/btnopen.jpg' width='15' height='15' onmouseover=\"style.cursor='pointer'\" id='itemjourledgernumbercreditimage[$i]' onclick=\"showsearchpage('ledger_number','ledger_numbercredit[$i]','ledger_namecredit[$i]','800','500')\">
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ledger_namecredit[$i]' id='ledger_namecredit[$i]' value='".$ledger_namecredit[$i]."' style='width:160px;'> </td>";
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  onchange=setprojectcostcenter(this.value,'project_codecredit[$i]','project_namecredit[$i]','itemjour','itemjourprojectcreditimg[$i]','project') name='project_codecredit[$i]' id='project_codecredit[$i]' value='".$project_codecredit[$i]."' style='width:140px;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='itemjourprojectcreditimg[$i]' onClick=\"showlistProject(2,'project_codecredit[$i]','project_namecredit[$i]');\"  /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_namecredit[$i]' id='project_namecredit[$i]' value='".$project_namecredit[$i]."' style='width:155px;'> </td>";

				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  onchange=setprojectcostcenter(this.value,'costcent_codecredit[$i]','costcent_namecredit[$i]','itemjour','itemjourcostcentercreditimg[$i]','costcenter') name='costcent_codecredit[$i]' id='costcent_codecredit[$i]' value='".$costcent_codecredit[$i]."' style='width:140px;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='itemjourcostcentercreditimg[$i]'  onClick=\"showlistCostcenter(2,'costcent_codecredit[$i]','costcent_namecredit[$i]');\" /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='costcent_namecredit[$i]' id='costcent_namecredit[$i]' value='".$costcent_namecredit[$i]."' style='width:155px;'> </td>";

				if ($Module_CostCenterDt == 1 && $journal_distribution == 0 ) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt1[$i]' id='costcentcodedt1[$i]' value='".$txtCostCentCodeDt1[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode1[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt1(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else if($journal_distribution == 1){
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt1[$i]' id='costcentcodedt1[$i]' value='".$txtCostCentCodeDt1[$i]."' class='roundedtext_amortization_medium' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode1[$i]');\" ".$KeyDown." /></span>
					<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt1(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				}
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_remark[$i]' id='itemjour_remark[$i]' value='".$itemjour_remark[$i]."' style='width:150px;'> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='".$ClassI." date' name='itemjour_previousdate[$i]'  onfocus=\"displayCalendar(document.getElementById('itemjour_previousdate[$i]'),'dd/mm/yyyy',this);  return false;\"  id='itemjour_previousdate[$i]' value='".$itemjour_previousdate[$i]."' style='width:140px;' readonly> </td>";
				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitjour[$i]' title='Save' onclick=\"submititemjour('$assetsdt_id','$i','i')\"></td>";
				echo"<input type='hidden'  name='autoincrement[$i]' id='autoincrement[$i]' value='".$autoincrement[$i]."' >";
				echo"</tr>";
					$i+=1;
			$k+=1;
			}	
		echo"</table></div>";	
		
		/*echo"<div>
		<table width='900' align=center border=0>
		<col width=100>
		<col width=300>
		<col width=150>
		<col width=150>
		<col width=200>
		<col width=50>
		<col width=150>
			<tr  height='20px'   bgcolor='#F6F6F6'>
				<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
				<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage(this.value,'$morelines','$orderby','$option');\">";
				
				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>';
					
					$fromrec = $perpage * (($startrange / $perpage)) + 1;
					
					$torec = $perpage * ($startrange / $perpage + 1);
					if ($torec > $totalrows)
						$torec = $totalrows;
				echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
				echo'<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='pointer'\"    onclick=\"changepagelimit('start','$orderby',$morelines,'".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

				$diff= $startrange - $perpage;
					
				if (($diff) >= 0 ){
					$prvstartrange = $startrange - $perpage;
					echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimit('previous','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
				}
				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' onclick=\"changepagelimit('next','$orderby',$morelines,'".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimit('last','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				if ($morelines==1)	$sel1 = 'selected';
				else if ($morelines==4)	$sel4 = 'selected';	
				else if ($morelines==8)	$sel8 = 'selected';	
				else if ($morelines==12)	$sel12 = 'selected';	
				else if ($morelines==16)	$sel16 = 'selected';	
			
				$pagenum = ($startrange / $perpage) + 1;
				$pageof = ceil(($totalrows / $perpage));
	echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
	echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"Refreshassetsdt('$startrange','$perpage','$morelines','$orderby','$option');\" height='20'></td>";

	echo"<td  valign=top align=right></td></tr>";
	echo"	</table></div>";*/
				
		
		

}



function draw_itemjour2($connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$StartFinancialDate,$EndFinancialDate,$DecimalBase,$DecimalBase1,$DecimalBase2,$DateTimePickerCloseYear,$searchedledger){

	$ClassI = 'grid_roundedtext2';
	
	if ($startrange=='')	
			$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	
	if ($perpage=='')
		$perpage = 10;
	
	$columnsarray = array("itemjour2ledger_number","itemjour2ledger_name","itemjour2journal_folio"
		,"itemjour2journal_refgovernment","itemjour2itemjour_prcnt","itemjour2itemjour_code","itemjour2itemjour_barcode","itemjour2itemjour_description"
		,"itemjour2journaldt_valuedate","itemjour2itemjour_location","itemjour2currency_code"		,"itemjour2itemjour_amount","itemjour2itemjour_amount1"
		,"itemjour2itemjour_amount2","itemjour2itemjour_previousdate","itemjour2itemjour_previousamount","itemjour2itemjour_previousamount1","itemjour2itemjour_previousamount2"
		,"itemjour2amortnymanual","itemjour2amortny1manual","itemjour2amortny2Manual","ItemJour2Amortny","itemjour2amortny1","itemjour2amortny2","ItemJour2Amortn"
		,"ItemJour2AmortnBase1","itemjour2itemjour_dateamortized","itemjour2amountamortized","itemjour2amountamortized1"
		,"itemjour2amountamortized2","ItemJour2AmountRemain","ItemJour2AmountRemain1","ItemJour2AmountRemain2","itemjour2costcent_code","itemjour2costcent_name","itemjour2project_code"
		,"itemjour2project_name"	,"Ledger_NumberDebit","Ledger_NameDebit","Ledger_NumberCredit","Ledger_NameCredit","costcent_codecredit","costcent_namecredit","project_codecredit"
		,"project_namecredit","ItemJour_Sold"	,"ItemJour_SaleDate","Ledger_NumberCash","Ledger_NameCash","CostCent_CodeCash","Project_CodeCash","ItemJour_CashAmount"
		,"ItemJour_CashAmount1","ItemJour_CashAmount2","Ledger_NumberProfit","Ledger_NumberLost","Ledger_NameLost","itemjour_remark");

	/*ledger_namedebit
	ledger_numbercredit
	ledger_namecredit
	project_codecredit
	project_namecredit
	costcent_codecredit
	costcent_namecredit
	itemjour_remark
	itemjour_previousdate*/

	$columnslist = implode(',', $columnsarray);
	
	
	
	echo"
	
	<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'assetsdt_id';
		
	$querycur = "select currency_code from currency order by currency_code";

		
	#Autoincrement, ItemJour_Code, Journaldt_id, ItemJour_Description, Currency_Code, Costcent_code, Project_Code, ItemJour_prcnt, ItemJour_amount, ItemJour_amount1, ItemJour_amount2, Ledger_Number, Ledger_NumberDebit, CostCent_CodeDebit, Project_codeDebit, Ledger_NumberCredit, CostCent_CodeCredit, Project_CodeCredit, Journal_Date, JournalDt_ValueDate, ItemJour_Remark, ItemJour_DateAmortized, ItemJour_PreviousDate, ItemJour_PreviousAmount, ItemJour_PreviousAmount1, ItemJour_PreviousAmount2, ItemJour_Sold, ItemJour_SaleDate, Ledger_NumberCash, CostCent_CodeCash, Project_CodeCash, ItemJour_CashAmount, ItemJour_CashAmount1, ItemJour_CashAmount2, Ledger_NumberProfit, Ledger_NumberLost, ItemJour_BelongsToGroup, Item_OriginalCode, Synchronized, itemjour_location, itemjour_barcode, assetsdt_id
	$query="select itemjour.Ledger_Number,ledger.ledger_name,journal.journal_folio,journal.Journal_refgovernment,itemjour.ItemJour_prcnt
					,ItemJour_Code,itemjour_barcode,ItemJour_Description,date_format(itemjour.JournalDt_ValueDate,'%d/%m/%Y')
					,itemjour_location,itemjour.Currency_Code,ItemJour_amount,ItemJour_amount1,ItemJour_amount2,date_format(ItemJour_PreviousDate,'%d/%m/%Y'),ItemJour_PreviousAmount,ItemJour_PreviousAmount1
					,ItemJour_PreviousAmount2,date_format(itemjour.JournalDt_ValueDate,'%m/%d/%Y')
					,date_format(ItemJour_DateAmortized,'%Y-%m-%d')
					,date_format(ItemJour_DateAmortized,'%d/%m/%Y'),itemjour.costcent_code,costcent.costcent_name
					,itemjour.project_code,project.project_name
					,Ledger_Debit.Ledger_Name,Ledger_Credit.Ledger_Name
					,costcent_credit.costcent_name,project_credit.project_name
					,itemjour.Ledger_NumberDebit
					,itemjour.Ledger_NumberCredit
					,itemjour.costcent_codecredit
					,itemjour.project_codecredit
					,date_format(itemjour.ItemJour_SaleDate,'%d/%m/%Y')
					,Ledger_NumberCash
					,CostCent_CodeCash
					,Project_CodeCash
					,ItemJour_CashAmount
					,ItemJour_CashAmount1
					,ItemJour_CashAmount2
					,Ledger_NumberProfit
					,Ledger_Profit.Ledger_Name
					,Ledger_NumberLost
					,Ledger_Lost.Ledger_Name
					,project_credit.project_name
					,itemjour.ItemJour_Sold
					,Ledger_Cash.Ledger_Name
					,itemjour.itemjour_remark
					,itemjour.autoincrement
					from itemjour left join project on project.project_code=itemjour.project_code
					left join costcent on costcent.costcent_code=itemjour.costcent_code             
					left join costcent as costcent_credit on costcent_credit.costcent_code=itemjour.costcent_codecredit             
					left join project as project_credit on project_credit.project_code=itemjour.project_codecredit             
					left join ledger on ledger.ledger_number=itemjour.Ledger_Number
					left join ledger as Ledger_Debit on Ledger_Debit.ledger_number=itemjour.Ledger_NumberDebit
					left join ledger as Ledger_Credit on Ledger_Credit.ledger_number=itemjour.Ledger_NumberCredit
					left join ledger as Ledger_Profit on Ledger_Profit.ledger_number=itemjour.Ledger_NumberProfit
					left join ledger as Ledger_Lost on Ledger_Lost.ledger_number=itemjour.Ledger_NumberLost
					left join ledger as Ledger_Cash on Ledger_Cash.ledger_number=itemjour.Ledger_NumberCash
					left join journal on journal.journal_id=itemjour.journaldt_id
					where (ifnull(itemjour.ledger_number,'') like '%$searchedledger%'  or ItemJour_Code like '%$searchedledger%' or ItemJour_Description like '%$searchedledger%')
					order by itemjour.Ledger_Number,itemjour.Currency_Code,itemjour.JournalDt_ValueDate,itemjour.ItemJour_Description   ";
	//left join journaldt on journaldt.journaldt_id=itemjour.journaldt_id
	//echo $query;
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='overflow:auto;width:1080px;height:320px'>";
	echo"<table border='0' 	align='center'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:1px solid black;border-spacing:0;width:3500px;' cellpadding='0' cellspacing='1'>
		";
	echo"
		<col width=35>
		<col width=120>
		<col width=160>
		<col width=120>
		<col width=120>
		<col width=60>
		<col width=120>
		<col width=120>
		<col width=200>
		<col width=75>
		
		<col width=120>
		<col width=100>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=100>
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=160>
		<col width=120>
		<col width=160>
		
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=160>
		<col width=120>
		<col width=160>
		
		<col width=120>
		<col width=160>
		
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=120>
		<col width=120>
		<col width=120>
		
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=160>
		
		<col width=25>
		";	
		
				
		echo"<tr  height=10px bgcolor='#F6F6F6'>
			<th id='resizable1'  height='15' align='left'></span></td>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Account No.</span></th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Acc. Name</span></th>
			<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Folio</span></th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Jv No.</span></th>
			<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Per.(%)</span></th>
			<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Item Code</span></th>
			<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Barcode</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Description</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Value Date</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Location</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Currency</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Previous Date</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Previous Amount</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Previous Amount $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Previous Amount $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny manual</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny1 manual</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny2 manual</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amortny2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amort n</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amort n $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amort n $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Last Amortizat.</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount Amort.</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount Amort. $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount Amort. $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Remain Amount</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Remain Amount $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Remain Amount $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Code</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Name</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Code</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Name</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Number(Db)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Name(Db)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Number(Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Ledger Name(Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Code (Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcent Name (Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Code (Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Name (Cr)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>P:Prepare S:Sold</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Sale Date</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Number (Cash)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Name (Cash)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Costcenter Code(Cash)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Project Code (Cash)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Cash Amount</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Cash Amount $base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Cash Amount $base2</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Number (Profit)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Name (Profit)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Number (Lost)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Name (Lost)</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Remark</span></th>
			
			
			<th id='resizable1'  height='15' align='left'></span></td>
			</tr>";
		
		$i=0;
		$j=1;
		
		
		
		
		echo"
		
			<input type='hidden' name='selectedtritemjour2' id='selectedtritemjour2' value='$selectedtritemjour2'>
			<input type='hidden' name='selectedtrcoloritemjour2' id='selectedtrcoloritemjour2' value='$selectedtrcoloritemjour2'>";
	$k=1;
			$morelines = 1;
		
			
			while ($k <= $morelines) {
			$recno = $i+1;

			if ($k==$morelines)
					$mode = 'i';
				else
					$mode = 'e';			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'jour2\')"';

				echo"<tr  height='30px' >";
				
				echo"<td align=center><img src='img/undo.png' width=15 height=15 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearitemjour('$i')\"></td>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  name='itemjour2ledger_number[$i]' id='itemjour2ledger_number[$i]' value='".$itemjour2ledger_number[$i]."' style='width:100;'></span>
						<img src='img/btnopen.jpg' width='15' height='20' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemjour2ledger_number','itemjour2ledger_number[$i]','itemjour2ledger_name[$i]','800','500')\">
							</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour2ledger_name[$i]' id='itemjour2ledger_name[$i]' value='".$itemjour2ledger_name[$i]."' style='width:150;'> </span></td>";					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2journal_folio[$i]' id='itemjour2journal_folio[$i]' value='".$itemjour2journal_folio[$i]."' style='width:110;'> </span>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' name='itemjour2journal_refgovernment[$i]' id='itemjour2journal_refgovernment[$i]' value='".$itemjour2journal_refgovernment[$i]."' style='width:100;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_vsmall'  name='itemjour2itemjour_prcnt[$i]' id='itemjour2itemjour_prcnt[$i]' value='".$itemjour2itemjour_prcnt[$i]."' style='width:55;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2itemjour_code[$i]' id='itemjour2itemjour_code[$i]' value='".$itemjour2itemjour_code[$i]."' style='width:110;'> </span>
							</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2itemjour_barcode[$i]' id='itemjour2itemjour_barcode[$i]' value='".$itemjour2itemjour_barcode[$i]."' style='width:110;'> </span></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour2itemjour_description[$i]' id='itemjour2itemjour_description[$i]' value='".$itemjour2itemjour_description[$i]."' style='width:190;'> </span>
						</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown     class='".$ClassI." date'     name='itemjour2journaldt_valuedate[$i]' id='itemjour2journaldt_valuedate[$i]' value='".$itemjour2journaldt_valuedate[$i]."' style='width:70;'> </span></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2itemjour_location[$i]' id='itemjour2itemjour_location[$i]' value='".$itemjour2itemjour_location[$i]."' style='width:110;'> </td>";
				echo"<td align=center $onclick><span class='style4'>";
				
				echo "<select $KeyDown   class='roundedtext_amortization'  name='itemjour2currency_code[$i]' id='itemjour2currency_code[$i]' value='".$itemjour2currency_code[$i]."' style='width:90;'>";
				echo "<option value=''></option>";
				$rescur = mysql_query($querycur, $connection);
				while ($rwcur = mysql_fetch_array($rescur)){
					echo "<option value='$rwcur[0]' ".($rwcur[0]==$itemjour2currency_code[$i]?'selected':'').">$rwcur[0]</option>";
				}
				echo "</select></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor;width:110;' name='itemjour2itemjour_amount[$i]' id='itemjour2itemjour_amount[$i]' value='".round($itemjour2itemjour_amount[$i],$DecimalBase)."' onchange=\"changeamounts(this,'itemjour2itemjour_amount1[$i]','itemjour2itemjour_amount2[$i]','$i');\" > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor1;width:110;' name='itemjour2itemjour_amount1[$i]' id='itemjour2itemjour_amount1[$i]' value='".round($itemjour2itemjour_amount1[$i],$DecimalBase1)."' readonly> </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor2;width:110;' name='itemjour2itemjour_amount2[$i]' id='itemjour2itemjour_amount2[$i]' value='".round($itemjour2itemjour_amount2[$i],$DecimalBase2)."' readonly> </td>";


				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown     class='".$ClassI." date'    name='itemjour2itemjour_previousdate[$i]' id='itemjour2itemjour_previousdate[$i]' value='".$itemjour2itemjour_previousdate[$i]."' style='width:90;' readonly>
					
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110;' name='itemjour2itemjour_previousamount[$i]' id='itemjour2itemjour_previousamount[$i]' value='".round($itemjour2itemjour_previousamount[$i],$DecimalBase)."' > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor1;width:110;'  name='itemjour2itemjour_previousamount1[$i]' id='itemjour2itemjour_previousamount1[$i]' value='".round($itemjour2itemjour_previousamount1[$i],$DecimalBase1)."' > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110;' name='itemjour2itemjour_previousamount2[$i]' id='itemjour2itemjour_previousamount2[$i]' value='".round($itemjour2itemjour_previousamount2[$i],$DecimalBase2)."' > </td>";
				
							
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortnymanual[$i]' id='itemjour2amortnymanual[$i]' value='".round($itemjour2amortnymanual[$i],$DecimalBase)."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny1manual[$i]' id='itemjour2amortny1manual[$i]' value='".round($itemjour2amortny1manual[$i],$DecimalBase1)."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny2Manual[$i]' id='itemjour2amortny2Manual[$i]' value='".round($itemjour2amortny2Manual[$i],$DecimalBase2)."' style='width:110;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortny[$i]' id='ItemJour2Amortny[$i]' value='".round($ItemJour2Amortny[$i],$DecimalBase)."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny1[$i]' id='itemjour2amortny1[$i]' value='".round($itemjour2amortny1[$i],$DecimalBase1)."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny2[$i]' id='itemjour2amortny2[$i]' value='".round($itemjour2amortny2[$i],$DecimalBase2)."' style='width:110;'>";

				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110;'  name='ItemJour2Amortn[$i]' id='ItemJour2Amortn[$i]' value='".round($ItemJour2Amortn[$i],$DecimalBase)."'>";
				echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2[$i]' id='ItemJour2Amortn2[$i]' value='".$ItemJour2Amortn2[$i]."'></td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110;'  name='ItemJour2AmortnBase1[$i]' id='ItemJour2AmortnBase1[$i]' value='".round($ItemJour2AmortnBase1[$i],$DecimalBase1)."' >";
				echo"<input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2Base1[$i]' id='ItemJour2Amortn2Base1[$i]' value='".$ItemJour2Amortn2Base1[$i]."'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110;'  name='ItemJour2AmortnBase2[$i]' id='ItemJour2AmortnBase2[$i]' value='".round($ItemJour2AmortnBase2[$i],$DecimalBase2)."' >";
				echo"<input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2Base2[$i]' id='ItemJour2Amortn2Base2[$i]' value='".$ItemJour2Amortn2Base2[$i]."'>";

				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown     class='".$ClassI." date'   name='itemjour2itemjour_dateamortized[$i]' id='itemjour2itemjour_dateamortized[$i]' value='".$itemjour2itemjour_dateamortized[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110;'  name='itemjour2amountamortized[$i]' id='itemjour2amountamortized[$i]' value='".round($itemjour2amountamortized[$i],$DecimalBase)."' >";
				echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort[$i]' id='itemjour2amountamort[$i]' value='".$itemjour2amountamort[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110;'  name='itemjour2amountamortized1[$i]' id='itemjour2amountamortized1[$i]' value='".round($itemjour2amountamortized1[$i],$DecimalBase1)."' >";
				echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort1[$i]' id='itemjour2amountamort1[$i]' value='".$itemjour2amountamort1[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110;'  name='itemjour2amountamortized2[$i]' id='itemjour2amountamortized2[$i]' value='".round($itemjour2amountamortized2[$i],$DecimalBase2)."'>";
				echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort2[$i]' id='itemjour2amountamort2[$i]' value='".$itemjour2amountamort2[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110;'  name='ItemJour2AmountRemain[$i]' id='ItemJour2AmountRemain[$i]' value='".round($ItemJour2AmountRemain[$i],$DecimalBase)."' >";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110;'  name='ItemJour2AmountRemain1[$i]' id='ItemJour2AmountRemain1[$i]' value='".round($ItemJour2AmountRemain1[$i],$DecimalBase1)."' >";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110;'  name='ItemJour2AmountRemain2[$i]' id='ItemJour2AmountRemain2[$i]' value='".round($ItemJour2AmountRemain2[$i],$DecimalBase2)."' >";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2costcent_code[$i]' id='itemjour2costcent_code[$i]' value='".$itemjour2costcent_code[$i]."' style='width:100;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'itemjour2costcent_code[$i]','');\" /></span></label>
				</td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='itemjour2costcent_name[$i]' id='itemjour2costcent_name[$i]' value='".$itemjour2costcent_name[$i]."' style='width:115;'></td> ";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2project_code[$i]' id='itemjour2project_code[$i]' value='".$itemjour2project_code[$i]."' style='width:100;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject(2,'itemjour2project_code[$i]','');\"  /></span></label>
				</td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2project_name[$i]' id='itemjour2project_name[$i]' value='".$itemjour2project_name[$i]."' style='width:115;'></td> ";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberDebit[$i]' id='Ledger_NumberDebit[$i]' value='".$Ledger_NumberDebit[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='Ledger_NameDebit[$i]' id='Ledger_NameDebit[$i]' value='".$Ledger_NameDebit[$i]."' style='width:110;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberCredit[$i]' id='Ledger_NumberCredit[$i]' value='".$Ledger_NumberCredit[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameCredit[$i]' id='Ledger_NameCredit[$i]' value='".$Ledger_NameCredit[$i]."' style='width:155;'>";
				
		echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='costcent_codecredit[$i]' id='costcent_codecredit[$i]' value='".$costcent_codecredit[$i]."' style='width:83%;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'costcent_codecredit[$i]','costcent_namecredit[$i]');\" /></span></label>
				</td>";
					echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='costcent_namecredit[$i]' id='costcent_namecredit[$i]' value='".$costcent_namecredit[$i]."' style='width:155;'>"; 

				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_codecredit[$i]' id='project_codecredit[$i]' value='".$project_codecredit[$i]."' style='width:83%;'> 
					<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject(2,'project_codecredit[$i]','project_namecredit[$i]');\"  /></span></label>
				</td>";
						echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_namecredit[$i]' id='project_namecredit[$i]' value='".$project_namecredit[$i]."' style='width:155;'> ";
			
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_Sold[$i]' id='ItemJour_Sold[$i]' value='".$ItemJour_Sold[$i]."' style='width:110;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown     class='".$ClassI." date'    name='ItemJour_SaleDate[$i]' id='ItemJour_SaleDate[$i]' value='".$ItemJour_SaleDate[$i]."' style='width:100;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberCash[$i]' id='Ledger_NumberCash[$i]' value='".$Ledger_NumberCash[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameCash[$i]' id='Ledger_NameCash[$i]' value='".$Ledger_NameCash[$i]."' style='width:110;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='CostCent_CodeCash[$i]' id='CostCent_CodeCash[$i]' value='".$CostCent_CodeCash[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Project_CodeCash[$i]' id='Project_CodeCash[$i]' value='".$Project_CodeCash[$i]."' style='width:110;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount[$i]'   style='color:$basecolor;width:95;' id='ItemJour_CashAmount[$i]' value='".$ItemJour_CashAmount[$i]."' >";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount1[$i]'   style='color:$basecolor1;width:95;' id='ItemJour_CashAmount1[$i]' value='".$ItemJour_CashAmount1[$i]."'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount2[$i]'   style='color:$basecolor2;width:95;' id='ItemJour_CashAmount2[$i]' value='".$ItemJour_CashAmount2[$i]."' >";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberProfit[$i]' id='Ledger_NumberProfit[$i]' value='".$Ledger_NumberProfit[$i]."' style='width:95;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameProfit[$i]' id='Ledger_NameProfit[$i]' value='".$Ledger_NameProfit[$i]."' style='width:95;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberLost[$i]' id='Ledger_NumberLost[$i]' value='".$Ledger_NumberLost[$i]."' style='width:95;'>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='Ledger_NameLost[$i]' id='Ledger_NameLost[$i]' value='".$Ledger_NameLost[$i]."' style='width:95;'>";
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_remark[$i]' id='itemjour_remark[$i]' value='".$itemjour_remark[$i]."' style='width:160;'> </td>";

				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitjour2[$i]' title='Save' onclick=\"submititemjour2('$autoincrement','$i','i')\"></td>";
				echo"<input type='hidden'  name='autoincrement[$i]' id='autoincrement[$i]' value='".$autoincrement[$i]."' >";
				echo"</tr>";
					$i+=1;
			$k+=1;
			}
			
			$DateTimePickerCloseYear = strtotime(($DateTimePickerCloseYear));
		
			$basecolor  = '#0000FF';
			$basecolor1 = '#A52A2A';
			$basecolor2 = '#006400';
		
	while($row=mysql_fetch_row($result)){
				
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		
		$itemjour2ledger_number[$i] = $row[0];
		$itemjour2ledger_name[$i] = $row[1];
		$itemjour2journal_folio[$i] = $row[2];
		$itemjour2journal_refgovernment[$i] = $row[3];
		$itemjour2itemjour_prcnt[$i] = $row[4];
		$itemjour2itemjour_code[$i] = $row[5]; 
		$itemjour2itemjour_barcode[$i] = $row[6];
		$itemjour2itemjour_description[$i] = $row[7];
		$itemjour2journaldt_valuedate[$i] = $row[8];
		
		$itemjour2itemjour_location[$i] = $row[9];
		$itemjour2currency_code[$i] = $row[10];
		$itemjour2itemjour_amount[$i] = $row[11];
		$itemjour2itemjour_amount1[$i] = $row[12];
		$itemjour2itemjour_amount2[$i] = $row[13];
		$itemjour2itemjour_previousdate[$i] = $row[14];
		$itemjour2itemjour_previousamount[$i] = $row[15];
		$itemjour2itemjour_previousamount1[$i] = $row[16];
		$itemjour2itemjour_previousamount2[$i] = $row[17];
		$itemjour_dateamortized[$i] = $row[19];
		$itemjour2itemjour_dateamortized[$i] = $row[20];
		
		$itemjour2costcent_code[$i] = $row[21];
		$itemjour2costcent_name[$i] = $row[22];
		
		$itemjour2project_code[$i] = $row[23];
		$itemjour2project_name[$i] = $row[24];
		
		$Ledger_NameDebit[$i] = $row[25];
		$Ledger_NameCredit[$i] = $row[26];
		$costcent_namecredit[$i] = $row[27];
		$project_namecredit[$i] = $row[28];

			
		$Ledger_NumberDebit[$i] = $row[29];
		$Ledger_NumberCredit[$i] = $row[30];
		$costcent_codecredit[$i] = $row[31];
		$project_codecredit[$i] = $row[32];
		
		$ItemJour_SaleDate[$i] = $row[33];
		$Ledger_NumberCash[$i] = $row[34];
		$CostCent_CodeCash[$i] = $row[35];
		$Project_CodeCash[$i] = $row[36];
		$ItemJour_CashAmount[$i] = $row[37];
		$ItemJour_CashAmount1[$i] = $row[38];
		$ItemJour_CashAmount2[$i] = $row[39];
		$Ledger_NumberProfit[$i] = $row[40];
		$Ledger_NameProfit[$i] = $row[41];
		$Ledger_NumberLost[$i] = $row[42];
		$Ledger_NameLost[$i] = $row[43];
		
		$ItemJour_Sold[$i] = $row[45];
		$Ledger_NameCash[$i] = $row[46];
		$itemjour_remark[$i] = $row[47];
		
		$autoincrement[$i] = $row[48];


		

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'jour2\')"';

			echo"<tr height='10px' id='itmjour2$i' onclick=\"returncoloritemjour(this,'selectedtritemjour2','selectedtrcoloritemjour2')\" style='background-color:$bgcolor'>";

			
		//echo strtotime(changedateformat($itemjour2journaldt_valuedate[$i]))."<br>";
		
		$ValidDay[$i]=0;
		$convert = 1;
		$valuedate[$i] = strtotime(changedateformat($itemjour2journaldt_valuedate[$i]));
		
		//echo strtotime(changedateformat($itemjour2journaldt_valuedate[$i]))."->". $itemjour2journaldt_valuedate[$i];echo "<br>";	
		
		$dateamortized[$i] = strtotime($itemjour_dateamortized[$i]);
		$previousdate[$i] = strtotime($itemjour2itemjour_previousdate[$i]);
		
		
        if ($itemjour2itemjour_prcnt[$i]<>0) 
	          $ValidDay[$i] =( ($valuedate[$i]/ 86400) - ($dateamortized[$i]/ 86400))+ ((100/$itemjour2itemjour_prcnt[$i])*365)  ;
			  
		

	   if ($ValidDay[$i]>0)  {
		
           $Days[$i]=round(($dateamortized[$i]-$valuedate[$i])/ 86400,0);
		   $Days[$i] = round($Days[$i],0);
		   
           if ($Days[$i]>0) { 
			//echo $itemjour2itemjour_amount[$i].":".$itemjour2itemjour_prcnt[$i].":".$Days[$i]."<br>";
              $itemjour2amountamortized[$i] = (($itemjour2itemjour_amount[$i]*$itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
              $itemjour2amountamortized1[$i] = (($itemjour2itemjour_amount1[$i]*$itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
              $itemjour2amountamortized2[$i] = (($itemjour2itemjour_amount2[$i]*$itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
           } else {
              $itemjour2amountamortized[$i]=0;
              $itemjour2amountamortized1[$i]=0;
              $itemjour2amountamortized2[$i]=0;
           }
        } else {
           $itemjour2amountamortized[$i]  =  $itemjour2itemjour_amount[$i];
           $itemjour2amountamortized1[$i] = $itemjour2itemjour_amount1[$i];
           $itemjour2amountamortized2[$i] = $itemjour2itemjour_amount2[$i];
        }
		
		if (($itemjour2itemjour_amount[$i] - $itemjour2itemjour_previousamount[$i] - $itemjour2amountamortized[$i]) <0){
			$itemjour2amountamortized[$i] = $itemjour2amountamortized[$i] + ($itemjour2itemjour_amount[$i] - $itemjour2itemjour_previousamount[$i] - $itemjour2amountamortized[$i]);
			$itemjour2amountamortized1[$i] = $itemjour2amountamortized1[$i] + ($itemjour2itemjour_amount1[$i] - $itemjour2itemjour_previousamount1[$i] - $itemjour2amountamortized1[$i]);
			$itemjour2amountamortized2[$i] = $itemjour2amountamortized2[$i] + ($itemjour2itemjour_amount2[$i] - $itemjour2itemjour_previousamount2[$i] - $itemjour2amountamortized2[$i]);
		} 

        if (($itemjour2itemjour_previousdate[$i]<>'') and ($previousdate[$i] <= $dateamortized[$i])) {
           if ($itemjour2itemjour_previousamount[$i]<=$itemjour2amountamortized[$i]) {
                $ItemJour2AmountRemain[$i]=$itemjour2itemjour_amount[$i]-$itemjour2amountamortized[$i];
                $ItemJour2AmountRemain1[$i]=$itemjour2itemjour_amount1[$i]-$itemjour2amountamortized1[$i];
                $ItemJour2AmountRemain2[$i]=$itemjour2itemjour_amount2[$i]-$itemjour2amountamortized2[$i];
           } else {
                $ItemJour2AmountRemain[$i]=$itemjour2itemjour_amount[$i]-$itemjour2itemjour_previousamount[$i];
                $ItemJour2AmountRemain1[$i]=$itemjour2itemjour_amount1[$i]-$itemjour2itemjour_previousamount1[$i];
                $ItemJour2AmountRemain2[$i]=$itemjour2itemjour_amount2[$i]-$itemjour2itemjour_previousamount2[$i];
           }
        } else {
            $ItemJour2AmountRemain[$i]=$itemjour2itemjour_amount[$i]-$itemjour2amountamortized[$i];
            $ItemJour2AmountRemain1[$i]=$itemjour2itemjour_amount1[$i]-$itemjour2amountamortized1[$i];
            $ItemJour2AmountRemain2[$i]=$itemjour2itemjour_amount2[$i]-$itemjour2amountamortized2[$i];
        }
		
	
   if ($itemjour2amountamortized[$i] > $itemjour2itemjour_previousamount[$i] ) {
     $ItemJour2Amortn[$i] = $itemjour2amountamortized[$i] - $itemjour2itemjour_previousamount[$i];
	 }
   else {
       $ItemJour2Amortn[$i] = 0;
       $itemjour2amountamortized[$i] = $itemjour2itemjour_previousamount[$i];
   }
   if ($itemjour2amountamortized1[$i] > $itemjour2itemjour_previousamount1[$i] )
     $ItemJour2AmortnBase1[$i] = $itemjour2amountamortized1[$i]-$itemjour2itemjour_previousamount1[$i];
   else {
        $ItemJour2AmortnBase1[$i] = 0;
        $itemjour2amountamortized1[$i]=$itemjour2itemjour_previousamount1[$i];
   }
   if ($itemjour2amountamortized2[$i]>$itemjour2itemjour_previousamount2[$i] )
     $ItemJour2AmortnBase2[$i]=$itemjour2amountamortized2[$i]-$itemjour2itemjour_previousamount2[$i];
   else {
        $ItemJour2AmortnBase2[$i]=0;
        $itemjour2amountamortized2[$i]=$itemjour2itemjour_previousamount2[$i];
   }
   
   $itemjour2amountamortized[$i]=Round($itemjour2amountamortized[$i]*100)/100;
   $itemjour2amountamortized1[$i]=Round($itemjour2amountamortized1[$i]*100)/100;
   $itemjour2amountamortized2[$i]=Round($itemjour2amountamortized2[$i]*100)/100;
   $ItemJour2AmountRemain[$i]=Round($ItemJour2AmountRemain[$i]*100)/100;
   $ItemJour2AmountRemain1[$i]=Round($ItemJour2AmountRemain1[$i]*100)/100;
   $ItemJour2AmountRemain2[$i]=Round($ItemJour2AmountRemain2[$i]*100)/100;




        $ValidDay[$i] = 0;
        if ($itemjour2itemjour_prcnt[$i]<>0) 
           if ($convert==1) 
             $ValidDay[$i]=($valuedate[$i]/86400)+((100/$itemjour2itemjour_prcnt[$i])*365) - $DateTimePickerCloseYear;
           else
            $ValidDay[$i]=($valuedate[$i]/86400)+((100/$itemjour2itemjour_prcnt[$i])*365) -  ($dateamortized[$i]/ 86400);
			
        if ($ValidDay[$i]>0) {
           if ($convert==1) 
              $Days[$i]=round(($DateTimePickerCloseYear/86400) - ($valuedate[$i]/86400),0);
           else
              $Days[$i]=round(($dateamortized[$i]/ 86400)-($valuedate[$i]/86400),0);
			 
		
   
           if ($Days[$i]>0) { 
              $itemjour2amountamort[$i]=(($itemjour2itemjour_amount[$i]*
                 $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
              $itemjour2amountamort1[$i]=(($itemjour2itemjour_amount1[$i]*
                 $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
              $itemjour2amountamort2[$i]=(($itemjour2itemjour_amount2[$i]*
                 $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
           } else {
              $itemjour2amountamort[$i]=0;
              $itemjour2amountamort1[$i]=0;
              $itemjour2amountamort2[$i]=0;
           }
        } else {
           $itemjour2amountamort[$i]=$itemjour2itemjour_amount[$i];
           $itemjour2amountamort1[$i]=$itemjour2itemjour_amount1[$i];
           $itemjour2amountamort2[$i]=$itemjour2itemjour_amount2[$i];
        }

   if ($itemjour2amountamort[$i]>$itemjour2itemjour_previousamount[$i] )
     $ItemJour2Amortn2[$i]=round(($itemjour2amountamort[$i]-$itemjour2itemjour_previousamount[$i])*100)/100;
   else {
       $ItemJour2Amortn2[$i] = 0;
       $itemjour2amountamort[$i] = $itemjour2itemjour_previousamount[$i];
   }
  
   

   
   if ($itemjour2amountamort1[$i] > $itemjour2itemjour_previousamount1[$i] )
     $ItemJour2Amortn2Base1[$i] = round(($itemjour2amountamort1[$i]-$itemjour2itemjour_previousamount1[$i])*100)/100;
   else {
        $ItemJour2Amortn2Base1[$i] = 0;
        $itemjour2amountamort1[$i] = $itemjour2itemjour_previousamount1[$i];
   }
   if ($itemjour2amountamort2[$i] > $itemjour2itemjour_previousamount2[$i] )
     $ItemJour2Amortn2Base2[$i] = round(($itemjour2amountamort2[$i]-$itemjour2itemjour_previousamount2[$i])*100)/100;
   else {
        $ItemJour2Amortn2Base2[$i] = 0;
        $itemjour2amountamort2[$i] = $itemjour2itemjour_previousamount2[$i];
   }
   $itemjour2amountamort[$i] = Round($itemjour2amountamortized[$i]*100)/100;
   $itemjour2amountamort1[$i] = Round($itemjour2amountamortized1[$i]*100)/100;
   $itemjour2amountamort2[$i] = Round($itemjour2amountamortized2[$i]*100)/100;


        $amtny = $itemjour2itemjour_amount[$i]*$itemjour2itemjour_prcnt[$i]/100;
        $amtny1 = $itemjour2itemjour_amount1[$i]*$itemjour2itemjour_prcnt[$i]/100;
        $amtny2 = $itemjour2itemjour_amount2[$i]*$itemjour2itemjour_prcnt[$i]/100;
        $Days[$i]=0;
		
		//echo $valuedate[$i]." ".strtotime($StartFinancialDate)."<br>";
        if ($valuedate[$i] > strtotime($StartFinancialDate)) {
          $Days[$i]=round(($valuedate[$i]/86400 - strtotime($StartFinancialDate)/86400),0) ;
        }

        $amtny=$amtny-($amtny/365*$Days[$i]);
        $amtny1=$amtny1-($amtny1/365*$Days[$i]);
        $amtny2=$amtny2-($amtny2/365*$Days[$i]);

        $amtny=round($amtny*100)/100;
        $amtny1=round($amtny1*100)/100;
        $amtny2=round($amtny2*100)/100;


	
        if ($amtny > $ItemJour2AmountRemain[$i])
            $ItemJour2Amortny[$i] = $ItemJour2AmountRemain[$i];
        else
            $ItemJour2Amortny[$i] = $amtny;
		
        if ($amtny1>$ItemJour2AmountRemain1[$i])
            $itemjour2amortny1[$i] = $ItemJour2AmountRemain1[$i];
        else
            $itemjour2amortny1[$i] = $amtny1;

        if ($amtny2 > $ItemJour2AmountRemain2[$i] )
            $itemjour2amortny2[$i] = $ItemJour2AmountRemain2[$i];
        else
            $itemjour2amortny2[$i] = $amtny2;

		if (strtotime($StartFinancialDate) > $valuedate[$i])  
            $DaysB[$i]=( strtotime($StartFinancialDate)/86400 - $valuedate[$i]/86400) ;
        else
            $DaysB[$i]=1;
			
		
        $DaysC[$i] = ($DateTimePickerCloseYear)/86400 + 1 - $valuedate[$i]/86400;
        $DaysD[$i]=0;
		
        if ($itemjour2itemjour_prcnt[$i]<>0 ) 
            $DaysD[$i] = ($itemjour2itemjour_amount[$i]/(($itemjour2itemjour_amount[$i]*$itemjour2itemjour_prcnt[$i]/100)/365))+1;
		
	
		
		if ($DaysB[$i]>$DaysD[$i]) 
             $Days[$i]=0;
			 
        else if ($DaysC[$i]>$DaysD[$i]) 
             $Days[$i]=$DaysD[$i]-$DaysB[$i];
        else
             $Days[$i]=$DaysC[$i]-$DaysB[$i];
			 
		
        if ($Days[$i]>0) { 
        $itemjour2amortnymanual[$i]  = (($itemjour2itemjour_amount[$i]* $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
        $itemjour2amortny1manual[$i] = (($itemjour2itemjour_amount1[$i]* $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
        $itemjour2amortny2Manual[$i] = (($itemjour2itemjour_amount2[$i]* $itemjour2itemjour_prcnt[$i])/100)/365*($Days[$i]);
        }
        else {
         $itemjour2amortnymanual[$i]  = '0';
         $itemjour2amortny1manual[$i] = '0';
         $itemjour2amortny2Manual[$i] = '0';
        }
		
						
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
			echo"<td  align=center onclick=\"deleteitemjour2('$autoincrement[$i]','$assetsdt_id','$startrange','$perpage','$morelines'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  name='itemjour2ledger_number[$i]' id='itemjour2ledger_number[$i]' value='".$itemjour2ledger_number[$i]."' style='width:100;'></span>
						</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour2ledger_name[$i]' id='itemjour2ledger_name[$i]' value='".$itemjour2ledger_name[$i]."' style='width:150;'> </span></td>";					
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2journal_folio[$i]' id='itemjour2journal_folio[$i]' value='".$itemjour2journal_folio[$i]."' style='width:110;'> </span>
			</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' name='itemjour2journal_refgovernment[$i]' id='itemjour2journal_refgovernment[$i]' value='".$itemjour2journal_refgovernment[$i]."' style='width:110;'> </span></td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_vsmall'  name='itemjour2itemjour_prcnt[$i]' id='itemjour2itemjour_prcnt[$i]' value='".$itemjour2itemjour_prcnt[$i]."' style='width:55;'> </span></td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2itemjour_code[$i]' id='itemjour2itemjour_code[$i]' value='".$itemjour2itemjour_code[$i]."' style='width:110;'> </span>
						</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'   name='itemjour2itemjour_barcode[$i]' id='itemjour2itemjour_barcode[$i]' value='".$itemjour2itemjour_barcode[$i]."' style='width:110;'> </span></td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_large' name='itemjour2itemjour_description[$i]' id='itemjour2itemjour_description[$i]' value='".$itemjour2itemjour_description[$i]."' style='width:190;'> </span>
					</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'    name='itemjour2journaldt_valuedate[$i]' id='itemjour2journaldt_valuedate[$i]' value='".$itemjour2journaldt_valuedate[$i]."' style='width:70;'> </span></td>";
			
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2itemjour_location[$i]' id='itemjour2itemjour_location[$i]' value='".$itemjour2itemjour_location[$i]."' style='width:110;'> </td>";
			echo"<td align=center $onclick><span class='style4'><select $KeyDown   class='roundedtext_amortization'  name='itemjour2currency_code[$i]' id='itemjour2currency_code[$i]' style='width:90;'> ";
			echo "<option value=''></option>";
			$rescur = mysql_query($querycur, $connection);
			while ($rwcur = mysql_fetch_array($rescur)){
				echo "<option value='$rwcur[0]' ".($rwcur[0]==$itemjour2currency_code[$i]?'selected':'').">$rwcur[0]</option>";
			}
			echo "</select></td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor;width:110px;' name='itemjour2itemjour_amount[$i]' id='itemjour2itemjour_amount[$i]' value='".round($itemjour2itemjour_amount[$i],$DecimalBase)."' onchange=\"changeamounts(this,'itemjour2itemjour_amount1[$i]','itemjour2itemjour_amount2[$i]','$i');\"> </td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor1;width:110px;' name='itemjour2itemjour_amount1[$i]' id='itemjour2itemjour_amount1[$i]' value='".round($itemjour2itemjour_amount1[$i],$DecimalBase1)."' readonly> </td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor2;width:110px;' name='itemjour2itemjour_amount2[$i]' id='itemjour2itemjour_amount2[$i]' value='".round($itemjour2itemjour_amount2[$i],$DecimalBase2)."' readonly> </td>";


			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'    name='itemjour2itemjour_previousdate[$i]' id='itemjour2itemjour_previousdate[$i]' value='".$itemjour2itemjour_previousdate[$i]."' style='width:90;' readonly>
				
			</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110px;' name='itemjour2itemjour_previousamount[$i]' id='itemjour2itemjour_previousamount[$i]' value='".round($itemjour2itemjour_previousamount[$i],$DecimalBase)."' style='width:110;'> </td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  style='color:$basecolor1;width:110px;'  name='itemjour2itemjour_previousamount1[$i]' id='itemjour2itemjour_previousamount1[$i]' value='".round($itemjour2itemjour_previousamount1[$i],$DecimalBase1)."' style='width:110;'> </td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110px;' name='itemjour2itemjour_previousamount2[$i]' id='itemjour2itemjour_previousamount2[$i]' value='".round($itemjour2itemjour_previousamount2[$i],$DecimalBase2)."' style='width:110;'> </td>";
			
						
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortnymanual[$i]' id='itemjour2amortnymanual[$i]' value='".round($itemjour2amortnymanual[$i],$DecimalBase)."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny1manual[$i]' id='itemjour2amortny1manual[$i]' value='".round($itemjour2amortny1manual[$i],$DecimalBase1)."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny2Manual[$i]' id='itemjour2amortny2Manual[$i]' value='".round($itemjour2amortny2Manual[$i],$DecimalBase2)."' style='width:110;'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortny[$i]' id='ItemJour2Amortny[$i]' value='".round($ItemJour2Amortny[$i],$DecimalBase)."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny1[$i]' id='itemjour2amortny1[$i]' value='".round($itemjour2amortny1[$i],$DecimalBase1)."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amortny2[$i]' id='itemjour2amortny2[$i]' value='".round($itemjour2amortny2[$i],$DecimalBase2)."' style='width:110;'>";

			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110px;'  name='ItemJour2Amortn[$i]' id='ItemJour2Amortn[$i]' value='".round($ItemJour2Amortn[$i],$DecimalBase)."' >";
			echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2[$i]' id='ItemJour2Amortn2[$i]' value='".$ItemJour2Amortn2[$i]."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110px;'  name='ItemJour2AmortnBase1[$i]' id='ItemJour2AmortnBase1[$i]' value='".round($ItemJour2AmortnBase1[$i],$DecimalBase1)."'>";
			echo"<input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2Base1[$i]' id='ItemJour2Amortn2Base1[$i]' value='".$ItemJour2Amortn2Base1[$i]."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110px;'  name='ItemJour2AmortnBase2[$i]' id='ItemJour2AmortnBase2[$i]' value='".round($ItemJour2AmortnBase2[$i],$DecimalBase2)."'>";
			echo"<input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='ItemJour2Amortn2Base2[$i]' id='ItemJour2Amortn2Base2[$i]' value='".$ItemJour2Amortn2Base2[$i]."'>";

			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'    name='itemjour2itemjour_dateamortized[$i]' id='itemjour2itemjour_dateamortized[$i]' value='".$itemjour2itemjour_dateamortized[$i]."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110px;'  name='itemjour2amountamortized[$i]' id='itemjour2amountamortized[$i]' value='".round($itemjour2amountamortized[$i],$DecimalBase)."'>";
			echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort[$i]' id='itemjour2amountamort[$i]' value='".$itemjour2amountamort[$i]."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110px;'  name='itemjour2amountamortized1[$i]' id='itemjour2amountamortized1[$i]' value='".round($itemjour2amountamortized1[$i],$DecimalBase1)."'>";
			echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort1[$i]' id='itemjour2amountamort1[$i]' value='".$itemjour2amountamort1[$i]."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110px;'  name='itemjour2amountamortized2[$i]' id='itemjour2amountamortized2[$i]' value='".round($itemjour2amountamortized2[$i],$DecimalBase2)."'>";
			echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='itemjour2amountamort2[$i]' id='itemjour2amountamort2[$i]' value='".$itemjour2amountamort2[$i]."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor;width:110px;'  name='ItemJour2AmountRemain[$i]' id='ItemJour2AmountRemain[$i]' value='".round($ItemJour2AmountRemain[$i],$DecimalBase)."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor1;width:110px;'  name='ItemJour2AmountRemain1[$i]' id='ItemJour2AmountRemain1[$i]' value='".round($ItemJour2AmountRemain1[$i],$DecimalBase1)."'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='color:$basecolor2;width:110px;'  name='ItemJour2AmountRemain2[$i]' id='ItemJour2AmountRemain2[$i]' value='".round($ItemJour2AmountRemain2[$i],$DecimalBase2)."'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2costcent_code[$i]' id='itemjour2costcent_code[$i]' value='".$itemjour2costcent_code[$i]."' style='width:100px;'> 
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'itemjour2costcent_code[$i]','');\" /></span></label>
			</td>";
			
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='itemjour2costcent_name[$i]' id='itemjour2costcent_name[$i]' value='".$itemjour2costcent_name[$i]."' style='width:110px;'></td> ";
			
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2project_code[$i]' id='itemjour2project_code[$i]' value='".$itemjour2project_code[$i]."' style='width:100px;'> 
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject(2,'itemjour2project_code[$i]','');\"  /></span></label>
			</td>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour2project_name[$i]' id='itemjour2project_name[$i]' value='".$itemjour2project_name[$i]."' style='width:110px;'></td> ";
			
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberDebit[$i]' id='Ledger_NumberDebit[$i]' value='".$Ledger_NumberDebit[$i]."' style='width:110px;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='Ledger_NameDebit[$i]' id='Ledger_NameDebit[$i]' value='".$Ledger_NameDebit[$i]."' style='width:110px;'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberCredit[$i]' id='Ledger_NumberCredit[$i]' value='".$Ledger_NumberCredit[$i]."' style='width:110px;'>";
						echo"<td $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameCredit[$i]' id='Ledger_NameCredit[$i]' value='".$Ledger_NameCredit[$i]."' style='width:155;'>";
			
	echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='costcent_codecredit[$i]' id='costcent_codecredit[$i]' value='".$costcent_codecredit[$i]."' style='width:83%;'> 
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'costcent_codecredit[$i]','costcent_namecredit[$i]');\" /></span></label>
			</td>";
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='costcent_namecredit[$i]' id='costcent_namecredit[$i]' value='".$costcent_namecredit[$i]."' style='width:155;'>"; 

			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_codecredit[$i]' id='project_codecredit[$i]' value='".$project_codecredit[$i]."' style='width:83%;'> 
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistProject(2,'project_codecredit[$i]','project_namecredit[$i]');\"  /></span></label>
			</td>";
					echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='project_namecredit[$i]' id='project_namecredit[$i]' value='".$project_namecredit[$i]."' style='width:155;'> ";
		
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_Sold[$i]' id='ItemJour_Sold[$i]' value='".$ItemJour_Sold[$i]."' style='width:110;'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'   name='ItemJour_SaleDate[$i]' id='ItemJour_SaleDate[$i]' value='".$ItemJour_SaleDate[$i]."' style='width:100;'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberCash[$i]' id='Ledger_NumberCash[$i]' value='".$Ledger_NumberCash[$i]."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameCash[$i]' id='Ledger_NameCash[$i]' value='".$Ledger_NameCash[$i]."' style='width:110;'>";
		
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='CostCent_CodeCash[$i]' id='CostCent_CodeCash[$i]' value='".$CostCent_CodeCash[$i]."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Project_CodeCash[$i]' id='Project_CodeCash[$i]' value='".$Project_CodeCash[$i]."' style='width:110;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount[$i]'   style='color:$basecolor;width:95;' id='ItemJour_CashAmount[$i]' value='".$ItemJour_CashAmount[$i]."' >";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount1[$i]'   style='color:$basecolor1;width:95;' id='ItemJour_CashAmount1[$i]' value='".$ItemJour_CashAmount1[$i]."' >";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='ItemJour_CashAmount2[$i]'   style='color:$basecolor2;width:95;' id='ItemJour_CashAmount2[$i]' value='".$ItemJour_CashAmount2[$i]."' >";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberProfit[$i]' id='Ledger_NumberProfit[$i]' value='".$Ledger_NumberProfit[$i]."' style='width:95;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NameProfit[$i]' id='Ledger_NameProfit[$i]' value='".$Ledger_NameProfit[$i]."' style='width:95;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='Ledger_NumberLost[$i]' id='Ledger_NumberLost[$i]' value='".$Ledger_NumberLost[$i]."' style='width:95;'>";
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_mediumlarge'  name='Ledger_NameLost[$i]' id='Ledger_NameLost[$i]' value='".$Ledger_NameLost[$i]."' style='width:95;'>";
		
						
			
			echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='itemjour_remark[$i]' id='itemjour_remark[$i]' value='".$itemjour_remark[$i]."' style='width:160;'> </td>";
			
			
			
			
			
			
			echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitjour2[$i]' title='Save' onclick=\"submititemjour2('$autoincrement','$i','e')\"></td>";
			echo"<input type='hidden'  name='autoincrement[$i]' id='autoincrement[$i]' value='".$autoincrement[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		
		
	echo"</table></div>";	
	
	echo"<div>
	<table width='900' align=center border=0>
	<col width=100>
	<col width=300>
	<col width=150>
	<col width=150>
	<col width=200>
	<col width=50>
	<col width=150>
		<tr  height='20px'   bgcolor='#F6F6F6'>
			<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
			<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshItemJourGrid2(this.value,'$orderby','$option');\">";
              
			if ($perpage==10)
				$s20 = 'selected';
			else if ($perpage==25)
				$s30 = 'selected';
			else if ($perpage==50)
				$s40 = 'selected';
			else if ($perpage==100)
				$s50 = 'selected';

						
					
			echo'<option '.$s20.' value="10">10</option>
				 <option '.$s30.' value="25">25</option>
				 <option '.$s40.' value="50">50</option>
				 <option '.$s50.' value="100">100</option>
				 </select></span></td>';
				 
				 $fromrec = $perpage * (($startrange / $perpage)) + 1;
				 
				 $torec = $perpage * ($startrange / $perpage + 1);
				 if ($torec > $totalrows)
					$torec = $totalrows;
			echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
			echo'<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='pointer'\"    onclick=\"changepagelimititemjour2('start','$orderby',$morelines,'".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimititemjour2('previous','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
			}
			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' onclick=\"changepagelimititemjour2('next','$orderby',$morelines,'".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimititemjour2('last','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				if ($morelines==1)	$sel1 = 'selected';
				else if ($morelines==4)	$sel4 = 'selected';	
				else if ($morelines==8)	$sel8 = 'selected';	
				else if ($morelines==12)	$sel12 = 'selected';	
				else if ($morelines==16)	$sel16 = 'selected';	
			
				$pagenum = ($startrange / $perpage) + 1;
				$pageof = ceil(($totalrows / $perpage));
	echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
	echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"Refreshitemjour2('$startrange','$perpage','$morelines','$orderby','$option');\" height='20'></td>";

	echo"<td  valign=top align=right></td></tr>";
	echo"	</table></div>";
				
		
		

}


function draw_FixedAssetscstjour($assetsdt_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2){

		
		if ($startrange=='')	$startrange = 0;
			
		if ($direction == 'asc')
			$direction = 'desc';
		else if ($direction == 'desc')
			$direction = 'asc';
		else $direction = 'asc';

		if ($perpage=='')
			$perpage = 20;
		
		$columnsarray = array("cstjourproject_code","cstjourcostcent_code","cstjour_prcnt","cstjour_amount","cstjour_amount1","cstjour_amount2");

		$columnslist = implode(',', $columnsarray);
		
		
		
	echo"
		
		<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'assetsdt_id';
		
		
	$query="select Cst_increment, temp_assetscstjour.Project_Code, temp_assetscstjour.Costcent_code, temp_assetscstjour.cstjour_prcnt
					, cstjour_amount, cstjour_amount1, cstjour_amount2,project.project_name,costcent.costcent_name
					, temp_assetscstjour.Costcent_Precode
					, cstjour_posted, temp_assetscstjour.Synchronized, Journal_JVRef, Variant_Code, user_account
					from temp_assetscstjour left join project on project.project_code = temp_assetscstjour.project_code
										left join costcent on costcent.costcent_code = temp_assetscstjour.costcent_code
				where assetsdt_id = '$assetsdt_id' order by $orderby $direction";

	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='width:1080px;height:170px;'>";
	echo"<table border='0' 	align='left'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1400px;align=left' cellpadding='0' cellspacing='1'>
		";
	echo"
		<col width=35>
		<col width=130>
		<col width=180>
		<col width=130>
		<col width=180>
		<col width=80>
		<col width=120>
		<col width=120>
		<col width=120>
		<col width=25>";	
		
				
		echo"<tr  height=10px bgcolor='#ffffff'>
			<th id='resizable1'  height='15' align='left'></th>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project</th>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" ></th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter</th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" ></th>
			<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Percentage</th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Amount</th>
					<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1</th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2</th>
			<th id='resizable1'  height='15' align='left'></th>
			</tr>";
		
		$i=0;
		$j=1;
		echo"
		
			<input type='hidden' name='selectedtrfixedassetscstjour' id='selectedtrfixedassetscstjour' value='$selectedtrfixedassetscstjour'>
			<input type='hidden' name='selectedtrcolorfixedassetscstjour' id='selectedtrcolorfixedassetscstjour' value='$selectedtrcolorfixedassetscstjour'>";

			
	while($row=mysql_fetch_row($result)){
				
			if ($i%2==0)
			$bgcolor='#F5FAFF';
		else	
			$bgcolor='#FFFFFF';
			
			//$onclick=" onclick='showrelationtoItemJour(\"$row[0]\")' ";
			
			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'fixedassetscstjour\')"';

				echo"<tr height='25px' id='cstjour$i' onclick=\"returncolorfixedassetscstjour(this,'selectedtrfixedassetscstjour','selectedtrcolorfixedassetscstjour')\" style='background-color:$bgcolor'>";

				$cstjourproject_code[$i] = $row[1];
				$cstjourcostcent_code[$i] = $row[2];
				$cstjour_prcnt[$i] = $row[3];
				$cstjour_amount[$i] = $row[4];
				$cstjour_amount1[$i] = $row[5];
				$cstjour_amount2[$i] = $row[6];
				$fixedassetscstjour_id[$i] = $row[0];
				
				$cstjourproject_name[$i] = $row[7];
				$cstjourcostcent_name[$i] = $row[8];

							
				$recno = $i+1;
				$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
				echo"<td  align=center onclick=\"deletecstjour('$fixedassetscstjour_id[$i]','$assetsdt_id','$startrange','$perpage','$morelines'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";
				
			
		
				echo"<td  align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  name='cstjourproject_code[$i]'  onchange=setprojectcostcenter(this.value,'cstjourproject_code[$i]','cstjourproject_name[$i]','cstjour','cstjourprojectimg[$i]','project')  id='cstjourproject_code[$i]' value='".$cstjourproject_code[$i]."' style='width:88%;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='cstjourprojectimg[$i]'  onClick=\"showlistProject(2,'cstjourproject_code[$i]','cstjourproject_name[$i]');\"  /></span></label>
				</td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'    name='cstjourproject_name[$i]' id='cstjourproject_name[$i]' value='".$cstjourproject_name[$i]."' style='width:180px;'> </span>
					</td>";
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' name='cstjourcostcent_code[$i]'  onchange=setprojectcostcenter(this.value,'cstjourcostcent_code[$i]','cstjourcostcent_name[$i]','cstjour','cstjourcostcenterimg[$i]','costcenter')  id='cstjourcostcent_code[$i]' value='".$cstjourcostcent_code[$i]."' style='width:130px;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0'   id='cstjourcostcenterimg[$i]'  onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistCostcenter(2,'cstjourcostcent_code[$i]','cstjourcostcent_name[$i]');\" /></span></label>
				</td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'    name='cstjourcostcent_name[$i]' id='cstjourcostcent_name[$i]' value='".$cstjourcostcent_name[$i]."' style='width:180px;'> </span>
					</td>";
					
					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'    name='cstjour_prcnt[$i]' id='cstjour_prcnt[$i]' value='".$cstjour_prcnt[$i]."'  onchange=\"changeamountsfixedassetcstjour('cstjour_amount[$i]','cstjour_amount1[$i]','cstjour_amount2[$i]','cstjour_prcnt[$i]','percentage')\" style='width:80px;'> </span></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='cstjour_amount[$i]' style='text-align:right;width:120px;' id='cstjour_amount[$i]' value='".$cstjour_amount[$i]."' onchange=\"changeamountsfixedassetcstjour('cstjour_amount[$i]','cstjour_amount1[$i]','cstjour_amount2[$i]','cstjour_prcnt[$i]','amount')\" > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='cstjour_amount1[$i]' style='text-align:right;width:120px;' readonly id='cstjour_amount1[$i]' value='".$cstjour_amount1[$i]."' > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  name='cstjour_amount2[$i]' style='text-align:right;width:120px;' readonly id='cstjour_amount2[$i]' value='".$cstjour_amount2[$i]."' > </td>";

				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitfixedassetscstjour[$i]' title='Save' onclick=\"submitfixedassetscstjour('$assetsdt_id','$i','e')\"></td>";
				echo"<input type='hidden'  name='fixedassetscstjour_id[$i]' id='fixedassetscstjour_id[$i]' value='".$fixedassetscstjour_id[$i]."' >";
				echo"</tr>";
				
				
				$i+=1;
			}
			
			
		$k=1;
			$morelines = 1;
			
					
			while ($k <= $morelines) {
			$recno = $i+1;
				if ($k==$morelines)
					$mode = 'i';
				else
					$mode = 'e';			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'fixedassetscstjour\')"';

				
			if ($assetsdt_id!='') {
				$queryremain = "select 100 - sum(ifnull(cstjour_prcnt,0))
						,ifnull(assetsdt_amount,0) - sum(ifnull(cstjour_amount,0))
						,ifnull(assetsdt_amount1,0) - sum(ifnull(cstjour_amount1,0))
						,ifnull(assetsdt_amount2,0) - sum(ifnull(cstjour_amount2,0))
						from temp_assetscstjour,temp_assetsdt
						where temp_assetscstjour.assetsdt_id = $assetsdt_id
						and temp_assetscstjour.assetsdt_id = temp_assetsdt.assetsdt_id
						group by temp_assetsdt.assetsdt_id ";
				$resultremain=mysql_query($queryremain,$connection)  or die(mysql_error());
				$rowremain=mysql_fetch_row($resultremain);	
					$cstjour_prcnt[$i] = $rowremain[0];		
					$cstjour_amount[$i]  = $rowremain[1];		
					$cstjour_amount1[$i] = $rowremain[2];		
					$cstjour_amount2[$i] = $rowremain[3];		
			}
			
			
				echo"<tr  height='30px' >";
				
				echo"<td align=center><img src='img/undo.png' width=15 height=15 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearfixedassetscstjour('$i')\"></td>";
			
			
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  onchange=setprojectcostcenter(this.value,'cstjourproject_code[$i]','cstjourproject_name[$i]','cstjour','cstjourprojectimg[$i]','project')  name='cstjourproject_code[$i]' id='cstjourproject_code[$i]' value='".$cstjourproject_code[$i]."' style='width:88%;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" id='cstjourprojectimg[$i]' onClick=\"showlistProject(2,'cstjourproject_code[$i]','cstjourproject_name[$i]');\"  /></span></label>
				</td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'   name='cstjourproject_name[$i]' id='cstjourproject_name[$i]' value='".$cstjourproject_name[$i]."' style='width:180px;'> </span>
					</td>";
				
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization' onchange=setprojectcostcenter(this.value,'cstjourcostcent_code[$i]','cstjourcostcent_name[$i]','cstjour','cstjourcostcenterimg[$i]','costcenter') name='cstjourcostcent_code[$i]' id='cstjourcostcent_code[$i]' value='".$cstjourcostcent_code[$i]."' style='width:130px;'> </span>
				<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  id='cstjourcostcenterimg[$i]' onClick=\"showlistCostcenter(2,'cstjourcostcent_code[$i]','cstjourcostcent_name[$i]');\" /></span></label>
				</td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization_medium'  name='cstjourcostcent_name[$i]' id='cstjourcostcent_name[$i]' value='".$cstjourcostcent_name[$i]."' style='width:180px;'> </span>
					</td>";
					
					
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown    class='roundedtext_amortization'  name='cstjour_prcnt[$i]' id='cstjour_prcnt[$i]' value='".$cstjour_prcnt[$i]."' onchange=\"changeamountsfixedassetcstjour('cstjour_amount[$i]','cstjour_amount1[$i]','cstjour_amount2[$i]','cstjour_prcnt[$i]','percentage')\" style='width:80px;'> </span></td>";
				
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  style='text-align:right;width:120px;' name='cstjour_amount[$i]' id='cstjour_amount[$i]' value='".$cstjour_amount[$i]."' onchange=\"changeamountsfixedassetcstjour('cstjour_amount[$i]','cstjour_amount1[$i]','cstjour_amount2[$i]','cstjour_prcnt[$i]','amount')\" > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  style='text-align:right;width:120px;' name='cstjour_amount1[$i]'  id='cstjour_amount1[$i]' value='".$cstjour_amount1[$i]."' > </td>";
				echo"<td align=center $onclick><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization'  style='text-align:right;width:120px;' name='cstjour_amount2[$i]'  id='cstjour_amount2[$i]' value='".$cstjour_amount2[$i]."' > </td>";

				echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitfixedassetscstjour[$i]' title='Save' onclick=\"submitfixedassetscstjour('$assetsdt_id','$i','i')\"></td>";
				echo"<input type='hidden'  name='fixedassetscstjour_id[$i]' id='fixedassetscstjour_id[$i]' value='".$fixedassetscstjour_id[$i]."' >";
				echo"</tr>";
					$i+=1;
			$k+=1;
			

			
			}
			
		echo"</table></div>";	
		
		/*echo"<div>
		<table width='900' align=center border=0>
		<col width=100>
		<col width=300>
		<col width=150>
		<col width=150>
		<col width=200>
		<col width=50>
		<col width=150>
			<tr  height='20px'   bgcolor='#F6F6F6'>
				<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
				<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage(this.value,'$morelines','$orderby','$option');\">";
				
				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>';
					
					$fromrec = $perpage * (($startrange / $perpage)) + 1;
					
					$torec = $perpage * ($startrange / $perpage + 1);
					if ($torec > $totalrows)
						$torec = $totalrows;
				echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
				echo'<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='pointer'\"    onclick=\"changepagelimit('start','$orderby',$morelines,'".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

				$diff= $startrange - $perpage;
					
				if (($diff) >= 0 ){
					$prvstartrange = $startrange - $perpage;
					echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimit('previous','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
				}
				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' onclick=\"changepagelimit('next','$orderby',$morelines,'".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimit('last','$orderby',$morelines,'".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				if ($morelines==1)	$sel1 = 'selected';
				else if ($morelines==4)	$sel4 = 'selected';	
				else if ($morelines==8)	$sel8 = 'selected';	
				else if ($morelines==12)	$sel12 = 'selected';	
				else if ($morelines==16)	$sel16 = 'selected';	
			
				$pagenum = ($startrange / $perpage) + 1;
				$pageof = ceil(($totalrows / $perpage));
	echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
	echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"Refreshassetsdt('$startrange','$perpage','$morelines','$orderby','$option');\" height='20'></td>";

	echo"<td  valign=top align=right></td></tr>";
	echo"	</table></div>";*/
				
		
		

	}


function draw_amortjournaldtgrid($journal_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$actionbefore){

	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	$columnsarray = array("ledger_number", "ledger_name", "currency_code", "assetsdt_description", "assetsdt_amount", "assetsdt_amount1", "assetsdt_amount2", "assetsdt_valuedate", "assetsdt_isvat");
	$columnslist = implode(',', $columnsarray);
	
	
	
echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


if ($orderby=='')
	$orderby = 'journaldt_id';
	
	
$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
//echo $query;	
$result=mysql_query($query,$connection)  or die(mysql_error());
$totalrows = mysql_num_rows($result);

$query = $query." limit ".$startrange.",".$perpage;
//echo $query;
$result=mysql_query($query,$connection);

$i=0;
//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
echo"<div style='overflow:auto;width:1133px;height:175px'>";
echo"<table border='0' 	align='left'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1000px;' cellpadding='0' cellspacing='1'>
	";
echo"
	<col width=100>
	<col width=170>
	<col width=75>
	<col width=200>
	<col width=60>
	<col width=120>
	<col width=120>
	<col width=120>
	<col width=100>
	";	
	
			
	 echo"<tr  height=10px bgcolor='#F6F6F6'>
		<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Account No. </th>
		<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Acc. Name </th>
		<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Currency </th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Description </th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >D/C </th>
		<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount </th>
		<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1 </th>
		<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2 </th>
		<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Value Date </th>
		</tr>";
	
	$i=0;
	$j=1;
	
	echo"
		 <input type='hidden' name='selectedamortjournaldttrcolor' id='selectedamortjournaldttrcolor' value='$selectedamortjournaldttrcolor'>
		 <input type='hidden' name='selectedamortjournaldt_id' id='selectedamortjournaldt_id' value='$selectedamortjournaldt_id'>
		 
		 ";
	
		 
while($row=mysql_fetch_row($result)){
			
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		
		$status = ' readonly ';
		
		$onclick=" onclick='showrelationtoItemJour(\"$row[0]\",\"$row[4]\")' ";
		
	
		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

		$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
		
		
			$amortjournaldtjournaldt_id[$i] = $row[0];
			$amortjournaldtledger_number[$i] = $row[1];
			$amortjournaldtledger_name[$i] = $row[2];
			$amortjournaldtcurrency_code[$i] = $row[3];
			$amortjournaldtjournaldt_desc[$i] = $row[4];
			$amortjournaldtjournaldt_dbcd[$i] = $row[5];
			$amortjournaldtjournaldtdt_amount[$i] = $row[6];
			$amortjournaldtjournaldtdt_amount1[$i] = $row[7];
			$amortjournaldtjournaldtdt_amount2[$i] = $row[8];
			$amortjournaldtjournaldt_valuedate[$i] = $row[9];
			
			
			
			echo"<tr height='20px' id='salmov$i' onclick=\"returncolorcstjourdt(this,'selectedamortjournaldttrcolor','selectedamortjournaldt_id','$row[0]')\" style='background-color:$bgcolor'>";

		
						
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
	
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization_small'     name='amortjournaldtledger_number[$i]' id='amortjournaldtledger_number[$i]' value='".$amortjournaldtledger_number[$i]."' style='width:100%;' ></span>	</td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status readonly class='roundedtext_amortization_mediumlarge' name='amortjournaldtledger_name[$i]' id='amortjournaldtledger_name[$i]' value='".$amortjournaldtledger_name[$i]."' style='width:100%;'> </span></td>";					

		
					
			echo"<td $onclick><span class='style4'>
			<input type='text'  class='roundedtext_amortization_small' name='amortjournaldtcurrency_code[$i]' id='amortjournaldtcurrency_code[$i]' value='$amortjournaldtcurrency_code[$i]' style='width:100%;'> 
			
			</td>";	
			
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_mediumlarge' name='amortjournaldtjournaldt_desc[$i]' id='amortjournaldtjournaldt_desc[$i]' value='".$amortjournaldtjournaldt_desc[$i]."' style='width:100%;'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_small' name='amortjournaldtjournaldt_dbcd[$i]' id='amortjournaldtjournaldt_dbcd[$i]' value='".$amortjournaldtjournaldt_dbcd[$i]."' style='width:100%;'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium' style='text-align:right;color:#0000FF;width:120px;' name='amortjournaldtjournaldtdt_amount[$i]' id='amortjournaldtjournaldtdt_amount[$i]' value='".round($amortjournaldtjournaldtdt_amount[$i],$DecimalBase)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#994E67;width:120px;' name='amortjournaldtjournaldtdt_amount1[$i]' id='amortjournaldtjournaldtdt_amount1[$i]' value='".round($amortjournaldtjournaldtdt_amount1[$i],$DecimalBase1)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount1','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#4B6318;width:120px;' readonly name='amortjournaldtjournaldtdt_amount2[$i]' id='amortjournaldtjournaldtdt_amount2[$i]' value='".round($amortjournaldtjournaldtdt_amount2[$i],$DecimalBase2)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount2','currency_code[$i],'lastcurrency[$i]')\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundeddate_amortization' name='amortjournaldtjournaldt_valuedate[$i]' id='amortjournaldtjournaldt_valuedate[$i]' value='".$amortjournaldtjournaldt_valuedate[$i]."'  style='width:100px'> </span></td>";
			
			
	
						
			echo"<input type='hidden'  name='amortjournaldtjournaldt_id[$i]' id='amortjournaldtjournaldt_id[$i]' value='".$amortjournaldtjournaldt_id[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		
		
	echo"</table></div>";
	

	echo"<div>
	<table width='900' align=center border=0>
	<col width=100>
	<col width=300>
	<col width=150>
	<col width=150>
	<col width=200>
	<col width=50>
	<col width=150>
		<tr  height='20px'   bgcolor='#F6F6F6'>
			<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
			<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPageamortjournaldt(this.value,'$morelines','$orderby','$option','$journal_id');\">";
              
			if ($perpage==10)
				$s20 = 'selected';
			else if ($perpage==25)
				$s30 = 'selected';
			else if ($perpage==50)
				$s40 = 'selected';
			else if ($perpage==100)
				$s50 = 'selected';

						
					
			echo'<option '.$s20.' value="10">10</option>
				 <option '.$s30.' value="25">25</option>
				 <option '.$s40.' value="50">50</option>
				 <option '.$s50.' value="100">100</option>
				 </select></span></td>';
				 
				 $fromrec = $perpage * (($startrange / $perpage)) + 1;
				 
				 $torec = $perpage * ($startrange / $perpage + 1);
				 if ($torec > $totalrows)
					$torec = $totalrows;
			echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
			echo'<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='pointer'\"    onclick=\"changepagelimitamortjournaldt('$journal_id','start','$orderby','$morelines','".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimitamortjournaldt('$journal_id','previous','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
			}
			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' onclick=\"changepagelimitamortjournaldt('$journal_id','next','$orderby','$morelines','".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimitamortjournaldt('$journal_id','last','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
				}
			} else
				echo "&nbsp;";
		
			if ($morelines==1)	$sel1 = 'selected';
			else if ($morelines==4)	$sel4 = 'selected';	
			else if ($morelines==8)	$sel8 = 'selected';	
			else if ($morelines==12)	$sel12 = 'selected';	
			else if ($morelines==16)	$sel16 = 'selected';	
		
			$pagenum = ($startrange / $perpage) + 1;
			$pageof = ceil(($totalrows / $perpage));
echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"Refreshamortjournaldt('$startrange','$perpage','$morelines','$orderby','$option','$journal_id');\" height='20'></td>";

echo"<td  valign=top align=right></td></tr>";
echo"	</table></div>";
			
	
	

}


function draw_salejourjournaldtgridgenerate($journal_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$actionbefore){

	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	$columnsarray = array("ledger_number", "ledger_name", "currency_code", "assetsdt_description", "assetsdt_amount", "assetsdt_amount1", "assetsdt_amount2", "assetsdt_valuedate", "assetsdt_isvat");
	$columnslist = implode(',', $columnsarray);
	
	
	
echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


if ($orderby=='')
	$orderby = 'journaldt_id';
	
	
$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
//echo $query;	
$result=mysql_query($query,$connection)  or die(mysql_error());
$totalrows = mysql_num_rows($result);

$query = $query." limit ".$startrange.",".$perpage;
//echo $query;
$result=mysql_query($query,$connection);

$i=0;
//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
echo"<div style='overflow:auto;width:1133px;height:175px'>";
echo"<table border='0' 	align='left'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1000px;' cellpadding='0' cellspacing='1'>
	";
echo"
	<col width=100>
	<col width=170>
	<col width=75>
	<col width=200>
	<col width=60>
	<col width=120>
	<col width=120>
	<col width=120>
	<col width=100>
	";	
	
			
	 echo"<tr  height=10px bgcolor='#F6F6F6'>
		<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Account No. </th>
		<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Acc. Name </th>
		<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Currency </th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Description </th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >D/C </th>
		<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Amount </th>
		<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1 </th>
		<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2 </th>
		<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Value Date </th>
		</tr>";
	
	$i=0;
	$j=1;
	
	echo"
		 <input type='hidden' name='selectedsalejourjournaldttrcolor' id='selectedsalejourjournaldttrcolor' value='$selectedsalejourjournaldttrcolor'>
		 <input type='hidden' name='selectedsalejourjournaldt_id' id='selectedsalejourjournaldt_id' value='$selectedsalejourjournaldt_id'>
		 
		 ";
	
		 
while($row=mysql_fetch_row($result)){
			
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		
		$status = ' readonly ';
		
		$onclick=" onclick='showrelationtoSaleJour(\"$row[0]\",\"$row[4]\")' ";
		
	
		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

		$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
		
		
			$salejourjournaldtjournaldt_id[$i] = $row[0];
			$salejourjournaldtledger_number[$i] = $row[1];
			$salejourjournaldtledger_name[$i] = $row[2];
			$salejourjournaldtcurrency_code[$i] = $row[3];
			$salejourjournaldtjournaldt_desc[$i] = $row[4];
			$salejourjournaldtjournaldt_dbcd[$i] = $row[5];
			$salejourjournaldtjournaldtdt_amount[$i] = $row[6];
			$salejourjournaldtjournaldtdt_amount1[$i] = $row[7];
			$salejourjournaldtjournaldtdt_amount2[$i] = $row[8];
			$salejourjournaldtjournaldt_valuedate[$i] = $row[9];
			
			
			
			echo"<tr height='20px' id='salmov$i' onclick=\"returncolorcstjourdt_salejour(this,'selectedsalejourjournaldttrcolor','selectedsalejourjournaldt_id','$row[0]')\" style='background-color:$bgcolor'>";

		
						
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
	
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization_small'     name='salejourjournaldtledger_number[$i]' id='salejourjournaldtledger_number[$i]' value='".$salejourjournaldtledger_number[$i]."' ></span>	</td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status readonly class='roundedtext_amortization_mediumlarge' name='salejourjournaldtledger_name[$i]' id='salejourjournaldtledger_name[$i]' value='".$salejourjournaldtledger_name[$i]."'> </span></td>";					

		
					
			echo"<td $onclick><span class='style4'>
			<input type='text'  class='roundedtext_amortization_small' name='salejourjournaldtcurrency_code[$i]' id='salejourjournaldtcurrency_code[$i]' value='$salejourjournaldtcurrency_code[$i]'>
			
			</td>";	
			
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_mediumlarge' name='salejourjournaldtjournaldt_desc[$i]' id='salejourjournaldtjournaldt_desc[$i]' value='".$salejourjournaldtjournaldt_desc[$i]."'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_small' name='salejourjournaldtjournaldt_dbcd[$i]' id='salejourjournaldtjournaldt_dbcd[$i]' value='".$salejourjournaldtjournaldt_dbcd[$i]."'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium' style='text-align:right;color:#0000FF' name='salejourjournaldtjournaldtdt_amount[$i]' id='salejourjournaldtjournaldtdt_amount[$i]' value='".$salejourjournaldtjournaldtdt_amount[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#994E67' name='salejourjournaldtjournaldtdt_amount1[$i]' id='salejourjournaldtjournaldtdt_amount1[$i]' value='".$salejourjournaldtjournaldtdt_amount1[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount1','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#4B6318' readonly name='salejourjournaldtjournaldtdt_amount2[$i]' id='salejourjournaldtjournaldtdt_amount2[$i]' value='".$salejourjournaldtjournaldtdt_amount2[$i]."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount2','currency_code[$i],'lastcurrency[$i]')\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundeddate_amortization' name='salejourjournaldtjournaldt_valuedate[$i]' id='salejourjournaldtjournaldt_valuedate[$i]' value='".$salejourjournaldtjournaldt_valuedate[$i]."'  style='width:100px'> </span></td>";
			
			
	
						
			echo"<input type='hidden'  name='salejourjournaldtjournaldt_id[$i]' id='salejourjournaldtjournaldt_id[$i]' value='".$salejourjournaldtjournaldt_id[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		
		
	echo"</table></div>";
	

	echo"<div>
	<table width='900' align=center border=0>
	<col width=100>
	<col width=300>
	<col width=150>
	<col width=150>
	<col width=200>
	<col width=50>
	<col width=150>
		<tr  height='20px'   bgcolor='#F6F6F6'>
			<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
			<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPageamortjournaldt(this.value,'$morelines','$orderby','$option','$journal_id');\">";
              
			if ($perpage==10)
				$s20 = 'selected';
			else if ($perpage==25)
				$s30 = 'selected';
			else if ($perpage==50)
				$s40 = 'selected';
			else if ($perpage==100)
				$s50 = 'selected';

						
					
			echo'<option '.$s20.' value="10">10</option>
				 <option '.$s30.' value="25">25</option>
				 <option '.$s40.' value="50">50</option>
				 <option '.$s50.' value="100">100</option>
				 </select></span></td>';
				 
				 $fromrec = $perpage * (($startrange / $perpage)) + 1;
				 
				 $torec = $perpage * ($startrange / $perpage + 1);
				 if ($torec > $totalrows)
					$torec = $totalrows;
			echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
			echo'<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='pointer'\"    onclick=\"changepagelimitamortjournaldt('$journal_id','start','$orderby','$morelines','".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimitamortjournaldt('$journal_id','previous','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
			}
			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' onclick=\"changepagelimitamortjournaldt('$journal_id','next','$orderby','$morelines','".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimitamortjournaldt('$journal_id','last','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
				}
			} else
				echo "&nbsp;";
		
			if ($morelines==1)	$sel1 = 'selected';
			else if ($morelines==4)	$sel4 = 'selected';	
			else if ($morelines==8)	$sel8 = 'selected';	
			else if ($morelines==12)	$sel12 = 'selected';	
			else if ($morelines==16)	$sel16 = 'selected';	
		
			$pagenum = ($startrange / $perpage) + 1;
			$pageof = ceil(($totalrows / $perpage));
echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"Refreshamortjournaldt('$startrange','$perpage','$morelines','$orderby','$option','$journal_id');\" height='20'></td>";

echo"<td  valign=top align=right></td></tr>";
echo"	</table></div>";
			
	
	

}


function draw_cstjour($journaldt_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2){

	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	$columnsarray = array("assetjourproject_code","assetjourcostcent_code","assetjour_prcnt","assetjour_amount","assetjour_amount1","assetjour_amount2");

	$columnslist = implode(',', $columnsarray);
	
	
	
echo"
	
	<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


if ($orderby=='')
	$orderby = 'Cst_increment';
	


	
$query="select Cst_increment, journaldt_id, cstjour.Project_Code, Project_Name
				, cstjour.Costcent_code, Costcent_Name, Cstjour_prcnt,Cstjour_amount,Cstjour_amount1
				, Cstjour_amount2
				from cstjour left join project on project.project_code = cstjour.project_code
									left join costcent on costcent.costcent_code = cstjour.costcent_code
			   where journaldt_id = '$journaldt_id' order by $orderby $direction";
//echo $query;
$result=mysql_query($query,$connection)  or die(mysql_error());
$totalrows = mysql_num_rows($result);

$query = $query." limit ".$startrange.",".$perpage;
//echo $query;
$result=mysql_query($query,$connection);

$i=0;
//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
echo"<div style='overflow:auto;width:1080px;height:75px'>";
echo"<table border='0' 	align='left'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1080px;align=left' cellpadding='0' cellspacing='1'>
	";
echo"
	
	<col width=120>
	<col width=240>
	<col width=120>
	<col width=240>
	<col width=75>
	<col width=95>
	<col width=95>
	<col width=95>	";	
	
			
	 echo"<tr  height=10px bgcolor='#F6F6F6'>
		
		<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project</span></th>
		<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project Name</span></th>
		<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter</span></th>
		<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter Name</span></th>
		<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Percentage</span></th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Amount</span></th>
		<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1</span></th>
		<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2</span></th>
		
		</tr>";
	
	$i=0;
	$j=1;
	echo"
	
		<input type='hidden' name='selectedtrcstjour' id='selectedtrcstjour' value='$selectedtrcstjour'>
		 <input type='hidden' name='selectedtrcolorcstjour' id='selectedtrcolorcstjour' value='$selectedtrcolorcstjour'>";
		$status = ' readonly ';
	while($row=mysql_fetch_row($result)){
			
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		
			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

			echo"<tr height='15px' id='cstjour$i' onclick=\"returncolorcstjour(this,'selectedtrcstjour','selectedtrcolorcstjour')\" style='background-color:$bgcolor'>";

			    
	
			$cstjourcst_increment[$i] = $row[0];
			$cstjourjournaldt_id[$i] = $row[1];
			$cstjourproject_code[$i] = $row[2];
			$cstjourproject_name[$i] = $row[3];
			$cstjourcostcent_code[$i] = $row[4];
			$cstjourcostcenter_name[$i] = $row[5];
			$cstjourcstjour_prcnt[$i] = $row[6]."%";
			$cstjourcstjour_amount[$i] = $row[6];
			$cstjourcstjour_amount1[$i] = $row[8];
			$cstjourcstjour_amount2[$i] = $row[9];			
									
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
				
	
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization'  name='cstjourproject_code[$i]'  id='cstjourproject_code[$i]' value='".$cstjourproject_code[$i]."' style='width:130px;'> </span>
			
			</td>";
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown $status   class='roundedtext_amortization_medium'    name='cstjourproject_name[$i]' id='cstjourproject_name[$i]' value='".$cstjourproject_name[$i]."' style='width:130px;'> </span>
				</td>";
			
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization' name='cstjourcostcent_code[$i]'  id='cstjourcostcent_code[$i]' value='".$cstjourcostcent_code[$i]."' style='width:130px;'> </span>
			</td>";
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='cstjourcostcenter_name[$i]' id='cstjourcostcenter_name[$i]' value='".$cstjourcostcenter_name[$i]."' style='width:130px;'> </span>
				</td>";
				
				
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='cstjourcstjour_prcnt[$i]' id='cstjourcstjour_prcnt[$i]' value='".$cstjourcstjour_prcnt[$i]."' style='width:100%;' > </span></td>";
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount[$i]' style='text-align:right;width:100%;' id='cstjourcstjour_amount[$i]' value='".$cstjourcstjour_amount[$i]."' > </td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount1[$i]' style='text-align:right;width:100%;' readonly id='cstjourcstjour_amount1[$i]' value='".$cstjourcstjour_amount1[$i]."'> </td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount2[$i]' style='text-align:right;width:100%;' readonly id='cstjourcstjour_amount2[$i]' value='".$cstjourcstjour_amount2[$i]."'> </td>";

			
			echo"<input type='hidden'  name='cstjourcst_increment[$i]' id='cstjourcst_increment[$i]' value='".$cstjour_idz[$i]."' style='width:100%;'>";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		
		
	echo"</table></div>";	
	
	

}


function draw_cstjour_salejour($journaldt_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2){

		
		if ($startrange=='')	$startrange = 0;
			
		if ($direction == 'asc')
			$direction = 'desc';
		else if ($direction == 'desc')
			$direction = 'asc';
		else $direction = 'asc';

		if ($perpage=='')
			$perpage = 20;
		
		$columnsarray = array("salejourcstjourproject_code","salejourcstjourproject_name","salejourcstjourcostcent_code","salejourcstjourcostcenter_name","salejourcstjourcstjour_prcnt"
				,"salejourcstjourcstjour_amount","salejourcstjourcstjour_amount1","salejourcstjourcstjour_amount2");

		$columnslist = implode(',', $columnsarray);
		
		
		











	if ($orderby=='')
		$orderby = 'Cst_increment';
		


		
	$query="select Cst_increment, journaldt_id, cstjour.Project_Code, Project_Name
					, cstjour.Costcent_code, Costcent_Name, Cstjour_prcnt,Cstjour_amount,Cstjour_amount1
					, Cstjour_amount2
					from cstjour left join project on project.project_code = cstjour.project_code
										left join costcent on costcent.costcent_code = cstjour.costcent_code
				where journaldt_id = '$journaldt_id' order by $orderby $direction";
	//echo $query;
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='overflow:auto;width:1080px;height:75px'>";
	echo"<table border='0' 	align='left'  class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1000px;align=left' cellpadding='0' cellspacing='1'>
		";
	echo"
		
		<col width=100>
		<col width=120>
		<col width=100>
		<col width=120>
		<col width=75>
		<col width=80>
		<col width=80>
		<col width=80>
		
		";	
		
				
		echo"<tr  height=10px bgcolor='#F6F6F6'>
			
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project</span></th>
			<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project Name</span></th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter</span></th>
			<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter Name</span></th>
			<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Percentage</span></th>
			<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Amount</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1</span></th>
			<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2</span></th>
			
			</tr>";
		
		$i=0;
		$j=1;
		echo"
		
			<input type='hidden' name='selectedtrcstjour_salejour' id='selectedtrcstjour_salejour' value='$selectedtrcstjour_salejour'>
			<input type='hidden' name='selectedtrcolorcstjour_salejour' id='selectedtrcolorcstjour_salejour' value='$selectedtrcolorcstjour_salejour'>";
			$status = ' readonly ';
	while($row=mysql_fetch_row($result)){
				
			if ($i%2==0)
			$bgcolor='#F5FAFF';
		else	
			$bgcolor='#FFFFFF';
			
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

				echo"<tr height='15px' id='cstjour$i' onclick=\"returncolorcstjour(this,'selectedtrcstjour_salejour','selectedtrcolorcstjour_salejour')\" style='background-color:$bgcolor'>";

					
		
				$salejourcstjourcst_increment[$i] = $row[0];
				$salejourcstjourjournaldt_id[$i] = $row[1];
				$salejourcstjourproject_code[$i] = $row[2];
				$salejourcstjourproject_name[$i] = $row[3];
				$salejourcstjourcostcent_code[$i] = $row[4];
				$salejourcstjourcostcenter_name[$i] = $row[5];
				$salejourcstjourcstjour_prcnt[$i] = $row[6]."%";
				$salejourcstjourcstjour_amount[$i] = $row[6];
				$salejourcstjourcstjour_amount1[$i] = $row[8];
				$salejourcstjourcstjour_amount2[$i] = $row[9];			
										
				$recno = $i+1;
				$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
				
					
		
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization'  name='salejourcstjourproject_code[$i]'  id='salejourcstjourproject_code[$i]' value='".$salejourcstjourproject_code[$i]."'> </span>
				
				</td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown $status   class='roundedtext_amortization_medium'    name='salejourcstjourproject_name[$i]' id='salejourcstjourproject_name[$i]' value='".$salejourcstjourproject_name[$i]."'> </span>
					</td>";
				
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization' name='salejourcstjourcostcent_code[$i]'  id='salejourcstjourcostcent_code[$i]' value='".$salejourcstjourcostcent_code[$i]."'> </span>
				</td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='salejourcstjourcostcenter_name[$i]' id='salejourcstjourcostcenter_name[$i]' value='".$salejourcstjourcostcenter_name[$i]."'> </span>
					</td>";
					
					
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='salejourcstjourcstjour_prcnt[$i]' id='salejourcstjourcstjour_prcnt[$i]' value='".$salejourcstjourcstjour_prcnt[$i]."'  > </span></td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='salejourcstjourcstjour_amount[$i]' style='text-align:right' id='salejourcstjourcstjour_amount[$i]' value='".$salejourcstjourcstjour_amount[$i]."' > </td>";
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='salejourcstjourcstjour_amount1[$i]' style='text-align:right' readonly id='salejourcstjourcstjour_amount1[$i]' value='".$salejourcstjourcstjour_amount1[$i]."'> </td>";
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='salejourcstjourcstjour_amount2[$i]' style='text-align:right' readonly id='salejourcstjourcstjour_amount2[$i]' value='".$salejourcstjourcstjour_amount2[$i]."'> </td>";

				
				echo"<input type='hidden'  name='salejourcstjourcst_increment[$i]' id='salejourcstjourcst_increment[$i]' value='".$salejourcstjour_idz[$i]."' >";
				echo"</tr>";
				
				
				$i+=1;
			}
			
			
			
		echo"</table></div>";	
		
		

}


function draw_salejourcstjour($journaldt_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2){

		
		if ($startrange=='')	$startrange = 0;
			
		if ($direction == 'asc')
			$direction = 'desc';
		else if ($direction == 'desc')
			$direction = 'asc';
		else $direction = 'asc';

		if ($perpage=='')
			$perpage = 20;
		
		$columnsarray = array("assetjourproject_code","assetjourcostcent_code","assetjour_prcnt","assetjour_amount","assetjour_amount1","assetjour_amount2");

		$columnslist = implode(',', $columnsarray);
		
		
		
	echo"
		
		<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'Cst_increment';
		


		
	$query="select Cst_increment, journaldt_id, cstjour.Project_Code, Project_Name
					, cstjour.Costcent_code, Costcent_Name, Cstjour_prcnt,Cstjour_amount,Cstjour_amount1
					, Cstjour_amount2
					from cstjour left join project on project.project_code = cstjour.project_code
										left join costcent on costcent.costcent_code = cstjour.costcent_code
				where journaldt_id = '$journaldt_id' order by $orderby $direction";
	//echo $query;
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='overflow:auto;width:1025px;height:75px'>";
	echo"<table border='0' 	align='center'  class='sample'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1000px;align=left' cellpadding='0' cellspacing='1'>
		";
	echo"
		
		<col width=100>
		<col width=120>
		<col width=100>
		<col width=120>
		<col width=75>
		<col width=80>
		<col width=80>
		<col width=80>
		
		";	
		
				
		echo"<tr  height=10px bgcolor='#F6F6F6'>
			
			<td id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project</span></td>
			<td id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Project Name</span></td>
			<td id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter</span></td>
			<td id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Costcenter Name</span></td>
			<td id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Percentage</span></td>
			<td id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Amount</span></td>
			<td id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1</span></td>
			<td id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2</span></td>
			
			</tr>";
		
		$i=0;
		$j=1;
		echo"
		
			<input type='hidden' name='selectedtrcstjour' id='selectedtrcstjour' value='$selectedtrcstjour'>
			<input type='hidden' name='selectedtrcolorcstjour' id='selectedtrcolorcstjour' value='$selectedtrcolorcstjour'>";
			$status = ' readonly ';
	while($row=mysql_fetch_row($result)){
				
			if ($i%2==0)
			$bgcolor='#F5FAFF';
		else	
			$bgcolor='#FFFFFF';
			
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

				echo"<tr height='15px' id='cstjour$i' onclick=\"returncolorcstjour(this,'selectedtrcstjour','selectedtrcolorcstjour')\" style='background-color:$bgcolor'>";

					
		
				$cstjourcst_increment[$i] = $row[0];
				$cstjourjournaldt_id[$i] = $row[1];
				$cstjourproject_code[$i] = $row[2];
				$cstjourproject_name[$i] = $row[3];
				$cstjourcostcent_code[$i] = $row[4];
				$cstjourcostcenter_name[$i] = $row[5];
				$cstjourcstjour_prcnt[$i] = $row[6]."%";
				$cstjourcstjour_amount[$i] = $row[7];
				$cstjourcstjour_amount1[$i] = $row[8];
				$cstjourcstjour_amount2[$i] = $row[9];			
										
				$recno = $i+1;
				$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
				
					
		
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization'  name='cstjourproject_code[$i]'  id='cstjourproject_code[$i]' value='".$cstjourproject_code[$i]."'> </span>
				
				</td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown $status   class='roundedtext_amortization_medium'    name='cstjourproject_name[$i]' id='cstjourproject_name[$i]' value='".$cstjourproject_name[$i]."'> </span>
					</td>";
				
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization' name='cstjourcostcent_code[$i]'  id='cstjourcostcent_code[$i]' value='".$cstjourcostcent_code[$i]."'> </span>
				</td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='cstjourcostcenter_name[$i]' id='cstjourcostcenter_name[$i]' value='".$cstjourcostcenter_name[$i]."'> </span>
					</td>";
					
					
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'    name='cstjourcstjour_prcnt[$i]' id='cstjourcstjour_prcnt[$i]' value='".$cstjourcstjour_prcnt[$i]."'  > </span></td>";
				
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount[$i]' style='text-align:right' id='cstjourcstjour_amount[$i]' value='".$cstjourcstjour_amount[$i]."' > </td>";
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount1[$i]' style='text-align:right' readonly id='cstjourcstjour_amount1[$i]' value='".$cstjourcstjour_amount1[$i]."'> </td>";
				echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization'  name='cstjourcstjour_amount2[$i]' style='text-align:right' readonly id='cstjourcstjour_amount2[$i]' value='".$cstjourcstjour_amount2[$i]."'> </td>";

				
				echo"<input type='hidden'  name='cstjourcst_increment[$i]' id='cstjourcst_increment[$i]' value='".$cstjour_idz[$i]."' >";
				echo"</tr>";
				
				
				$i+=1;
			}
			
			
			
		echo"</table></div>";	
		
		

}


function draw_salejourjournaldtgrid($journal_id,$connection,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$actionbefore){

	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 10;
	
	$columnsarray = array("ledger_number", "ledger_name", "currency_code", "assetsdt_description", "assetsdt_amount", "assetsdt_amount1", "assetsdt_amount2", "assetsdt_valuedate", "assetsdt_isvat");
	$columnslist = implode(',', $columnsarray);
	
	
		
	echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


	if ($orderby=='')
		$orderby = 'journaldt_id';
		
		
	$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
	//echo $query;	
	$result=mysql_query($query,$connection)  or die(mysql_error());
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;
	$result=mysql_query($query,$connection);

	$i=0;
	//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
	echo"<div style='overflow:auto;width:1133px;height:175px'>";
	echo"<table border='0' 	align='center'  class='sample'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1000px;' cellpadding='0' cellspacing='1'>
		";
	echo"
	<col width=100>
	<col width=250>
	<col width=50>
	<col width=200>
	<col width=60>
	<col width=120>
	<col width=120>
	<col width=120>
	<col width=80>
	";	
	
			
	 echo"<tr  height=10px bgcolor='#F6F6F6'>
		<th id='resizable2'  height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Account No. </span></th>
		<th id='resizable3'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Acc. Name </span></th>
		<th id='resizable4'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Currency </span></th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >Description </span></th>
		<th id='resizable5'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" >D/C </span></th>
		<th id='resizable6'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1><span class='style8' >Amount </span></th>
		<th id='resizable7'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base1 </span></th>
		<th id='resizable8'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>$base2 </span></th>
		<th id='resizable9'   height='15' align='left' onmouseover=\"style.cursor='pointer'\" colspan=1>Value Date </span></th>
		</tr>";
	
	$i=0;
	$j=1;
	
	echo"
		<input type='hidden' name='selectedtrsalejour' id='selectedtrsalejour' value='$selectedtrsalejour'>
		 <input type='hidden' name='selectedtrcolorsalejour' id='selectedtrcolorsalejour' value='$selectedtrcolorsalejour'> 
		 ";
	
		 
	while($row=mysql_fetch_row($result)){		
			
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		
		$status = ' readonly ';
		
		$onclick=" onclick='showrelationtoItemJour(\"$row[0]\",\"$row[4]\")' ";
		
	
		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\')"';

		$query="select journaldt_id,  journaldt.ledger_number,ledger.ledger_name,journaldt.Currency_code,Journaldt_desc,Journaldt_dbcd,Journaldt_amount
		,Journaldt_amount1,Journaldt_amount2,date_format(Journaldt_ValueDate,'%d/%m/%Y'),date_format(Journal_date,'%d/%m/%Y')
		from journaldt inner join ledger on ledger.ledger_number = journaldt.ledger_number 
		where journal_id = '$journal_id'  order by $orderby $direction";
		
		
			$amortjournaldtjournaldt_id[$i] = $row[0];
			$amortjournaldtledger_number[$i] = $row[1];
			$amortjournaldtledger_name[$i] = $row[2];
			$amortjournaldtcurrency_code[$i] = $row[3];
			$amortjournaldtjournaldt_desc[$i] = $row[4];
			$amortjournaldtjournaldt_dbcd[$i] = $row[5];
			$amortjournaldtjournaldtdt_amount[$i] = $row[6];
			$amortjournaldtjournaldtdt_amount1[$i] = $row[7];
			$amortjournaldtjournaldtdt_amount2[$i] = $row[8];
			$amortjournaldtjournaldt_valuedate[$i] = $row[9];
			
			
			
			echo"<tr height='20px' id='salejourjournaldt$i' onclick=\"returncolorsalejour(this,'selectedtrcolorsalejour','selectedtrsalejour','$row[0]')\" style='background-color:$bgcolor'>";

		
						
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
	
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status class='roundedtext_amortization_small'     name='amortjournaldtledger_number[$i]' id='amortjournaldtledger_number[$i]' value='".$amortjournaldtledger_number[$i]."' ></span>	</td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status readonly class='roundedtext_amortization_mediumlarge' name='amortjournaldtledger_name[$i]' id='amortjournaldtledger_name[$i]' value='".$amortjournaldtledger_name[$i]."'> </span></td>";					

		
					
			echo"<td $onclick><span class='style4'>
			<input type='text'  class='roundedtext_amortization_small' name='amortjournaldtcurrency_code[$i]' id='amortjournaldtcurrency_code[$i]' value='$amortjournaldtcurrency_code[$i]'>
			
			</td>";	
			
			
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_mediumlarge' name='amortjournaldtjournaldt_desc[$i]' id='amortjournaldtjournaldt_desc[$i]' value='".$amortjournaldtjournaldt_desc[$i]."'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_small' name='amortjournaldtjournaldt_dbcd[$i]' id='amortjournaldtjournaldt_dbcd[$i]' value='".$amortjournaldtjournaldt_dbcd[$i]."'> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium' style='text-align:right;color:#0000FF' name='amortjournaldtjournaldtdt_amount[$i]' id='amortjournaldtjournaldtdt_amount[$i]' value='".round($amortjournaldtjournaldtdt_amount[$i],$DecimalBase)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#994E67' name='amortjournaldtjournaldtdt_amount1[$i]' id='amortjournaldtjournaldtdt_amount1[$i]' value='".round($amortjournaldtjournaldtdt_amount1[$i],$DecimalBase1)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount1','currency_code[$i]','lastcurrency[$i]'))\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundedtext_amortization_medium'  style='text-align:right;color:#4B6318' readonly name='amortjournaldtjournaldtdt_amount2[$i]' id='amortjournaldtjournaldtdt_amount2[$i]' value='".round($amortjournaldtjournaldtdt_amount2[$i],$DecimalBase2)."' onchange=\"changeamountsassetsdt('assetsdt_amount[$i]','assetsdt_amount1[$i]','assetsdt_amount2[$i]','amount2','currency_code[$i],'lastcurrency[$i]')\"> </span></td>";
			echo"<td $onclick><span class='style4'><input type='text'   $KeyDown  $status  class='roundeddate_amortization' name='amortjournaldtjournaldt_valuedate[$i]' id='amortjournaldtjournaldt_valuedate[$i]' value='".$amortjournaldtjournaldt_valuedate[$i]."'> </span></td>";
			
			
	
						
			echo"<input type='hidden'  name='amortjournaldtjournaldt_id[$i]' id='amortjournaldtjournaldt_id[$i]' value='".$amortjournaldtjournaldt_id[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		
		
	echo"</table></div>";
	

	echo"<div>
	<table width='900' align=center border=0>
	<col width=100>
	<col width=300>
	<col width=150>
	<col width=150>
	<col width=200>
	<col width=50>
	<col width=150>
		<tr  height='20px'   bgcolor='#F6F6F6'>
			<td align='left' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'>
			<select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPagesalejourjournaldt(this.value,'$morelines','$orderby','$option','$journal_id');\">";
              
			if ($perpage==10)
				$s20 = 'selected';
			else if ($perpage==25)
				$s30 = 'selected';
			else if ($perpage==50)
				$s40 = 'selected';
			else if ($perpage==100)
				$s50 = 'selected';

						
					
			echo'<option '.$s20.' value="10">10</option>
				 <option '.$s30.' value="25">25</option>
				 <option '.$s40.' value="50">50</option>
				 <option '.$s50.' value="100">100</option>
				 </select></span></td>';
				 
				 $fromrec = $perpage * (($startrange / $perpage)) + 1;
				 
				 $torec = $perpage * ($startrange / $perpage + 1);
				 if ($torec > $totalrows)
					$torec = $totalrows;
			echo'<td align=left><span class="style4">Rec:['.$fromrec.' - '.$torec.'] / '.$totalrows.'</span></td>';
			echo'<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='pointer'\"    onclick=\"changepagelimitsalejourjournaldt('$journal_id','start','$orderby','$morelines','".$startrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"changepagelimitsalejourjournaldt('$journal_id','previous','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";
			}
			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' onclick=\"changepagelimitsalejourjournaldt('$journal_id','next','$orderby','$morelines','".$startrange1."','".$perpage."','".$option."','".$totalrows."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"changepagelimitsalejourjournaldt('$journal_id','last','$orderby','$morelines','".$prvstartrange."','".$perpage."','".$option."','".$totalrows."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				if ($morelines==1)	$sel1 = 'selected';
				else if ($morelines==4)	$sel4 = 'selected';	
				else if ($morelines==8)	$sel8 = 'selected';	
				else if ($morelines==12)	$sel12 = 'selected';	
				else if ($morelines==16)	$sel16 = 'selected';	
			
				$pagenum = ($startrange / $perpage) + 1;
				$pageof = ceil(($totalrows / $perpage));
	echo"		</td><td >&nbsp;<span class='style4'>Page $pagenum / $pageof</span></td>";
	echo"		<td align=center><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"    width='20' onclick=\"RefreshPagesalejourjournaldt('$perpage','$morelines','$orderby','$option','$journal_id');\" height='20'></td>";

	echo"<td  valign=top align=right></td></tr>";
	echo"	</table></div>";

		
		

}



function Create_FixedAssetsJv($PAssId, $DbName, $DbLabel, $UserAccount, $UserName) {
	 
	include("config.inc.php"); 

	$conn = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
	mysql_select_db($DbName, $conn) or die("Could not find DB");

	// mysql_query($sql,$conn);


	fbegin();
	$resultvars = mysql_query("set @id :=0 ", $conn);

	$query = "call Create_FixedAssetsAutoJv(".$PAssId.", 1, '".$DbName."', '".$DbLabel."', '".$UserAccount."', '".$UserName."', 0, @id) ";
	//  echo $query; exit;
	$result = mysql_query($query,$conn);
	$error = '';
	$error = mysql_error();
	// if  ($error != '')
	// 		mysql_query($sql,$conn);
	// $error = $error. mysql_errno() ;
	// if  ($error != '')
	// 		mysql_query($sql,$conn);
	
	$query1 = " select @id from dual ";
	$result1 = mysql_query($query1,$conn) or die(mysql_error());
	$cur1 = mysql_fetch_row($result1); 

	fcommit();
	
			// mysql_query($sql,$conn);
    if ($cur1[0] == -2)
	   $error = 'Error In Procedure Create_FixedAssetsAutoJv: '.$error;
	else if  ($cur1[0] == -1)  
	   $error =  'Error In Procedure Create_Jv: '.$error;
	else if  ($error != '' && $error != '0')  
		$error = 'Error In Function Create_FixedAssetsJv: '.$error;
	 
  
	mysql_query($sql,$conn);
	Return $error;
	

}


function Calculate_MasterAmountsFixedAssets($PId , $connection) {
		//Read From PurchaseSetup Table
		$queryPurchaseSetup="Select PurchaseTTC From PurchaseSetup";
		$resultPurchaseSetup=mysql_query($queryPurchaseSetup,$connection) or die(mysql_error());
		while($rowPurchaseSetup=mysql_fetch_array($resultPurchaseSetup)){
			extract($rowPurchaseSetup);
		}
		
		//Read From Setup Table							
		$querysetup= " select base1, base2, Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
		$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
		while($rowsetup=mysql_fetch_array($resultsetup)){
			extract($rowsetup);
		}

			//Calculating Master Amounts
		$sub_query = " Select currency_code, Assets_date From Temp_Assets  Where Assets_id = ".$PId;
		$result=mysql_query($sub_query,$connection)  or die(mysql_error());
		$sub_result=mysql_fetch_row($result);
		$HeadCurr 		= $sub_result[0];
		$Assets_date	= $sub_result[1];
		
		$vPrdTotalCost      = 0;
		$vPrdTotalCostBase1 = 0;
		$vPrdTotalCostBase2 = 0;
		$vPrdTotalCostIdeal = 0;

		//Calculating Master Amounts
		$sub_query = " Select currency_code,assetsdt_amount,assetsdt_amount1,assetsdt_amount2,assetsdt_valuedate, ifnull(assetsdt_isvat,0) ".
					" From Temp_Assetsdt ".
					" Where Assets_id = ".$PId;
		
		$result=mysql_query($sub_query,$connection)  or die(mysql_error());
		
		$amt  = 0 ;
		$amt1 = 0 ;
		$amt2 = 0 ;
		
		
		$vat  = 0 ;
		$vat1 = 0 ;
		$vat2 = 0 ;
		
		$price  = 0 ;
		$price1 = 0 ;
		$price2 = 0 ;
		
	while($sub_result=mysql_fetch_row($result)){
		$vVat = 0;
		$amount = ConvertCurrency($sub_result[0], $HeadCurr , $sub_result[4], $sub_result[1], $connection);
		
		
		if ($sub_result[5] == 1 && $Setup_VatPercentage > 0 ){
			$vVat = $amount*($Setup_VatPercentage/100);
			$vat = $vat + $vVat;
		}
		$price = $price + $amount;
		$amt = $amt + ($amount);
		
		/* if ($PurchaseTTC == 1){
			$price = $amount + ($amount-($amount*$Setup_VatPercentage/100));
			$amt = $amount + $amt;
		} else {
			$price = $price + $amount;
			$amt = $amt + ($amount+($amount*$Setup_VatPercentage/100));
			
		} */
	}
		$amt = $price + $vat;
		if ($amt > 0){
			$amt1 = ConvertCurrency($HeadCurr, $base1, $Assets_date, $amt, $connection);
			$amt2 = ConvertCurrency($HeadCurr, $base2 , $Assets_date, $amt, $connection);
		}
		
		
		if ($price > 0){
			$price1 = ConvertCurrency($HeadCurr, $base1 , $Assets_date, $price, $connection);
			$price2 = ConvertCurrency($HeadCurr, $base2 , $Assets_date, $price, $connection);
		}
		
		if ($vat > 0){
			$vat1 = ConvertCurrency($HeadCurr, $base1 , $Assets_date, $vat, $connection);
			$vat2 = ConvertCurrency($HeadCurr, $base2 , $Assets_date, $vat, $connection);
		}
		
		fbegin();
		
		$sub_query1 = " UPDATE temp_assets SET ".
					" Assets_amount = $amt, Assets_amount1 = $amt1, Assets_amount2 = $amt2, ".
					" assets_price = $price, assets_price1 = $price1, assets_price2 = $price2, ".
					" assets_vat = $vat, assets_vat1 = $vat1, assets_vat2 = $vat2 ".
					" WHERE assets_id = ".$PId; //echo $sub_query1;
		//exit;
		$sub_result1=mysql_query($sub_query1,$connection);
		
		if ($sub_result1){
			fcommit();
							
		}else{
			$message  = mysql_error(); 
			$error = 'Error In Function Calculate_MasterAmountsFixedAssets: '.$message;
			frollback();
			Return $error;	
		}
				
			

}

	function displayToday(){
		return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
	}

	//Return Date in YYYY-MM-DD HH:MM:SS format. Supplied Format: DD/MM/YYYY
	function insertMySQLDate($data){
		$data = insertDate($data);
		return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2)." ".strftime("%H").":".strftime("%M").":".strftime("%S");;
	}
	//Return Today's Date in YYYYMMDD format. Supplied Format: DD/MM/YYYY
	function insertDate($data){
		return substr($data, 6, 4) . substr($data, 3, 2) . substr($data, 0, 2);
	}

		//Return Date in YYYY-MM-DD format. Supplied Format: DD/MM/YYYY
	function insertMySQLDate1($data){
		$data = insertDate($data);
		return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2);
	}
	function fbegin()
	{
		mysql_query("START TRANSACTION");
	}
	function fcommit(){
		mysql_query("COMMIT");
	}
	function frollback()
	{
		mysql_query("ROLLBACK");
	}				
	
	
	function updateData($conn, $query, $commit){
		if (mysql_query($query, $conn)){				
			return true;
		}else{
			return false;
		}
	}
	
function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
{
	$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull('$Amount',0)),0) From Dual ";
	$result = selectData($connection, $query);
	//Return $query;
	Return	$result[0];

}	

function selectData($conn, $query){
		$result = mysql_query($query, $conn);
		$cur = mysql_fetch_row($result);		
		return $cur;
	}
	
function changedateformat($data){
		$data = insertDate($data);
		return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2);
}


	
?>