<?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('M');
    //$finaldate='Today: '.$date
   
    $y=intval($_GET['Year']);
    if($y=='' || $y==null)
    {
        $yr=$date->format('Y');
    }else
    {
         $yr=$y;
    }
    
   include('expe.php');
    $sql=mysqli_query($con,"UPDATE Expenditure SET January='$janexpe',February='$febexpe', March='$marexpe',April='$aprexpense', May='$mayexpe', June='$junexpe', July='$julyexpe', August='$augexpe', September='$sepexpe', October='$octexpe', November='$novexpe', December='$decexpe' WHERE Year='$yr' AND Item='Other Expenses'");
    if($sql)
    {
        
    }else{
       
    }
      
   
 include('sala.php');
 
    //UniformUpdate
    $sql=mysqli_query($con,"UPDATE Expenditure SET January='$jansala',February='$febsala', March='$marsala',April='$aprsala', May='$maysala', June='$junsala', July='$julysala', August='$augsala', September='$sepsala', October='$octsala', November='$novsala', December='$decsala' WHERE Year='$yr' AND Item='Salaries'");
    if($sql)
    {
        
    }else{
       
    }
    
     include('nhif.php');
     
    $sql=mysqli_query($con,"UPDATE Expenditure SET January='$jannhif',February='$febnhif', March='$marnhif',April='$aprnhif', May='$maynhif', June='$junnhif', July='$julynhif', August='$augnhif', September='$sepnhif', October='$octnhif', November='$novnhif', December='$decnhif' WHERE Year='$yr' AND Item='NHIF'");
    if($sql)
    {
    }else{
    }
    
    include('nssf.php');
    $sql=mysqli_query($con,"UPDATE Expenditure SET January='$jannssf',February='$febnssf', March='$marnssf',April='$aprnssf', May='$maynssf', June='$junnssf', July='$julynssf', August='$augnssf', September='$sepnssf', October='$octnssf', November='$novnssf', December='$decnssf' WHERE Year='$yr' AND Item='nssf'");
    if($sql)
    {
        
    }else{
       
    }
    
    include('pro.php');
    $sql=mysqli_query($con,"UPDATE Expenditure SET January='$janpro',February='$febpro', March='$marpro',April='$aprpro', May='$maypro', June='$junpro', July='$julypro', August='$augpro', September='$seppro', October='$octpro', November='$novpro', December='$decpro' WHERE Year='$yr' AND Item='Projects'");
    if($sql)
    {
        
    }else{
    }
    
    
    //include('farmincome.php');
    
     //$sql2=mysqli_query($con,"UPDATE income SET January='$janfam',February='$febfam', March='$marfam',April='$aprfam'  WHERE Year='$yr' AND Item='Farm Income'");
    //if($sql2)
    //{}
?>
<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">Expenses 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">Expenditure</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');
                //$sql=mysqli_query($con,"SELECT * FROM income where Year='$yr' AND ");
               // $num=mysqli_fetch_array($sql);
                //if($num>0)
                //{
                    
                //}else
                //{
                    
                //}
       
                $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="yearfilter" 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">All Expenses</a></li>
                  <!--li class="nav-item"><a class="nav-link" href="#divfarm" data-toggle="tab">Projects</a></li>
                  <li class="nav-item"><a class="nav-link" href="#" data-toggle="tab">Other Expenses</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="divincome">
                 <table class="table table-bordered" id="idmonthincome" >
                     <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 Expenditure 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 style="font-size:14px;color:brown"><strong><?php echo $row["Item"]; ?></strong></td>
                        <td><strong><?php echo $row["January"]; ?></strong></td>
                        <td><strong><?php echo $row["February"]; ?></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["August"]; ?></strong></td>
                        <td><strong><?php echo $row["September"]; ?></strong></td>
                        <td><strong><?php echo $row["October"]; ?></strong></td>
                        <td><strong><?php echo $row["November"]; ?></strong></td>
                        <td><strong><?php echo $row["December"]; ?></td>
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }
                            ?>
                     </tbody>
                 </table> 
              </div>
              </div>
              </div>
              </div>
              
              <div class="tab-pane" id="divfarm">
                  <div class="col-md-12"> 
                      <h5>Farm Income</h5>
                  </div>
             </div>
              </div>
              
            </div>
          </div>
          </div>
          </div>
    </section>
</div>

