<?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>
<?php
$role = $_SESSION["role"];
if($role=="priaccount"){
echo "<th>Primary</th>";

}elseif($role=="secaccount"){
echo "<th>Secondary</th>";
}

?>
</tr>
</thead>
<?php
include ("connect.php");

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

    $datz = "and ((datez>='$date1')&&(datez<='$date2'))";
}else{
$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'");
$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'");
$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'");
$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'");
$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();

echo "
<tbody>
<tr>
<td>Number of children</td>";
if($role=="priaccount"){
echo "<td>".$countpri."</td>";
}elseif($role=="secaccount"){
echo "<td>".$countsec."</td>";
}

echo "
</tr>
<tr>
<td>Cash</td>";
if($role=="priaccount"){
echo "<td>".$rowcashpri[0]."</td>";
}elseif($role=="secaccount"){
echo "<td>".$rowcashsec[0]."</td>";
}


echo "
</tr>
<tr>
<td>Mobile money</td>";
if($role=="priaccount"){
echo "<td>".$rowmmpri[0]."</td>";
}elseif($role=="secaccount"){
echo "<td>".$rowmmsec[0]."</td>";
}

echo "
</tr>
<tr>
<td>Cheque</td>";
if($role=="priaccount"){
echo "<td>".$rowchepri[0]."</td>";
}elseif($role=="secaccount"){
echo "<td>".$rowchesec[0]."</td>";
}
echo "
</tr>
<tr>
<td>Bank transfer</td>";
if($role=="priaccount"){
echo "<td>".$rowbtrpri[0]."</td>";
}elseif($role=="secaccount"){
echo "<td>".$rowbtrsec[0]."</td>";
}
echo "
</tr>
<tr>
<td>Bankslip</td>";
if($role=="priaccount"){
echo "<td>".$rowbspri[0]."</td>";
}elseif($role=="secaccount"){
echo "<td>".$rowbssec[0]."</td>";
}
echo "
</tr>

<tr>
<td>Total</td>
<td>";
if($role=="priaccount" or $role=="overadmin"){
    echo number_format($rowcashpri[0] + $rowmmpri[0] + $rowchepri[0] + $rowbtrpri[0] + $rowbspri[0]);
}elseif($role=="secaccount" or $role=="overadmin"){
    echo number_format($rowcashsec[0] + $rowmmsec[0] + $rowchesec[0] + $rowbtrsec[0] + $rowbssec[0]);
}
echo "
</td>
</tr>
</tbody>
</table>";
?>
</div> 
                   </div>


                   
                             
                                </div>
                                
                           


<div class="col-lg-12">
  <div class="panel panel-yellow">
                <div class="panel-heading">
                                <h3 class="panel-title">Income details</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='dater256' class='btn btn-sm btn-primary' value='Filter'>
</form>

<table class='table table-bordered table-hover table-striped sortable'>
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Names</th>
<th>Amount</th>
<th>Items</th>
</tr>
</thead>
<tbody>
<?php
include("connect.php");

if(isset($_POST["dater256"])){
    $date1 = $_POST["date1"];
    $date2 = $_POST["date2"];
    
    $querm = "select * from received where ((datez>='$date1')&&(datez<='$date2')) order by autodate desc";

}else{
    $querm = "select * from received order by autodate desc limit 0,20";
}

$result = $dbh->query("$querm");
$row = $result->fetchObject();
$count = $result->rowCount();

if($count>0){
do{
$result2 = $dbh->query("select * from children where cid='$row->cid'");
$row2 = $result2->fetchObject();

$result3 = $dbh->query("select sum(p_fees) + sum(p_uniform) + sum(p_contribution) + sum(p_registration) + sum(p_holiday) + sum(p_admission) + sum(p_transport) + sum(p_mockfa) + sum(p_other1) + sum(p_other2) + sum(p_other3) from received where cid='$row->cid'");
$row3 = $result3->fetch();

echo "
<tr>
<td>".$row->cid."</td>
<td>".$row->autodate."</td>
<td>".$row2->fname." ".$row2->sname."</td>
<td>".number_format($row3[0])."</td>
<td>";
if($row->p_fees>0){
    echo "Fees : ".$row->p_fees."<br>";
}
if($row->p_uniform>0){
    echo "Unif : ".$row->p_uniform."<br>";
}
if($row->p_contribution>0){
    echo "Cont : ".$row->p_contribution."<br>";
}
if($row->p_registration>0){
    echo "Reg : ".$row->p_registration."<br>";
}
if($row->p_holiday>0){
    echo "Holi : ".$row->p_holiday."<br>";
}
if($row->p_admission>0){
    echo "Adm : ".$row->p_admission."<br>";
}
if($row->p_transport>0){
    echo "Tp : ".$row->p_transport."<br>";
}
if($row->p_mockfa>0){
    echo "Mock : ".$row->p_mockfa."<br>";
}
if($row->p_other1>0){
    echo "Other1 : ".$row->p_other1."<br>";
}
if($row->p_other2>0){
    echo "Other2 : ".$row->p_other2."<br>";
}
if($row->p_other3>0){
    echo "Other3 : ".$row->p_other3."<br>";
}

echo "
</td>
</tr>";
}while($row = $result->fetchObject());
}else{echo "<tr><td colspan='5'>So far, there is NO data. </td></tr>";}
?>
</tbody>
</table>

                
                  
                  </div> 
                   </div>


                   
                             
                                </div>
                                
                            </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>