<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
$function_filter[]=$_REQUEST['site'];
$function_filter[]=$_REQUEST['store'];
$data_date=explode('/',$_REQUEST['date']);
echo $date55=$data_date[2].'-'.$data_date[1].'-'.$data_date[0];
$date22= strtotime(date("Y-m-d", strtotime($date55)) . " +0 day");
$date1= date("Y-m-d",$date22);
$function_filter[]=$date1;
?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<h2 align="center">&nbsp;</h2>
<form name="form1" action="" method="post">
  <div style="overflow: scroll; height: 300px" id="ItemListDiv">
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
<tr>
<th width="5%"><strong>Select</strong></th>
<th width="20%"><strong>Charge Code</strong></th>
<th width="20%"><strong>Charge Name</strong></th>
</tr>



<?php 
 $sql=DB_query("Select * from dbl_dealer_charge_master  ",$db); ?>
<?php
$i=0;
if(DB_num_rows($sql)>0)
{
while($myrow=DB_fetch_array($sql))
{ 	
$parameter=$myrow['id'];
?>
<tr bgcolor="#CCCCCC">
<td width="9%"><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['charge_code'];?>','<?php echo  $myrow['charge_name'];?>','<?php echo $myrow['taxrate'];?>','<?php echo $i;?>')"/></td>
<td width="20%"><strong><?php echo $myrow['charge_code'];?></strong></td>
<td width="20%"><?php echo  $myrow['charge_name'];?></td>

</tr>
<?php $i++;} }?>

</table>
</div>
</form>

<script language="javascript" type="text/javascript">
function getItemsList(id,code,shade,excise,ctr)
{

var data= addRow('dataTable1')	
var dup='empty';
	var itemcount=parseInt(window.opener.document.getElementById('hiditemcount1').value)+1;
	var edit_cnt=window.opener.document.getElementById('edit_cnt1').value;
	if(edit_cnt=='')
		{var counter=1;} 
	else if(edit_cnt>itemcount)
		{var counter=edit_cnt;
		var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	
	if(document.getElementById("row_id_"+ctr).checked==true){
		if(window.opener.document.getElementById('chargeid').value=='')
		{
			if(edit_cnt==''){var counter=0;}
			for(var j=0; j<counter; j++)
			{
				if(window.opener.document.getElementById('itemid1_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
			if(dup=='empty'){
	window.opener.document.getElementById('chargeid').value = id;
	window.opener.document.getElementById('chargecode').value = code;
	window.opener.document.getElementById('chargename').value = shade;
	window.opener.document.getElementById("chargeper").value=excise;
	var data= addRow('dataTable');	

	//window.opener.document.getElementById('mrpper').value = mrprate;
			}
		}
		else
		{
			for(var i=counter; i<=itemcount; i++)
			{	if(edit_cnt==''){var counter=0;}
				for(var j=0; j<counter; j++)
				{
					if(window.opener.document.getElementById('itemid1_'+j).value==id)
					{
						alert("Duplicate Value"); 
						document.getElementById("row_id_"+ctr).checked=false;
						var dup = "dup";
						break;
					}
				}
				if(window.opener.document.getElementById('chargeid').value==id)
					{
						alert("Duplicate Value");
						document.getElementById("row_id_"+ctr).checked=false;
						break;
					}
				if(window.opener.document.getElementById('chargeid_'+i).value==id)
					{
						alert("Duplicate Value"); 
						document.getElementById("row_id_"+ctr).checked=false;
						break;
					}
				if(dup=='empty'){	
							
					if(window.opener.document.getElementById('chargeid_'+i).value=='')
					{
			window.opener.document.getElementById('chargeid_'+i).value = id;
	window.opener.document.getElementById('chargecode_'+i).value = code;
	window.opener.document.getElementById('chargename_'+i).value = shade;
	window.opener.document.getElementById("chargeper_"+i).value=excise;
	var data= addRow('dataTable');	

	//window.opener.document.getElementById('mrpper_'+i).value = mrprate;	
	break;
						break;
					}
					else
					{
						continue;
					}
				}
			}
		}
	}
	else
	{
		if(window.opener.document.getElementById('chargeid').value==document.getElementById("row_id_"+ctr).value)
		{
	window.opener.document.getElementById('chargeid').value = '';
	window.opener.document.getElementById('chargecode').value = '';
	window.opener.document.getElementById('chargename').value = '';
	window.opener.document.getElementById("chargeper").value='';
	//var data1=deleteRowOrder('dataTable',0);
	
		}
		else
		{
			for(var i=counter; i<itemcount; i++)
			{
				if(window.opener.document.getElementById('chargeid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
     window.opener.document.getElementById('chargeid_'+i).value = '';
	window.opener.document.getElementById('chargecode_'+i).value = '';
	window.opener.document.getElementById('chargename_'+i).value = '';
	window.opener.document.getElementById("chargeper_"+i).value='';
	//var data1=deleteRowOrder('dataTable',i);
	
				}
			}
		}
	}
	
	
	
}

function addRow(tableID) 
{
	
	var table = window.opener.document.getElementById(tableID);
	var rowCount = table.rows.length;	
	var row = table.insertRow(rowCount);
	window.opener.document.getElementById("hiditemcount1").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
}
function deleteRowOrder(tableID,k) 
{
	try 
	{
	var table = window.opener.document.getElementById(tableID);
	var rowCount = table.rows.length;
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = k;
	if(chkbox==0)
	{
	}
	else 
	{
	if(rowCount <= 1) 
	{
	alert("Cannot delete all the rows.");
	break;
	}
	table.deleteRow(chkbox);
	rowCount--;
	i--;
	}
	}
	window.opener.document.getElementById("hiditemcount1").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
	alert(e);
	}
}





</script>
