<?php
$pid=$_GET['proid'];
 $id='';
 $sql = "select * from projects where ProCode='$pid'";
 $result = $con->query($sql);
while($row = $result->fetch_assoc()) 
{
 $id= $row["id"];
 $pname= $row["Pname"];
 $sd= $row["SDate"];
 $sta= $row["Status"];
 $des= $row["Description"];
}
?>

<div class="content-wrapper" id="mainprojdiv">
    <!-- 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">Project Title: <strong class="text-info"><?php echo  $pname;?></strong>   Project ID: <strong class="text-info"><?php echo  $pid;?></strong></h4>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">Dashboard</li>
              <li class="breadcrumb-item ">Expenses</li>
              <li class="breadcrumb-item ">Projects</li>
              <li class="breadcrumb-item active">Project 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-3 col-sm-6 col-12">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="fa fa-dollar"></i></span>
                    <?php
                    $total='';
                    $result = mysqli_query($con,"SELECT SUM(Amount) as tot FROM prodata where proid='$id'");
                    while($row = $result->fetch_assoc()) 
                    {
                       $total=$row["tot"]; 
                    }
                    ?>
              <div class="info-box-content">
                <span class="info-box-text">Total Cost (KES)</span>
                <h4 class="info-box-number budge"><?php echo $total; ?></h4>
              </div>
                
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box alert-success">
  
              <div class="info-box-content">
                <center>
                <a href="Expenditure.php?page=Projects" class="btn btn-success">
                  <i class="fa fa-arrow-left"></i> Add new project </a>
                </center>
              </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 col-sm-6 col-12">
            
            </div>
            
            <h4>
                Project Expenses 
            </h4>
             <div class="table-responsive" id="table-responsive">
                 <table class="table table-bordered table-success" id="tableprojects">
                     <thead class="bg-info">
                         <tr>
                             <th># </th>
                             <th>Date</th>
                             <th>Particular</th>
                             <th>Amount Spent (KES)</th>
                             <th>Cheque No</th>
                             <th>Bank Debited</th>
                             <th>Entry Date</th>
                             <th>Added by</th>
                             <th>Actio</th>
                         </tr>
                     </thead>
                     <tbody>
        <?php
        //$sql = "select prodata.*, bankdata.Bname as bnam, bankdata.Account as act,Staffs.Name as snam from prodata join bankdata ON bankdata.id=prodata.Bank join Staffs ON Staffs.id=prodata.User where prodata.proid='$id'";
        
        $sql = "select prodata.*,bankdata.Bname as bnam,bankdata.Account as act, Staffs.Name as snam from prodata left join bankdata ON bankdata.id=prodata.Bank left join Staffs ON Staffs.id=prodata.User where prodata.proid='$id' ORDER BY prodata.id 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["Dat"]; ?></td>
        <td><strong><?php echo $row["Item"]; ?></strong></td>
        <td class="alert-danger"><strong><?php echo $row["Amount"]; ?></strong></td>
        <td><?php echo $row["Cheq"]; ?></td>
        <td><?php echo $row["bnam"]; ?> (<small><?php echo $row["act"] ?></small>)</td>
        <td><?php echo $row["EntryDate"]; ?></td>
        <td><?php echo $row["snam"]; ?></td>
        <td>
        <input type="hidden" name="proidh" class="prodataclass" value="<?php echo $row["id"]; ?>" />
        
        <i class="fa fa-edit btn-xs text-success expeedit" id="expeedit"></i>
        <i class="fa fa-trash btn-xs text-danger btn deledata" id="deledata"></i>
        </td>
        </tr>
        <?php
        $cnt=$cnt+1;
        }
        }else
        {
        echo 'No details';
        }
                            ?>
                     </tbody>
                 </table> 
              </div>
            </div>
            <input type="hidden" id="projectidholdar" value="<?php echo $pid; ?>" />
    </section>
  
</div>

