<?php
if(isset($_POST['Save']))
{

for($t=0;$t<count($_REQUEST['code']);$t++)
{
 if($_REQUEST['code'][$t]!='')
 {
   $data['code']=$_REQUEST['code'][$t];
   $data['category_name']=$_REQUEST['category_name'][$t];
   $data['parent_id']=$_REQUEST['parent_category'][$t];
   $data['CompanyId']=$_SESSION['ACGCompanyId'];
   $data['created_date']=date('Y-m-d');
   $data['created_by']=$_SESSION['UserID'];
   $s->RecordInsert('account_cost_category',$data);
 }
}

$s->pageLocation("index.php?route=cost_category_index".$rurl);
}

?>

<link href="css/new_mxerp.css" rel="stylesheet" />
<div class="body_contain">
<div class="tab_div">
<form method="post" action="" name="frm">
<h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></h1>
<div id="companyact">
  <table width="100%" cellspacing="0" cellpadding="3" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
  <tbody>
  <tr>
    <th width="5%">S. No.</th>
    <th width="20%">Code </th>
    <th>Category</th>
    <th width="20%">Parent Category</th>
  </tr>
   <?php //  $AccountMaster->AccountGroup($MainGroupId,'MainGroupId'); 
              //$pcode= $MainGroupId;
      function CategoryShow($pcode, $PcateID, $dashVal)
      {
          global $db;
        $dashVal = $dashVal . "-";
         echo $sqlCate = "select * from account_cost_category where  parent_id = '".$PcateID."' ";
        $rsCate  = DB_query($sqlCate,$db);  
        if(DB_num_rows($rsCate)>0)
        {
          while($rowCate = DB_fetch_array($rsCate))
          {
            $sqlCateSel = "select * from account_cost_category where id  =".$rowCate['parent_id']." ";
            $rsCateSel  = DB_query($sqlCateSel,$db);
            $px='';
             if($rowCate['id']==$pcode)
             $px="selected";
        ?>
            <option value="<?php echo $rowCate['id'];?>" <?php echo $px ?>><?php echo $dashVal;?>
             <?php echo $rowCate['category_name'];?> </option>
         <?php      
               CategoryShow($pcode,$rowCate['id'], $dashVal);
          }
        }
      }  
  ?>
 
  <?php for($k=1;$k<=10;$k++)
  {
    ?>
  
  <tr bgcolor="#fff">
        <td><?php echo $k;?></td>
        <td><input type="text" name="code[]" id="code" style="width:98%;"></td>
        <td><input type="text" name="category_name[]" id="category_name" style="width:98%;"></td>
        <td><select name="parent_category[]"  id="parent_category" style="width:98%;">
               <option value="0">Root</option>
            <?php 
  $dashVal = "&nbsp;&nbsp;&nbsp;";
  $sqlCate = "select * from  account_cost_category where parent_id=0 ";
  $rsCate  = DB_query($sqlCate,$db);
  if(DB_num_rows($rsCate)>0)
  {
    while($rowCate =DB_fetch_array($rsCate))
    {
        $sqlCateSel = "select * from account_cost_category where id =".$rowCate['parent_id']." ";
        $rsCateSel  = DB_query($sqlCateSel,$db);
        $px='';
         if($rowCate['id']==$pcode)
         $px="selected";
      echo $dashVal;  
      ?>
    <option value="<?php echo $rowCate['id'];?>"<?php echo $px ?>> 
    <?php echo  $rowCate['category_name'] ;?></option>
    <?php     
       CategoryShow($pcode, $rowCate['id'], $dashVal);
    }
  }
?></select> 
        </td>
  </tr>
 <?php } ?>  
</tbody></table>

</div>
  <p align="center"><a href="index.php?route=cost_category_master&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><input type="submit" name="Save" value="Save" class="search" /></a></p>
</form>
</div>
</div>
<script>
/*function show(val)
{
  
if(val=='Company Act')
{
  
document.getElementById("companyact").style.display='block';
document.getElementById("incomeact").style.display='none';

document.getElementById("code1").disabled='true';
document.getElementById("asset1").disabled='true';

document.getElementById("code1").disabled='false';
document.getElementById("asset1").disabled='false';
document.getElementById("sngwdv").disabled='false';
document.getElementById("sngslm").disabled='false';
document.getElementById("dblwdv").disabled='false';
document.getElementById("dblslm").disabled='false';
document.getElementById("tplwdv").disabled='false';
document.getElementById("tplslm").disabled='false';

}
else
{
  
document.getElementById("incomeact").style.display='block';
var gid=document.getElementById("group").value;
document.getElementById("companyact").style.display='none';
if(gid=='Root')
{
  document.getElementById("rate").disabled='true';
}
document.getElementById("sngwdv").disabled='true';
document.getElementById("sngslm").disabled='true';
document.getElementById("dblwdv").disabled='true';
document.getElementById("dblslm").disabled='true';
document.getElementById("tplwdv").disabled='true';
document.getElementById("tplslm").disabled='true';
}

} */
</script>