<?php 
require_once("config/configDB.php"); 
require "userPermission.php";
require "financial_year_calculation.php";
require "accEmpFetchData.php";

$edit_id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM employee_attendance_hdr WHERE id='$edit_id' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

//$triptinvoice   = $row['invoicedate'];
$tdate_temp     = new DateTime(stripslashes($row['invoicedate']));
$invoicedate 		  = $tdate_temp->format('d-m-Y');


$Details_Result  = mysqli_query($conn,"SELECT lm.ename as ename,lad.shifttype,lad.extraworkinghrs,lad.shiftworkamt,lad.extrahoursamt,lad.enameid,lad.payedsalary,lad.advancesalary,lad.isdelete
FROM employee_attendance_dtl as lad 
LEFT JOIN employee_master as lm ON lm.id=lad.enameid 
WHERE  lad.hdr_id='$edit_id'");


?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      
      require 'header.php'; 
    ?>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Create  Employee Details</strong></h3>
    <form class="form-horizontal" action="accEmpUpdate.php" method="post" id="accLabourForm">
      <div class="col-sm-12 ">
      
      <div class="col-sm-1"></div>
        <div class="col-sm-3 form-group">
          <label class="control-label">Date</label>
          <input class="form-control input-lg datepicker-invoicedate"  type="text" name="invoicedate" autocomplete="off" readonly value="<?php echo $invoicedate; ?>">
          <input type="hidden" value=<?php echo $edit_id; ?> name="edit_id">
        </div>
        
        
      </div>
      
           
  
<div class="container-fluid">
      
      <div class="col-sm-4" style="padding-top: 10px;margin-top: 10px;">          
      <table class="table  table-striped table-bordered dt-responsive" style="overflow-x:auto;" id="oilDetailsVerticalH">
          <tr>
            <th>Labour Employee Name</th>
            <td>
              <select class="form-control input-lg select-labour-employee" id="labouremployeename" >
                <option value="0">Select your option </option>
                <?php echo  $sqlename; ?>
              </select>
            </td>
          </tr>
          <tr>
            <th>Shift</th>
            <td>
              <select class="form-control input-lg customerName-select " name="shifttype" id="shifttype">
               <option value="0">0</option>
                <option value="0.5">0.5</option>
                <option value="1">1</option>
                 <option value="1.5">1.5</option>       
                <option value="2">2</option>
                        <option value="2.5">2.5</option>
                        <option value="3">3</option>


              </select>
              
            </td>
          </tr>
          <tr>
            <th>Extra Working Hours</th>
            <td>
            <input class="form-control input-lg acc-extraworkinghrs" type="text" value="0" id="extraworkinghrs">         </td> 
          </tr>
          <!-- <tr>
            <th>Advance Salary</th>
            <td>
              <input class="form-control input-lg acc-advancesalary" type="text" value="0" id="advancesalary"> 
            </td>
          </tr> -->
          <tr>
            <th>Action</th>
            <td><input type="button" class="btn btn-default add-accLabour" value="Add">
            <input class="form-control trip-count" type="hidden" value="0" id="tripcount">
          </td>
          </tr>
        
      </table>
      </div>
      <div class="col-sm-7" style="padding-top: 10px;margin-top: 10px;">          
        <table class="table table-responsive table-striped table-bordered dt-responsive nowrap" id="accLabourDetailsAdd" cellspacing="0">
          <thead>
            <tr>
              <th> Employee Name</th>
              <th>Shift</th>
              <th>Extra Working Hours</th>
              <!-- <th>Advance Salary</th> -->
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
          <?php
            $trlength = 0;
            //lm.ename,lad.shifttype,lad.extraworkinghrs,lad.shiftworkamt,lad.extrahoursamt,lad.enameid
            while($drow = mysqli_fetch_array($Details_Result))
            {
              $trlength++;
              $DetailsTable ='<tr id="'.$trlength.'">';
                $DetailsTable .=  '<td class="product_name">'.$drow["ename"].'<input class="form-control labouremployeenameID" name="labouremployeenameID[]"  value="'.$drow["enameid"].'" type="hidden"></td>';
            
                $DetailsTable .= '<td>'.$drow["shifttype"].'<input class="form-control shifttypeID" name="shifttypeID[]" type="hidden" value="'.$drow["shifttype"].'" ></td>';
            
                $DetailsTable .= '<td>'.$drow["extraworkinghrs"].'<input class="form-control extraworkinghrs" name="extraworkinghrs[]" type="hidden" value="'.$drow["extraworkinghrs"].'" ></td>';
                
               // $DetailsTable .= '<td>'.$drow["advancesalary"].'<input class="form-control advancesalary" name="advancesalary[]" type="hidden" value="'.$drow["advancesalary"].'" ></td>';

                if($drow["isdelete"]==1) {
                  $DetailsTable .= '<td><input type="button" class="btn btn-default removeTripDetails" id="removeTripDetails" value="-"></td>';
                } else {
                  $DetailsTable .= '<td>Not Editable </td>';

                }
             
              $DetailsTable .= '</tr>';
     
              echo $DetailsTable;
                   
            }
          ?>
          </tbody>
        </table>
      </div>


    </div> 



    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default btn-lg accLabourSubmit" >Save</button>
      </div>
    </div>
    </form>   
  </div>
  <?php require 'footer.php' ?>
  
  <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
  <script type="text/javascript" src="js/accEmpEditScript.js"></script>
  
   <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
  
<script>
	$(document).ready(function(){
	  var date_input=$('input[name="invoicedate"]'); //our date input has the name "date"
		var container=$('form > .datepicker-invoicedate').length>0 ? $('form > .datepicker-invoicedate').parent() : "body";
		date_input.datepicker({
			  format: 'dd-mm-yyyy',
        container: container,
			  todayHighlight: true,
			  autoclose: true,
    });
    //$('input[name="invoicedate"]').datepicker( "setDate", new Date());   

      
    
  

  });
  

</script>
</body>
</html>