<?php 
$branch=$_SESSION['branch'];
$date=date('Y-m-d');
$curr_session=$_SESSION['current_session'];
  
  // getting fee of current month
 $qr="SELECT SUM(fee.tutionfee) as tution,SUM(fee.transportfee) as trans,SUM(fee.total_fine) as fine, SUM(fee.balance) as balance,SUM(fee.misc_fee) as misc, SUM(fee.collected_amount) as coll  FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.classs_id=std.class_id and fee.student_id=std.student_id and fee.branch_id='$branch' AND fee.session_id='$curr_session' AND std.status='0' AND fee.month_id=".date('m');
 
 //echo $qr;
 
  $amount = $m->query($qr);
  $total_exp=$amount[0]['tution']+$amount[0]['trans']+$amount[0]['fine']+$amount[0]['balance']+$amount[0]['misc_fee'];
  $recieved3=$amount[0]['coll'];
  $pending=intVal($total_exp)-intVal($recieved3);


//getting branch details

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

  $m->where("Month_Id", date('m'));
  $month=$m->get("eduportal_month_config");




?>




<?php 



  $m->where("status", 0);
  $m->where("branch_id", $_SESSION['branch']);
  $total_students=$m->get("edu_student_details");
  $total_today= count($total_students);
     


   $qr="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='P'  and branch_Id='$branch' and date='$date'";

 
   $result=$m->query($qr);
   $p=$result[0]['total'];

   $qr_ab="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='A' and branch_Id='$branch' and message_status='1' and date='$date'";
   
   $result_lev=$m->query($qr_ab);
   $lev=$result_lev[0]['total'];

   $qr_ab="SELECT count(*) as total FROM eduportal_attendance_detail WHERE attendance='A' and branch_Id='$branch' and date='$date'";
   $result_ab=$m->query($qr_ab);
   $abs=$result_ab[0]['total'];


   // getting details of students fee submitted 
    $dt=date('d-m-Y');
    $qr="SELECT * FROM eduportal_monthly_challan as ch,edu_student_details as std WHERE ch.branch_id='$branch' AND ch.session_id='$curr_session' AND ch.paying_date='$dt' AND std.student_id=ch.student_id"; 

    $pay = $m->query($qr);
  
  // $qr="SELECT SUM(fee.tutionfee) as tution,SUM(fee.transportfee) as trans,SUM(fee.total_fine) as fine, SUM(fee.balance) as balance, SUM(fee.collected_amount) as coll  FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and fee.branch_id='$branch' AND std.status='0' ";
  
  
  // getting fee of daily basic
  $date=date('d-m-Y');


$qr="SELECT SUM(fee.tutionfee) as tution,SUM(fee.transportfee) as trans,SUM(fee.total_fine) as fine, SUM(fee.balance) as balance, SUM(fee.collected_amount) as coll  FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and fee.branch_id='$branch' AND fee.session_id='$curr_session' AND fee.paying_date='$date'";

 // echo $qr;
  $amount = $m->query($qr);
  
  $total=$amount[0]['tution']+$amount[0]['trans']+$amount[0]['fine']+$amount[0]['balance'];
  $recieved=$amount[0]['coll'];
  
  

?>



<?php  

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

$qr_ab="SELECT * FROM edu_messages_details WHERE branch_id='$branch' and msg_date like '$date-%' ";
$msgs=$m->query($qr_ab);

// getting other msgs
$qr_oth="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branch' and other_msg='1' and msg_date like '$date-%' ";
$other_sms=$m->query($qr_oth);

// getting attendance msgs
$qr_att="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branch' and attendance_msg='1' and msg_date like '$date-%' ";
$att_sms=$m->query($qr_att);

// getting result msgs
$qr_res="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branch' and result_msg='1' and msg_date like '$date-%' ";
$result_sms=$m->query($qr_res);

// getting fee msgs
$qr_fee="SELECT SUM(msg_count) as msg_count FROM edu_messages_details WHERE branch_id='$branch' and fee_msg='1' and msg_date like '$date-%' ";
$fee_sms=$m->query($qr_fee);




// print_r($resl_sms);

$total_sms=$att_sms[0]['msg_count']+$fee_sms[0]['msg_count']+$result_sms[0]['msg_count']+$other_sms[0]['msg_count'];


  $data = array('sms_limit' => $branch_record[0]['monthly_credit']-$total_sms);
  $m->where ("branch_id",$_SESSION['branch']);
  $result =$m->update('edu_branch_config', $data);

?>




<div class="row" style="margin-top:0%;margin-right:0px;">	<!-- chang margin-top -->
 
 
 
 <div class="col-md-9" >



<?php // restricting user from this page || $_SESSION['user_id']!=213 

if($_SESSION['user_id']!=213 && $_SESSION['user_id']!=212 && $_SESSION['user_id']!=227){

?>



    <div class="col-md-3 no_padding" >
        
            <div class="col-md-12 col_style" >
                
                <div class=" col-sm-12 ">
                    <h4 class="dashboard_thumbnail_detail font_size" style="background-color: transparent;color:#17ab17;text-align:center;"><b>
                            <?php
                                echo number_format($total_exp);
                            ?> 
                        </b></h4>
                </div>

                <div class="col-md-12" style="background-color: transparent;color:black">
                    <p class="dashboard_thumbnail_title" style="color:#bfbfbf">Expected Fee (<?php echo $month[0]['Month_Name'];?>)</p> 
                </div>

           
            </div>
    
    </div>

    <div class="col-md-3 no_padding" >
        <a href="print_fee_reports.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&session=<?php echo $_SESSION['current_session']; ?>&month=<?php echo date('m'); ?>&fee=1&from=&to=">
            <div class="col-md-12 col_style" >
                
                <div class=" col-sm-12 ">
                    <h4 class="dashboard_thumbnail_detail font_size" style="background-color: transparent;color:#3865e0;text-align:center;"><b>
                            <?php
                                echo number_format($recieved3);
                            ?> 
                        </b></h4>
                </div>

                <div class="col-md-12" style="background-color: transparent;color:black">
                    <p class="dashboard_thumbnail_title" style="color:#bfbfbf">Fee Recieved (<?php echo $month[0]['Month_Name'];?>)</p>
                </div>

           
            </div>
            
      </a>

    </div>


    <div class="col-md-3 no_padding" >
        <a href="fee_reporting.php?session=gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1gv7dus9tmrqlsae170i962isu1&class_id=All&session=<?php echo $_SESSION['current_session']; ?>&month=<?php echo date('m'); ?>&fee=0&from=&to=">
            <div class="col-md-12 col_style">
                
                <div class="col-sm-12 ">
                    <h4 class="dashboard_thumbnail_detail font_size" style="background-color: transparent;color:#de7f0b;text-align:center;">
                        <b>
                           <?php
                                echo number_format($pending);
                            ?> 
                        </b>
                    </h4>
                </div>

             <div class="col-md-12" style="background-color: transparent;color:black">
                <p class="dashboard_thumbnail_title" style="color:#bfbfbf"> Recieveable (<?php echo $month[0]['Month_Name'];?>)</p>
            </div>                            
    

            </div>

        </a>
    </div>
   
 <div class="col-md-3 no_padding" >
        <a href="manage_students.php">
            <div class="col-md-12 col_style">
                
                <div class="col-sm-12 ">
                    <h4 class="dashboard_thumbnail_detail font_size" style="background-color: transparent;color:#00AFEF;text-align:center;"><b>

                    <?php 

                          $m->where("status", 0);
                          $m->where("branch_id", $_SESSION['branch']);
                          $total_students=$m->get("edu_student_details");
                          echo count($total_students);
                    ?>

                    </b></h4>

                </div>
            
                
                <div class="col-md-12" style="background-color: transparent;color:black">
                    <p class="dashboard_thumbnail_title" style="color:#bfbfbf">Total Students</p>
                </div>

            </div>
        </a>
 </div>
 
<?php   } ?>
												<!--Start Fee Collection Chart-->
<div class="col-md-4 graphstyle" style="width:;">
 <h4 style="color:gray;">Collected Fee (May) </h4>
            <div class="clearfix">
                <div class="c100 p<?php echo ceil($recieved3*100/$total_exp); ?> medium green" style="margin-left:60px;">
				
                    <span><?php echo ceil($recieved3*100/$total_exp); ?>%</span>
                    <div class="slice">
                        <div class="bar"></div>
                        <div class="fill"></div>
                    </div>
                </div>
            </div>
</div>
												<!--End Fee Collection Chart-->
												
												<!--Start Attendance Chart-->
<div class="col-md-4 graphstyle" style="width:; margin-left:1.5%;">
<h4 style="color:gray;">Students Present (Today)  </h4>
            <div class="clearfix">
                <div class="c100 p<?php echo ceil ($p*100/$total_today);?> medium" style="margin-left:60px;">
                    <span><?php echo ceil ($p*100/$total_today);?>%</span>
                    <div class="slice">
                        <div class="bar"></div>
                        <div class="fill"></div>
                    </div>
                </div>
            </div>
</div>
												<!--End Attendance Chart-->
																								
												<!--Start SMS  Chart -->
<div class="col-md-4 graphstyle" style="width:;margin-left:1.5%;">
	<h4 style="color:gray;">SMS Usage (May) </h4>
            <div class="clearfix">
                <div class="c100 p<?php echo ceil ($total_sms*100/$branch_record[0]['monthly_credit']);?> medium orange" style="margin-left:60px;">
                    <span><?php echo ceil ($total_sms*100/$branch_record[0]['monthly_credit']);?>%</span>
                    <div class="slice">
                        <div class="bar"></div>
                        <div class="fill"></div>
                    </div>
                </div>
            </div>
</div>
												<!--End SMS  Chart 
<div class="col-md-12" style="margin-top:13px; border: 1px solid #cecece; background:white;">
<script>
window.onload = function () {

var options = {
	exportEnabled: true,
	animationEnabled: true,
	title:{
		text: "Profit & Loss Statement"
	},
	subtitles: [{
		text: ""
	}],
	axisX: {
		title: "States"
	},
	axisY: {
		title: "Fee Collection",
		titleFontColor: "#4F81BC",
		lineColor: "#4F81BC",
		labelFontColor: "#4F81BC",
		tickColor: "#4F81BC",
		includeZero: false
	},
	axisY2: {
		title: "Expenses",
		titleFontColor: "#C0504E",
		lineColor: "#C0504E",
		labelFontColor: "#C0504E",
		tickColor: "#C0504E",
		includeZero: false
	},
	toolTip: {
		shared: true
	},
	legend: {
		cursor: "pointer",
		itemclick: toggleDataSeries
	},
	data: [{
		type: "spline",
		name: "Fee Collection",
		showInLegend: true,
		xValueFormatString: "MMM YYYY",
		yValueFormatString: "#,##0 Rupees",
		dataPoints: [
			{ x: new Date(2016, 0, 1),  y: 120 },
			{ x: new Date(2016, 1, 1), y: 135 },
			{ x: new Date(2016, 2, 1), y: 144 },
			{ x: new Date(2016, 3, 1),  y: 103 },
			{ x: new Date(2016, 4, 1),  y: 93 },
			{ x: new Date(2016, 5, 1),  y: 129 },
			{ x: new Date(2016, 6, 1), y: 143 },
			{ x: new Date(2016, 7, 1), y: 156 },
			{ x: new Date(2016, 8, 1),  y: 122 },
			{ x: new Date(2016, 9, 1),  y: 106 },
			{ x: new Date(2016, 10, 1),  y: 137 },
			{ x: new Date(2016, 11, 1), y: 142 }
		]
	},
	{
		type: "spline",
		name: "Expenses",
		axisYType: "secondary",
		showInLegend: true,
		xValueFormatString: "MMM YYYY",
		yValueFormatString: "Rs:#,##0.#",
		dataPoints: [
			{ x: new Date(2016, 0, 1),  y: 19034.5 },
			{ x: new Date(2016, 1, 1), y: 20015 },
			{ x: new Date(2016, 2, 1), y: 27342 },
			{ x: new Date(2016, 3, 1),  y: 20088 },
			{ x: new Date(2016, 4, 1),  y: 20234 },
			{ x: new Date(2016, 5, 1),  y: 29034 },
			{ x: new Date(2016, 6, 1), y: 30487 },
			{ x: new Date(2016, 7, 1), y: 32523 },
			{ x: new Date(2016, 8, 1),  y: 20234 },
			{ x: new Date(2016, 9, 1),  y: 27234 },
			{ x: new Date(2016, 10, 1),  y: 33548 },
			{ x: new Date(2016, 11, 1), y: 32534 }
		]
	}]
};
$("#chartContainer").CanvasJSChart(options);

function toggleDataSeries(e) {
	if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
		e.dataSeries.visible = false;
	} else {
		e.dataSeries.visible = true;
	}
	e.chart.render();
}

}
</script> 

<div id="chartContainer" style="height: 400px; width: 100%;"></div>

</div>					 -->							
							
	</div>  <!-- ending 9 col  -->
	

    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12 pull-right search_div_right ">

                         <ul class="total_booking">


<h2>Daily Short Summary </h2>

  <li>
     
      <div class="read_able">
          <ul>


    <?php $tot=intVal(totalStudents($m))-($p+$abs);?>
    <li><span class="color_2"></span> Students Without 
	<span  class="report_color"><?php echo $tot;?> </span></li>
    <li><span class="color_2"></span> Total Students Present <span  class="report_color"><?php echo $p;?> </span></li>
    <li><span class="color_3"></span> Total Students Absent  <span  class="report_color"><?php echo $abs;?> </span></li>
    <li><span class="color_4"></span> SMS To Parents Of Absence <span  class="report_color"><?php echo $lev;?> </span></li>
    <li><span class="color_1"></span> No. of Students Submited Fee <span  class="report_color"><?php echo count($pay); ?> </span></li>
    <li>

 

 <a href="print_fee_reports.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'); ?>">

    <span class="color_3"></span> Today Fee Collection <span  class="report_color"><?php echo number_format($recieved); ?> </span>

</a>
    </li>
                                </ul>


                            </div>
                        </li>
                        <div class="clearfix"></div>
                    </ul>



          <ul class="total_booking">

                        
                        <h2>Most Absentees (<?php echo $month[0]['Month_Name'];?>) </h2> 

                        <li>
                           
                            <div class="read_able">
                                <ul>

<li><span class="color_2"></span><a target="_blank" href="absent_students.php?<?php echo session_id().session_id();?>&type=fee"> List of Most Absentees Students</a></li>
                                </ul>

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


                    </ul>


                  <ul class="total_booking">

                        
                        <h2>SMS Report of (<?php echo $month[0]['Month_Name'];?>) </h2> 

                        <li>
                           
                            <div class="read_able">
                                <ul>

<li><span class="color_1"></span> Credit Limit <span  class="report_color"> <?php echo $branch_record[0]['monthly_credit']; ?> </span></li>
<li><span class="color_2"></span><a href="sent_message.php?<?php echo session_id().session_id().session_id().session_id();?>&type=fee">  Fee Notifications Sent <span  class="report_color"> <?php echo $fee_sms[0]['msg_count']+0; ?> </span></a></li>

<li><a href="sent_message.php?<?php echo session_id().session_id().session_id().session_id();?>&type=att"><span class="color_3"></span> Attendance Notifications Sent <span  class="report_color"> <?php echo $att_sms[0]['msg_count']+0; ?> </span></a></li>
<li><span class="color_4"></span> <a href="sent_message.php?<?php echo session_id().session_id().session_id().session_id();?>&type=result"> Result Notifications Sent  <span  class="report_color"> <?php echo $result_sms[0]['msg_count']+0; ?></a> </span></li>
<li><span class="color_1"></span> <a href="sent_message.php?<?php echo session_id().session_id().session_id().session_id();?>&type=other">Other Notifications Sent <span  class="report_color"> <?php echo $other_sms[0]['msg_count']+0; ?>  </a></span></li>

<li><div class="total_sub_box"> SMS Used <span class="pull-right"> <?php echo $total_sms; ?> </span></div></li>
<!-- 
<li><div class="total_sub_box" style="background-color:#00AFEF;"> Brand SMS Limit <span class="pull-right"> <?php echo $brid[0]['brand_sms_limit']; ?> </span></div></li>
<li><div class="total_sub_box"> Brand SMS Left <span class="pull-right"> <?php echo $brid[0]['brand_sms_usage']; ?></span></div></li>

 -->
                                </ul>

                                


                            </div>
                        </li>
                        <div class="clearfix"></div>
                    </ul>

                  

    </div>  <!-- ending 8 col  -->

</div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"> </script>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>