<?php
    $date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
    $timenow=$date->format('Y-m-d H:i:s');
    $timenow2=$date->format('Y-m-d');
    $month=$date->format('F');
    //$finaldate='Today: '.$date
   
    $y=intval($_GET['Year']);
    if($y=='' || $y==null)
    {
        $yr=$date->format('Y');
    }else
    {
         $yr=$y;
    }
    
 include('feeincome.php');
    //UniformUpdate
    $sql=mysqli_query($con,"UPDATE income SET January='$janfee',February='$febfee', March='$marfee',April='$aprfee', May='$mayfee', June='$junfee', July='$julyfee', August='$augfee', September='$sepfee', October='$octfee', November='$novfee', December='$decfee' WHERE Year='$yr' AND Item='School Fees'");
    if($sql)
    {}
    
 include('farmincome.php');
    
     $sql2=mysqli_query($con,"UPDATE income SET January='$janfam',February='$febfam', March='$marfam',April='$aprfam',May='$mayfam',June='$junfam',July='$julyfam',August='$augfam',September='$sepfam',October='$octfam',November='$novfam',December='$decfam'  WHERE Year='$yr' AND Item='Farm Income'");
    if($sql2)
    {}
    
    
    include('vehicleincome.php');
    
     $sql3=mysqli_query($con,"UPDATE income SET January='$janveh',February='$febveh',March='$marveh',April='$aprveh',May='$mayveh',June='$junveh',July='$julyveh',August='$augveh',September='$sepveh',October='$octveh',November='$novveh',December='$decveh'  WHERE Year='$yr' AND Item='School Vehicles'");
    if($sql3)
    {}
    
    
    include('otherincomesummary.php');
    
     $sql4=mysqli_query($con,"UPDATE income SET January='$janoth',February='$feboth',March='$maroth',April='$aproth',May='$mayoth',June='$junoth',July='$julyoth',August='$augoth',September='$sepoth',October='$octoth',November='$novoth',December='$decoth'  WHERE Year='$yr' AND Item='Other Sources'");
    if($sql4)
    {}
?>

<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">
            <h5 class="m-0">Income Reports</h5>
          </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">Income</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-5 col-sm-12 col-12">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="far fa-envelope"></i></span>
              <?php
                include('../include/config.php');
                $result = mysqli_query($con,"SELECT SUM($month) as tincome FROM income where year='$yr'");
                while($row = $result->fetch_assoc()) 
                {
                  $income=$row["tincome"];
                }
                ?>
              <div class="info-box-content">
                <span class="info-box-text">Total Income this Month (<small><?php echo $month;?></small>)</span>
                <h4 class="info-box-number budge"><?php echo $income.' Ksh'; ?></h4>
              </div>
    
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          
          <div class="col-md-5 col-sm-12 col-12">
            <div class="info-box">
              <span class="info-box-icon bg-success"><i class="far fa-filter"></i></span>
              
              <div class="info-box-content">
                <div class="form-group">
                <label for="inputStatus">Year <span class="requireds">*</span>
                </label>
                 <select id="yearfilterincome" class="form-control custom-select" required>
                <option selected disabled value="<?php echo $yr; ?>"><?php echo $yr; ?></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>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          </div>
         </div>
    </section>
          
    
    <section class="content" style="text-decoration:none;font-weight:normal;font-family:Times;font-size:12px">
         <div class="row">
         <div class="col-md-12">   
         <div class="card">
              
           <div class="card-header p-2">
                <ul class="nav nav-pills">
                  <li class="nav-item"><a class="nav-link active" href="#divfee" data-toggle="tab">School Fees</a></li>
                  <li class="nav-item"><a class="nav-link" href="#divfarm" data-toggle="tab">Fee Per Class</a></li>
                </ul>
             </div><!-- /.card-header -->  
             <div class="card-body">
                <div class="tab-content">
                    
            <div class="active tab-pane" id="divfee">
             <div class="post">
             <div class="user-block table-respo" > 
             <div class="table-responsive" id="divincomeanysis">
                 <table class="table table-bordered table-warning" id="incomeanalysis" >
                     <thead>
                         <tr class="alert-success">
                             <th>#</th>
                             <th>Item</th>
                             <th>January</th>
                             <th>February</th>
                             <th>March</th>
                             <th>April</th>
                             <th>May</th>
                             <th>June</th>
                             <th>July</th>
                             <th>August</th>
                             <th>September</th>
                             <th>October</th>
                             <th>November</th>
                             <th>December</th>
                         </tr>
                     </thead>
                     <tbody>
                        <?php
                        //include('../include/config.php');
                        $sql = "select * from income where Year='$yr'";
                        $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["Item"]; ?></td>
                        <td><strong><?php echo $row["January"]; ?></strong></td>
                        <td><strong><?php echo $row["Feb"]; ?></strong></td>
                        <td><strong><?php echo $row["March"]; ?></strong></td>
                        <td><strong><?php echo $row["April"]; ?></strong></td>
                        <td><strong><?php echo $row["May"]; ?></strong></td>
                        <td><strong><?php echo $row["June"]; ?></strong></td>
                        <td><strong><?php echo $row["July"]; ?></strong></td>
                        <td><strong><?php echo $row["Aug"]; ?></strong></td>
                        <td><strong><?php echo $row["Sep"]; ?></strong></td>
                        <td><strong><?php echo $row["Oct"]; ?></strong></td>
                        <td><strong><?php echo $row["Nov"]; ?></strong></td>
                        <td><strong><?php echo $row["December"]; ?></td>
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }
                        
                        
                        include('incomeanalysis.php');
        
                        
                        
                            ?>
                        <tr class="bg-secondary">
                        <td colspan="2"><strong>Total (KES)</strong></td>
                        <td><?php echo $ja; ?></td>
                        <td><?php echo $fe; ?></td>
                        <td><?php echo $ma; ?></td>
                        <td><?php echo $ap; ?></td>
                        <td><?php echo $may; ?></td>
                        <td><?php echo $ju; ?></td>
                        <td><?php echo $jul; ?></td>
                        <td><?php echo $au; ?></td>
                        <td><?php echo $sep; ?></td>
                        <td><?php echo $oct; ?></td>
                        <td><?php echo $nov; ?></td>
                        <td><?php echo $de; ?></td>
                        </tr>
                     </tbody>
                 </table> 
              </div>
              </div>
              </div>
              </div>
              
              <div class="tab-pane" id="divfarm">
                  <div class="col-md-12"> 
                      <h5>Fee Per Class as paid for year: <strong class="text-danger"><?php echo $yr; ?> </strong></h5>
                      
                       <div class="table-responsive divincome2" id="divincome2">
                 <table class="table table-bordered table-success incomeperclasstable" id="incomeperclasstable" >
                     <thead>
                         <tr class="alert-success">
                             <th>#</th>
                             <th>Class</th>
                             <th>Term One</th>
                             <th>Term Two</th>
                             <th>Term Three</th>
                             <th>Total (KES)</th>
                         </tr>
                     </thead>
                     <tbody>
                        <?php
                        $baby1='';
                         $baby2='';
                          $baby2='';
                        //include('../include/config.php');
                        $sql = "select (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='BABY CLASS') as baby1,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='BABY CLASS') as baby2, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='BABY CLASS') as baby3, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='PP1') as pp11, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='PP1') as pp12, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='PP1') as pp13,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='PP2') as pp21, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='PP2') as pp22,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='PP2') as pp23, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 1') as gra11, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 1') as gra12, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 1') as gra13, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 2') as gra21, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 2') as gra22, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 2') as gra23, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 3') as gra31, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 3') as gra32, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 3') as gra33, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 4') as gra41, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 4') as gra42, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 4') as gra43, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 5') as gra51, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 5') as gra52, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 5') as gra53, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 6') as gra61, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 6') as gra62,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 6') as gra63, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='GRADE 7') as gra71, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='GRADE 7') as gra72, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='GRADE 7') as gra73, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One' AND Grad='CLASS 8') as cla81,  (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two' AND Grad='CLASS 8') as cla82,  (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three' AND Grad='CLASS 8') as cla83, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term One') as tarm1, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Two') as tarm2, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Term='Term Three') as tarm3,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='BABY CLASS') as BAT,  (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='PP1') as PP1T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='PP2') as PP2T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 1') as GRA1T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 2') as GRA2T,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 3') as GRA3T,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 4') as GRA4T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 5') as GRA5T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 6') as GRA6T,(SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='GRADE 7') as GRA7T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr' AND Grad='CLASS 8') as CLA8T, (SELECT SUM(PaidAmount) FROM feestatement where Year='$yr') as TTT
                        from feestatement where Year='$yr' GROUP BY count";
                        $result = $con->query($sql);
                        if ($result->num_rows > 0) 
                        {
                            $cnt='1';
                            while($row = $result->fetch_assoc()) 
                            {
                                $baby1=$row["baby1"]; 
                                $baby2=$row["baby2"]; 
                                $baby3=$row["baby3"]; 
                                
                                $pp11=$row["pp11"]; 
                                $pp12=$row["pp12"]; 
                                $pp13=$row["pp13"]; 
                                
                                $pp21=$row["pp21"]; 
                                $pp22=$row["pp22"]; 
                                $pp23=$row["pp23"]; 
                                
                                $gra11=$row["gra11"]; 
                                $gra12=$row["gra12"]; 
                                $gra13=$row["gra13"]; 
                                
                                $gra21=$row["gra21"]; 
                                $gra22=$row["gra22"]; 
                                $gra23=$row["gra23"];
                                
                                $gra31=$row["gra31"]; 
                                $gra32=$row["gra32"]; 
                                $gra33=$row["gra33"];
                                
                                $gra41=$row["gra41"]; 
                                $gra42=$row["gra42"]; 
                                $gra43=$row["gra43"];
                                
                                $gra51=$row["gra51"]; 
                                $gra52=$row["gra52"]; 
                                $gra53=$row["gra53"];
                                
                                $gra61=$row["gra61"]; 
                                $gra62=$row["gra62"]; 
                                $gra63=$row["gra63"];
                                
                                $gra71=$row["gra71"]; 
                                $gra72=$row["gra72"]; 
                                $gra73=$row["gra73"];
                                
                                $cla81=$row["cla81"]; 
                                $cla82=$row["cla82"]; 
                                $cla83=$row["cla83"];
                                
                                $tarm1=$row["tarm1"];
                                $tarm2=$row["tarm2"];
                                $tarm3=$row["tarm3"];
                                
                                $BAT=$row["BAT"];
                                $PP1T=$row["PP1T"];
                                $PP2T=$row["PP2T"];
                                $PP2T=$row["PP2T"];
                                $GRA1T=$row["GRA1T"];
                                $GRA2T=$row["GRA2T"];
                                $GRA3T=$row["GRA3T"];
                                $GRA4T=$row["GRA4T"];
                                $GRA5T=$row["GRA5T"];
                                $GRA6T=$row["GRA6T"];
                                $GRA7T=$row["GRA7T"];
                                $CLA8T=$row["CLA8T"];
                                
                                $TTT=$row["TTT"];
                            }
                            ?>	
                        <tr>
                        <td>1</td>
                        <td>BABY CLASS</td>
                        
                        <td><strong><?php echo $baby1; ?></strong></td>
                         <td><strong> <?php echo $baby2; ?></strong></td>
                          <td><strong><?php echo $baby3; ?></strong></td>
                          <td class="bg-secondary"><strong><?php echo $BAT; ?></strong></td>
                        </tr>
                        
                         <tr>
                        <td>2</td>
                        <td>PP1</td>
                        <td><strong><?php echo $pp11; ?></strong></td>
                        <td><strong><?php echo $pp12; ?></strong></td>
                        <td><strong><?php echo $pp13; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $PP1T; ?></strong></td>
                        </tr>
                        
                         <tr>
                        <td>3</td>
                        <td>PP2</td>
                        <td><strong><?php echo $pp21; ?></strong></td>
                        <td><strong><?php echo $pp22; ?></strong></td>
                         <td><strong><?php echo $pp23; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $PP2T; ?></strong></td>
                        </tr>
                        
                         <tr>
                        <td>4</td>
                        <td>Grade 1</td>
                        <td><strong><?php echo $gra11; ?></strong></td>
                        <td><strong><?php echo $gra12; ?></strong></td>
                         <td><strong><?php echo $gra13; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA1T; ?></strong></td>
                         </tr>
                         
                         <tr>    
                        <td>5</td>
                        <td>Grade 2</td>
                        <td><strong><?php echo $gra21; ?></strong></td>
                        <td><strong><?php echo $gra22; ?></strong></td>
                        <td><strong><?php echo $gra23; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA2T; ?></strong></td>
                      
                        </tr>
                        
                          <tr>    
                        <td>6</td>
                        <td>Grade 3</td>
                       <td><strong><?php echo $gra31; ?></strong></td>
                        <td><strong><?php echo $gra32; ?></strong></td>
                        <td><strong><?php echo $gra33; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA3T; ?></strong></td>
                  
                        </tr>
                        
                          <tr>    
                        <td>7</td>
                        <td>Grade 4</td>
                        <td><strong><?php echo $gra41; ?></strong></td>
                        <td><strong><?php echo $gra42; ?></strong></td>
                        <td><strong><?php echo $gra43; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA4T; ?></strong></td>
                        </tr>
                        
                          <tr>    
                        <td>8</td>
                        <td>Grade 5</td>
                        <td><strong><?php echo $gra51; ?></strong></td>
                        <td><strong><?php echo $gra52; ?></strong></td>
                        <td><strong><?php echo $gra53; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA5T; ?></strong></td>
                        </tr>
                        
                          <tr>    
                        <td>9</td>
                        <td>Grade 6</td>
                        <td><strong><?php echo $gra61; ?></strong></td>
                        <td><strong><?php echo $gra62; ?></strong></td>
                        <td><strong><?php echo $gra63; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA6T; ?></strong></td>
                        </tr>
                        
                          <tr>    
                        <td>10</td>
                        <td>Grade 7</td>
                        <td><strong><?php echo $gra71; ?></strong></td>
                        <td><strong><?php echo $gra72; ?></strong></td>
                        <td><strong><?php echo $gra73; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $GRA7T; ?></strong></td>
                        </tr>
                        
                          <tr>    
                        <td>11</td>
                        <td>Class 8</td>
                        <td><strong><?php echo $cla81; ?></strong></td>
                        <td><strong><?php echo $cla82; ?></strong></td>
                        <td><strong><?php echo $cla83; ?></strong></td>
                        <td class="bg-secondary"><strong><?php echo $CLA8T; ?></strong></td>
                        </tr>
                        
                        <tr class="alert-info">    
                        <td colspan="2"><strong style="font-weight:800">Total (KES) </strong></td>
                        <td><strong><?php echo $tarm1; ?></strong></td>
                        <td><strong><?php echo $tarm2; ?></strong></td>
                        <td><strong><?php echo $tarm3; ?></strong></td>
                        <td CLASS='alert-danger'><strong style="font-family:Robot,font-size:24px"><u><?php echo $TTT; ?></u></strong></td
                        </tr>
                        
                            <?php
                            $cnt=$cnt+1;
                            
                        }
                            ?>
                     </tbody>
                 </table> 
                 <hr />
                 <button id="down" class="pull-right">Dowload To Excel <i class="fa fa-cloud-download"></i></button>
              </div>
                  </div>
             </div>
              </div>
              
            </div>
          </div>
          </div>
          </div>
    </section>
</div>

