<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>

<?php


 $branch=$_SESSION['branch'];
 $groupID=$_REQUEST['group'];
 $categoryID=$_REQUEST['category'];

if($_REQUEST['category']=="All"){

  $sql = "SELECT * FROM eduportal_chart_of_accounts where all_data='All'";
  $WorkAssignListings = $m->query($sql); 


} else {

$sql = "SELECT * FROM eduportal_chart_of_accounts where all_data='All' ";


/* if($_REQUEST['category']=="All"){
    
    } else {
     $sql .= " where level_one = '" .$_REQUEST['category']. "' ";

    }

 if($_REQUEST['group']=="All"){
    
    } else {
     $sql .= " AND level_two = '" .$_REQUEST['group']. "' ";

    }*/

  if($_REQUEST['subgroup']=="All"){
    
    } else {
     $sql .= " and parent_id = '" .$_REQUEST['subgroup']. "' ";

    }
  //print_r($sql);
  $WorkAssignListings = $m->query($sql); 

}
  $m->where("coa_id", $_REQUEST['category']);  
  $COAname = $m->get("eduportal_chart_of_accounts");


  $m->where("coa_id", $_REQUEST['group']);  
  $COAgroupName = $m->get("eduportal_chart_of_accounts");
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Opening Balances | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  
<script type="text/javascript">


function addCurrenBalance(str,id) {

document.getElementById("cr"+id).value=str; 

 
}


function getGroup(id){

//alert(id);

if (window.XMLHttpRequest) {

// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

} else { // code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

document.getElementById("group").innerHTML=xmlhttp.responseText;
// alert(xmlhttp.responseText);

}

}

xmlhttp.open("GET","get_account_group.php?account_id="+id,true);

xmlhttp.send();




}




function getSubGroup(id){

//alert(id);

if (window.XMLHttpRequest) {

// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

} else { // code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

document.getElementById("subgroup").innerHTML=xmlhttp.responseText;
// alert(xmlhttp.responseText);

}

}

xmlhttp.open("GET","get_account_sub_group.php?account_id="+id,true);

xmlhttp.send();




}



</script>



  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="" style="background-color: white;">

      <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
    
         <a href="#">Define Opening Balances </a> 

          <br><br>

            
    <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
     
      <div class="clearfix"></div>
    </div>


      

<form class="form-style-7" action="opening_balances.php" method="get"  enctype="multipart/form-data">


      
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Level One</label>
                   <select name="category" onChange="getGroup(this.value)" class="form-control">

                    <option value="All">All</option>

                    <?php
                    $m->where("parent_id", 0); 
                    $accounts = $m->get("eduportal_chart_of_accounts");
                    foreach ($accounts as $account) { ?>

                <option <?php if ($_REQUEST['category']==$account['coa_id']) { echo 'selected'; } ?> value="<?php echo $account['coa_id']; ?>"><?php echo $account['account_title']; ?></option>

                    <?php } ?>

                  </select> 
                </div>
              </div>


<div class="col-md-3 col-xs-12" style="padding: 8px;">
<div class="form-group ">
<label class="required">Level Two</label>
<select name="group" onChange="getSubGroup(this.value)" id="group" class="form-control">

<option value="All">All Level Two</option>


<?php
if($_REQUEST['group']!='')
{ 

$m->where("parent_id", $_REQUEST['category']); 
$secondLevel = $m->get("eduportal_chart_of_accounts");

foreach($secondLevel as $secondLevel_val)
{

?>
<option <?php if($_REQUEST['group']==$secondLevel_val['coa_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['coa_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['account_title'])); ?></option>

<?php }   ?>

<?php } ?>

</select> 
</div>
</div>  


<div class="col-md-3 col-xs-12" style="padding: 8px;">
<div class="form-group ">
<label class="required">Level Three</label>
<select name="subgroup" id="subgroup" class="form-control">

<option value="All">All Level Three</option>


<?php
if($_REQUEST['subgroup']!='')
{ 

$m->where("parent_id", $_REQUEST['group']); 
$secondLevel = $m->get("eduportal_chart_of_accounts");

foreach($secondLevel as $secondLevel_val)
{

?>
<option <?php if($_REQUEST['subgroup']==$secondLevel_val['coa_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['coa_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['account_title'])); ?></option>

<?php }   ?>

<?php } ?>

</select> 
</div>
</div>
  

<div class="col-md-2 " style="padding:2px;">


<div class="form-group ">

<button type="submit" class="btn btn-primary" style="margin-top: 31px;">Search</button>

</div>


</div>


</form>


<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

<input type="hidden" name="action" value="CreateAccountOpeningBalances">
<input type="hidden" name="category" value="<?php echo $_REQUEST['category'];?>">
<input type="hidden" name="group" value="<?php echo $_REQUEST['group'];?>">
<input type="hidden" name="subgroup" value="<?php echo $_REQUEST['subgroup'];?>">

<table  style="font-size: 17px;" data-page-length='100' class="table table-striped table-bordered" style="width:100%">

<thead>
<tr>
<th width="3%" class=" center"> S.No</th>
<th width="8%" class="center"> Level Four Code</th>
<th width="15%" class=" center"> Level Four Name</th>
<th width="7%" class=" center"> Opening Balances </th>
<th width="7%" class=" center"> Current Balances </th>

</tr>
</thead>
<tbody>
<?php 
$count=1;
foreach($WorkAssignListings as $WorkAssignListVal)
{ 

$m->where("branch_id",  $branch);
$m->where("coa_id_fk", $WorkAssignListVal['coa_id']); 
$opeingBalance = $m->get("eduportal_branch_account_opening_balances");

?>
<input type="hidden" name="account_id[]" value="<?php echo $WorkAssignListVal['coa_id'];  ?>">
<tr> 
<td class="center"> <?php echo $count; $count++;?> </td>
<td style="padding-left:1%;"><?php echo $WorkAssignListVal['account_code'];  ?></td>

<td style="padding-left:1%;"><?php echo  $WorkAssignListVal['account_title'];  ?></td>

<td style="padding-left:1%;"><input style="" type="text" <?php if ($opeingBalance[0]['opening_balance']!=NULL) {
  echo "readonly";
}?> name="opening_balances[]" onkeyup="addCurrenBalance(this.value,<?php echo $WorkAssignListVal['coa_id'];  ?>)" id="op<?php echo $WorkAssignListVal['coa_id'];  ?>" value="<?php echo $opeingBalance[0]['opening_balance'];?>"></td>

<td style="padding-left:1%;"><input style="" type="text" readonly id="cr<?php echo $WorkAssignListVal['coa_id'];  ?>" name="current_balance[]" value="<?php echo $opeingBalance[0]['current_balance'];?>"></td>


</tr>

<?php } ?>





</tbody>

</table>
<?php if (isset($_REQUEST['category'])) { ?>
<button type="submit" class="btn btn-primary" style="float:right;" name="submit" >Submit </button>
<?php } ?>

</form>

</div>

    <br><br>


  </div>
  <div class="clearfix"></div>
</section>

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>

  <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <script>
        $(document).ready(function() {
        $('#listofstudents').DataTable();
        } 
        );
    </script>
  </body>
</html>
