<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">Graduation Payment</h5>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">Dashboard</li>
              <li class="breadcrumb-item ">Income</li>
              <li class="breadcrumb-item ">Other Earnings</li>
              <li class="breadcrumb-item active">Graduation</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-4 col-sm-5 col-xs-12 col-12">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="far fa-dollar"></i></span>
              <?php
                include('../include/config.php');
                $result = mysqli_query($con,"SELECT SUM(Amount) as ama FROM Gradpayment where Year='$year'");
                while($row = $result->fetch_assoc()) 
                {
                  $totincome=$row["ama"];
                }
                ?>
              <div class="info-box-content">
                <span class="info-box-text">Graduation Income Year -   (<small><?php echo $year;?></small>)</span>
            <h4 class="info-box-number budge"><?php echo $totincome.' Ksh'; ?></h4>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
           <div class="col-md-3 col-sm-3 col-6">
            <div class="info-box">
              <div class="info-box-content">
                 <a href="index.php?page=Other_Earning" class="btn btn-success"> <i class="fa fa-arrow-left"></i> Other Income </a>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          
           <div class="col-md-3 col-sm-3 col-6">
            <div class="info-box">
              <div class="info-box-content">
                <a href="index.php?page=Graduations" class="btn btn-info" id="btnaddtour"> <i class="fa fa-plus"></i> Add Graduation Data </a>
              </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-3"> 
              <h5 class="m-0 alert-success">Graduation Payment</h5>
                <div class="modal-body panel-primary">
                  <form action="" method="POST" onsubmit="return false">
                      <div class="form-group">
                      <label for="inputProjectLeader">Select Pupil<span class="requireds">*</span></label>
                           <select id="stuidd" class="form-control custom-select" style="height:35px;font-size:13px">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM pupils where Status='Active'";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['count'];?>"> 
                            <?php echo $row['Names'];?> (<small> <?php echo $row['AdmNo'].'-'.$row['Claz']; ?></small>)
                            </option>
                            <?php
                            }
                            ?>
                         </select>
                     
                      </div>
                      
                      <div class="form-group">
                      <label for="inputProjectLeader">Graduation Title<span class="requireds">*</span></label>
                           <select id="txttour" class="form-control custom-select">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM graduations";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['gid'];?>"> 
                            <?php echo $row['Title'];?>
                            </option>
                            <?php
                            }
                            ?>
                         </select>
                      </div>
         
                      <div class="form-group">
                      <label for="inputProjectLeader">Date <span class="requireds">*</span></label>
                      <input type="date" class="form-control" name="" id="txtdate" required />
                      </div>
                      
                      <div class="form-group">
                      <label for="inputProjectLeader">Amount Received (Ksh) <span class="requireds">*</span></label>
                      <input type="text"  onkeypress="return /[0-9]/i.test(event.key)" class="form-control farmamount" max-length="6" name="" id="txtamount" required />
                      </div>
                      
                      <div class="form-group">
                      <label for="inputProjectLeader">Account Credited</label>
                       <select id="txtbank" class="form-control custom-select">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM bankdata";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['id']; ?>"> <?php echo $row['Bname'].'->'; ?> <small><?php echo $row['Account']; ?> </small>
                            </option>
                            <?php
                            }
                            ?>
                     </select>
                       </div>
                       
                        <div class="form-group">
                      <label for="inputProjectLeader">Amount Paid in Term?</label>
                       <select id="txtterm" class="form-control custom-select" required>
                            <option selected value="">Select ---</option>
                            <option value="Term One">Term One </option>
                            <option value="Term Two">Term Two </option>
                            <option value="Term Three">Term Three </option>
                     </select>
                       </div>
                       
                     <div class="form-group">
                      <label for="inputProjectLeader">Receipt No (If any) </label>
                      <input type="text" class="form-control" name="" id="txtreceipt" />
                     </div>
                    
                     <div class="form-group">
                         <label id="otherincomemsg" style="color:#FFF">.</label> <br />
                         <button style="margin-right:0px;position:relative" class="btn btn-info btn-sm pull-right" id="btnsavegraduation">Save <i class="fa fa-save"></i>
                        </button>
                     </div>
                  </form>
                </div>
              </div>
               
             <div class="col-md-9">  
             <div class="table-responsive" id="divbus">
                  <div class="col-md-6"> 
                   <div class="container">
                      <form action="" method="POST" onsubmit="return false">
                       <div class="form-group">
                            <label id="otherincomemsg" style="color:">Filter by Graduation Name</label> 
                           <select id="txtgrads" class="form-control custom-select">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM graduations order by Dat DESC";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['gid'];?>"> 
                            <?php echo $row['Title'];?>
                            </option>
                            <?php
                            }
                            ?>
                         </select>
                     </div>
                      </form>
                  
                   </div>
                  </div>
               <?php
               $tuid=$_GET["Select"];
               if($tuid=='' || $tuid==null)
               {
                   $tuid=0;
               }else
               {
                   
               }
               ?>
                 <table class="table table-bordered table-secondary" id="tabletour" >
                     <thead>
                         <tr>
                             <th>#</th>
                             <th>Pupil</th>
                             <th>Class</th>
                             <th>Tour Title</th>
                             <th>Amount Paid</th>
                             <th>Balance</th>
                             <th>Date Paid</th>
                              <th>Bank Credited</th>
                              <th>Receipt No.</th>
                             <th>Entry Date</th>
                             <th>Action</th>
                         </tr>
                     </thead>
                     <tbody>
                        <?php
                        //include('../include/config.php');
                        $sql = "select Gradpayment.*,graduations.Title as tit,graduations.Fee as feee,pupils.Names as pnm,pupils.AdmNo as clz,pupils.count as cou,pupils.Claz as cla,bankdata.Bname as bnk,bankdata.Account as bact,(SELECT SUM(Amount) from Gradpayment where Gid='$tuid' AND pupils.count=Gradpayment.pid) as sumpaid from Gradpayment left join graduations ON graduations.gid=Gradpayment.Gid left join pupils ON pupils.count=Gradpayment.pid left join bankdata ON bankdata.id=Gradpayment.Bank where Gradpayment.Gid='$tuid'";
                        $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["pnm"].' ('.$row["clz"].')'; ?></td>
                        <td><?php echo $row["Grad"]; ?></td>
                        <td class="bg-secondary"><?php echo $row["tit"]; ?>
                        </td>
                        <td class="alert-success"><strong><?php echo $row["Amount"]; ?></strong> </td>
                        <td class="alert-danger"><?php echo $row["feee"]-$row["sumpaid"]; ?></td>
                        <td><?php echo $row["Dat"]; ?></td>
                        <td><?php echo $row["bnk"]; ?> <small>(<?php echo $row["bact"]; ?> )</small>
                        </td>
                         <td><?php echo $row["Receipt"]; ?></td>
                        <td> <?php echo $row["EntryDate"]; ?></td>
                        <td>
                        <input type="hidden" name="otid" class="gradataid" value="<?php echo $row["count"]; ?>" />
                        <i class="fa fa-trash btn-xs text-danger btn dele" id="">
                        </i>
                        </td>
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }
                            ?>
                     </tbody>
                    <tfooter>
                        <tr class="alert-danger">
                            <?php
                              $sql = "SELECT SUM(Amount) as Tsum FROM Gradpayment where gid='$tuid'";
                              $result = $con->query($sql);
                              while($row = $result->fetch_assoc()) 
                            {
                               $tsum=$row["Tsum"];  
                            }
                            ?>
                            <td colspan="4"><strong style="font-size:16px">Total (KES)</strong></td>
                            <td><strong style="font-size:18px"><?php echo $tsum; ?></strong></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                             <td></td>
                        </tr>
                    </tfooter>
                 </table> 
              </div>
              </div>
              
            </div>
    </section>
</div>

