<?php 
include ("kfunctions.php");
adminall("overadmin","secaccount","priaccount");
?>

<html>
<head>
<?php kheader(); ?>

<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script src="js/sorttable.js"></script>
</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

      

                <!-- /.row -->

                

     <form method="post">               
<div class="col-lg-12">
  <div class="panel panel-green">
                <div class="panel-heading">
                                <h3 class="panel-title">Income summary</h3>
                            </div>
                            <div class="panel-body">

                            <form method='post'>
                            <div class='input-append date form_date col-lg-3' data-date='' data-date-format='yyyy-mm-dd' data-link-field='dtp_input2' data-link-format='yyyy-mm-dd'>
<input size='16' type='text' name='date1' style='cursor:pointer' placeholder='Date 1' class='form-control readonly' required>
<span class='add-on'><i class='icon-th'></i></span>
</div>

<div class='input-append date form_date col-lg-3' data-date='' data-date-format='yyyy-mm-dd' data-link-field='dtp_input2' data-link-format='yyyy-mm-dd'>
<input size='16' type='text' name='date2' style='cursor:pointer' placeholder='Date 2' class='form-control readonly' required>
<span class='add-on'><i class='icon-th'></i></span>
</div>

<input type='submit' name='daterz' class='btn btn-sm btn-primary' value='Filter'>
</form>
<table class='table table-bordered table-hover table-striped sortable'>
<thead>
<tr>
<th></th>
<th>Primary</th>
<th>Secondary</th>
<th>Total</th>
</tr>
</thead>
<?php
include ("connect.php");

if(isset($_POST["daterz"])){
    $date1 = $_POST["date1"];
    $date2 = $_POST["date2"];

$datz = "and ((datez>='$date1')&&(datez<='$date2'))";
}else{
$date1 = date("Y-m-d");
$date2 = date("Y-m-d");
$dat2 = date("Y-m-d");
$datz = "and datez='$dat2'";
}

$resultpri = $dbh->query("select cid from received where ((cid>='10000')&&(cid<='49999')) $datz");
$countpri = $resultpri->rowCount();

$resultsec = $dbh->query("select cid from received where cid>='50000' $datz");
$countsec = $resultsec->rowCount();

$resultcashpri = $dbh->query("select sum(am_cash) from received where ((cid>='10000')&&(cid<='49999')) $datz");
$rowcashpri = $resultcashpri->fetch();

$resultcashsec = $dbh->query("select sum(am_cash) from received where cid>='50000' $datz");
$rowcashsec = $resultcashsec->fetch();

$resultmmpri = $dbh->query("select sum(am_mobile) from received where ((cid>='10000')&&(cid<='49999')) $datz");
$rowmmpri = $resultmmpri->fetch();

$resultmmsec = $dbh->query("select sum(am_mobile) from received where cid>='50000' $datz");
$rowmmsec = $resultmmsec->fetch();

$resultchepri = $dbh->query("select sum(am_cheque) from received where ((cid>='10000')&&(cid<='49999')) $datz");
$rowchepri = $resultchepri->fetch();

$resultchesec = $dbh->query("select sum(am_cheque) from received where cid>='50000' $datz");
$rowchesec = $resultchesec->fetch();

$resultbtrpri = $dbh->query("select sum(am_banktfer) from received where ((cid>='10000')&&(cid<='49999')) $datz");
$rowbtrpri = $resultbtrpri->fetch();

$resultbtrsec = $dbh->query("select sum(am_banktfer) from received where cid>='50000' $datz");
$rowbtrsec = $resultbtrsec->fetch();

$resultbspri = $dbh->query("select sum(am_bslip) from received where ((cid>='10000')&&(cid<='49999')) $datz");
$rowbspri = $resultbspri->fetch();

$resultbssec = $dbh->query("select sum(am_bslip) from received where cid>='50000' $datz");
$rowbssec = $resultbssec->fetch();

$prirange="((cid>='10000')&&(cid<='49999'))"; 

$resultfeespri = $dbh->query("select sum(p_fees) from received where $prirange $datz");
$rowfeespri = $resultfeespri->fetch();

$resultcontripri = $dbh->query("select sum(p_contribution) from received where $prirange $datz");
$rowcontripri = $resultcontripri->fetch();

$resultmockfapri = $dbh->query("select sum(p_mockfa) from received where $prirange $datz");
$rowmockfapri = $resultmockfapri->fetch();

$resultuniformpri = $dbh->query("select sum(p_uniform) from received where $prirange $datz");
$rowuniformpri = $resultuniformpri->fetch();


?>
<tbody>
<tr>
<td>Number of children</td>
<td><?php echo "<a href='paytype.php?date1=".$date1."&date2=".$date2."'>".number_format($countpri)."</a>"; ?></td>
<td><?php echo "<a href='paytype.php?date1=".$date1."&date2=".$date2."'>".number_format($countsec)."</a>"; ?></td>
<td><?php echo number_format($countpri + $countsec); ?></td>
</tr>
<tr>
<td>Cash</td>
<td><?php echo number_format($rowcashpri[0]); ?></td>
<td><?php echo number_format($rowcashsec[0]); ?></td>
<td><?php echo number_format($rowcashsec[0] + $rowcashpri[0]); ?></td>
</tr>
<tr>
<td>Mobile money</td>
<td><?php echo number_format($rowmmpri[0]); ?></td>
<td><?php echo number_format($rowmmsec[0]); ?></td>
<td><?php echo number_format($rowmmsec[0] + $rowmmpri[0]); ?></td>
</tr>
<tr>
<td>Cheque</td>
<td><?php echo number_format($rowchepri[0]); ?></td>
<td><?php echo number_format($rowchesec[0]); ?></td>
<td><?php echo number_format($rowchesec[0] + $rowchepri[0]); ?></td>
</tr>
<tr>
<td>Bank transfer</td>
<td><?php echo number_format($rowbtrpri[0]); ?></td>
<td><?php echo number_format($rowbtrsec[0]); ?></td>
<td><?php echo number_format($rowbtrsec[0] + $rowbtrpri[0]); ?></td>
</tr>
<tr>
<td>Bankslip</td>
<td><?php echo number_format($rowbspri[0]); ?></td>
<td><?php echo number_format($rowbssec[0]); ?></td>
<td><?php echo number_format($rowbssec[0] + $rowbspri[0]); ?></td>
</tr>

<tr>
<td colspan='3'>Total</td>
<td><?php echo number_format($rowcashsec[0] + $rowcashpri[0] + $rowmmsec[0] + $rowmmpri[0] + $rowchesec[0] + $rowchepri[0] + $rowbtrsec[0] + $rowbtrpri[0] + $rowbssec[0] + $rowbspri[0]); ?></td>
</tr>
</tbody>

</table>

            <?php
$prirange="((cid>='10000')&&(cid<='49999'))"; 

$resultfeespri = $dbh->query("select sum(p_fees) from received where $prirange $datz");
$rowfeespri = $resultfeespri->fetch();

$resultcontripri = $dbh->query("select sum(p_contribution) from received where $prirange $datz");
$rowcontripri = $resultcontripri->fetch();

$resultmockfapri = $dbh->query("select sum(p_mockfa) from received where $prirange $datz");
$rowmockfapri = $resultmockfapri->fetch();

$resultother1pri = $dbh->query("select sum(p_other1) from received where $prirange $datz");
$rowother1pri = $resultother1pri->fetch();

$resultuniformpri = $dbh->query("select sum(p_uniform) from received where $prirange $datz");
$rowuniformpri = $resultuniformpri->fetch();

$resultadmissionpri = $dbh->query("select sum(p_admission) from received where $prirange $datz");
$rowadmissionpri = $resultadmissionpri->fetch();

$resultregistrationpri = $dbh->query("select sum(p_registration) from received where $prirange $datz");
$rowregistrationpri = $resultregistrationpri->fetch();

$resultholidaypri = $dbh->query("select sum(p_holiday) from received where $prirange $datz");
$rowholidaypri = $resultholidaypri->fetch();

$resultother3pri = $dbh->query("select sum(p_other3) from received where $prirange $datz");
$rowother3pri = $resultother3pri->fetch();



$secrange="(cid>='50000')"; 

$resultfeessec = $dbh->query("select sum(p_fees) from received where $secrange $datz");
$rowfeessec = $resultfeessec->fetch();

$resultcontrisec = $dbh->query("select sum(p_contribution) from received where $secrange $datz");
$rowcontrisec = $resultcontrisec->fetch();

$resultmockfasec = $dbh->query("select sum(p_mockfa) from received where $secrange $datz");
$rowmockfasec = $resultmockfasec->fetch();

$resultother1sec = $dbh->query("select sum(p_other1) from received where $secrange $datz");
$rowother1sec = $resultother1sec->fetch();

$resultuniformsec = $dbh->query("select sum(p_uniform) from received where $secrange $datz");
$rowuniformsec = $resultuniformsec->fetch();

$resultadmissionsec = $dbh->query("select sum(p_admission) from received where $secrange $datz");
$rowadmissionsec = $resultadmissionsec->fetch();

$resultregistrationsec = $dbh->query("select sum(p_registration) from received where $secrange $datz");
$rowregistrationsec = $resultregistrationsec->fetch();

$resultholidaysec = $dbh->query("select sum(p_holiday) from received where $secrange $datz");
$rowholidaysec = $resultholidaysec->fetch();

$resultother3sec = $dbh->query("select sum(p_other3) from received where $secrange $datz");
$rowother3sec = $resultother3sec->fetch();


$feestotal=$rowfeespri['0']+$rowfeessec['0'];
$contributiontotal=$rowcontripri['0']+$rowcontrisec['0'];
$mockfatotal=$rowmockfapri['0']+$rowmockfasec['0'];
$other1total=$rowother1pri['0']+$rowother1sec['0'];
$other3total=$rowother3pri['0']+$rowother3sec['0'];
$uniformtotal=$rowuniformpri['0']+$rowuniformsec['0'];
$registrationtotal=$rowregistrationpri['0']+$rowregistrationsec['0'];
$admissiontotal=$rowadmissionpri['0']+$rowadmissionsec['0'];
$holidaytotal=$rowholidaypri['0']+$rowholidaysec['0'];
            ?>    
                  
                  </div> 
                   </div>


                   
            </div>
                                                             <div class="col-lg-12">
  <div class="panel panel-green">
                <div class="panel-heading">
                                <h3 class="panel-title">Fees Summary </h3>
                            </div>
                            <div class="panel-body">

<table class="table table-bordered table-hover table-striped sortable">
<thead>
  <tr>
    <th>Fee Type</th>
    <th>Primary</th>
    <th>Secondary</th>
    <th>Total</th>
  </tr>
</thead>
<tbody>
<tr>
<td>School Fees</td>
<td><?php echo number_format($rowfeespri[0]);?></td>
<td><?php echo number_format($rowfeessec[0]);?></td>
<td><?php echo number_format($feestotal);?></td>
</tr>

<tr><td>Contribution</td>
<td><?php echo number_format($rowcontripri[0]);?></td>
<td><?php echo number_format($rowcontrisec[0]);?></td>
<td><?php echo number_format($contributiontotal);?></td>
</tr>
<tr>
    <td>Uniform</td>
    <td><?php echo number_format($rowuniformpri[0]);?></td>
    <td><?php echo number_format($rowuniformsec[0]);?></td>
    <td><?php echo number_format($uniformtotal);?></td>
</tr>
<tr>
    <td>Trip</td>
    <td><?php echo number_format($rowother1pri[0]);?></td>
    <td><?php echo number_format($rowother1sec[0]);?></td>
    <td><?php echo number_format($other1total);?></td>
</tr>
<tr>
    <td>Mock/Facillitation</td>
    <td><?php echo number_format($rowmockfapri[0]);?></td>
    <td><?php echo number_format($rowmockfasec[0]);?></td>
    <td><?php echo number_format($mockfatotal);?></td>
</tr>
<tr>
    <td>Admission</td>
    <td><?php echo number_format($rowadmissionpri[0]);?></td>
    <td><?php echo number_format($rowadmissionsec[0]);?></td>
    <td><?php echo number_format($admissiontotal);?></td>
    </tr>
<tr>
    <td>Registration</td>
    <td><?php echo number_format($rowregistrationpri[0]);?></td>
    <td><?php echo number_format($rowregistrationsec[0]);?></td>
    <td><?php echo number_format($registrationtotal);?></td>
</tr>
<tr>
    <td>Other studies</td>
    <td><?php echo number_format($rowholidaypri[0]);?></td>
    <td><?php echo number_format($rowholidaysec[0]);?></td>
    <td><?php echo number_format($holidaytotal);?></td>
</tr>
<tr>
    <td>Bank Charges</td>
    <td><?php echo number_format($rowother3pri[0]);?></td>
     <td><?php echo number_format($rowother3sec[0]);?></td>
         <td><?php echo number_format($other3total);?></td>
</tr>
</tbody>
</table>
                    
                            </div>
                   
                <!-- /.row -->





                 
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript">
    $('.form_datetime').datetimepicker({
        //language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });
    $('.form_date').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    $('.form_time').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    });
</script>


    <!-- Morris Charts JavaScript -->
    <?php useractivity("on page","4"); ?>

</body>

</html>