<!-- Add -->
<?php
  include 'includes/session.php';
  include 'includes/sessions.php'; 

  if(isset($_POST['add'])){
    $employee_id = $_POST['employee_id'];
    $salary = $_POST['salary'];
    $date=$_POST['dates'];
    $month=$_POST['month'];
    $gross=$_POST['gross'];
    $bonus=$_POST['bonus'];
    $absent=$_POST['absent'];
    $name=$_POST['name'];

    $sql = "INSERT INTO salary (employee_id, salary,dates,month,gross,bonus,absent,name) VALUES ('$employee_id', '$salary','$date','$month','$gross','$bonus','$absent','$name')";
    if($conn->query($sql)){

      $_SESSION['success'] = 'salary added successfully';
    }
    else{ 
      $_SESSION['error'] = $conn->error;
    }
  } 
  else{
    $_SESSION['error'] = 'Fill up add form first';
  }

  header('location: pay_salary.php');

?>
<div class="modal fade" id="addnew">
    <div class="modal-dialog">
        <div class="modal-content"> 
          	<div class="modal-header">
            	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
              		<span aria-hidden="true">&times;</span></button>
            	<h4 class="modal-title"><b>Add Salary</b></h4>
          	</div>
          	<div class="modal-body">
            	<form class="form-horizontal" method="POST" action="salary_add.php">
          		  <div class="form-group">
                  	<label for="title" class="col-sm-3 control-label">Employee ID</label>

                  	<div class="col-sm-9">
                      <?php
                      $sql = "SELECT * FROM employees";
                      $result = $conn->query($sql);
                       
                      ?>
<select class="form-control" id="title" name="employee_id" required>
  <?php while($row = $result->fetch_assoc()) {?>
  <option value="<?php echo $row["employee_id"];?>"><?php echo $row["employee_id"];?></option>
   <?php
                    }
                      ?>
</select>

                  	</div>
                </div>
                 <div class="form-group">
                    <label for="title" class="col-sm-3 control-label">Employee Name</label>

                    <div class="col-sm-9">
 <?php
                      $sql = "SELECT * FROM employees";
                      $result = $conn->query($sql);
                       
                      ?>
                        <select class="form-control" id="title" name="name" required>
  <?php while($row = $result->fetch_assoc()) {?>
  <option value="<?php echo $row["lastname"];?>"><?php echo $row["lastname"];?></option>
   <?php
                    }
                      ?>
</select>

                    
                    </div>
                </div>
                 <div class="form-group">
                    <label for="rate" class="col-sm-3 control-label">Date</label>

                    <div class="col-sm-9">
                      <input type="date" class="form-control" id="rate" name="dates" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="rate" class="col-sm-3 control-label">Month</label>

                    <div class="col-sm-9">
                      <select name="month" class="form-select" >
                        <option value="January">January</option>
                        <option value="February">February</option>
                        <option value="March">March</option>
                        <option value="April">April</option>
                        <option value="May">May</option>
                        <option value="June">June</option>
                        <option value="July">July</option>
                        <option value="August">August</option>
                        <option value="September">September</option>
                        <option value="October">October</option>
                        <option value="November">November</option>
                        <option value="December">December</option>
                      </select>
                    
                    </div>
                </div>
               
                 <div class="form-group">
                    <label for="title" class="col-sm-3 control-label">Gross</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="title" name="gross" required>
                    </div>
                </div>
                 <div class="form-group">
                    <label for="title" class="col-sm-3 control-label">Bonus</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="title" name="bonus" required>
                    </div>
                </div>
                   <div class="form-group">
                    <label for="rate" class="col-sm-3 control-label">Absent</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="rate" name="absent" required>
                    </div>
                </div>
                
                 <div class="form-group">
                    <label for="rate" class="col-sm-3 control-label">Net Amount</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="rate" name="salary" required>
                    </div>
                </div>
          	</div>
          	<div class="modal-footer">
            	<button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal"><i class="fa fa-close"></i> Close</button>
            	<button type="submit" class="btn btn-primary btn-flat" name="add"><i class="fa fa-save"></i> Save</button>
            	</form>
          	</div>
        </div>
    </div>
</div>

<!-- Edit -->
<div class="modal fade" id="edit">
    <div class="modal-dialog">
        <div class="modal-content">
          	<div class="modal-header">
            	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
              		<span aria-hidden="true">&times;</span></button>
            	<h4 class="modal-title"><b>Update Position</b></h4>
          	</div>
          	<div class="modal-body">
            	<form class="form-horizontal" method="POST" action="position_edit.php">
            		<input type="hidden" id="posid" name="id">
                <div class="form-group">
                    <label for="edit_title" class="col-sm-3 control-label">Position Title</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="edit_title" name="title">
                    </div>
                </div>
                <div class="form-group">
                    <label for="edit_rate" class="col-sm-3 control-label">Salary Per Hour</label>

                    <div class="col-sm-9">
                      <input type="text" class="form-control" id="edit_rate" name="rate">
                    </div>
                </div>
          	</div>
          	<div class="modal-footer">
            	<button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal"><i class="fa fa-close"></i> Close</button>
            	<button type="submit" class="btn btn-success btn-flat" name="edit"><i class="fa fa-check-square-o"></i> Update</button>
            	</form>
          	</div>
        </div>
    </div>
</div>

<!-- Delete -->
<div class="modal fade" id="delete">
    <div class="modal-dialog">
        <div class="modal-content">
          	<div class="modal-header">
            	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
              		<span aria-hidden="true">&times;</span></button>
            	<h4 class="modal-title"><b>Deleting...</b></h4>
          	</div>
          	<div class="modal-body">
            	<form class="form-horizontal" method="POST" action="position_delete.php">
            		<input type="hidden" id="del_posid" name="id">
            		<div class="text-center">
	                	<p>DELETE POSITION</p>
	                	<h2 id="del_position" class="bold"></h2>
	            	</div>
          	</div>
          	<div class="modal-footer">
            	<button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal"><i class="fa fa-close"></i> Close</button>
            	<button type="submit" class="btn btn-danger btn-flat" name="delete"><i class="fa fa-trash"></i> Delete</button>
            	</form>
          	</div>
        </div>
    </div>
</div>


     