<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');
$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];
$page_title="Salary Payroll Report";
$page="61_employee_03.php";	
$table='employee_monthly_salary';	
$unique='id';


?>


<!DOCTYPE html>
<html lang="en">


<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->

<?php
  do_calander('#fdate');
  do_calander('#tdate');

  ?>
  

<body>

  <!-- ======= Header ======= -->
 
  
  <?php 
  require_once('inc_files/inc_header.php');
  ?>
  
  <!-- End Header -->

  <!-- ======= Sidebar ======= -->
   <?php  require_once('inc_files/inc_menu.php'); ?><!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
		  <li class="breadcrumb-item"> Reports</li>    
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
        <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
			<p class="card-title" style="font-size:14px; margin-bottom:0; padding-bottom:0;"><a href="61_reports_all.php?active_id=901&menu_id=9">< Back To Report List </a></p>
			
            <form class="row g-3" action="" method="post" name="codz" id="codz">
   		       
			
	<table width="80%" border="0" align="center">
      
      
        <tr height="50">
          <td align="right">Month:&nbsp;&nbsp;</td>
          <td align="left">
		 <select id="mon" name="mon"  class="form-select"  required  >
		  <option></option>
			
			<?php foreign_relation($conn,'month','month_id','month_name',$_POST['mon'],'1 order by month_id');?>
        	</select>		  </td>
          <td align="right">Department:&nbsp;&nbsp;</td>
          <td width="21%">
	
			<select id="department" name="department"  class="form-select"    >
		  <option></option>
			
			<?php foreign_relation($conn,'department','id','department',$_POST['department'],'1 order by id');?>
        	</select>		  </td>
          <td width="11%" align="right">Gender:&nbsp;&nbsp;</td>
          <td width="17%">
		  <select id="gender" name="gender"  class="form-select"    >
			<option></option>
			<?php foreign_relation($conn,'gender','id','gender',$_POST['gender'],'1 order by id');?>
		
        	</select></td>
          <td width="16%" rowspan="6" align="center" ><strong>
            &nbsp;&nbsp;&nbsp;
            <button type="submit" name="run_data" id="run_data" class="btn btn-success rounded-pill btn-sm">&nbsp;<i class="bi bi-filter me-1"></i> Run Report&nbsp;&nbsp;</button>
          </strong></td>
        </tr>
        <tr height="50">
        <td width="11%" align="right">Year:&nbsp;&nbsp;</td>
        <td width="12%" align="left">
		<select id="year" name="year"  class="form-select"  required  >
			<option></option>
			<?php foreign_relation($conn,'year','year','year',$_POST['year'],'1 order by year');?>
        	</select>		</td>
        <td width="12%" align="right">Designation:&nbsp;&nbsp;</td>
        <td>
	
			<select id="designation" name="designation"  class="form-select"    >
		  <option></option>
			
			<?php foreign_relation($conn,'designation','id','designation',$_POST['designation'],'1 order by id');?>
        	</select>
			</td>
        <td align="right">EMP Name:&nbsp;&nbsp;</td>
        <td>
		 <?php
			 auto_complete_from_db_sql($conn,'SELECT concat(emp_code," :: ",emp_name), concat(emp_code," :: ",emp_name) FROM employee_info
			WHERE 1 order by emp_code','employee_name');
		?>
                  <input type="text" class="form-control" id="employee_name" name="employee_name" value="<?php echo $_REQUEST['employee_name']?>" >	
		</td>
        </tr>
    </table>
               
  </form>
  <br>
	
              <!-- Table with stripped rows -->
             <table width="100%" class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="117" scope="col">EMP Code </span></th>
                    <th width="319" scope="col">EMP Name </span></th>
                    <th width="183" scope="col"><div style="text-align:right">Gross Salary</div></th>
                    <th width="183" scope="col"><div style="text-align:right">Tot benefits</div></th>
                    <th width="183" scope="col"><div style="text-align:right">Tot  earnings</div></th>
                    <th width="183" scope="col"><div style="text-align:right">Tot deduction</div></th>
                    <th width="183" scope="col"><div style="text-align:right">net salary</div></th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
					
 $employee_name = $_REQUEST['employee_name'];
  $employee=explode(' :: ',$employee_name);
   $employee_code=$employee[0];
  
if($employee_code!=''){
$employee_con=" and s.emp_code='".$employee_code."' ";
}

if($_POST['mon']!=''){
$mon_con=" and s.mon='".$_POST['mon']."' ";
}

if($_POST['year']!=''){
$year_con=" and s.year='".$_POST['year']."' ";
}


if($_POST['department']!=''){
$department_con=" and s.department='".$_POST['department']."' ";
}

if($_POST['designation']!=''){
$designation_con=" and s.designation='".$_POST['designation']."' ";
}

if($_POST['gender']!=''){
$gender_con=" and e.gender='".$_POST['gender']."' ";
}

if($_POST['religion']!=''){
$religion_con=" and e.religion='".$_POST['religion']."' ";
}


if($_POST['job_status']!=''){
$job_status_con=" and e.job_status='".$_POST['job_status']."' ";
}
	
		 $sql = "select id, designation from designation where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $designation[$info->id]=$info->designation;
		}	
		
		$sql = "select id, gender from gender where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $gender[$info->id]=$info->gender;
		}		
					
		 $sql = "select id, job_status from job_status where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $job_status[$info->id]=$info->job_status;
		}
					
					    $sql = 'select s.*, e.emp_name from '.$table.' s, employee_info e  where s.emp_code=e.emp_code '.$employee_con.$designation_con.$department_con.$job_status_con.$gender_con.$religion_con.$mon_con.$year_con.' order by s.emp_code';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
		<?php if(isset($_POST['run_data'])){?>			
      <tr>
      <td><a href="view_file/salary_payslip_print_view.php?tr_no=<?php echo $data->tr_no;?>" target="_blank"><?php echo $data->emp_code;?></a></td>
      <td><?php echo $data->emp_name;?></td>
      <td align="right"><?php echo number_format($data->gross_salary,2); $tot_gross_salary+=$data->gross_salary;?></td>
      <td align="right"><?php echo number_format($tot_benefits=$data->benefits+$data->ot_wages,2); $net_tot_benefits+=$tot_benefits;?></td>
      <td align="right"><?php echo number_format($data->total_earnings,2); $net_total_earnings+=$data->total_earnings;?></td>
      <td align="right"><?php echo number_format($data->total_deduction,2); $tot_total_deduction+=$data->total_deduction;?></td>
      <td align="right"><?php echo number_format($data->net_salary,2); $tot_net_salary+=$data->net_salary;?></td>
      </tr>
				  <?php }}?>
				  
     <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td align="right"><strong><?php echo number_format($tot_gross_salary,2);?></strong></td>
      <td align="right"><strong><?php echo number_format($net_tot_benefits,2);?></strong></td>
      <td align="right"><strong><?php echo number_format($net_total_earnings,2);?></strong></td>
      <td align="right"><strong><?php echo number_format($tot_total_deduction,2);?></strong></td>
      <td align="right"><strong><?php echo number_format($tot_net_salary,2);?></strong></td>
      </tr>
                </tbody>
              </table>
              <!-- End Table with stripped rows -->

            </div>
          </div>

        </div>

        
      </div>
    </section>

  </main><!-- End #main -->

  
 <!-- ======= Footer ======= -->
 <?php require_once('inc_files/inc_footer.php'); ?>
<!-- ======= End Footer ======= -->

</body>

</html>