<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);

if (!empty($_GET["action"])) {
	$dftorderby   = $_GET["dftorderby"];
	$action 	  = $_GET["action"];
	$orderby 	  = $_GET["orderby"];
	$morelines	  = $_GET["morelines"];
	$startrange   = $_GET["startrange"];
	$perpage 	  = $_GET["perpage"];
	$totalrows    = $_GET["totalrows"];
	$direction    = $_GET["direction"];
	$filepath     = $_GET["filepath"];
	$transid      = $_GET["transid"];
	$transdtid    = $_GET["transdtid"];
	$form      	  = $_GET["form"];
	
	
	
	include("config.inc.php");
	include("Functions_Sales.php");
	
	$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
	mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
	
	
	if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
		mysql_query("SET NAMES 'utf8'"); 
		mysql_query('SET CHARACTER SET utf8'); 
		mysql_set_charset('utf8', $connection);
	}


		
	if ($form == 'SalesOrderJv-TOT') {
		ShowSalesOrderJvTotals($connection, $transid,$_SESSION['SalesOrderJv_parameters'],$_SESSION['gSalesJv_arrayaccess']);
	}
	else if ($form == 'JSO') {
		ShowSalesOrderJvDtGrid($connection,$form, $transid,$_SESSION['SalesOrderJv_parameters'],$_SESSION['gSalesJv_arrayaccess']);
		
}

}
function showDataGridFooter($filepath,$form,$transid,$gridid,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction ,$perpage_label,$page_label,$record_to_view) {
	
	echo"<div  style='background-color:C8C8C8;width:1100'>
			<table width='100%' border=0 >
			<tr>";
	
	$rangefrom = ($startrange + 1);
	if (($startrange + $perpage) >= $totalrows) $rangeto = $totalrows; else $rangeto = ($startrange + $perpage);
				
	if ($totalrows > 0)			
		echo"	<td align='left' style='width:350px; padding-left:10px;'><span class='toolbar_style'>View ".$rangefrom." - ".$rangeto." of ".$totalrows."</span></td>";
	else
		echo"	<td align='left' style='width:350px; padding-left:10px;'><span class='toolbar_style'>$record_to_view</span></td>";
	
	echo"		<td align='center' style='width:120px;'><span class='toolbar_style'>$perpage_label </span><span class='toolbar_style'><select name='perpage' id='perpage' value='$perpage' onchange=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'CP','".$orderby."','".$morelines."',0,this.value,'".$totalrows."','".$direction."');\">";
				  
				if ($perpage==10)		$s10 = 'selected';
				else 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 '.$s10.' value="10">10</option>
					 <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>';
				
	echo"		<td  style='width:100px;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=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'F','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');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=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'P','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";
				}
				else
					echo "&nbsp;";
			
	echo"		</td><td  align='left' style='width:100px;'>";
			
			
				if ($startrange <= $totalrows){
					$startrange1 = $startrange + $perpage;
					if  ($startrange1 < $totalrows){ 
						echo"<img src='img/arrowright.png' title='Next' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'N','".$orderby."','".$morelines."','".$startrange1."','".$perpage."','".$totalrows."','".$direction."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'L','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				
				$currentpage = ($startrange / $perpage) + 1;
				$totalpages  = ceil($totalrows / $perpage);
				
	echo"		</td><td style='text-align:center; width:150px;'>&nbsp;<span class='toolbar_style'>$page_label $currentpage / $totalpages</span></td>";
	

	
	echo"		<td style='text-align:center; width:60px;'><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"  width='20' height='20' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'R','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ></td>";
	echo"		<td align='right' style='width:210px; padding-right:10px;'>&nbsp;</td>";
	
	echo"	</tr>";
	echo"	</table></div>";

}

function ShowSalesOrderJvTotals($connection,$txtSalesOrderJVId,$arrayparams,$arrayaccess){


	$DecimalBase  	= $arrayparams['DecimalBase'];
	$DecimalBase1 	= $arrayparams['DecimalBase1'];
	$DecimalBase2 	= $arrayparams['DecimalBase2'];
	$Base1 			= $arrayparams['Base1'];
	$Base2 			= $arrayparams['Base2'];
	
	$txtClientCode = $arrayparams['txtClientCode'];
	
	
	$Setup_VatPercentage = $arrayparams['Setup_VatPercentage'];
	$VatApplied 		 = $arrayparams['VatApplied'];
	$AllowModifyVAT 	 = $arrayparams['AllowModifyVAT'];
	$FA_SalesJvVAT 		 = $arrayparams['FA_SalesJvVAT'];
	$costcent_applyvat   = $arrayparams['costcent_applyvat'];
	if($FA_SalesJvVAT==0) $AllowModifyVAT = ' disabled ';
	
	if($txtSalesOrderJVId!='') {
	$query = " Select SalesOrderJV_ID, SalesOrderJV_Reference, Date_Format(SalesOrderJV_Date,'%d/%m/%Y') As SalesOrderJV_Date, ".
	         " Date_Format(JournalDt_ValueDate,'%d/%m/%Y') As MaturityDate, ".
			 " SalesOrderJV.Client_Code As ClientCode, Clients.Ledger_name As ClientName, Client_VAT,   ".
			 " SalesOrderJV.Salesman_Code As SalesmanCode, Salesmen.Ledger_name As SalesmanName, ".
			 " SalesOrderJV.Currency_Code, Sales_Remark, SalesOrderJV.Project_Code, SalesOrderJV.Costcenter_Code,  ".
			 " Round(ifNull(SalesOrderJV_Taxable,0), ".$DecimalBase."), Round(ifNull(SalesOrderJV_NoneTaxable,0), ".$DecimalBase."), ".
			 " Round(ifNull(SalesOrderJV_Total,0), ".$DecimalBase.") As GrossTotal, ".
			 " Round(ifNull(SalesOrderJV_DiscountPer,0), ".$DecimalBase."), Round(ifNull(SalesOrderJV_DiscountAmount,0), ".$DecimalBase."),  ".
			 " Round(ifNull(SalesOrderJV_VAT,0), ".$DecimalBase.") As SalesOrderJV_VAT, ".
			 " Round((ifNull(SalesOrderJV_Total,0) + IfNull(SalesOrderJV_VAT,0) - IfNull(SalesOrderJV_DiscountAmount,0)), ".$DecimalBase.") As SalesOrderJV_NetTotal,  ".
			 " ifNull(SalesOrderJV_VatCheck,0) As SalesOrderJV_VatCheck, null, null, SalesOrderJV.SalesOrderJv_ManualNo ".
			 " From Temp_SalesOrderJV As SalesOrderJV ".
			 " Left Join Clients on SalesOrderJV.Client_Code = Clients.Ledger_Number ".
			 " Left Join Salesmen on SalesOrderJV.Salesman_Code = Salesmen.Ledger_Number ".
	         " Where SalesOrderJV_ID = ".$txtSalesOrderJVId;
			 
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtClientVat    = $rows[6];

	$txtTaxable      = $rows[13];
	$txtNoneTaxable  = $rows[14];
	$txtGrossTotal   = $rows[15];
	$txtDiscountPer  = $rows[16];
	$txtDiscountAmt  = $rows[17];
	$txtVatAmt       = $rows[18];
	$txtNetTotal     = $rows[19];
	$txtVatChk       = $rows[20];
	}else {
		$sub_query = " Select ifNull(Client_VAT,0) From Clients Where Ledger_Number = '".$txtClientCode."'";			 
		
		$sub_result = selectData($connection, $sub_query);
		$txtVatChk = $sub_result[0];
		if($costcent_applyvat==0) $txtVatChk=0;
	}
	
	
	
echo"<table border='0' style='table-layout:fixed' cellspacing=0 cellpadding=0>";


echo"<tr>
		<td id='total-top' style='width:240px;height:12px;'></td>
		</tr>
		<tr><td id='total-content' style='width:240px;height:12px;'>";
				
		echo"	<table border='0' cellspacing=0 width=100% >
		<col width=100>
		<col width=110>
			
		<tr  height='20'>
			<td valign='center' align='right' ><span class='style10'>Taxable</span>&nbsp;</td> 
			<td align='left'><input type='text' name='txtTaxable' value='$txtTaxable' maxlength='20' readonly style='text-align:right; width:100px; height=18px;'></td>
		</tr>
		<tr  height='25'>
			<td valign='center' align='right' ><span class='style10'>None Taxable</span>&nbsp;</td> 
 			<td align='left'><input type='text' name='txtNoneTaxable' value='$txtNoneTaxable' maxlength='20' readonly style='text-align:right; width:100px; height=18px;'></td>
		</tr>
		<tr  height='20'>
			<td valign='center' align='right' ><span class='style10'>Gross Total</span>&nbsp;</td> 
			<td align='left'><input type='text' name='txtGrossTotal' value='$txtGrossTotal' maxlength='20' readonly style='text-align:right; width:100px; height=18px;'></td>
		</tr>
		<tr  height='20'>
			<td valign='center' align='right' ><span class='style10'>Discount</span>&nbsp;</td> 
			<td align='left'><input type='text' name='txtDiscountPer' value='$txtDiscountPer' maxlength='5'  style='text-align:right; width:40px; height=18px;' onKeyup='CalcDiscount(1, $DecimalBase,$VatApplied,$Setup_VatPercentage);' $DiscountMode ><span class='style10'>%</span>
			                 <input type='text' name='txtDiscountAmt' value='$txtDiscountAmt' maxlength='20' style='text-align:right; width:44px; height=18px;' onKeyup='CalcDiscount(2, $DecimalBase,$VatApplied,$Setup_VatPercentage);' $DiscountMode ></td>
		</tr>";
		  


echo "  <tr  height='20'>
			<td valign='center' align='right' >
				<input type='hidden' name='txtVatChk' id='txtVatChk' value='$txtVatChk' size='1'/>
				<input name='chkVat' type='checkbox' id='chkVat' value='1' onClick='SetVat($DecimalBase,$VatApplied,$Setup_VatPercentage);'   "; 
			  if ($txtVatChk==1 ) echo " checked $AllowModifyVAT />";  else echo " $AllowModifyVAT />";   
	          
echo "   	<span class='style10'>VAT $Setup_VatPercentage%</span></td> 
			<td align='left'>
				<input type='text' name='txtVatAmt' value='$txtVatAmt' maxlength='20' style='text-align:right; width:100px; height=18px;' readonly >
			</td>
		</tr>";

	
echo"   <tr  height='20'>
			<td valign='center' align='right' ><span class='style10'>Net Total</span>&nbsp;</td> 
			<td align='left'><input type='text' name='txtNetTotal' value='$txtNetTotal' maxlength='20' readonly style='text-align:right; width:100px; height=18px;";
		if($txtNetTotal<0) echo " color:#FF0000;";	
			
			echo"'></td>
		</tr>";
		  

echo "	</table></td>
				</tr><tr>
					<td id='total-bottom' style='width:240px;height:12px;'></td>
				</tr>";	
		echo"</table>";
}


function ShowSalesOrderJvDtGrid($connection,$form,$salesjv,$arrayparams,$arrayaccess){
	
   $Login_AllowPrice 			= $arrayparams['Login_AllowPrice'];
   $Login_NegativeQty 			= $arrayparams['Login_NegativeQty'];
   $Login_ModifySellingPrice 	= $arrayparams['Login_ModifySellingPrice'];
   $Login_ModifyDiscount 		= $arrayparams['Login_ModifyDiscount'];
   $Allow_MinimumPrice			= $arrayparams['Allow_MinimumPrice']; 		
   $Module_Unit1Method			= $arrayparams['Module_Unit1Method']; 		
   $Module_Pack					= $arrayparams['Module_Pack']; 				
   $Module_DoubleUnit			= $arrayparams['Module_DoubleUnit']; 		
   $Module_ProjectDt			= $arrayparams['Module_ProjectDt']; 		
   $Module_CostCenterDt			= $arrayparams['Module_CostCenterDt'];		
   $Module_RestrictProjCost		= $arrayparams['Module_RestrictProjCost'];	
   $Module_RestrictCost			= $arrayparams['Module_RestrictCost']; 		
   $ShowCostCentLayout			= $arrayparams['ShowCostCentLayout']; 		
   $DecimalBase					= $arrayparams['DecimalBase']; 				
   $Setup_VatPercentage			= $arrayparams['Setup_VatPercentage']; 		
   $Module_AdditionalTaxes		= $arrayparams['Module_AdditionalTaxes'];	
   $VatApplied					= $arrayparams['VatApplied']; 				
   $AllowModifyVAT				= $arrayparams['AllowModifyVAT']; 			
   $txtClientCode				= $arrayparams['txtClientCode'];  			
   $FA_SalesJvVAT				= $arrayparams['FA_SalesJvVAT']; 			
   $costcent_applyvat			= $arrayparams['costcent_applyvat']; 		
   $FI_SalesCheckSalesman		= $arrayparams['FI_SalesCheckSalesman']; 	
   $salesjv_paymentmode			= $arrayparams['salesjv_paymentmode']; 		
   
	$ClassI = 'grid_roundedtext2';
	$filepath = 'Forms_DataGridSalesOrderJV.php';
	
	$txtSalesOrderJVId = $salesjv;
	
	$PriceLabel = 'Price';	
	if ($PurchaseTTC == 1)  $PriceLabel = 'Price TTC';	
	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
	// User Has No Access To Modify The Price / Discount	
	$ModeModifySellPrice = '';
	$DiscountMode = '';
	
	if ($Login_ModifySellingPrice == 0) $ModeModifySellPrice = ' readonly ';
	if ($Login_ModifyDiscount == 0)	$DiscountMode = ' readonly ';


	if (empty($txtDtManualNo)) $txtDtManualNo = $PManualNo;

	if (empty($txtDtCurr))
	{
		if ($sub_result[0] != '')	$txtDtCurr = $sub_result[0];
		else		$txtDtCurr = $base1;
	}	

	if ($PClientCode != '') {
		$sub_query1 = " Select ifNull(Client_VAT,0) From Clients ".
					  " Where Ledger_Number = '".$PClientCode."' ";
		$sub_result1 = selectData($connection, $sub_query1);	
		$txtDtVat = $sub_result1[0];
		$chkDtVat = $sub_result1[0];
	}	


	
	$columnsarray = array("txtLedgerNo"
						,"txtLedgerName"
						,"txtDescription1"
						);

	$columnsarray[] = 'txtDescription2';
			
	$columnsarray[] = 'txtDtManualNo';
			
	$columnsarray[] = 'txtDtQty';
	$columnsarray[] = 'txtDtPrice';
	if ($salesjv_paymentmode==1)
    $columnsarray[] = 'txtDtCost';

	$columnsarray[] = 'txtDtDiscPer';
	$columnsarray[] = 'txtDtTotal';
	$columnsarray[] = 'chkDtVat';
	
	if ($Module_ProjectDt == 1) $columnsarray[] = 'projectcodedt'; 
	if ($Module_CostCenterDt == 1) $columnsarray[] = 'costcentcodedt'; 

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


if ($orderby=='')
	$orderby = 'prqstdt_id';
	
	
	  
	if ($txtSalesOrderJVId != '' )
	{
		$querydt = " Select SalesOrderJVDt.SalesOrderJVDt_ID, SalesOrderJVDt.Ledger_Number, Ledger.Ledger_Name, SalesOrderJVDt_Description, SalesOrderJvDt_Description2, SalesOrderJVDt.Currency_Code, ".
	           " ifNull(SalesOrderJVDt_Quantity,0), Round(ifNull(SalesOrderJVDt_Price,0), ".$DecimalBase."), SalesOrderJVDt_PriceBase1, SalesOrderJVDt_PriceBase2, ".
			   " Round(ifNull(SalesOrderJVDt_DiscountPer,0), ".$DecimalBase."), Round(ifNull(SalesOrderJVDTCalcTotal,0), ".$DecimalBase.") As Total, ".
			   " ifNull(SalesOrderJVDt.SalesOrderJVDt_VAT, 0) As SalesOrderJVDtVAT, SalesOrderJvDt_ManualNo, SalesOrderJVDt.Project_Code, SalesOrderJVDt.Costcenter_Code ".
			   " From Temp_SalesOrderJVDt As SalesOrderJVDt  Left Join Ledger on SalesOrderJVDt.Ledger_Number = Ledger.Ledger_Number ".
			   " Where SalesOrderJVDt.SalesOrderJV_ID = ".$txtSalesOrderJVId.
			   " Order By SalesOrderJVDt.SalesOrderJVDt_Id Asc ";
			   
			 //  echo $querydt;
			   
		$result=mysql_query($querydt,$connection)  or die(mysql_error());
		$totalrows = mysql_num_rows($result);

		$querydt = $querydt." limit ".$startrange.",".$perpage;
		$result=mysql_query($querydt,$connection);	
	}
						
					
					

$TableWidth = 1295;
if ($Module_ProjectDt == 1)    $TableWidth += 160;
if ($Module_CostCenterDt == 1) $TableWidth += 160;

$TableWidthStyle = 'width:'.$TableWidth.'px;';

$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 id='container' style='position: relative;z-index:1;' >";
echo"	<div id='Loader' class=''></div>";
echo"<div id='prequestdtdiv' style='overflow:scroll;width:1100px;height:200px'>";
echo"<table border='0' align='center'   class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0; $TableWidthStyle' cellpadding='0' cellspacing='1'>
		  
		  <col width=25>
		  <col width=130>  
		  <col width=170>	
		  <col width=200>	
		  <col width=200>
		  <col width=100>	
		  <col width=60>
		  <col width=85>	  
		  <col width=85>	  
		  <col width=85>";

echo "	   <col width=85>
		  <col width=35>";
		  
	if ($Module_ProjectDt == 1) {
		echo" <col width=160>";
	}
	if ($Module_CostCenterDt == 1) {
		echo" <col width=160>";
	}		  
		  
	echo" <col width=35> ";	  

				
		echo"<tr height='25px'>";
		echo"  <th  align='left'><span class='style27'>&nbsp;</th>";
		echo"  <th  align='left'>Ledger Number</th>";
		echo"  <th  align='left'>Ledger Name</th>";
		echo"  <th  align='left'>Description</th>";
		echo"  <th  align='left'>Description 2</th>";
		echo"  <th  align='center'>Manual No</th>";
		echo"  <th  align='center'>Currency</th>";
		echo"  <th  align='center'>Quantity</th>";
		echo"  <th  align='center'>Price</th>";
		echo"  <th  align='center'>Disc(%)</th>";
		echo"  <th  align='center'>Total</th>";
		echo"  <th  align='center'>Vat</th>";	

		if ($Module_ProjectDt == 1) {
			echo"  <th align='center'>Project</th>";	
		}
		if ($Module_CostCenterDt == 1) {
			echo"  <th align='center'>Costcenter</th>";	
		}	
		
		echo"  <th  align='center'></th>";		
        echo"</tr>";

	$i=0;
	$j=1;
	
	echo"<input type='hidden' name='SelectedRec' id='SelectedRec' value='$SelectedRec'>
		 <input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value='$SelectedRecColor'>
		 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";

$i=0;		 
while($rowsdt=mysql_fetch_row($result)){
			   
	$txtDtId[$i]           = $rowsdt[0];
	$txtLedgerNo[$i]       = $rowsdt[1];
	$txtLedgerName[$i]	   = $rowsdt[2];
	$txtDescription1[$i]   = $rowsdt[3];
	$txtDescription2[$i]   = $rowsdt[4];
	$txtDtCurr[$i]		   = $rowsdt[5];
	$txtDtQty[$i]          = $rowsdt[6];
	$txtDtPrice[$i] 	   = $rowsdt[7];
	$txtDtCost[$i] 	       = $rowsdt[16];
	$txtDtDiscPer[$i]  	   = $rowsdt[10];
	$txtDtTotal[$i]        = $rowsdt[11];
	$chkDtVat[$i]          = $rowsdt[12];
	$txtDtVat[$i]          = $rowsdt[12];
	$txtDtManualNo[$i]     = $rowsdt[13];
	$txtProjectCodeDt[$i]  = $rowsdt[14];
	$txtCostCentCodeDt[$i] = $rowsdt[15];
	
			
		if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
			
			$KeyDown   = 'onkeydown="return dokeysalesjvdt(event,this,'.$i.',\''.$columnslist.'\',\'SalesOrderJvDt\')"';

			echo "<input type='hidden' name='txtDtId' value='$txtDtId' >";

			echo"<tr id='CurRec$i' bgcolor='$bgcolor' class='$bgcolor table-focus-g1'>";
				
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
							
			echo "	<td align='center' $bgcolorvalign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeleteDetail('".$rowsdt[0]."')\" title='Delete Record'  ></span></td>";
			
			
			echo"<td><input type='text'  class='roundedtext_amortization_medium'   name='txtLedgerNo[$i]' id='txtLedgerNo[$i]' $KeyDown value='$txtLedgerNo[$i]' maxlength='10' size='8'  onchange=setaccountno(this.value,'txtLedgerNo[$i]','txtLedgerName[$i]','salesjv','salesjvdtimg[$i]','salesjvdtimg1[$i]',1) style='font-size:11px; width:90px; height:22px;' >";
			echo"&nbsp;<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Ledger ' id='salesjvdtimg[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onclick=\"showsearchpage('txtLedgerNo','txtLedgerNo[$i]','txtLedgerName[$i]','projectcodedt[$i]','costcentcodedt[$i]','800','500')\"   /></span></label>";
			echo"</td>";
			echo"<td >
			<input type='text'  class='roundedtext_amortization_medium'   $KeyDown   name='txtLedgerName[$i]'  id='txtLedgerName[$i]' onkeyup=\"searchLedger(event)\"  onchange=setaccountno(this.value,'txtLedgerNo[$i]','txtLedgerName[$i]','salesjv','salesjvdtimg[$i]','salesjvdtimg1[$i]',2)   value='".htmlspecialchars($txtLedgerName[$i], ENT_QUOTES)."' style='width:165px;'>
			<img src='img/btnopen.jpg' title=' Select Ledger ' id='salesjvdtimg1[$i]' hidden width='15' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('txtLedgerNo','txtLedgerNo[$i]','txtLedgerName[$i]','800','500')\"   />
			</td>";
					
					
			echo"<td ><span class='style4'><input type='text' $KeyDown   class='roundedtext_amortization_mediumlarge'   name='txtDescription1[$i]' id='txtDescription1[$i]' onchange=\"SetModRecord('ModRec_G1','$i');\" value='".htmlspecialchars($txtDescription1[$i], ENT_QUOTES)."'  style='width:190px;'></span></td>";
	
			echo"<td><input type='text' class='roundedtext_amortization_mediumlarge'  name='txtDescription2[$i]'   $KeyDown   id='txtDescription2[$i]'  class='roundedtext_amortization_m'  onchange=\"SetModRecord('ModRec_G1','$i');\" value='".htmlspecialchars($txtDescription2[$i], ENT_QUOTES)."'  style='width:190px;'></td>";

	
				
			echo"<td><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtDtManualNo[$i]'  style='width:70px;background-image:transparent;text-align:right'  id='txtDtManualNo[$i]'  value='".$txtDtManualNo[$i]."'  onchange=\"SetModRecord('ModRec_G1','$i');\" size=4> 
				<label><img src='img/btnopen.jpg' title='Select Manual No' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(6,$i); '   /></label>
				</td>";
		
			echo"<td><input type='hidden' name='txtDtCurr[$i]' id='txtDtCurr[$i]' value='$txtDtCurr[$i]'><span class='style13'>
				$txtDtCurr[$i] </td>";
			
			
			
			echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='txtDtQty[$i]' id='txtDtQty[$i]' value='".$txtDtQty[$i]."'   onchange=\"SetModRecord('ModRec_G1','$i');\"  onKeyup='CalcDtTotal(1,$DecimalBase,$i);'  > </span></td>";
			echo"<td ><span class='style4'><input type='text'  $KeyDown     class='roundedtext_amortization_medium'    name='txtDtPrice[$i]'   id='txtDtPrice[$i]' value='$txtDtPrice[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'  onchange=\"SetModRecord('ModRec_G1','$i');\"  onKeyup='CalcDtTotal(1,$DecimalBase,$i);' $ModeModifySellPrice></span></td>";
			
			echo"<td ><span class='style4'><input type='text'  $KeyDown     class='roundedtext_amortization_medium'   name='txtDtDiscPer[$i]'  id='txtDtDiscPer[$i]' value='$txtDtDiscPer[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'  onchange=\"SetModRecord('ModRec_G1','$i');\"  onKeyup='CalcDtTotal(1,$DecimalBase,$i);' $DiscountMode></span></td>";
			echo"<td ><span class='style4'><input type='text'  $KeyDown      class='roundedtext_amortization_medium'   name='txtDtTotal[$i]'   id='txtDtTotal[$i]' value='$txtDtTotal[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'  onchange=\"SetModRecord('ModRec_G1','$i');\"  onKeyup='CalcDtTotal(2,$DecimalBase,$i);' $ModeModifySellPrice></span></td>";
			
			
			
			echo"<td ><span class='style4'><input type='hidden' name='txtDtVat[$i]' id='txtDtVat[$i]' value='$txtDtVat[$i]'><input name='chkDtVat[$i]' type='checkbox' id='chkDtVat[$i]' value='1' onclick='SetVatDt($i);SetModRecord(\"ModRec_G1\",\"$i\")'  $KeyDown ";	
			if($chkDtVat[$i]==1 || $txtDtVat[$i] == 1) echo "checked"; echo " /> </span></td></span></td>";
		
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$txtProjectCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:120px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 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>";	
			} else {
				echo"  <input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
			}
			
			echo"<td><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitSalesOrderJvDt[$i]' title='Save' onclick=\"submitSalesOrderJvDt('$txtDtId[$i]','$txtSalesOrderJVId[$i]','$i','e','$Module_RestrictProjCost','$Module_RestrictCost','$FI_SalesCheckSalesman','$filepath')\"></td>";
			echo"<input type='hidden'  name='txtDtId[$i]' id='txtDtId[$i]' value='".$txtDtId[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
}
	
		
	if (empty($warehousecode[$i])) { //echo $_SESSION['prqstdefaultwarehouse'];
				if(!empty($_SESSION['prqstsetupdefaultWareHouse'] ))
					$warehousecode[$i] = $_SESSION['prqstsetupdefaultWareHouse'] ;
				else	
					$warehousecode[$i] = $_SESSION['prqstdefaultwarehouse'];
			}
			
	$k=1;
		$morelines = 1;
		//echo $morelines;
		while ($k <= $morelines) {
			$recno = $i+1;
			if ($k==$morelines)
				$mode = 'i';
			else
				$mode = 'e';			
			
			$KeyDown   = 'onkeydown="return dokeysalesjvdt(event,this,'.$i.',\''.$columnslist.'\',\'SalesOrderJvDt\');"';

			echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1'>";
			
			echo"<td align=center><img src='img/undo-1.png' width=20 height=20 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearsalesjvdt('$i')\"></td>";
						
						
			echo"<td><input type='text'   class='roundedtext_amortization_medium'  name='txtLedgerNo[$i]' id='txtLedgerNo[$i]' $KeyDown value='$txtLedgerNo[$i]' maxlength='10' size='8'   onchange=\"setaccountno(this.value,'txtLedgerNo[$i]','txtLedgerName[$i]','','salesjvdtimg[$i]','salesjvdtimg1[$i]','1'); SetRecordGridDefaults('$i');\"  style='font-size:11px; width:90px; height:22px;' >";
			echo"&nbsp;<label><span class='style11'><img src='img/btnopen.jpg' title=' Select Ledger ' id='salesjvdtimg[$i]' width='15' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onclick=\"showsearchpage('txtLedgerNo','txtLedgerNo[$i]','txtLedgerName[$i]','projectcodedt[$i]','costcentcodedt[$i]','800','500')\"  /></span></label>";
			echo"</td>";
			echo"<td ><input type='text'   class='roundedtext_amortization_medium'   $KeyDown   name='txtLedgerName[$i]'   id='txtLedgerName[$i]'    onchange=setaccountno(this.value,'txtLedgerNo[$i]','txtLedgerName[$i]','salesjv','salesjvdtimg[$i]','salesjvdtimg1[$i]',2)   value='".htmlspecialchars($txtLedgerName[$i], ENT_QUOTES)."' style='width:165px;'>
			<img src='img/btnopen.jpg' title=' Select Ledger ' id='salesjvdtimg1[$i]' hidden width='15' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('txtLedgerNo','txtLedgerNo[$i]','txtLedgerName[$i]','800','500')\"   />
			</td>";
					
					
				echo"<td ><span class='style4'><input type='text'     $KeyDown   class='roundedtext_amortization_mediumlarge'   name='txtDescription1[$i]' id='txtDescription1[$i]'  onchange=\"SetModRecord('ModRec_G1','$i');\" value='".htmlspecialchars($txtDescription1[$i], ENT_QUOTES)."' style='width:190px;'></span></td>";
	
				echo"<td><input type='text'  name='txtDescription2[$i]'   $KeyDown   id='txtDescription2[$i]'  class='roundedtext_amortization_mediumlarge'    onchange=\"SetModRecord('ModRec_G1','$i');\" value='".htmlspecialchars($txtDescription1[$i], ENT_QUOTES)."'  style='width:190px;'></td>";

	
				
				echo"<td><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtDtManualNo[$i]'  style='width:70px;background-image:transparent;text-align:right'  id='txtDtManualNo[$i]'  value='".$txtDtManualNo[$i]."'  onchange=\"SetModRecord('ModRec_G1','$i');\" size=4> 
				<label><img src='img/btnopen.jpg' title='Select Manual No' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(6,$i); '  /></label>
				</td>";
		
				echo"<td><input type='hidden' name='txtDtCurr[$i]' id='txtDtCurr[$i]' value='$txtDtCurr[$i]'><span class='style13'>
				$txtDtCurr[$i] </td>";
			
			
			
			echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='txtDtQty[$i]' id='txtDtQty[$i]' value='".$txtDtQty[$i]."'  onKeyup='CalcDtTotal(1,$DecimalBase,$i);'   onchange=\"SetModRecord('ModRec_G1','$i');\"  > </span></td>";
			echo"<td ><span class='style4'><input type='text'  $KeyDown     class='roundedtext_amortization_medium'    name='txtDtPrice[$i]' id='txtDtPrice[$i]' value='$txtDtPrice[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'   onchange=\"SetModRecord('ModRec_G1','$i');\" onKeyup='CalcDtTotal(1,$DecimalBase,$i);' $ModeModifySellPrice></span></td>";
		
			echo"<td ><span class='style4'><input type='text'  $KeyDown    class='roundedtext_amortization_medium'    name='txtDtDiscPer[$i]'   id='txtDtDiscPer[$i]' value='$txtDtDiscPer[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'   onchange=\"SetModRecord('ModRec_G1','$i');\" onKeyup='CalcDtTotal(1,$DecimalBase,$i);' $DiscountMode></span></td>";
			echo"<td ><span class='style4'><input type='text'  $KeyDown    class='roundedtext_amortization_medium'     name='txtDtTotal[$i]'   id='txtDtTotal[$i]' value='$txtDtTotal[$i]' style='text-align:right; font-size:12px; width:70px; height=18px;'  onchange=\"SetModRecord('ModRec_G1','$i');\"  onKeyup='CalcDtTotal(2,$DecimalBase,$i);'></span></td>";
			
			
			
			echo"<td ><span class='style4'><input type='hidden' name='txtDtVat[$i]'  id='txtDtVat[$i]' value='$txtDtVat[$i]'><input name='chkDtVat[$i]' type='checkbox' id='chkDtVat[$i]' value='1' onclick='SetVatDt($i);' ".$KeyDown." ";	
			if($chkDtVat[$i]==1 || $txtDtVat[$i] == 1) echo "checked"; echo " /> </span></td></span></td>";
		
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$txtProjectCodeDt[$i]."' class='roundedtext_amortization_medium' style='width:120px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 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>";	
			} else {
				echo"  <input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
			}
			
			echo"<td><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitSalesOrderJvDt[$i]' title='Save' onclick=\"submitSalesOrderJvDt('$txtDtId[$i]','$txtSalesJVId[$i]','$i','i','$Module_RestrictProjCost','$Module_RestrictCost','$FI_SalesCheckSalesman','$filepath')\"></td>";
			echo"<input type='hidden'  name='txtDtId[$i]' id='txtDtId[$i]' value='".$txtDtId[$i]."' >";
			echo"</tr>";
			
		$i+=1;
		$k+=1;
		}	
	
	echo"</table></div></div>";
	

	

}


?>