<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">Tour 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">Tour Payment</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-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');
                $tuid=$_GET["Tour"];
                $result = mysqli_query($con,"SELECT SUM(Amount) as ama FROM TourPayment where Tid='$tuid'");
                while($row = $result->fetch_assoc()) 
                {
                  $totincome=$row["ama"];
                }
                ?>
              <div class="info-box-content">
                <span class="info-box-text">Total income for the selected tour</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=Tours" class="btn btn-info" id="btnaddtour"> <i class="fa fa-plus"></i> Add Tour 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-4"> 
              <h5 class="m-0 alert-success">Add new 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">Tour Title<span class="requireds">*</span></label>
                           <select id="txttour" class="form-control custom-select">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM Tours";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['id'];?>"> 
                            <?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="btnsavetouramt">Save <i class="fa fa-save"></i>
                        </button>
                     </div>
                  </form>
                </div>
              </div>
               
             <div class="col-md-8">  
             <div class="table-responsive" id="divbus">
                  <div class="row"> 
                  <div class="col-md-6"> 
                      <form action="" method="POST" onsubmit="return false">
                       <div class="form-group">
                            <label id="otherincomemsg" style="color:">Filter by Tour Name</label> 
                           <select id="txttours" class="form-control custom-select">
                            <option selected value="">Select ---</option>
                            <?php
                            $sql = "SELECT * FROM Tours order by Dat1 DESC";
                            $result = $con->query($sql);
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>
                            <option value="<?php echo $row['id'];?>"> 
                            <?php echo $row['Title'];?>
                            </option>
                            <?php
                            }
                            ?>
                         </select>
                     </div>
                     </div>
                     
                     <div class="col-md-4"> 
                      <div class="form-group">
                           <label id="" style="">Class</label> 
                           <select id="txttoursclass" class="form-control custom-select">
                                <option selected value="">Select ---</option>
                                <option value="BABY CLASS">BABY CLASS</option>
                                <option value="PP1">PP1</option>
                                <option value="PP2">PP2</option>
                                <option value="GRADE 1">GRADE 1</option>
                                <option value="GRADE 2">GRADE 2</option>
                                <option value="GRADE 3">GRADE 3</option>
                                <option value="GRADE 4">GRADE 4</option>
                                <option value="GRADE 5">GRADE 5</option>
                                <option value="GRADE 6">GRADE 6</option>
                                <option value="GRADE 7">GRADE 7</option>
                                <option value="GRADE 8">GRADE 8</option>
                                <option value="GRADE 9">GRADE 9</option>
                                <option value="CLASS 8">CLASS 8</option>
                         </select>
                     </div>
                      </form>
                  
                   </div>
                   </div>
                  </div>
               <?php
               $tuid=$_GET["Tour"];
               $cla=$_GET["claz"];
               
               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>Date Paid</th>
                              <th>Bank Credited</th>
                             <th>Entry Date</th>
                             <th>Action</th>
                         </tr>
                     </thead>
                     <tbody>
                        <?php
                        //include('../include/config.php');
                        $sql = "select TourPayment.*,Tours.Title as tit,pupils.Names as pnm,pupils.AdmNo as clz,bankdata.Bname as bnk,bankdata.Account as bact from TourPayment left join Tours ON Tours.id=TourPayment.Tid
                        left join pupils ON pupils.count=TourPayment.pid left join bankdata ON bankdata.id=TourPayment.Bank where TourPayment.Tid='$tuid' AND TourPayment.Grad='$cla'  order by idd 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["pnm"].' ('.$row["clz"].')'; ?></td>
                        <td><?php echo $row["Grad"]; ?></td>
                        <td class="alert-success"><?php echo $row["tit"]; ?>
                        </td>
                        <td class="alert-danger"><strong><?php echo $row["Amount"]; ?></strong> </td>
                        <td><?php echo $row["Dat"]; ?></td>
                        <td><?php echo $row["bnk"]; ?> <small>(<?php echo $row["bact"]; ?> )</small>
                        </td>
                        <td> <?php echo $row["EntryDate"]; ?></td>
                        <td>
                        <input type="hidden" name="otid" class="toidd" value="<?php echo $row["idd"]; ?>" />
                        <i class="fa fa-trash btn-xs text-danger deletetourpayment btn" id="otherdelete">
                        </i>
                        </td>
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }
                            ?>
                     </tbody>
                    <tfooter>
                        <tr class="alert-danger">
                            <?php
                              $sql = "SELECT SUM(Amount) as Tsum FROM TourPayment where Tid='$tuid' AND Grad='$cla'";
                              $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>
                        </tr>
                    </tfooter>
                 </table> 
                 <a class="btn pull-right" href="print_tour.php?tr=<?php echo $tuid; ?>&Grade=<?php echo $cla; ?>" target="_blank">Download Report <i class="fa fa-cloud-download"></i></a>
                 <br />
                 <br >
                 <hr />
              </div>
              </div>
              
            </div>
    </section>
       <hr />
</div>

