<?php
if(basename($_SERVER['PHP_SELF']) == 'rrepo.php') 
  $cm=" class='current'";
include'header.php';
$dato=$datos=$Date;
$p=0;

// search request by date
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$p=1;
		}




		if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
?>


<div class="container-fluid main-content">
        <div class="page-title">
          <h1 style='margin-top:-20px; margin-bottom: 5px;'>
         Contribute
          </h1>
                 </div>
     
         <div class="row">
  <div class="col-lg-2 hidden-print">
   <ul class="list-group"> 
   
   <li class="list-group-item">
	  <a href="rollrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payroll Report
                </p>
              </a></li> 
              
     <li class="list-group-item">
	  <a href="payerepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payroll Report & PAYE
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="bankrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payroll Report & BANK
                </p>
              </a></li>    

    <li class="list-group-item">
	  <a href="handrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payroll Report & HAND
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="adrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Advance Report
                </p>
              </a></li>  

    <li class="list-group-item">
	  <a href="allrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Allowance Report
                </p>
              </a></li>

	 <li class="list-group-item">
	  <a href="derepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Deduction Report
                </p>
              </a></li>    

<li class="list-group-item">
	  <a href="parepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payment Report
                </p>
              </a></li>     

<li class="list-group-item">
	  <a href="erepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Employees Report
                </p>
              </a></li>      

<li class="list-group-item active">
	  <a href="rrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Contribution Report
                </p>
              </a></li>
                         
            </ul>
  </div>
	
      <div class="col-lg-10">
                  <div class="row">
         
           <div class="col-lg-2" style="padding-left:50px;">
		  
		  
		  </div><div class="col-lg-1 hidden-xs"> </div>
          
        <form action="" method="post" class="form-horizontal ">                  
                       <div class="col-lg-8 hidden-print"><div class="col-lg-4"> 					
					 
					   </div>
             <div class="col-lg-3"> 
           <div class="input-group date datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" id="to" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-3"> 
           <div class="input-group date datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" id="to" 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"><?php echo"<input type='hidden' name='pg' value='$pg'>"; ?>
        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div></form>               
            </div>
               <?php
               if($p)
	$dok=mysqli_query($conn, "SELECT *FROM `request` WHERE `Status`='0' AND `Date` BETWEEN '$dato' AND '$datos' ORDER BY `Number` ASC LIMIT 15");
		        else
		$dok=mysqli_query($conn, "SELECT *FROM `request` WHERE `Status`='0' AND `Approve`!='0' ORDER BY `Number` ASC LIMIT 15");
				if($fo=mysqli_num_rows($dok)){
				?>
                 
            <div class="divFooter"><center><u><b>LOAN REQUEST REPORT <?php echo $mpri ?></b></u></center></div>
             <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right hidden-print"><?php echo"$bank   $account"; ?>&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></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

	<table class="table table-striped table-hover">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs" style='padding:1px;' width='2%'>&nbsp;&nbsp;No&nbsp;&nbsp;</th>
					 <th style='text-align:center; padding:1px;'>&nbsp;&nbsp;&nbsp;Date </th>
					 <th style='padding:1px;'>&nbsp;&nbsp;&nbsp;User </th><th style='padding:1px;'>&nbsp;&nbsp;&nbsp;Employee </th>
					 <th style='padding:1px;'><div align='center'> Loan&nbsp;Name </th>
					 <th style='padding:1px;'><div align='center'> Loan </th>
					 <th style='padding:1px;'><div align='center'> Rate </th>
					 <th style='padding:1px;'><div align='center'> Total </th>
					 <th style='padding:1px;'><div align='center'> Monthly </th>
					 <th style='padding:1px;'><div align='center'> Paid&nbsp;Amount </th>
					 <th style='padding:1px;'><div align='center'> Balance </th>
					 
					 </tr>
                    </thead>
                                        <tbody>
					<?php
				$i=1;		$tamo=$tpay=$tpaid=$tbal=0;
		while($rok=mysqli_fetch_assoc($dok)){
			$dte=$rok['Date'];
			$empo=$rok['Employee'];
			$user=$rok['User'];
			$lim=$rok['Amount'];
			$rate=$rok['Percent'];
			$pay=$rok['Payment'];
			$nuo=$rok['Number'];
			$loa=$rok['Loan'];
			$mot=$rok['Period'];
			$appo=$ro['Approve'];
			$paid=$rok['Paid'];
			
		$doe=mysqli_query($conn, "SELECT `Fname`, `Lname`, `Salary` FROM `employees` WHERE `Eid`='$empo' ORDER BY `Fname` ASC");
		$foe=mysqli_num_rows($doe);
		$roe=mysqli_fetch_assoc($doe);
			$fna=$roe['Fname'];
			$lna=$roe['Lname'];
			$sal=$roe['Salary'];

		$doi=mysqli_query($conn, "SELECT `Name` FROM `loans` WHERE `Number`='$loa' ORDER BY `Number` DESC");
		$roi=mysqli_fetch_assoc($doi);
				$name=$roi['Name'];
				
				$all=$lim+($lim*$rate/100);
				$bal=$all-$paid;
				
				$balo=number_format($bal);
				$paido=number_format($paid);

	$stl="padding:1px;";					$limo=number_format($lim);			$payo=number_format($pay);				$salo=number_format($sal);
	        $allo=number_format($all);
            $inco=($all-$lim)/$mot;
            $incoo=number_format($inco);
            $month = date('F', strtotime($dte));
				$monthly=($pay+$inco);

				print("<tr><td class='hidden-xs' style='$stl $clr'><div align='right'>$i&nbsp;</td>
						<td style='$stl $clr'><div align='center'> $dte </td><td class='hidden-xs' style='$stl $clr'> $user </td>
	<td class='hidden-xs' style='$stl $clr'> $fna $lna </td><td style='$stl $clr'> $name </td><td style='$stl $clr'><div align='right' style='padding-right:20px;'> $limo </td>
						<td style='$stl $clr'><div align='right'> $rate % &nbsp;&nbsp;</td><td style='$stl $clr'><div align='right' style='padding-right:20px;'> $allo </td>
						
						<td style='$stl $clr padding-right:10px;'>
						<div align='right'> $payo + $incoo </td><td style='$stl $clr padding-right:10px;'>
						<div align='right'> $paido </td><td style='$stl $clr padding-right:10px;'>
						<div align='right'> $balo </td></tr>");
						
    $dose=mysqli_query($conn, "UPDATE `request` SET `Total`='$all', `Perm`='$inco', `Monthly` = '$monthly' WHERE `Number`='$nuo' ORDER BY `Number` ASC LIMIT 1");

		$i++;						$tamo+=$lim;				$tpay+=$all;
		$tpai+=$paid;               $tbal+=$bal;
						}
								$tamo=number_format($tamo);				
								$tpay=number_format($tpay);				
								$tpai=number_format($tpai);				
								$tbal=number_format($tbal);					
						?>
						
                    </tbody>
		<tr><th class='hidden-xs'> </th><th colspan='3'> Total Amount </th>
			<th colspan='2' class='text-right' style='padding-right:20px;'>
			<?php echo $tamo ?></th><th colspan='2' class='text-right' style='padding-right:20px;'><?php echo $tpay ?></th>
			<th colspan='2' class='text-right' style='padding-right:10px;'>
			<?php echo $tpai ?></th>
			<th class='text-right' style='padding-right:10px;'>
			<?php echo $tbal ?></th>
			
			</tr></table> 
						
						</div></div>
			<span class="pull-right hidden-print">
			 <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></span><br><br><br>  

			<?php
				}
				else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b> 0 </b></span>
            <div class='widget-container fluid-height clearfix'>
            <div class='widget-content padded clearfix'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'>
	Report not available on selected date</a></div><br><br><br><br><br><br>";
					}
			
					?>
                                      
                
              </div>
            </div></div>
                  </div>
   <?php
   include'footer.php';
   ?>