<?php
if(basename($_SERVER['PHP_SELF']) == 'slips.php') 
  $pr=" class='current'";
 
include'connection.php';
if(!$_SESSION['Payro'])
Header("location:home.php");
include'header.php';
$dato=$datos=$Date;

$cond='LIMIT 12';
$perpagevalue=20;
$conde="LIMIT $perpagevalue";
$ope=0;


		    
	// ***************** Load contribution holders ***********
		    $nu=$mn=$pda=$hol=array();                  $k=1;
	$hd=mysqli_query($conn, "SELECT `Number`, `Holder`, `Month` FROM `holders` ORDER BY `Number` ASC");
	while($rd=mysqli_fetch_assoc($hd)){
	    $hol[$k]=$rd['Holder'];
	    $nu[$k]=$rd['Number'];
	    $mn[$k]=$rd['Month'];
	            $k++;
	        }

if(isset($_POST['perpage']))
		{
			$perpagevalue=$_POST['perpagevalue'];
			$cond="LIMIT $perpagevalue";
		}

		// *************************** Open a given payroll *************************************
if(isset($_POST['open_id']))
		{
			$mt=$_POST['mt'];
			$yr=$_POST['yr'];			
			$sd=$_POST['std'];			
			$ed=$_POST['end'];
			$ope=1;
		}
		
		// ****************************** Delete a given payroll *******************************
if(isset($_POST['delete_id']))
		{
			$mt=$_POST['mt'];
			$yr=$_POST['yr'];			
			$sd=$_POST['std'];			
			$ed=$_POST['end'];
			$perpagevalue=$_POST['perpagevalue'];
			$cond="LIMIT $perpagevalue";

$sso=mysqli_query($conn, "SELECT `Number`, `Amount`, `Advance`, `Employee` FROM `advance` WHERE `Month`='$mt' AND `Year`='$yr' AND `Starting`='$sd' AND `Ending`='$ed'");
			while($sro=mysqli_fetch_assoc($sso)){
				$eidi=$sro['Employee'];
				$advas=$sro['Amount'];
				$numbs=$sro['Advance'];
				$nuos=$sro['Number'];

$dots=mysqli_query($conn, "UPDATE `request` SET `Paid`=`Paid`-'$advas' WHERE `Number` = '$numbs' AND `Employee`='$eidi' AND `Status`='0' ORDER BY `Number` DESC LIMIT 1");

	$dos=mysqli_query($conn, "DELETE FROM `advance` WHERE `Number`='$nuos' ORDER BY `Number` ASC LIMIT 1");	
			}

	$do=mysqli_query($conn, "DELETE FROM `payrolls` WHERE `Month`='$mt' AND `Year`='$yr'");	
		
			$pto=30;
		}

		// **************************** Create fixed payroll *********************************
if(isset($_POST['submit_pay']))
		{
			$dato=$_POST['dato'];
			$user=$_POST['user'];
			$month=$_POST['month'];
			$year=$_POST['year']; 
			$mti = date("m", strtotime($month, '01'));
			$std="$year-$mti-01";
			$days = date('t', strtotime($month) );
			$end="$year-$mti-$days";
	
	$dot=mysqli_query($conn, "SELECT *FROM `payrolls` WHERE `Month`='$month' AND `Year`='$year'");
		if($fot=mysqli_num_rows($dot)){
			$pto=20;
		}
		else{
$do=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Eid`!='1001' AND `Status`='0' AND `Salary`>'0' ORDER BY `Fname` ASC");
		$fo=mysqli_num_rows($do);
		while($ro=mysqli_fetch_assoc($do)){
			$eid=$ro['Eid'];
			$sala=$ro['Salary'];
			$curp=$ro['Currentp'];
			$bank=$ro['Bank'];
			$acco=$ro['Account'];
			$depat=$ro['Depart'];
			$brce=$ro['Branch'];

			// **************************** Balance from last month **************************************
	$dote=mysqli_query($conn, "SELECT `Closing` FROM `payrolls` WHERE `Ending`<='$std' AND `Year`<='$year' AND `Employee`='$eid' ORDER BY `Ending` DESC, `Number` DESC LIMIT 1");
		if($fote=mysqli_num_rows($dote)){
			$rote=mysqli_fetch_assoc($dote);
				$bal=$rote['Closing'];
		}
		else
			$bal=0;

// **************************** Load allowances in current month **************************************
$dota=mysqli_query($conn, "SELECT SUM(`Amount`) AS 'Allo' FROM `allows` WHERE `Date` BETWEEN '$std' AND '$end' AND `Employee`='$eid' AND `Status`='0' ORDER BY `Number` DESC LIMIT 1000");
		if($fota=mysqli_num_rows($dota)){
			$rota=mysqli_fetch_assoc($dota);
				$allo=$rota['Allo'];
		}
		else
			$allo=0;

// **************************** Load deductions in current month **************************************
$doti=mysqli_query($conn, "SELECT SUM(`Amount`) AS 'Dedo' FROM `deduct` WHERE `Date` BETWEEN '$std' AND '$end' AND `Employee`='$eid' AND `Status`='0' ORDER BY `Number` DESC LIMIT 1000");
		if($foti=mysqli_num_rows($doti)){
			$roti=mysqli_fetch_assoc($doti);
				$dedu=$roti['Dedo'];
		}
		else
			$dedu=0;
			
	// **************************** Load contributions in current month **************************************
	 for($i=1; $i<$k; $i++){
	    $hold=$hol[$i];
	    $cno=$nu[$i];
$dota=mysqli_query($conn, "SELECT `Amount` FROM `paid` WHERE `Employee`='$eid' AND `Status`='0' AND `Holder`='$hold' ORDER BY `Number` DESC LIMIT 1");
		if($fota=mysqli_num_rows($dota)){
			$rota=mysqli_fetch_assoc($dota);
				$paid=$rota['Amount'];
		}
		else{
			$paid=0;
			$cno=0;
		}
			
			$pda[$i]+=$paid;
			
switch ($i) {
  case 1:
    $conte1=$paid;
    $cno1=$cno;
    break;
  case 2:
    $conte2=$paid;
    $cno2=$cno;
    break;
  case 3:
    $conte3=$paid;
    $cno3=$cno;
    break;
  case 4:
    $conte4=$paid;
    $cno4=$cno;
    break;
  case 5:
    $conte5=$paid;
    $cno5=$cno;
    break;
}
			
	}
			
                    
                    $pay=$bal+$dedu;
                    $paid=$conte1+$conte2+$conte3+$conte4+$conte5;
                    
$so=mysqli_query($conn, "INSERT INTO `payrolls` (`Date`, `User`, `Employee`, `Month`, `Year`, `Salary`, `Currentp`, `Bank`, `Account`, `Advance`, `Balance`, `Allowance`, `Deduction`, `Payment`, `Starting`, `Ending`, `Depart`, `Branch`, `Paid`, `Conte1`, `Contno1`, `Conte2`, `Contno2`, `Conte3`, `Contno3`, `Conte4`, `Contno4`, `Conte5`, `Contno5`) VALUES ('$dato', '$user', '$eid', '$month', '$year', '$sala', '$curp', '$bank', '$acco', '$adva', '$bal', '$allo', '$dedu', '$pay', '$std', '$end', '$depat', '$brce', '$paid', '$conte1', '$cno1', '$conte2', '$cno2', '$conte3', '$cno3', '$conte4', '$cno4', '$conte5', '$cno5')");

		}
		
	        for($i=1; $i<$k; $i++){
	            if($pda[$i]>0)
	   $do=mysqli_query($conn, "UPDATE `holders` SET `Status`='0', `Month`='$month', `Count`='0' WHERE `Number`='".$nu[$i]."'");
	            elseif($mn[$i]!=$month AND $pda[$i]==0)
	   $do=mysqli_query($conn, "UPDATE `holders` SET `Status`='1', `Month`='$month', `Count`=`Count`+'1' WHERE `Number`='".$nu[$i]."'");
	            else
	   $do=mysqli_query($conn, "UPDATE `holders` SET `Status`='1', `Month`='$month', `Count`='1' WHERE `Number`='".$nu[$i]."'");
	        }
	        
        $pto=10;
		$month='';
		$dato=$Date;
		$year=date("Y");
		}	
		}
		

    	// *************************** Confirm a given payroll *************************************
    if(isset($_POST['confirm']))
		{
			$mt=$_POST['mt'];
			$yr=$_POST['yr'];
	
	$do=mysqli_query($conn, "UPDATE `payrolls` SET `Status`='1' WHERE `Month`='$mt' AND `Year`='$yr' ORDER BY `Number` ASC");
			// $ope=1;
		}	
		
		
		// *************************** Confirm a given payroll *************************************
    if(isset($_POST['release']))
		{
			$mt=$_POST['mt'];
			$yr=$_POST['yr'];
	
	$do=mysqli_query($conn, "UPDATE `payrolls` SET `Status`='0' WHERE `Month`='$mt' AND `Year`='$yr' ORDER BY `Number` ASC");
			// $ope=1;
		}
		


	if($ope=='1')
$do=mysqli_query($conn, "SELECT *FROM `payrolls` WHERE `Month`='$mt' AND `Year`='$yr' GROUP BY `Starting`, `Ending` ORDER BY `Number` ASC");
	else
$do=mysqli_query($conn, "SELECT *FROM `payrolls` GROUP BY `Starting`, `Ending` ORDER BY `Ending` DESC $cond");
$fo=mysqli_num_rows($do);
?>

<script type="text/javascript">


  function sendData()
{
  var sala = document.getElementById("sala").value;
  var bala = document.getElementById("bala").value;
  var pay = document.getElementById("pay").value;
  var numb = document.getElementById("numb").value;
  $.ajax({
    type: 'post',
    url: 'send_data.php',
    data: {
      sala:sala,
      bala:bala,
      pay:pay,
      numb:numb
    },
    success: function (response) {
      $('#res').html("Your data was saved successfull");
    }
  });
    
  return false;
}



function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>

<div class="container-fluid main-content">
<div class="page-title">
 
 <h1 style='margin-top:-20px; margin-bottom: 5px;'>Payrolls</h1>

</div>
<div class="row"></div>
 <div class="row">

        <div class="col-md-12">
         <div class="row">
             <div class="col-lg-4 hidden-print"> 
           <form action="" method="POST" class="form-horizontal ">
        <input name="searchkeyword" value="" type="hidden">
        <input name="column_name" value="" type="hidden">
     
            <div class="col-lg-6 hidden-print"> 
           <select name="perpagevalue" class="form-control">
                              <option selected="selected" value="20">20 per page</option>
                              <option value="50">50 per page</option>
                              <option value="100">100 per page</option>
                              <option value="200">200 per page</option>
                              <option value="1000">1000 per page</option>
                            
               </select>
          
         </div>    
        
                    <div class="col-lg-4 hidden-print"> 
      
    <button class="btn  btn-success  btn-block" type="submit" name="perpage"><i class="lnr lnr-chevron-right-circle"></i> Show</button>
          </div> 
    
        </form>
           
           
              </div>


		    <div class="col-md-8 hidden-print" style="text-align:right;">

		<div class="col-md-8 hidden-print">
    
	     <?php 
if($pto==10)
echo"<center><div class='alert alert-success' style='text-align:center; float:center; border-radius:5px; padding:6px;'>
<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; New Payrool Has Been Created.
<button class='close' data-dismiss='alert' type='button'>&times</button></div></center>";

if($pto==20)
echo"<center><div class='alert alert-danger' style='text-align:center; float:center; border-radius:5px; padding:6px;'>
		<i class='lnr lnr-checkmark-sad'></i> &nbsp;&nbsp; Payroll for $month $year alread exist in your database.
		<button class='close' data-dismiss='alert' type='button' style='margin:0px;'>&times</button></div></center>";
		
if($pto==30)
echo"<center><div class='alert alert-danger' style='text-align:center; float:center; border-radius:5px; padding:6px;'>
		<i class='lnr lnr-checkmark-sad'></i> &nbsp;&nbsp; Payroll for $mt $yr is deleted from your database.
		<button class='close' data-dismiss='alert' type='button' style='margin:0px;'>&times</button></div></center>";
		?>
          
                    </div><div class="col-md-1 "></div><div class="col-md-3 "> 
                 <button class="btn btn-block btn-info" type="submit" name="create" style="width:120px;" onclick="window.location.href='pays.php'">CREATE NEW</button>
          </div> 

		 
            <div class="col-md-1 hidden-print"> 
        
           
         </div></form></div>
         
         <!--  Mark Attendance -->
<!-- mark attendance end  -->
         
        
          
         
          </div>
		  
          <div class="row">
            <div class="col-md-12">
     
              <span>Total Records Found : <b><?php echo $fo ?></b></span>
			  <span class="pull-right"><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">
			<?php
			if($ope=='1'){
	$do=mysqli_query($conn, "SELECT *FROM `payrolls` WHERE `Month`='$mt' AND `Year`='$yr' ORDER BY `Currentp` ASC");

?>
    </form><table class="table table-striped table-hover">
                       
                                      <thead>
                    <tr role="row"><th> No</th> 					  
                       <th align='center'> Full Name </th>			  
                       <th> Position </th><th> Month </th>
                       <th> Year </th><th> Balance </th><th> Salary </th>
                       <th class='text-center'> Loan </th> 
                       <th class="text-center"> Allow. </th>	  
                       <th class="text-center"> Deduct </th>
                       <th class="text-center"> Payment </th> 	
                       <th class="text-center"> Net&nbsp;Pay </th>
    <th> Closing </th><th class="text-center hidden-print"> #&nbsp; </th>
                     </tr></thead>
                        <tbody>
<?php
$n=1;

	while($ro=mysqli_fetch_assoc($do)){
$numb=$ro['Number'];
$mt=$ro['Month'];
$user=$ro['User'];
$yr=$ro['Year'];
$dati=$ro['Date'];
$st=$ro['Status'];
$sal=$ro['Salary'];
$empo=$ro['Employee'];
$currentp=$ro['Currentp'];
$allow=$ro['Allowance'];
$paid=$ro['Paid'];
$duct=$ro['Deduction'];
$adva=$ro['Advance'];
$bala=$ro['Balance'];
$pay=$ro['Payment'];
$my="$mt $yr";

$doe=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Eid`='$empo' ORDER BY `Fname` ASC");
		$foe=mysqli_num_rows($doe);
		while($roe=mysqli_fetch_assoc($doe)){
			$fna=$roe['Fname'];
			$lna=$roe['Lname'];
		}

$dei=mysqli_query($conn, "SELECT *FROM `position` WHERE `Postid`='$currentp' ORDER BY `Postname` ASC");
			 if($fei=mysqli_num_rows($dei)){
				 $rei=mysqli_fetch_assoc($dei);
					$post=$rei['Postname'];
			 }
			 else
				 $post="N/A";
	
           $salo=number_format($sal);
		   $advao=number_format($adva);

$allowo=number_format($allow);
$ducto=number_format($duct);
if($count)
$net=$count+$allow-$adva-$pay;
else
$net=$sal+$allow-$adva-$pay;

$clo=$bala+$duct-$pay;
$neto=number_format($net);
$balao=number_format($bala);
$payo=number_format($pay+$adva);
$paso=number_format($pay);
$paido=number_format($paid);
	
	$dots=mysqli_query($conn, "UPDATE `payrolls` SET `Closing`='$clo', `Home`='$net' WHERE `Number` = '$numb'");

			  $tot=$empor;
		   $toto=number_format($tot);
		   $cloo=number_format($clo);							$stn="style='padding:1px;'";
		   
		echo"<script type='text/javascript'>

  function sendData$n()
    {
  var sala = document.getElementById('sala$n').value;
  var bala = document.getElementById('bala$n').value;
  var pay = document.getElementById('pay$n').value;
  var numb = document.getElementById('numb$n').value;
    $.ajax({
    type: 'post',
    url: 'send_data.php',
    data: {
      sala:sala,
      bala:bala,
      pay:pay,
      numb:numb
    },
    success: function (response) {
      $('#res').html('Your data was saved successfull');
    }
  });
    
  return false;
}
    </script>";		
    
	
		echo"<div class='modal fade' id='exampleModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'
		style='top:40px; padding:0px; height:380px; float:center;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>PAYMENT CONFIGURATION 
    <label class='pull-right text-right'><b> $fna $lna [$empo] </b></label></h5>

      </div><form method='post' onsubmit='return sendData$n();'>
      <div class='modal-body' style='height:250px;'>
        <div class='col-md-12'>


			<div class='col-md-6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Basic Salary <br>
              <input name='sala$n' id='sala$n' class='form-control text-center' type='text' value='$salo' onkeyup='format(this);' onkeypress='return isNumberKey(event)' required>
            </div> 


			<div class='col-md-6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Balance Amount <br>
              <input name='bala$n' id='bala$n' class='form-control text-center' type='text' value='$balao' onkeyup='format(this);' onkeypress='return isNumberKey(event)' required>
            </div> 
</div>

		
		 <div class='col-md-12'>


			<div class='col-md-6'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allowance Amount <br>
              <input name='allo$n' id='allo$n' class='form-control text-center' type='text' value='$allowo' onkeypress='return isNumberKey(event)' onkeyup='format(this);' readonly required>
            </div> 


			<div class='col-md-6'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Deduction Amount <br>
              <input name='duct$n' id='duct$n' class='form-control text-center' type='text' value='$ducto' readonly onkeypress='return isNumberKey(event)' onkeyup='format(this);' required>
            </div> 

    </div>
    
     <div class='col-md-12'>


			<div class='col-md-6'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Self Payment <br>
              <input name='pay$n' id='pay$n' class='form-control text-center' type='text' value='$paso' onkeypress='return isNumberKey(event)' onkeyup='format(this);' required>
            </div> 


			<div class='col-md-6'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Loan Amount <br>
              <input name='adva$n' id='adva$n' class='form-control text-center' type='text' value='$advao' readonly onkeypress='return isNumberKey(event)' onkeyup='format(this);' required>
            </div> 

		</div><br><br><br><br>
      </div><input type='hidden' name='numb$n' id='numb$n' value='$numb'>
      <div class='modal-footer' style='margin-top:0px; height:46px; padding-top:5px; border:0px solid blue;'>
	<hr style='border:1px solid #ffffff; margin:-10px 0px 10px 0px; padding:0px;'>";
	    
	    if(!$st){
	    ?>
        <button type="button" class="btn btn-sm btn-warning" data-dismiss="modal" style="width:120px;">&nbsp;CLOSE&nbsp;</button>
    <button type="submit" class="btn btn-sm btn-success" onclick="this.style.display='none'" name="submit_form" style="width:120px;">SAVE</button>
      </div></form>
        
        <?php
	    }
	    ?>
	    
      </div></form>
    </div>
  </div>
</div>


    <?php
    
    if($st)
    $bnn="default";
    else
    $bnn="success";
    
				print("<tr onclick=this.style.color='#0066ff'>
						<td $stn class='text-right'>$n &nbsp;</td><td $stn>$fna $lna</td><td $stn> $post </td>
                        <td $stn> $mt </td><td $stn> $yr </td><td $stn class='text-right'>$balao</td>
						<td $stn class='text-right'>$salo</td>
						<td $stn class='text-right'> $advao </td>
						<td $stn class='text-right'> $allowo </td><td $stn class='text-right'> $ducto </td>
						<td $stn class='text-right'> $paso </td><td $stn class='text-right'> $neto </td>
						<td $stn class='text-right'> $cloo&nbsp;&nbsp;</td>
						
						<td class='hidden-print' align='right' style='width:20px; padding:0px;'>
					<button type='button' class='btn btn-xs btn-$bnn hidden-print' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px; width:25px;' data-placement='top' data-toggle='modal' data-target='#exampleModal$n'>
						 <i class='lnr lnr-pencil'></i></button></td></tr>");
	$n++;
	$isal+=$sal;
	$iadv+=$adva;

	$inet+=$net;
	$iall+=$allow;
	$ided+=$duct;
	$ibal+=$bala;
	$ipay+=($pay+$adva);
	$iclo+=$clo;
	$ipaid+=$paid;

		   $itot+=$tot;
	}

			$isalo=number_format($isal);
		   $iadvo=number_format($iadv);
		   $iallo=number_format($iall);
		   $idedo=number_format($ided);
		   $ineto=number_format($inet);
		   
		   $itoto=number_format($itot);
		   $ibalo=number_format($ibal);
		   $ipayo=number_format($ipay);
		   $iclo=number_format($iclo);
		   $ipaido=number_format($ipaid);
		   $stn="style='padding-right:1px;'";

	print("<tr><th> </th> 
	<th colspan='4' style='align:center; padding-left:80px;'> TOTAL AMOUNT </th>
	<th class='text-right' $stn> $ibalo </th><th class='text-right' $stn> $isalo </th><th class='text-right' $stn> $iadvo </th><th class='text-right' $stn> $iallo </th><th class='text-right' $stn> $idedo </th><th class='text-right' $stn> $ipayo </th>
	<th class='text-right' $stn> $ineto </th><th class='text-right' $stn> $iclo&nbsp;&nbsp;</th>
	<th class='text-left hidden-print'> -- </th></tr></tr>");
	?>              
                    </tbody>   
                  </table>

			<?php

			  }
			  else{
				  ?>
                
                                 <table class="table table-striped table-hover">
                       
                                      <thead>
                    <tr role="row">
                      <th> No </th> 					  
                       <th align='center'> Due&nbsp;Date </th> 							  
                       <th> Done&nbsp;By </th> 					  
                       <th> Type </th><th> Month </th>
                       <th> Year </th>
                       <th> Employees </th> 
                       <th class="text-center"> Amount </th>
                       <th class="text-center"> Allowance </th>
                       <th class="text-center"> Contribution </th>
                       <th class="text-center"> Deduction </th>
                       <th class="text-center"> Payment </th>
					   <th class="hidden-xs hidden-print" style="width: 40px;text-align:center;"> Status </th>
                        <th class="hidden-xs hidden-print" style="text-align:center;" colspan='2'>Actions</th>
                     </tr>
                    </thead>
                                        <tbody>
<?php
$n=1;
	while($ro=mysqli_fetch_assoc($do)){
$numb=$ro['Number'];
$mt=$ro['Month'];
$user=$ro['User'];
$yr=$ro['Year'];
$dati=$ro['Date'];
$st=$ro['Status'];
$lv=$ro['Level'];
$std=$ro['Starting'];
$end=$ro['Ending'];
$stn="style='padding:1px;'";

	$lvo="PAYROLL";

	if($st){
		$lbt="<span class='label label-success' style='width:80px; height:20px; margin:0px; padding:3px 0px 0px 0px; font-size:12px;'>CONFIRMED</span>";
        $act="<td class='text-center hidden-xs hidden-print' $stn><center> -- </td>";
		$acti="<td class='text-right hidden-xs hidden-print' style='width:20px; padding:1px;'>
      <button type='submit' name='open_id' class='btn btn-xs btn-info hidden-print text-center' name='edit_id' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px; width:25px; text-align:center; padding-right:5px;' title='Open' data-toggle='tooltip' data-placement='top'>&nbsp;&nbsp;<i class='lnr lnr-download'></i></button></td>";
	}
	else{
		$lbt="<span class='label label-warning' style='width:80px; height:20px; margin:0px; padding:3px 0px 0px 0px; font-size:12px;'>PENDING</span>";
		$act="<td class='text-right hidden-xs hidden-print' style='width:20px; padding:1px;'>
     <button class='btn btn-xs btn-danger hidden-print' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px; width:25px;' type='button'  data-toggle='modal' data-target='#exampleModal$n'><i class='lnr lnr-trash'></i></button></td>";

		$acti="<td class='text-right hidden-xs hidden-print' style='width:20px; padding:1px;'>
      <button type='submit' name='open_id' class='btn btn-xs btn-info hidden-print text-center' name='edit_id' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px; width:25px; text-align:center; padding-right:5px;' title='Open' data-toggle='tooltip' data-placement='top'>	&nbsp;&nbsp;<i class='lnr lnr-download'></i></button></td>";
	}
	
		$amo=$adva=$ded=$allo=$paid=0;
$dot=mysqli_query($conn, "SELECT *FROM `payrolls` WHERE `Month`='$mt' AND `Year`='$yr'");
		if($fot=mysqli_num_rows($dot)){
			while($rot=mysqli_fetch_assoc($dot)){
					$amo+=$rot['Salary'];
					$dedu+=$rot['Deduction'];
					$allo+=$rot['Allowance'];
					$pay+=($rot['Payment']+$rot['Advance']);
					$paid+=$rot['Paid'];
			}
		}	

	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='text-right pull-right'><b> $mt $yr </b></label></b></h5>

      </div>
      <div class='modal-body' style='height:40px;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this payroll?</h5>
      </div><form method='post' action=''>
						<input type='hidden' value='$numb' name='numb'>
						<input type='hidden' value='$mt' name='mt'>
						<input type='hidden' value='$yr' name='yr'>
						<input type='hidden' value='$std' name='std'>
						<input type='hidden' value='$end' name='end'>
						<input type='hidden' value='$perpagevalue' name='perpagevalue'>
						<input type='hidden' value='$lv' name='lv'>
      <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;&nbsp;NO&nbsp;</button>
        <button type='submit' name='delete_id' class='btn btn-sm btn-danger'>YES</button>
      </div></form>
    </div>
  </div>
</div>";


 $amoo=number_format($amo);			$alloo=number_format($allo);			$paido=number_format($paid);				$deduo=number_format($dedu);
         $payo=number_format($pay);
		print("<tr><form action='slips.php' method='post'>
                        <td $stn class='text-right'>$n &nbsp;
						<input type='hidden' value='$numb' name='numb'>
						<input type='hidden' value='$mt' name='mt'>
						<input type='hidden' value='$yr' name='yr'>
						<input type='hidden' value='$std' name='std'>
						<input type='hidden' value='$end' name='end'>
						<input type='hidden' value='$perpagevalue' name='perpagevalue'>
						<input type='hidden' value='$lv' name='lv'></td>
                        <td $stn class='text-center'>$dati</td>
                        <td $stn>$user</td>
                        <td $stn> $lvo </td> <td $stn> $mt </td><td $stn> $yr </td>
                        <td $stn class='text-center'> $fot </td>
                        <td align='right' style='padding:1px; padding-right:10px;'> $amoo </td>
                        <td align='right' style='padding:1px; padding-right:10px;'> $alloo </td>
                        <td align='right' style='padding:1px; padding-right:10px;'> $paido </td>
                        <td align='right' style='padding:1px; padding-right:10px;'> $deduo </td>
                        <td align='right' style='padding:1px; padding-right:10px;'> $payo&nbsp;&nbsp;</td>
                        <td align='right' style='padding:1px; padding-right:10px;' class='hidden-xs hidden-print'> $lbt </td>
                             $act    $acti       	
                        </form></tr>");
	$n++;                   $allo=$deduo=$advao=$amoo=$payo=$paido=0;
	$allo=$amo=$adva=$pay=$dedu=$paid=0;
	}
	?>
              
                    </tbody>   
                  </table>
				  <?php
			  }
					?>
                                      <div class="row">
                  <div class="col-md-12 hidden-print">
            <div class="col-md-6 hidden-print">
                  <ul class="pagination">
                      <li>
                                 <a class="icon" href="#">
           <i class="lnr lnr-chevron-left"></i></a>
                                            </li>
                      <li class="active">
                        <a href="#">
                        1                       </a>
                      </li>

                                            <li>
                                              <a class="icon" href="#">
                        <i class="lnr lnr-chevron-right"></i></a>
                                           </li>
                    </ul>
              </div>
              
            <div class="col-md-6 hidden-print"><div class="pull-right">
                      <?php
                      if($ope=='1'){
                            if(!$st){
            echo"<div class='modal fade' id='modalconfi' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:120px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content text-left'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>CONFIRMATION 
		<label class='text-right pull-right'> $mt / $yr </label></h5>

      </div>
      <div class='modal-body' style='height:60px;'>
        <h5 style='color:#ff0033'>Are you sure you want to confirm this payrool?</h5>
      </div><form method='post' action=''>
						<input type='hidden' value='$mt' name='mt'>
						<input type='hidden' value='$yr' name='yr'>
      <div class='modal-header' style='height:50px; padding:10px; border:0px solid blue; text-align:right'>
        <button type='button' class='btn btn-sm btn-danger' data-dismiss='modal'>&nbsp;&nbsp;NO&nbsp;</button>
        <button type='submit' name='confirm' class='btn btn-sm btn-success' title='CONFIRM' data-toggle='tooltip' data-placement='top'>YES</button>
      </div></form>
    </div>
  </div>
</div>";            
            echo"<button class='btn  btn-warning  btn-block' type='button' name='confirm' style='width:120px; margin-left:60px; margin-top:10px;' data-toggle='modal' data-target='#modalconfi'>CONFIRM</button>";
                            }
				else{
				    if($_SESSION['Pcance']){
	 echo"<div class='modal fade' id='modalconfi' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:120px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content text-left'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>CONFIRMATION 
		<label class='text-right pull-right'> $mt / $yr </label></h5>

      </div>
      <div class='modal-body' style='height:60px;'>
        <h5 style='color:#ff0033'>Are you sure you want to release this payrool?</h5>
      </div><form method='post' action=''>
						<input type='hidden' value='$mt' name='mt'>
						<input type='hidden' value='$yr' name='yr'>
      <div class='modal-header' style='height:50px; padding:10px; border:0px solid blue; text-align:right'>
        <button type='button' class='btn btn-sm btn-danger' data-dismiss='modal'>&nbsp;&nbsp;NO&nbsp;</button>
        <button type='submit' name='release' class='btn btn-sm btn-success' title='CONFIRM' data-toggle='tooltip' data-placement='top'>YES</button>
      </div></form>
    </div>
  </div>
</div>";            
			echo"<button class='btn  btn-success  btn-block' type='button' data-toggle='modal' data-target='#modalconfi' style='width:120px; margin-left:60px; margin-top:10px;' data-toggle='modal' data-target='#modallease'>RELEASE</button>";
				}
				}
                      }
				  ?></div></div></div></div>
                                
              </div>
            </div>
        </div>
</div></div></div></div>
<?php
include'footer.php';
?>