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

 if($_REQUEST['schedule']!='') 
 $data['schedule']=$_REQUEST['schedule'];
 else
 $data['schedule']=$_REQUEST['appendex']; 
 if($_REQUEST['section']!='') 
 $data['section']=$_REQUEST['section'];
 else
 $data['section']=$_REQUEST['rules']; 

 if($_REQUEST['com_effective_from']!='')
 $data['effective_from']=FormatDateForSQL($_REQUEST['com_effective_from']);
 else
 $data['effective_from']=FormatDateForSQL($_REQUEST['income_effective_from']);
if($_REQUEST['com_effective_to']!='')
 $data['effective_to']=FormatDateForSQL($_REQUEST['com_effective_to']);
 else
 $data['effective_to']=FormatDateForSQL($_REQUEST['income_effective_to']);

 $data['act']=$_REQUEST['Act'];
 $data['created_by']=$_SESSION['UserID'];
 $data['created_date']=date('Y-m-d');
 $data['company_id']=$_SESSION['ACGCompanyId'];
 $s->RecordInsert('tpl_rate_deprications',$data);
 $Lastreq_id=DB_Last_Insert_ID($db,'tpl_rate_deprications',$ErrMsg);

for($t=0;$t<count($_REQUEST['code']);$t++)
{
 if($_REQUEST['code'][$t]!='')
 {
 $data1['parent_id']=$Lastreq_id;
 $data1['code']=$_REQUEST['code'][$t];
 $data1['asset_name']=$_REQUEST['asset_name'][$t];
 $data1['sng_wdv']=$_REQUEST['sng_wdv'][$t];
 $data1['sng_slm']=$_REQUEST['sng_slm'][$t];
 $data1['dbl_wdv']=$_REQUEST['dbl_wdv'][$t];
 $data1['dbl_slm']=$_REQUEST['dbl_slm'][$t];
 $data1['tpl_wdv']=$_REQUEST['tpl_wdv'][$t];
 $data1['tpl_slm']=$_REQUEST['tpl_slm'][$t];
 $data1['rate']=$_REQUEST['rate'][$t];
 $data1['group_id']=$_REQUEST['group'];
 $data1['asset_life']=$_REQUEST['asset_life'][$t];
 $s->RecordInsert('tpl_rate_deprications_details',$data1);
 }


}
if($_REQUEST['Act']='Company Act')
$s->pageLocation("index.php?route=ToolPlants/maintenance/act_index&tab=1&type=company_act".$rurl);
else
 $s->pageLocation("index.php?route=ToolPlants/maintenance/act_index&tab=2&type=income_act".$rurl); 
}
?>



<style type="text/css">
.company_act{width:100%;}
.income_act{width:100%;}
</style>
<link href="css/new_mxerp.css" rel="stylesheet" />

<div class="body_contain">
<div class="tab_div">
<form method="post" action="" name="frm">
<h1><strong><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></strong></h1>
  <div class="row1">
    <h1><input type="radio" name="Act" id="act1" onclick="show(this.value)" value="Company Act" checked="checked" /> <strong>As Per Company Act</strong> &nbsp;
     <input type="radio" name="Act" id="act2" onclick="show(this.value)" value="Income Act"  /> <strong>As Per Income Act</strong></h1>
</div>
<div  id="companyact">
<table width="100%" cellspacing="0" cellpadding="3" border="0">
  <tbody>
  <tr class="row1">
    <td width="10%" style="text-align:right;">Schedule <font color="#FF0000">*</font></td>
    <td width="15%"><input type="text" name="schedule" id="schedule" ></td>
    <td width="10%" style="text-align:right;">Section <font color="#FF0000">*</font></td>
    <td width="15%"><input type="text" name="section" id="section" ></td>
    <td width="10%" style="text-align:right;">Effective From <font color="#FF0000">*</font></td>
    <td width="15%"><input type="text" name="com_effective_from"  id="effective_from" class="datepicker"></td>
    <td width="10%" style="text-align:right;">Effective To <font color="#FF0000">*</font></td>
    <td><input type="text" name="com_effective_to"  id="effective_to" class="datepicker"></td>
  </tr>
  </tbody>
  </table>
<br>
	<table width="100%" cellspacing="0" cellpadding="3" border="0" class="thborder">
  <tbody>
  <tr>
    <th width="10%">Code <font color="#FF0000">*</font></th>
    <th width="15%">Nature of Asset <font color="#FF0000">*</font></th>
    <th>Useful life of Asset <font color="#FF0000">*</font></th>
    <th style="text-align:center;" colspan="2">Single Shift </th>
    <th style="text-align:center;" colspan="2">Double Shift </th>
    <th style="text-align:center;" colspan="2">Triple Shift </th>
    </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th width="10%" class="text-center">WDV</th>
    <th width="10%" class="text-center">SLM</th>
    <th width="10%" class="text-center">WDV</th>
    <th width="10%" class="text-center">SLM</th>
    <th width="10%" class="text-center">WDV</th>
    <th width="10%" class="text-center">SLM</th>
  </tr>
  <?php for($k=1;$k<=10;$k++)
  {
    ?>
  
  <tr>
    <td><input type="text" name="code[]" id="code1" ></td>
    <td><input type="text" name="asset_name[]" id="asset1" ></td>
    <td><input type="text" name="asset_life[]" id="asset_life" ></td>
    <td><input type="text" name="sng_wdv[]"  id="sngwdv" ></td>
    <td><input type="text" name="sng_slm[]" id="sngslm" ></td>
    <td><input type="text" name="dbl_wdv[]" id="dblwdv" ></td>
    <td><input type="text" name="dbl_slm[]" id="dblslm" ></td>
    <td><input type="text" name="tpl_wdv[]" id="tplwdv" ></td>
    <td><input type="text" name="tpl_slm[]"  id= "tplslm" ></td>
  </tr>
 <?php } ?>
  
</tbody></table>

</div>

<div class="income_act"  id="incomeact" style="display:none;">
<table width="100%" cellspacing="0" cellpadding="3" border="0">
  <tbody>
  <tr class="row1">
    <td width="10%" style="text-align:right;">Appendex <font color="#FF0000">*</font></td>
    <td width="15%"><input type="text" name="appendex" id="appendex" ></td>
    <td width="10%" style="text-align:right;">See Rules	<font color="#FF0000">*</font></td>
    <td width="15%"><input type="text" name="rules" id="rules" ></td>
    <td width="10%" style="text-align:right;">Effective From <font color="#FF0000">*</font> </td>
    <td width="15%"><input type="text" name="income_effective_from" id="income_effective_from"  class="datepicker"></td>
    <td width="10%" style="text-align:right;">Effective To <font color="#FF0000">*</font></td>
    <td><input type="text" name="income_effective_to"  id="income_effective_to" class="datepicker"></td>
  </tr>

  <tr class="row1">
  <td colspan="2">&nbsp;</td>
  <td >Under Group</td>
  <td style="padding:0px;" colspan="2"><select name="group" id="group" style="width:59%">
    <option select="0">Root</option>
  <?php
  $sql=DB_query("select asset_name,tpl_rate_deprications_details.id as id from tpl_rate_deprications_details
    inner join tpl_rate_deprications on tpl_rate_deprications.id=tpl_rate_deprications_details.parent_id where tpl_rate_deprications.act='Income Act'
    and tpl_rate_deprications_details.group_id=0 order by tpl_rate_deprications.id ",$db);
  while($row1=DB_fetch_array($sql))
  {
  ?>
  <option value="<?php echo $row1['id']; ?>"><?php echo $row1['asset_name']; ?> </option>
  <?php } ?>
  </select></td>
  <td colspan="3">&nbsp;</td>
  </tr>
</tbody>
</table>
<br>
	<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border:#808080 1px solid; border-collapse:collapse;">
  <tbody>
  <tr>
    <th width="10%">Code <font color="#FF0000">*</font></th>
    <th width="15%">Nature of Asset <font color="#FF0000">*</font></th>
    <th>Useful life of Asset <font color="#FF0000">*</font></th>
    <th width="15%" style="text-align:center;">Rate <font color="#FF0000">*</font></th>
    </tr>
    <?php
   for($k=1;$k<=10;$k++)
    {
    ?>
  <tr>
    <td><input type="text" name="code[]" id="code1" ></td>
    <td><input type="text" name="asset_name[]" id="asset1" ></td>
    <td><input type="text" name="asset_life[]" id="asset123" ></td>
    <td><input type="text" name="rate[]" id="rate" ></td>
    </tr>
  <?php } ?>
</tbody></table>

</div>

  <p style="text-align:center;"><input type="submit" name="Save" value="Save" class="search" onclick="return validate();" /><a href="index.php?route=ToolPlants/maintenance/act_index&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"> <input type="button" name="Save" value="Cancel" 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';
}

}


function validate()
{
  //  alert(document.getElementById("act").value);

   if(document.getElementById("act1").checked==true)
   {
    //alert("hi");
       if(document.getElementById("schedule").value=='')
       {
        alert("Please Enter Schedule");
        return false;
       }
       else if(document.getElementById("section").value=='')
       {
        alert("Please Enter Section");
        return false;
       }
       else if(document.getElementById("effective_from").value=='')
       {
        alert("Please Enter effective from");
        return false;
       }
       else if(document.getElementById("effective_to").value=='')
       {
        alert("Please Enter effective to");
        return false;
      }  
       else if(document.getElementById("code1").value=='')
       {
        alert("Please Enter code");
        return false;
      }  
      else if(document.getElementById("asset1").value=='')
       {
        alert("Please Enter Asset");
        return false;
      }  
      else if(document.getElementById("asset_life").value=='')
       {
        alert("Please Enter Useful life of Asset");
        return false;
      }  
  }
  else if(document.getElementById("act2").checked==true)
  {
      if(document.getElementById("appendex").value=='')
       {
        alert("Please Enter Appendex");
        return false;
       }
       else if(document.getElementById("rules").value=='')
       {
        alert("Please Enter Rules");
        return false;
       }
       else if(document.getElementById("rules").value=='')
       {
        alert("Please Enter Rules");
        return false;
       } 
       else if(document.getElementById("income_effective_from").value=='')
       {
        alert("Please Enter Effective From");
        return false;
       } 
        else if(document.getElementById("effective_to").value=='')
       {
        alert("Please Enter Effective To Date");
        return false;
       } 
        else if(document.getElementById("code1").value=='')
       {
        alert("Please Enter Code");
        return false;
       } 
       else if(document.getElementById("asset1").value=='')
       {
        alert("Please Enter Asset");
        return false;
       } 
       else if(document.getElementById("asset123").value=='')
       {
        alert("Please Enter Useful life of Asset");
        return false;
       } 
       else if(document.getElementById("rate").value=='')
       {
        alert("Please Enter Rate");
        return false;
       } 
  }

}
</script>