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



<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title> View Students | EduPortal </title>
     <?php include('RootMe/css_links.php');?> 
  </head>
  


  <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="row" style="background-color: white;">
  

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

<?php 

$brID="SELECT branch_id, monthly_credit FROM edu_branch_config WHERE Status='0' group by branch_id";
$branches=$m->query($brID);

foreach ($branches as $branch) {

$branchid=$branch['branch_id'];


for ($month=1; $month <= 1 ; $month++) { 



  $monthID = sprintf("%02d", $month);
  
  $yearMonth=date("Y")."-".$monthID;

// check duplicate data 
        $m->where ("month_id", $monthID);

        $m->where ("year", date('Y'));

        $m->where ("branch_id", $branchid);             

        $old_record =  $m->get ('eduportal_branch_monthly_sms_history');

        //echo count($old_challan);

        if(count($old_record)>0){

          continue;

        } else {

/*$msgs="SELECT SUM(attendance_msg) as att, SUM(result_msg) as rslt, SUM(fee_msg) as fee, SUM(other_msg) as othr FROM edu_messages_details WHERE branch_id='$branchid' and msg_date like '$yearMonth-%' ";  
$branch_monthly_sms=$m->query($msgs);*/

// getting fee msgs
$qr_fee="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branchid' and fee_msg='1' and msg_date like '$yearMonth-%' "; 
$fee_sms=$m->query($qr_fee);
$fees_sms=$fee_sms[0]['msg_count'];

// getting result msgs
$qr_res="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branchid' and result_msg='1' and msg_date like '$yearMonth-%' "; 
$result_sms=$m->query($qr_res);
$results_sms=$result_sms[0]['msg_count'];

// getting other msgs
$qr_oth="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branchid' and other_msg='1' and msg_date like '$yearMonth-%' ";
$other_sms=$m->query($qr_oth);
$others_sms=$other_sms[0]['msg_count'];

// getting attendance msgs
$qr_att="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branchid' and attendance_msg='1' and msg_date like '$yearMonth-%' ";
$att_sms=$m->query($qr_att);
$attendance_sms=$att_sms[0]['msg_count'];

$sessionID=date("Y");
$qr="SELECT SUM(add_sms) as TaditionalSms FROM eduportal_branches_SMScredit_limit WHERE month_id='$monthID'  and branch_id='$branchid' AND session_id=".$sessionID;

$AdSMS = $m->query($qr);

//echo $branch_monthly_sms[0]['othr']."<br>";


$data = array(

      'branch_id' => $branchid,
      'month_id' => $monthID,
      'year' => date('Y'),
      'date' => $yearMonth,
      'att_sms' => $attendance_sms,
      'rslt_sms' => $results_sms,
      'fee_sms' => $fees_sms,
      'other_sms' => $others_sms,
      'monthly_sms_limit' => $branch['monthly_credit'],
      'additional_sms' => $AdSMS[0]['TaditionalSms']
    );

      $m->insert ('eduportal_branch_monthly_sms_history', $data);
}
 }
  /*
   $fee_sms=$m->query($qr_fee);
}

/*for ($month=1; $month <= 12 ; $month++) { 

  $monthID = sprintf("%02d", $month);
  
  $yearMonth=date("Y")."-".$monthID;

  $qr_fee="SELECT * FROM edu_messages_details WHERE and fee_msg='1' and msg_date like '$yearMonth-%' ";
echo $qr_fee."<br>";
  /*
   $fee_sms=$m->query($qr_fee);
}*/

}

   ?>





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

        </div> 
        </div>


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


     
        <!-- /page content -->


 <!-- jQuery -->
    <script src="js/ajax_functions.js"></script>
  <?php include('RootMe/js_linksscript.php');?> 
  <!-- Links for Datatable-->

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

  $("#checkAll").change(function () {

      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });


</script>
  
  </body>
</html>
