<?php
if(basename($_SERVER['PHP_SELF']) == 'plist.php') 
  $pr=" class='current'";
include'header.php';
$dato=$datos=$Date;
$custo='';

	$conde="ORDER BY `Number` DESC LIMIT 20";

if(isset($_POST['delete_id']))
		{
			$rowid=$_POST['rowid'];
			if($_POST['dte']==$Date)
			$then=mysqli_query($conn, "DELETE FROM `paid` WHERE `Number`='$rowid' LIMIT 1");
			else
			$then=mysqli_query($conn, "UPDATE `paid` SET `Status`='1' WHERE `Number`='$rowid' LIMIT 1");
			$p=$_POST['p'];
			$im=$_POST['im'];
			$file_to_delete = "allows/$im";
			unlink($file_to_delete);
		}
		
    if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			
		if($custo)
	$conde="AND `Holder`='$custo' GROUP BY `Employee` ORDER BY `Number` DESC";
		else
		    $conde="AND `Date` BETWEEN '$dato' AND '$datos'";
		    }
		

$do=mysqli_query($conn, "SELECT *FROM `paid` WHERE `Status`='0' $conde");
$fo=mysqli_num_rows($do);
?>
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
        Contribute
          </h1>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">
      
    <li class="list-group-item active">
	  <a href="plist.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Contribution List
                </p>
              </a></li>  

	   <li class="list-group-item">
              <a href="paid.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create New Record
                </p>
              </a></li> 
                         
            </ul>
  </div>
                    
           
           
       
        <div class="col-lg-10"><div class="row hidden-print">
           <div class="col-lg-5"> </div>
        <form action="" method="post" class="form-horizontal ">
                  
         <div class="col-lg-7"><div class="col-lg-3">
             <select class="form-control" name="custo">
				<option value='' selected>Select Holder</option>
			 <?php
			$dois=mysqli_query($conn, "SELECT `Holder` FROM `paid` WHERE `Holder`!='' GROUP BY `Holder` ORDER BY `Holder` ASC");
			while($rois=mysqli_fetch_assoc($dois)){
				$cust=$rois['Holder'];
				if($cust==$custo)
					$sli="selected";
				else
					$sli='';
			echo"<option value='$cust' $sli> $cust </option>";
			    }
			?>    
        </select></div> 
             
             
             
             <div class="col-md-3"> 
           <div class="input-group date datepicker">
      <input class="form-control form-center" id="from" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>

		  <div class="col-md-3"> 
           <div class="input-group date datepicker">	
      <input class="form-control form-center" id="to" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>
                       
         <div class="col-lg-2 hidden-xs hidden-print">
        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div></div></form> 
               
            </div>
             <div class="row">
            <div class="col-lg-12">
             <span class="hidden-print">Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
            <table class="table table-striped">                                     <thead>
                    <tr role="row">
                     <th> &nbsp;&nbsp;No </th>
                        <th> Due&nbsp;Date </th>
                       <th> Employee`s&nbsp;Name</th> 
                       <th> Contribution&nbsp;Holder</th> 
                        <th> Purpose/Issue </th>
						 <th> Monthly&nbsp;Amount </th>
                        <th class='hidden-print' colspan='2' style="width: 40px;text-align:center;">Actions</th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;           $tot=0;
						while($ro=mysqli_fetch_assoc($do)){
$code=$ro['Number'];
$emplo=$ro['Employee'];
$amo=$ro['Amount'];
$amoo=number_format($amo);
$holder=$ro['Holder'];
$purpo=$ro['Purpose'];
$dte=$ro['Date'];
$im=$ro['File1'];

$doi=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Eid`='$emplo'");
			$roi=mysqli_fetch_assoc($doi);
				$fna=$roi['Fname'];
				$lna=$roi['Lname'];
/*
if($file1)
	$dfile="<a href='down_contra.php?link=$file1'>Download&nbsp;File</a>";
else
	$dfile="";
*/
$stn="style='padding:0px;'";

echo"<div class='modal fade' id='exampleModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:220px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION 
<label class='pull-right'><b> $amoo $holder </b></label></h5>

      </div>
      <div class='modal-body' style='height:40px;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this record?</h5>
      </div><form method='post' action=''><input type='hidden' name='rowid' value='$code'>
	  <input value='$p' name='p' type='hidden'><input value='$im' name='im' type='hidden'><input value='$dte' name='dte' type='hidden'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-success' data-dismiss='modal'>&nbsp;NO&nbsp;</button>
        <button type='submit' name='delete_id' class='btn btn-sm btn-danger' $disa>YES</button>
      </div></form>
    </div>
  </div>
</div>";
           
		print("<tr><td $stn class='text-center'>$n</td>
                        <td $stn> $dte </td>
                        <td $stn> $fna $lna </td><td $stn> $holder </td><td $stn> $purpo </td>
						<td class='text-right' style='padding:0px 40px 0px 0px;'> $amoo </td>

                     <form method=post action='paid.php'>
                     <td class='hidden-print' align='right' style='width:20px; padding:0px;'>
                        <input type='hidden' name='rowid' value='$code'>
                           <button type='submit' class='btn btn-xs btn-warning hidden-print text-center' name='edit_id' style='height:18px; padding:0px; margin-top:2px; margin-botton:0px; width:25px; text-align:center; padding-right:5px;' title='Edit' data-toggle='tooltip' data-placement='top'>
						  &nbsp;&nbsp;<i class='lnr lnr-pencil'></i></td></form>
						   
						   <td class='hidden-print' align='right' style='width:20px; padding:0px;'>
						  <button type='button' class='btn btn-xs btn-danger hidden-print' style='height:18px; padding:0px; margin-top:2px; margin-botton:0px; width:25px;' data-placement='top' data-toggle='modal' data-target='#exampleModal$n' $disa>
						  <i class='lnr lnr-trash'></i></button></td></form></tr>");
						  $n++;        $tot+=$amo;
						}
						$tot=number_format($tot);
				
					print("<tr><th> </th> 
	<th colspan='4' style='align:center; padding-left:80px;'> Total Amount </th>
	<th class='text-right' style='padding:0px 40px 0px 0px;'> $tot </th><th colspan='2' class='text-right hidden-print' $stn>  </th></tr>");
						?>
						
                    </tbody>   
                  </table>
                                        
                
              </div></div>
              
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </div>
                  </div>
      
  <?php
  include'footer.php';
  ?>