<?php 
include('includes/AccountGroupMaster_Class.php');
$table='accountledger';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$url="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=Account/LedgerDayBook".$url;
$msgErr='';
$status=true;
if($_REQUEST['Save'])
{
 $flag=0;
	if(empty($_REQUEST['AccountName']))
	{
		$flag=1;
 	   $msgErr[]='Please Enter AccountName';
	   $status=false;
	}
	elseif(empty($_REQUEST['chkdtl']))
{
$flag=1;
 $msgErr[]='Please Select Branch';
	   $status=false;
}
	 
	 /*if(empty($_REQUEST['UnderGroup']))
	{
 	   $msgErr[]='Please Enter UnderGroup';
	   $status=false;
	}*/
	 
	 
	 	$condition='AccountName="'.$_REQUEST['AccountName'].'"';
		$allready=$s->GetRecord($table,  $condition);
		$row=DB_query($allready,$db);
		if(DB_num_rows($row)>0 && $action!='Edit')
		{
			 $msgErr[]='Identification and AccountName Already Exist.Please Try Again...';
			 $status=false;
		}
		
} 

//************************Delete*********************************************** 
if( $action=='del')
{
	 /*
	$condition="CaseBankId='".$_REQUEST['AccountsID']."'";
  	$r=$s->GetRecordById('cashbankvoucher_master',$condition);
	$numrows = DB_num_rows($r);
	if($numrows>0)
	{
	$s->pageLocation($targetpage.'&daction=1');
	}else
	{*/
 
			$condition="AccountsID='".$_REQUEST['AccountsID']."'";
			$s->DeleteRecord($table,$condition);
			$s->pageLocation($targetpage.'&daction=Deleted');
			//}
	//	}
}
 
  
//************************Edit*********************************************** 

if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
	unset($_SESSION['daction']);
 	$condition="AccountsID='".$_REQUEST['AccountsID']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		



$AccountName=$RData['AccountName'];
$MaintainSubLed=$RData['MaintainSubLed'];
$AccountsType=$RData['AccountsType'];
$openingBalance=$RData['openingBalance'];
$openingtype=$RData['openingtype'];
$openingdate=ConvertSqlDate($RData['openingdate']);
$BankName=$RData['BankName'];
$BankBranch=$RData['BankBranch'];
$BankAccountsType=$RData['BankAccountsType'];
$BankRateofInt=$RData['BankRateofInt'];
$LinkWithEmp=$RData['LinkWithEmp'];
$MultiCurrency=$RData['MultiCurrency'];
$CurrencyId=$RData['CurrencyId'];
$GroupId=$RData['GroupId'];
$NatureId=$RData['NatureId'];
$MGID=$RData['MGID'];
$Inactive=$RData['Inactive'];
$UnderGroup=$RData['UnderGroup'];
 $ledgertype=$RData['ledgertype'];
$Identification=$RData['Identification'];
$SubLedger=$RData['SubLedger'];
$AnalysesCode=$RData['AnalysesCode'];
$GLBaseCurrency=$RData['GLBaseCurrency'];
}
else
{
	$openingdate=ConvertSqlDate($_SESSION['financialYrStart']);
} 

$sql_get=DB_query("select * from accountledger_dtls where accountledger_id='".$_REQUEST['AccountsID']."' and openingdate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ",$db);
while($row1=DB_fetch_array($sql_get))
{
 $data_row[$row1['site']][site]=$row1['site'];
 $data_row[$row1['site']][id]=$row1['id'];
 $data_row[$row1['site']][openingtype]=$row1['openingtype'];
 $data_row[$row1['site']][opening_bal]=$row1['openingBalance'];
 $data_row[$row1['site']][opening_dat]=$row1['openingdate'];

}


if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
 
$data['AccountName']=$_REQUEST['AccountName'];
$data['MaintainSubLed']=$_REQUEST['MaintainSubLed'];
$data['AccountsType']=$_REQUEST['AccountsType'];
$data['BankName']=$_REQUEST['BankName'];
//$data['openingBalance']=$_REQUEST['openingBalance'];
//$data['openingdate']=FormatDateForSQL($_REQUEST['openingdate']); 
//$data['openingtype']=$_REQUEST['openingtype'];
$data['BankBranch']=$_REQUEST['BankBranch'];
$data['BankAccountsType']=$_REQUEST['BankAccountsType'];
$data['BankRateofInt']=$_REQUEST['BankRateofInt'];
$data['LinkWithEmp']=$_REQUEST['LinkWithEmp'];
$data['MultiCurrency']=$_REQUEST['MultiCurrency'];
$data['CurrencyId']=$_REQUEST['CurrencyId'];
$data['GroupId']=$_REQUEST['GroupId'];
$data['NatureId']=$_REQUEST['NatureId'];
$data['MGID']=$_REQUEST['MGID'];
$data['Inactive']=$_REQUEST['Inactive'];
$data['UnderGroup']=$_REQUEST['UnderGroup'];
if($_REQUEST['Ltype']!='vendor'){
$data['ledgertype']=$_REQUEST['ledgertype'];}
$data['Identification']=$_REQUEST['Identification'];
$data['SubLedger']=$_REQUEST['SubLedger'];
$data['AnalysesCode']=$_REQUEST['AnalysesCode'];
$data['GLBaseCurrency']=$_REQUEST['GLBaseCurrency'];
//echo "<pre>";print_r($data); exit;
$cond="AccountsID='".$_REQUEST['AccountsID']."'";
 	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);

	 $Lastreq_id=$_REQUEST['AccountsID'];
DB_query("delete from accountledger_dtls where accountledger_id='".$Lastreq_id."' and openingdate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ",$db);
        for($i=0;$i<count($_REQUEST['chkdtl']);$i++)
	              {
	              	if(isset($_REQUEST['chkdtl'][$i]))
	              	{
	              		$site=$_REQUEST['chkdtl'][$i];
			        if($_REQUEST['openingBalance'][$site]!='')
			        {
			        	$data_dtls['accountledger_id']=$Lastreq_id;
				        $data_dtls['site']=$site;
				        $data_dtls['openingtype']=$_REQUEST['openingtype'][$site];
				        $data_dtls['openingBalance']=$_REQUEST['openingBalance'][$site];
				        $data_dtls['openingdate']=FormatDateForSQL($_REQUEST['openingdate'][$site]);
				        //$cond1="id='".$_REQUEST['accountledger_dtls_id'][$site]."'";
				        //$s->RecordEdit('accountledger_dtls', $data_dtls,$cond1);
				        $s->RecordInsert('accountledger_dtls', $data_dtls);		
			        }
			      /*  else if($_REQUEST['openingBalance'][$site]!='' && $_REQUEST['accountledger_dtls_id'][$site]=='')
			        {
				   	$data_dtls['accountledger_id']=$Lastreq_id;
			        $data_dtls['site']=$site;
			        $data_dtls['openingtype']=$_REQUEST['openingtype'][$site];
			        $data_dtls['openingBalance']=$_REQUEST['openingBalance'][$site];
			        $data_dtls['openingdate']=FormatDateForSQL($_REQUEST['openingdate'][$site]);
			        $s->RecordInsert('accountledger_dtls', $data_dtls);	 
			        }*/
			    }
	   }
	if(!$row)
	{
	   die('Error'.DB_error());
	}
	 
 $s->pageLocation($targetpage.'&daction=Updated');
 unset($data_row);
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status && $action=='')
{
	$data['AccountName']=$_REQUEST['AccountName'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];

	$data['MaintainSubLed']=$_REQUEST['MaintainSubLed'];
	$data['AccountsType']=$_REQUEST['AccountsType'];
	//$data['openingBalance']=$_REQUEST['openingBalance'];
	//$data['openingdate']=FormatDateForSQL($_REQUEST['openingdate']);  
	//$data['openingtype']=$_REQUEST['openingtype'];
	$data['BankName']=$_REQUEST['BankName'];
	$data['BankBranch']=$_REQUEST['BankBranch'];
	$data['BankAccountsType']=$_REQUEST['BankAccountsType'];
	$data['BankRateofInt']=$_REQUEST['BankRateofInt'];
	$data['LinkWithEmp']=$_REQUEST['LinkWithEmp'];
	$data['MultiCurrency']=$_REQUEST['MultiCurrency'];
	$data['CurrencyId']=$_REQUEST['CurrencyId'];
	$data['GroupId']=$_REQUEST['GroupId'];
	$data['NatureId']=$_REQUEST['NatureId'];
	$data['MGID']=$_REQUEST['MGID'];
	$data['Inactive']=$_REQUEST['Inactive'];
	$data['UnderGroup']=$_REQUEST['UnderGroup'];
	$data['ledgertype']=$_REQUEST['ledgertype'];
	$data['Identification']=$_REQUEST['Identification'];
	$data['SubLedger']=$_REQUEST['SubLedger'];
	$data['AnalysesCode']=$_REQUEST['AnalysesCode'];
	$data['GLBaseCurrency']=$_REQUEST['GLBaseCurrency'];

  
 	$row= $s->RecordInsert($table, $data);	 
    $Lastreq_id=DB_Last_Insert_ID($db,$table,$ErrMsg);

	  for($i=0;$i<count($_REQUEST['chkdtl']);$i++)
	              {
	          if(isset($_REQUEST['chkdtl'][$i]))
	              	{
	              		$site=$_REQUEST['chkdtl'][$i];
				        if($_REQUEST['openingBalance'][$site]!='')
				        { 
					   	$data_dtls['accountledger_id']=$Lastreq_id;
				        $data_dtls['site']=$site;
				        $data_dtls['openingtype']=$_REQUEST['openingtype'][$site];
				        $data_dtls['openingBalance']=$_REQUEST['openingBalance'][$site];
				        $data_dtls['openingdate']=FormatDateForSQL($_REQUEST['openingdate'][$site]);
				        $s->RecordInsert('accountledger_dtls', $data_dtls);	 
				        }
				    }
	   }



	if(!$row)
	{
	   die('Error'.DB_error());
	}
	 
 $s->pageLocation($targetpage.'&daction=Inserted');
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<!-- <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td ><div align="right"><A HREF="javascript:history.go(-1)"> [Go Back]</A> </div></td>
  </tr>
</table> -->

<form action="" method="post">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?> </h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
  <?php if(isset($_REQUEST['daction']))
  {?>
    <tr>
     <td colspan="3" ><div class="success"><?php 
	 if($_REQUEST['daction']!=1)
	 echo "Record ".$_REQUEST['daction']." Successfully";
	 elseif($_REQUEST['daction']==1)
	 	 echo "Can't Delete This Record because AccountName Attatch with CashBankVoucher Master table ";
 	 elseif($_REQUEST['daction']==2)		 
	 echo "Can't Delete This Record. First Delete it's Parent Record   ";

 	 ?></div></td>
  </tr>
  <?php 
   }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
    <td colspan="3" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
 	if($flag)
 	{
		echo  $msgErr[$kp].'<br>';
 	}
 	
 }
  ?></div></td>
  </tr>
   <?php }?>
 <tr class="row1">
  <?php if($UnderGroup=='0'){$r='readonly';$d='disabled';}else{$r='';$d='';}?>
    <td width="10%" align="right">Account Name</td>
    <td><input name="AccountName" type="text" size="27"  value="<?php echo $AccountName;?>" <?php echo $r;?>></td>
    <td width="10%" align="right">Under Group </td>
    <td width="17%"><select name="UnderGroup" <?php echo $d;?>>
	
	<?php   
	$accountGroup=DB_query("Select * from accountgroupmaster where Type='G' order by GroupName ASC",$db);
	while($accountResult=DB_fetch_array($accountGroup))
	{?>
		<option value="<?php echo $accountResult['GroupId'];?>" <?php if($UnderGroup==$accountResult['GroupId']) echo "selected";?>><?php echo $accountResult['GroupName'];?></option>
	<?php 	
	}
	

	//$AccountMaster->AccountGroup($UnderGroup,'UnderGroup'); ?> 	
 </select></td>
    <td width="10%" align="right">Type</td>
    <td width="17%"><select name="ledgertype" id="ledgertype" <?php echo $d;?>>
	<option value="">Select</option>
	<option value="client" <?php if($ledgertype=='client')echo "selected";?>>Customer</option>
	<option value="freight" <?php if($ledgertype=='freight')echo "selected";?>>Freight</option>
	<option value="surcharge" <?php if($ledgertype=='surcharge')echo "selected";?>>Surcharge</option>
	<option value="pckcharge" <?php if($ledgertype=='pckcharge')echo "selected";?>>Packaging Charges</option>
	<option value="addcharge" <?php if($ledgertype=='addcharge')echo "selected";?>>Other Charges</option>
	<option value="round" <?php  if($ledgertype=='round') echo "selected";?>>Round Off</option>
	<option value="bank" <?php if($ledgertype=='bank') echo "selected";?>>Bank</option>
	<option value="opening_stock" <?php if($ledgertype=='opening_stock')echo "selected";?>>Opening Stock</option>
	<option value="closing_stock" <?php if($ledgertype=='closing_stock')echo "selected";?>>Closing Stock</option>
	<option value="p&l" <?php if($ledgertype=='p&l')echo "selected";?>>Profit &amp; Loss</option>
	<option value="loan" <?php if($ledgertype=='loan')echo "selected";?>>Loan</option>
	<option value="Adv" <?php if($ledgertype=='Adv')echo "selected";?>>Advance</option>
	<option value="cash" <?php if($ledgertype=='cash')echo "selected";?>>Cash</option>
	<option value="sales" <?php if($ledgertype=='sales')echo "selected";?>>Sales</option>
	<option value="tds" <?php if($ledgertype=='tds')echo "selected";?>>TDS</option>
	<option value="expence" <?php if($ledgertype=='expence')echo "selected";?>>Expence</option>
	<option value="tax" <?php if($ledgertype=='tax')echo "selected";?>>Tax</option>
	<option value="lib" <?php if($ledgertype=='lib')echo "selected";?>>Liabilities</option>
	<option value="income" <?php if($ledgertype=='income')echo "selected";?>>Income</option>
	<option value="purchase" <?php if($ledgertype=='purchase')echo "selected";?>>Purchase</option>
	<option value="insurance" <?php if($ledgertype=='insurance')echo "selected";?>>Insurance</option>
	<option value="Asset" <?php if($ledgertype=='Asset')echo "selected";?>>Asset</option>
	<option value="Commission" <?php if($ledgertype=='Commission')echo "selected";?>>Commission/Share</option>
	</select><input type="hidden" name="Ltype" value="<?php echo $ledgertype;?>" />
	</td>
	<td width="10%" align="right">Inactive</td>
    <td width="7%"><input name="Inactive" type="checkbox" value="1" <?php  echo ($Inactive==1?"checked":"")?> <?php echo $d;?>/></td>
  </tr>
</table>
<br>
<h3>Opening Details</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
  	<th width="6%">Select</th>
  	<th>Site</th>
  	<th width="12%">Opening Balance</th>
  	<th width="9%">Opening Date</th>
    <th width="12%" class="text-center">DR/CR</th>	 
  </tr>
  <?php
  $i=0;
   $sql=DB_query("select loccode,locationname from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' ",$db);
   while($row1=DB_fetch_array($sql))
   {9
   ?>
   <tr>   
   	<td><input type="checkbox" name="chkdtl[]" id="chk_<?php echo $i; ?>" value="<?php echo $row1['loccode'];?>" onclick="searchdata(<?php echo $i; ?>)"
    <?php if($data_row[$row1['loccode']][site]==$row1['loccode']) { $dis=""; ?> checked <?php } else { $dis="readonly"; }?>	></td>
    <td ><?php echo $row1['locationname']; ?><input name="site[]" type="hidden" size="27"  value="<?php echo $row1['loccode'];?>">
     <input type="hidden" name="accountledger_dtls_id[<?php echo $row1['loccode'];?>]" value="<?php echo  $data_row[$row1['loccode']][id]; ?>"></td>
    <td style="text-align:center"><input name="openingBalance[<?php echo $row1['loccode'];?>]" id="openingBalance_<?php echo $i; ?>" type="text" size="27"  value="<?php echo  $data_row[$row1['loccode']][opening_bal]; ?>" <?php echo $dis; ?> ></td> 
    <td style="text-align:center"><input name="openingdate[<?php echo $row1['loccode'];?>]" id="openingdate_<?php echo $i; ?>"  type="text" size="27"  
    	value="<?php if($data_row[$row1['loccode']][opening_dat]) echo  ConvertSQLDate($data_row[$row1['loccode']][opening_dat]); else echo ConvertSQLDate($_SESSION['financialYrStart']); ?>" class='datepicker' <?php echo $dis; ?> ></td> 
    <td style="text-align:center"><input name="openingtype[<?php echo $row1['loccode'];?>]" id="opp_<?php echo $i; ?>" type="radio" size="27"  value="DR" 
    	<?php  echo ($data_row[$row1['loccode']][openingtype]=='DR'?'checked':'')?>  >DR	
	<input name="openingtype[<?php echo $row1['loccode'];?>]" type="radio" size="27" id="opp_<?php echo $i; ?>" value="CR"
	 <?php  echo ($data_row[$row1['loccode']][openingtype]=='CR'?'checked':'')?>  >CR </td>   
  </tr>
  <?php $i++; } ?>
</table>
<p align="center"><?php if($_REQUEST['action'] == 'Edit') {?>
<input type="submit" name="Save" class="search" value="Edit" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>/><?php } else {?>
<input type="submit" name="Save" value="Save" class="search" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>/></p><?php } ?>
</form>
<form action="" method="Post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="13%" align="right">Search Filter</td>
	<td width="20%"><select name='searchamount' >
	<option value="">Select </option>
	<option value="amount">Having Amount</option>
	<option value="notamount">Blank</option>	
	</select></td>
	<td width="13%" align="right">Under Group</td>
	<td width="20%"><select name="account_group" id="account_group">
	 <option value="0">Select</option>
	 <?php
	 $row_ac=DB_query("select * from accountgroupmaster where Type='G' order by GroupName ASC",$db);
	while($row_account=DB_fetch_array($row_ac))
	{
		$g='';
		if($row_account['GroupId']==$_REQUEST['account_group'])
			$g="selected";
	?>
	<option value="<?php echo $row_account['GroupId']; ?>"<?php echo $g; ?>><?php echo $row_account['GroupName']; ?></option>
	<?php }  ?>
	</select></td>
	<td width="13%" align="right">Account Name</td>
	<td><input type="text" name="account_name_search" value="<?php echo $_REQUEST['account_name_search']; ?>"></td>
</tr>
<tr class="row1">
	<td colspan="6" align="center"><input type="submit" name="Search" value="Search" class="search" /></td>
</tr>
</table>
</form>
 <br>
 <div style="overflow:scroll; height:300px">
   <table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
   	<tr>
    	<th width="4%">S. No.</td>
	  	<th>Account Name</td>
	 	<!-- <th>AccountsType</td>-->
	    <th width="20%">Under Group</td>
	    <th width="15%">Opening Balance</td>
	   	<!-- <th width="15%">Opening Date</td>-->
      	<th width="10%">Type</td>
  <?php if($_SESSION['frmEdit']=='1'){?><th width="6%" class="text-center">Edit</td><?php } ?>
   <?php if($_SESSION['frmDelete']=='1'){?><th width="6%" class="text-center">Delete</td><?php } ?>
  </tr>
   <?php 
   if(isset($_POST['Search']))
   {
    $filter=array();


   	if($_REQUEST['searchamount']=='amount')
	{
	$filter[]="openingBalance!=''";	
	}
	else if($_REQUEST['searchamount']=='notamount')
	{
	$filter[]="(openingBalance='' ||   openingBalance is null)";
	}
	if($_REQUEST['account_group']!='0')
	{
	$filter[]="UnderGroup ='".$_REQUEST['account_group']."'";	
	}
	if($_REQUEST['account_name_search']!='')
	{
	$filter[]="AccountName like '%".$_REQUEST['account_name_search']."%'";	
	}
   }
   if(!empty($filter))
   {
   	$filter1=implode(" and ",$filter);
   	$fll="";
   }
   else
   {
  	 $filter1="1=1";
   	$fll="limit 0,20";
   }
   //$GetRecord = "Select * from $table where ".$filter1." Order By AccountsID ASC ".$fll."";

     $GetRecord = "Select * from $table where ".$filter1." Order By AccountName ASC";
 
   //echo $GetRecord;
   // $GetRecord = "Select * from $table where CompanyId='".$_SESSION['ACGCompanyId']."' Order By UnderGroup ASC limit 0,20";

   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='3'>--No Record--</td>";
   $count2=0;
   while($RowData = DB_fetch_array($ResultData))
   {
   	$dramount='';
   	$cramount='';
   	$dramt='';
   	$cramt='';
   	$totalamt='';
    $sql_dtl=DB_query("select openingBalance,openingtype from accountledger_dtls where accountledger_id='".$RowData['AccountsID']."' and openingdate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'",$db);
    while($ro1=DB_fetch_array($sql_dtl))
    {
    	if($ro1['openingtype']=='DR')
    	$dramount[]=$ro1['openingBalance'];	
        if($ro1['openingtype']=='CR')
        $cramount[]=$ro1['openingBalance'];		
    }
    if(!empty($dramount)) $dramt=array_sum($dramount); else $dramt=0;
    if(!empty($cramount)) $cramt=array_sum($cramount); else $cramt=0;
    if($dramt>$cramt)
    $totalamt=($dramt-$cramt)."(DR)";	
    if($dramt<$cramt)
    $totalamt=($cramt-$dramt)."(CR)";

   		$checkVoucher=DB_query("Select * from account_book_details where ledgerid='".$RowData['AccountsID']."'",$db);
		$count1=DB_num_rows($checkVoucher);		
   		if($RowData['openingBalance']!='' && $RowData['openingBalance']!='0.00'){$count2=1;}else{$count2=0;}
   ?>
   <tr>
   	<td><?php echo $i; ?></td>
    <td><?php echo $RowData['AccountName']; //echo "<br />count2===".$count2."<br />numrows===".$count1;?></td>
	<!-- <td><?php //echo $RowData['AccountsType']; ?>	  </td>-->
	<td><?php 
	   if($RowData['UnderGroup']=='0'){echo "Primary";}else{
	   echo $s->getField( 'accountgroupmaster','GroupId',$RowData['UnderGroup'],'GroupName');}
	  ?></td>
	<td><?php  echo  $totalamt; ?>	</td>
	 <!-- <td width="16%"><?php  echo ConvertSQLDate($RowData['openingdate']);?></td>-->
	<td><?php if($RowData['ledgertype']=='client')echo "Customer"; else {echo $RowData['ledgertype']; } ?></td>
   
   <?php if($_SESSION['frmEdit']=='1'){?><td class="text-center">
   
   <?php if($RowData['ledgertype']=='excisetax' || $RowData['ledgertype']=='vendor' || $RowData['ledgertype']=='salestax' || $RowData['ledgertype']=='servicetax' || $RowData['ledgertype']=='client')
   {?>
   	<a href="" onclick="return inValid();"><img src="images/icon-edit.png"  width="15" title="Edit" /></a>
   <?php 	
   }else{
   ?>
  <a href="<?php  echo $targetpage;?>&action=Edit&AccountsID=<?php echo $RowData['AccountsID'].$url; ?>"><img src="images/icon-edit.png" width="15" title="Edit" /></a>
   <?php } ?>
   </td><?php } ?>
	<?php if($_SESSION['frmDelete']=='1')
	{
	?>
	<td class="text-center">
	<?php
           if($_SESSION['UserType']=='SuperAdmin') {
           	?>
           	<a href="<?php  echo $targetpage;?>&action=del&AccountsID=<?php echo $RowData['AccountsID'].$url; ?>" onclick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="15" title="Delete" /></a>
<?php } else if($RowData['UnderGroup']=='0'){echo "Not allowed";} 
	else
	{
	if($count1>0 || $count2==1){echo "No Permission";}else{?>
	<a href="<?php  echo $targetpage;?>&action=del&AccountsID=<?php echo $RowData['AccountsID'].$url; ?>" onclick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="15" title="Delete" /></a>
	<?php
   }
   }?></td>
	<?php } ?>
  </tr>
	<?php $i++; } ?>  
</table>
</div>
</div>
</div>
<script type="text/javascript" language="javascript">
function inValid()
{
	alert('Please edit the details of this ledger from its master');
	return false;
}
function searchdata(str)
{
  if(document.getElementById("chk_"+str).checked)
  {

  	document.getElementById("openingBalance_"+str).removeAttribute("readonly");

  	document.getElementById("openingdate_"+str).removeAttribute("readonly");
  }
  else  
  {
  	document.getElementById("openingBalance_"+str).setAttribute("readonly", "true");
  	document.getElementById("openingdate_"+str).setAttribute("readonly", "true");
  }


}

</script>
