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

    $received_total=0;

    $b=$_SESSION['branch'];
    $s=$_SESSION['current_session'];
    $mn=date("m");




$qr="SELECT SUM(chl.collected_amount) as received, SUM(chl.paid_again_amount) as againPay, SUM(chl.collected_fine) as total_fine FROM eduportal_monthly_challan as chl, edu_student_details as std  WHERE chl.student_id=std.student_id and std.status='0' and chl.branch_id='$b' AND chl.session_id='$s' and chl.month_id='$mn' and chl.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  FROM employee_payroll WHERE branch_id='$b' and session_id='$s' and paid_date like '$paidDate%'";

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

    $salary=$paid_salary[0]['total']+$paid_salary[0]['again_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'];
?>
<!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 -->

             <?php if ($NewSchoolStudents>'0') { ?>
            
        
          <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a href="monthly_fee_summary1.php?seion=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu">
                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="item-icon bg-light-green">
                                        <i class="flaticon-money text-green"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title">Expected Fee (<?php echo date("M");?>)</div>
                                        <div class="item-number"><span></span><span class="counter" data-num=""><?php $monthly_total= getExpectedMonthlyFee($m)+getCompleteOtherMonthlyFee(date("m"),$m);
                  echo number_format($monthly_total);
                ?></span></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </a>
            </div>

        <?php } else { ?>


            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a href="watch_video.php?videourl=xc7oLgJbnqY" target="_blank">
                        <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="fa fa-video-camera text-red" style="margin-top: 10px;"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title">New Customers Guideline</div>
                                        <div class="item-number"><span></span><span class="counter textblink" style="background-color: red;color: white;padding: 5px;" data-num="">Watch A Short Video</span></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </a>
            </div>


       <?php } ?> 
<!-- print_fee_reports -->
               <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <a href="tracking_fee_summary1.php?gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1">
                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="item-icon bg-light-green">
                                        <i class="flaticon-money text-green"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title" style="font-size: 15px;">Fee Received (<?php echo date("M");?>)</div>
                                        <div class="item-number" style="font-size: 15px;"><span></span><span class="counter" data-num=""></span>
                                        <?php 


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

 $branch=$_SESSION['branch'];
 $curr_session=$_SESSION['current_session'];

 $qr1="SELECT * FROM eduportal_monthly_challan WHERE paid_status='1' and branch_id='$branch' AND session_id='$curr_session' AND month_id=".date('m');
 //echo $qr1;
  $PaidChallan = $m->query($qr1);

  /*$qr2="SELECT * FROM eduportal_monthly_challan WHERE paid_status='0' and branch_id='$branch' AND session_id='$curr_session' AND month_id=".date('m');*/

  $qr2="SELECT * FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and std.status='0' and std.branch_id='$branch' AND fee.session_id = '$curr_session' AND fee.paid_status = '0' AND fee.month_id=".date('m');

  $unPaidChallan = $m->query($qr2);


  $qr="SELECT SUM(fee.collected_amount) as fee_received, SUM(fee.paid_again_amount) as againPay FROM eduportal_monthly_challan as fee,edu_student_details as std WHERE std.student_id=fee.student_id and fee.branch_id='$branch' AND fee.session_id='$curr_session' AND fee.month_id=".date('m');

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


  $received_amount=$amount[0]['fee_received']+$amount[0]['againPay'];


          //echo $received_amount;


                 ?><span class="item-title" style="font-size: 20px;"> Click to View</span></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </a>
            </div>

               <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            
                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="item-icon bg-light-green">
                                        <i class="flaticon-money text-green"></i>
                                    </div>
                                </div>
                                <div class="col-md-9" style="margin-top: -20px;">
                                    <div class="item-content">
                                  
                                        <div class="item-title">Receiveable (<?php echo date("M");?>)</div>
                                    
                                        <div class="item-number" style="font-size: 14px;"><span></span><span class="counter" data-num=""></span>
                                          <?php echo number_format(intval($monthly_total)-intval($TotalReceived_amount)/*-intval($CurrentMonthAgain)*/);?><span class="item-title" style="font-size: 11px;"> (UnPaid Challan: <?php echo count($unPaidChallan) ?>)</span><br>
                                                <a target="_blank" href="print_unpaid_partialy_fee.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&section=All&session=<?php echo $_SESSION['current_session']; ?>&month=<?php echo date('m'); ?>&fee=0&from=&to=&student_name=1&class_sec=1&cell_no=1&roll_no=1&father_name=1">
                                                <span class="btn btn-primary" style="font-size: 11px;color: white;"> Print Receiveable</span></a>


                                                <a target="_blank" href="fee_reporting.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&section=All&session=<?php echo $_SESSION['current_session']; ?>&month=<?php echo date('m'); ?>&fee=0&from=&to=">
                                                <span class="btn btn-primary" style="font-size: 11px;color: white;"> Manage Fee</span></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      
            </div>


            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <a href="print_received_amount_inactive_std.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&section=All&session=<?php echo $_SESSION['current_session']; ?>&fee=1&from=<?php echo date("01-m-Y"); ?>&to=<?php echo date("t-m-Y"); ?>&student_name=1&roll_no=1">
                        <div class="dashboard-summery-one" style="border: 1px solid lightgray;">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="item-icon bg-light-green">
                                        <i class="flaticon-money text-green"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title">Fee Received (<?php echo date("M");?>)</div>
                                        <div class="item-number" style="font-size: 15px;"><span></span><span class="counter" data-num=""></span>
                                        <?php 


$Inactivereceived_total=getCurrentMonthFeeInactiveStdReceived($_SESSION['current_session'],date('m'),$m); 


          //echo $received_amount;


               echo number_format($Inactivereceived_total); ?><span class="item-title" style="font-size: 12px;"> (InActive Students) </span></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </a>
            </div>

              <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                 <a href="print_daily_fee_report.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&session=<?php echo $_SESSION['current_session']; ?>&month=<?php echo date('m'); ?>&fee=1&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-blue">
                                        <i class="flaticon-money text-blue"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title">Today Collection (<?php echo date("d-M");?>)</div>
                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>
                                        <?php echo number_format(today_Fee($m)+today_PaidAgainFee($m));?></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </a>
                    
            </div>

            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                 <a href="print_fee_disc_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo date("m");?>&session=<?php echo $_SESSION['current_session'];?>&class_id=All">
                        <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 Discount  (<?php echo date("d-M");?>)</div>
                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>
                                        <?php $disc=getCurrentMonthFeeDiscount($s,$mn,$m); echo number_format($disc); ?></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">
                        <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(getCurrentMonthExpense($_SESSION['current_session'],date('m')+0,$m));?></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="profitloss_report.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-red">
                                        <i class="flaticon-money text-red"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="item-content">
                                        <div class="item-title">Profit (<?php echo date("M");?>)</div>
                                        <div class="item-number"><span></span><span class="counter" data-num=""></span>
                                        <?php echo number_format($RevenueMonthly[0]['total']+$received_total-$salary-getCurrentMonthExpense($_SESSION['current_session'],date('m')+0,$m),2);?></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    
                 </a>  
            </div>



            <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 $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>
