<?php
   $sch='';
   //$query=mysqli_query($con,"select * FROM companydata");
   //while($row=mysqli_fetch_array($query))
   //{
    //$sch=$row['School'];
   //}
   ?>
<div class="content-wrapper">
   <!-- Content Header (Page header) -->
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h4 class="m-0">income Statement </h4>
            </div>
            <!-- /.col -->
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item">Dashboard</li>
                  <li class="breadcrumb-item">Reports</li>
                  <li class="breadcrumb-item active"><a href="#" id="linkdownn"> Summary</a></li>
               </ol>
            </div>
            <!-- /.col -->
         </div>
         <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
   </div>
   <section class="content container">
      <div class="row">
         <div class="col-md-12">
            <div class="col-md-6">
               <form action="" method="POST" onsubmit="return false">
                  <div class="row">
                     <div class="col-md-4">
                        <div class="form-group">
                           <label for="inputStatus" class="titles"> Select Year <span class="requireds">*</span>
                           </label>
                           <select id="yeah" class="form-control custom-select" required>
                              <option selected disabled value="">Select ---</option>
                              <option value="2022">2022</option>
                              </option>
                              <option value="2023">2023</option>
                              <option value="2024">2024</option>
                              <option value="2025">2025</option>
                              <option value="2026">2026</option>
                              <option value="2027">2027</option>
                              <option value="2028">2028</option>
                              <option value="2029">2029</option>
                              <option value="2030">2030</option>
                              <option value="2031">2031</option>
                              <option value="2032">2032</option>
                              <option value="2033">2033</option>
                              <option value="2034">2034</option>
                              <option value="2035">2035</option>
                              <option value="2036">2036</option>
                              <option value="2037">2037</option>
                              <option value="2038">2038</option>
                              <option value="2039">2039</option>
                              <option value="2040">2040</option>
                           </select>
                        </div>
                     </div>
                     <div class="col-md-4">
                        <div class="form-group">
                           <label for="inputStatus" class="titles">Select Period<span class="requireds">*</span>
                           </label>
                           <select id="perio" class="form-control custom-select" required>
                              <option selected disabled value="">---</option>
                              <option value="January-April">January-April</option>
                              <option value="May-August">May-August</option>
                              <option value="September-December">September-December</option>
                           </select>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label for="inputStatus" class="titles">Filter Data<span class="requireds"></span>
                           </label> <br />
                           <button class="btn btn-default" id="btnfilters"> <i class="fa fa-filter"></i>
                           </button>
                        </div>
                     </div>
                  </div>
               </form>
            </div>
            <ul class="nav nav-tabs">
               <li class="nav-item">
                  <a class="nav-link active" data-toggle="tab" href="#summar">income & Expenditure  </a>
               </li>
               <li class="nav-item">
                  <a class="nav-link" data-toggle="tab" href="#tabproject">Projects</a>
               </li>
               <li class="nav-item">
                  <a class="nav-link" data-toggle="tab" href="#enroldiv">Enrolment</a>
               </li>
               <li class="nav-item">
                  <a class="nav-link" data-toggle="tab" href="#accounts">Cash and Cash Equivalents</a>
               </li>
            </ul>
            <div class="tab-content">
               <div id="accounts" class=" tab-pane">
                  <div class="container-fluid">
                     <?php include('Accountssummary.php'); ?>     
                     <hr />
                     <h6 style="color:#006600">Banks Status</h6>
                     <table class="table table-bordered table-sm" id="tablebankdata" style="font-size:11px;font-family:Tahoma">
                        <thead>
                           <tr>
                              <th>#</th>
                              <th>Bank Name</th>
                              <th>Bank Balance as at 1st January <?php echo $yr; ?> </th>
                              <th>Total Income (KES)</th>
                              <th>Total Expenditure (KES)</th>
                              <th colspan="2" class="alert-info">Balances (KES)</th>
                           </tr>
                        </thead>
                        <tbody>
                           <?php
                              $sql = "select bankdata.*,bankdata.id as baid,Bankreports.Amount as amt, (SELECT SUM(income) from bankanalysis where Year='$year' AND bid=baid) as mwakaincome,(SELECT SUM(Expe) from bankanalysis where Year='$year' AND bid=baid) as mwakaexpe from bankdata left join Bankreports ON Bankreports.bid=bankdata.id where Bankreports.Year='$yr'  order by bankdata.Bname DESC";
                              $result = $con->query($sql);
                              if ($result->num_rows > 0) 
                               {
                                $cnt='1';
                                while($row = $result->fetch_assoc()) 
                                 {
                                    ?>	
                           <tr>
                              <td><?php echo $cnt; ?></td>
                              <td><?php echo $row["Bname"].' '; ?> <small>(<?php echo $row["Account"]; ?>)</small> </td>
                              <td class="alert-success"><?php echo $row["amt"]; ?></td>
                              <td class="alert-success"><?php echo $row["mwakaincome"]; ?></td>
                              <td class="alert-danger"><?php echo $row["mwakaexpe"]; ?></td>
                              <td class="alert-info"><strong><?php echo ($row["amt"]+$row["mwakaincome"])-$row["mwakaexpe"]; ?></strong></td>
                           </tr>
                           <?php
                              $cnt=$cnt+1;
                               }
                              }
                                ?>
                        </tbody>
                     </table>
                  </div>
               </div>
               <div id="summar" class=" tab-pane active">
                  <?php
                     if($pe =='' || $pe ==null)
                     {
                       echo 'No data filtered';
                     }else
                     {
                     if($pe=='January-April')
                     {
                      include('Calculation1.php'); 
                      include('JantoApr.php');
                     }else if($pe=='May-August')
                     {
                     include('Calculation2.php');  
                     include('MaytoAug.php');
                     }else if($pe=='September-December')
                     {
                     include('Calculation3.php');    
                     include('SeptoDec.php');
                     }else
                     {
                     //include('Calculation4.php'); 
                     //include('OcttoDec.php');  
                     }
                     }
                     ?>
               </div>
               <div id="enroldiv" class="tab-pane">
                  <h5>Classes Enrolment <strong class="text-warning"><u><?php echo $samu; ?></u></strong></h5>
                  <div class="table-responsive" id="divenrollmentt">
                     <table class="table table-bordered" id="tableenrollmentt" style="font-size:11px">
                        <thead>
                           <tr>
                              <th>#</th>
                              <th>Class</th>
                              <th>Boys</th>
                              <th>Girls</th>
                              <th>Total</th>
                           </tr>
                        </thead>
                        <tbody>
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='BABY CLASS' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='BABY CLASS' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='BABY CLASS' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>1</td>
                              <td>BABAY CLASS</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!--PP1 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='PP1' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='PP1' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='PP1' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>2</td>
                              <td>PP1</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!-- pp2 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='PP2' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='PP2' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='PP2' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>3</td>
                              <td>PP2</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!--GRADE 1 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 1' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 1' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 1' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>4</td>
                              <td>GRADE 1</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!--GRADE 2 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 2' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 2' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 2' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>5</td>
                              <td>GRADE 2</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!-- GRADE 3 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 3' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 3' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 3' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>6</td>
                              <td>GRADE 3</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!-- GRADE 4-->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 4' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 4' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 4' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>7</td>
                              <td>GRADE 4</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!-- GRADE 5 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 5' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 5' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 5' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>8</td>
                              <td>GRADE 5</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!--GRADE 6 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 6' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 6' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 6' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>9</td>
                              <td>GRADE 6</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!--GRADE 7 -->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 7' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 7' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 7' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>10</td>
                              <td>GRADE 7</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <!-- CLASS 8 --->
                           <tr>
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 8' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $baba=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 8' AND Gender='Male' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Claz='GRADE 8' AND Gender='Female' AND Status='Active'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 
                                 ?>
                              <td>11</td>
                              <td>GRADE 8</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td><?php echo $baba; ?></td>
                           </tr>
                           <tr class="alert-success">
                              <?php
                                 $result = mysqli_query($con,"SELECT * FROM pupils WHERE Status='Active' AND Claz !='CLASS 8'");
                                 $num_rows1 = mysqli_num_rows($result);
                                 {
                                 $tot=htmlentities($num_rows1); 
                                 }
                                 
                                 $resultt = mysqli_query($con,"SELECT * FROM pupils where Gender='Male' AND Status='Active' AND Claz !='CLASS 8'");
                                 $num_rows1 = mysqli_num_rows($resultt);
                                 {
                                 $boyz=htmlentities($num_rows1); 
                                 }
                                 
                                 $resulttt = mysqli_query($con,"SELECT * FROM pupils where Gender='Female' AND Status='Active' AND Claz !='CLASS 8'");
                                 $num_rows1 = mysqli_num_rows($resulttt);
                                 {
                                 $fem=htmlentities($num_rows1); 
                                 }
                                 ?>
                              <td colspan="2">TOTAL</td>
                              <td><?php echo $boyz; ?></td>
                              <td><?php echo $fem; ?></td>
                              <td class="alert-warning" ><strong><?php echo $tot; ?></strong></td>
                           </tr>
                        </tbody>
                     </table>
                  </div>
                  <button class="btn btn-success btn-sm pull-right" id="btnenroll">Download Excel File <i class="fa fa-cloud-downlaod"></i></button>
                  <hr />
               </div>
               <div id="tabproject" class="tab-pane">
                  <h5><u>Projects Cash & Cash Equivalent</u></h5>
                  <hr />
                  <table class="table table-sm" id="tabledatacash" style='font-size:11px'>
                     <thead>
                        <tr>
                           <th>#</th>
                           <th>Date</th>
                           <th>Particular</th>
                           <th>Cheque No.</th>
                           <th>Money Out</th>
                        </tr>
                     </thead>
                     <tbody>
                        <?php
                           $cnt=1;
                           $query=mysqli_query($con,"select projects.*,prodata.Dat, prodata.Item,prodata.Cheq,prodata.Amount FROM projects left join prodata ON prodata.proid=projects.id where prodata.Year='$yr'");
                           while($row=mysqli_fetch_array($query))
                           {
                           ?>
                        <tr>
                           <td><?php echo $cnt; ?></td>
                           <td tiltle="<?php echo $row['Pname']; ?>"><?php echo $row['Dat']; ?></td>
                           <td><?php echo $row['Item']; ?></td>
                           <td><?php echo $row['Cheq']; ?></td>
                           <td><?php echo $row['Amount']; ?></td>
                        </tr>
                        <?php
                           $cnt= $cnt+1;
                           }
                           ?>
                     </tbody>
                     <tfooter>
                        <?php
                           $query=mysqli_query($con,"SELECT SUM(Amount) as sam from prodata where Year='$yr'");
                           while($row=mysqli_fetch_array($query))
                           {
                           $prosam=$row['sam'];
                           }
                           ?>
                        <tr class="alert-warning">
                           <td colspan="4"><strong>Total</strong></td>
                           <td><strong><?php echo $prosam; ?></strong></td>
                        </tr>
                     </tfooter>
                  </table>
               </div>
            </div>
         </div>
      </div>
   </section>
</div>