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

<?php  include("sessioncheck.php"); 



 $b=$_SESSION['branch'];

 $s=$_SESSION['current_session'];

 $mn=date("m");



 $from=date("Y-m-01");

 $to=date("Y-m-t");



/*new code for total received*/



$qr1="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$b' and paid_status='1' ";



  $qr1 .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";

//print_r($qr1);

  //$revenue = $m->query($qr1);







  $qr2="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$b' and paid_status='1' ";



  $qr2 .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";

//print_r($qr);

  //$againReceivedrevenue = $m->query($qr2);



$received_total_new=$revenue[0]['received']+$revenue[0]['total_fine']+$againReceivedrevenue[0]['againreceived'];





$paidDate=date("Y-m");

$qr="SELECT SUM(expense_amount) as total FROM eduportal_expense_detail where branch_id ='$b' and status = '0' and expense_date like '$paidDate%' ";

   //echo "$qr";

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



   $totalExpCurrentMonth=$Texpense[0]['total'];





  /*new code end*/    

           





    $received_total=0;



   









$qr="SELECT SUM(collected_amount) as received, SUM(paid_again_amount) as againPay, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan  WHERE branch_id='$b' AND session_id='$s' and month_id='$mn' and paid_status='1' ";

 

  //$amount = $m->query($qr);



  $TotalReceived_amount=$amount[0]['received']+$amount[0]['total_fine']+$amount[0]['againPay'];





    //$received_total=getCurrentMonthFeeReceived($_SESSION['current_session'],date('m'),$m); 



     $m->where ("branch_id", $_SESSION['branch']);

    $branchStudents =  $m->get('edu_student_details');

    $NewSchoolStudents =count($branchStudents);





     $date1=date('Y-m');

    $qr3="SELECT SUM(amount) AS total  FROM eduportal_revenue_details WHERE branch_id='$b' and session_id='$s' and paid_date like '$date1-%'";



    

  //echo $qr3;

    $RevenueMonthly = $m->query($qr3);





    $paidDate=date("Y-m");

    $qr="SELECT SUM(paid_amount) AS total, SUM(paid_again_amount) as again_total, SUM(paid_again_salary_amount) as again_salary_total  FROM employee_payroll WHERE branch_id='$b' and paid_date like '$paidDate%'";



  //echo $qr;

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



    $salary=$paid_salary[0]['total']+$paid_salary[0]['again_total']+$paid_salary[0]['again_salary_total'];







    /*$FreeStudent="SELECT count(*) as total FROM eduportal_student_fee_structure as fee, edu_student_details as std WHERE fee.student_id=std.student_id and std.status='0' and fee.session_id='$s' and std.branch_id='$b' and fee.std_tution_fee = '0'"; 

 //print_r($FreeStudent);

   $TotalFreeStudent=$m->query($FreeStudent);

   $TotalStdFree=$TotalFreeStudent[0]['total'];*/







$branch=$_SESSION['branch'];

 $sessionIDs=$_SESSION['current_session'];



$sql = "SELECT std.student_id, std.first_name,std.last_name,std.father_name,std.cell_no,std.image,std.status,std.branch_id,std.class_id,std.candidate_roll_no,std.ref_no,std.section_id,std.session_id,std.family_code,fee.student_id,fee.std_tution_fee,fee.discount_reason  FROM eduportal_student_fee_structure as fee, edu_student_details as std WHERE fee.student_id=std.student_id and fee.class_id=std.class_id and std.status='0' and std.branch_id=".$_SESSION['branch']. " ";



 

      $sql .= " AND fee.std_tution_fee = 0  ";

 

  

   if($_REQUEST['session']!=NULL){

    $sql .= " AND fee.session_id = '" .$_REQUEST['session']. "' ";

  }else {

    $sql .= " AND fee.session_id = '" .$_SESSION['current_session']. "' ";

  }



  $sql .= " GROUP BY fee.student_id ";

 // print_r($sql);



  $TotalStdFree = $m->query($sql);







   /*

   function getUnpaidReceivable($m)

{

 $branch=$_SESSION['branch'];

 $curr_session=$_SESSION['current_session'];



  

  $qr="SELECT SUM(chl.balance) as bal, SUM(chl.tutionfee) as tuti, SUM(chl.transportfee) as trns, SUM(chl.misc_fee) as misc, SUM(chl.disc_amount) as disc FROM eduportal_monthly_challan as chl, edu_student_details as std WHERE chl.branch_id='$branch' and chl.session_id='$curr_session' and chl.paid_status='0' AND std.status='0' and chl.student_id=std.student_id AND chl.month_id=".date('m');

//print_r($qr);

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

  $total_recevable_unpaid=$amount[0]['bal']+$amount[0]['tuti']+$amount[0]['trns']+$amount[0]['misc']-$amount[0]['disc'];



   return $total_recevable_unpaid;



}*/




/*
function getUnpaidReceivableOtherAmount($m)

{

 $branch=$_SESSION['branch'];

 $curr_session=$_SESSION['current_session'];



  

  $qr="SELECT SUM(detil.fee_amount) as amt FROM `eduportal_monthly_challan_details` as detil, eduportal_monthly_challan as chl WHERE detil.branch_id='$branch' and detil.session_id='$curr_session' and chl.paid_status='0' and detil.student_id=chl.student_id AND detil.month_id=".date('m');

//print_r($qr);

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

  $total_recevable_unpaidOtherAmount=$amount[0]['amt'];



   return $total_recevable_unpaidOtherAmount;



}


*/

/*
function getPaidChallanReceivable($m)

{

 $branch=$_SESSION['branch'];

 $curr_session=$_SESSION['current_session'];



  

  $qr="SELECT SUM(chl.remaining_amount) as rem FROM eduportal_monthly_challan as chl, edu_student_details as std WHERE chl.branch_id='$branch' and chl.session_id='$curr_session' and chl.paid_status='1' and std.status='0' and chl.student_id=std.student_id AND chl.month_id=".date('m');

//print_r($qr);

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

  $PaidChallanReceivable=$amount[0]['rem'];



   return $PaidChallanReceivable;



}

*/

?>

<!DOCTYPE html>

<html lang="en">

  <head>

    <title> Income & Expense Dashboard | EduPortal </title>

    <!-- bootstrap-progressbar -->

    <link href="../vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">

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

    <script src="https://cdn.zingchart.com/zingchart.min.js"></script>

    <script src="https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

     <!-- Flaticon CSS -->

    <link rel="stylesheet" href="fonts/flaticon.css">

       

    <link rel="stylesheet" href="stylebox.css">



  </head>



  <input type="hidden" name="month" id="month" value="<?php echo $_REQUEST['month'];?>">

<input type="hidden" name="session" id="session" value="<?php echo $_REQUEST['session'];?>">

  <script type="text/javascript">



function getInactiveStudents(str)

{

  //alert(str);



  var month=document.getElementById("month").value;

  var session=document.getElementById("session").value;

if(str=="1"){

document.getElementById("activeStudents").style.display="none";



var ajx;  // The variable that makes Ajax possible!



if(window.XMLHttpRequest)

ajx=new XMLHttpRequest();

ajx.onreadystatechange = function()

{



if(ajx.readyState == 4)

{

//alert(ajx.responseText); 

document.getElementById("inActiveStudents").innerHTML= ajx.responseText;

document.getElementById("inActiveStudents").style.display="block";

}

}

ajx.open("GET", "get_inactive_student_box_stats.php?student_status="+str+"&month="+month+"&session="+session,true);

ajx.send(); 

}

  





if(str=="0"){

document.getElementById("activeStudents").style.display="block";

document.getElementById("inActiveStudents").style.display="none";

}



}



</script>

  

   <body class="nav-md" <?php if (isset($_REQUEST['session'])) { ?> onload="getInactiveStudents(1)"  <?php } ?> >

    <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="">

            <div class="row top_tiles">



<div style="background-color: white; margin-bottom: 10px; padding: 20px;">



 <h3 style="text-align: center;">Income and Expense Dashboard</h3>



</div>



<div class="col-md-12">

<div class="col-md-2 col-xs-12 pull-right" style="padding: 8px; background-color: white;">              



<select name="active_inactive" id="active_inactive" style="background-color:white;" class="form-control" onChange="getInactiveStudents(this.value)" >



<option value="0">Active Students</option>

<option <?php if($_REQUEST['inactive']=="1"){echo "Selected";} ?> value="1">In-Active Students</option>



</select>



</div>

</div>



<div id="activeStudents"> <!-- active student box -->

                

              

            


            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">

                 <a href="add_expenses.php">

                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">

                            <div class="row">

                                <div class="col-md-4">

                                    <div class="item-icon bg-light-blue">

                                        <i class="flaticon-money text-blue"></i>

                                    </div>

                                </div>

                                <div class="col-md-8">

                                    <div class="item-content">

                                        <div class="item-title">Total Expenses (<?php echo date("M");?>)</div>

                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>

                                        <?php echo number_format($totalExpCurrentMonth);?></div>

                                    </div>

                                </div>

                            </div>

                        </div>

                     

                 </a>  

            </div>







            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">

                 <a href="add_expenses.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&from=<?php echo date('Y-m-d'); ?>&to=<?php echo date('Y-m-d'); ?>">

                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">

                            <div class="row">

                                <div class="col-md-4">

                                    <div class="item-icon bg-light-red">

                                        <i class="flaticon-money text-red"></i>

                                    </div>

                                </div>

                                <div class="col-md-8">

                                    <div class="item-content">

                                        <div class="item-title">Daily Expenses (<?php echo date("d-M");?>)</div>

                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>

                                        <?php echo number_format(getTodayExpense($_SESSION['current_session'],date('m')+0,$m));?></div>

                                    </div>

                                </div>

                            </div>

                        </div>

                     

                 </a>  

            </div>



<?php //echo $received_total;?>





            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">

                 <a href="print_report_zerofee.php?fee=0">

                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">

                            <div class="row">

                                <div class="col-md-4">

                                    <div class="item-icon bg-light-red">

                                        <i class="flaticon-money text-red"></i>

                                    </div>

                                </div>

                                <div class="col-md-8">

                                    <div class="item-content">

                                        <div class="item-title">Total Free Students </div>

                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>

                                        <?php echo count($TotalStdFree);?></div>

                                    </div>

                                </div>

                            </div>

                        </div>

                     

                 </a>  

            </div>





            







                            <div style="text-align: center;">

                              <ul class="verticle_bars list-inline">

                                <li>

                                  <div class="progress vertical progress_wide bottom">

                                    <div class="progress-bar progress-bar-dark" role="progressbar" data-transitiongoal=""></div>

                                  </div>

                                </li>

                               

                                

                               

                              </ul>

                            </div>

                                                        



    </div> <!-- end active students box -->



<div class="col-md-12" id="inActiveStudents" style="display: none;">



</div>                    





               





              </div>



              

                

    </div>

    </div>

          

            </div>

          </div>

        </div>

        <!-- /page content -->

  



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

    <!-- Chart.js -->

    <script src="../vendors/Chart.js/dist/Chart.min.js"></script>

     <!-- ECharts -->

    <script src="../vendors/echarts/dist/echarts.min.js"></script>

    <script src="../vendors/echarts/map/js/world.js"></script>

    <!-- bootstrap-progressbar -->

    <script src="../vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>

     <script src="../vendors/morris.js/morris.min.js"></script>

    <!-- Custom Theme Scripts -->

    <script src="../build/js/custom.min.js"></script>

     <!-- easy-pie-chart -->

    <script src="../vendors/jquery.easy-pie-chart/dist/jquery.easypiechart.min.js"></script>

      <!-- morris.js -->

    <script src="../vendors/raphael/raphael.min.js"></script>

    <script src="../vendors/morris.js/morris.min.js"></script>



  </body>

</html>

