
@extends('layouts.appn')

@section('content')
<style>
  .select2-container {
    width: 100% !important;
  }
  #productsTable{
/* min-height: 300px !important; */
margin-bottom: 100px;
  }
  </style>
<div class="content-wrapper">
  <div class="content">
{{--     <div class="card card-default border-0 bg-transparent">
      <div class="card-header align-items-center p-0">
        <h2>Employee Master</h2>
      
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-add-event">
          <i class="mdi mdi-plus mr-1"></i> Add New Event
        </button>
      </div>
      
    </div> --}}
    <div class="card card-default" id="card-default-page">
      
  <div class="card-header">
    <h2>Employee Master</h2>

    <button type="button" id="btn-page" class="btn btn-primary" data-toggle="modal" data-target="#modal-add-event">
      <i class="mdi mdi-plus mr-1"></i> Add New Employee
    </button>

  </div>
  <div class="card-body" id="card-body-page">
    <div class="collapse" id="collapse-data-tables">

    </div>
    <table id="productsTable" class="table table-hover table-product" style="width:100%">
      <thead>
      <tr>
      <th>Employee Name</th>
      <th>Employee Code</th>
      <th>Place</th>
      <th>Branch</th>
      <th>Department</th>
      <th>Employee Name</th>
      </tr>
      </thead>
      <tbody>
     
      </tbody>
      </table>
   <!-- <table id="productsTable" class="table table-hover table-product" style="width:100%">
      <thead>
        <tr>
          <th>Image</th>
          <th>Product Name</th>
          <th>ID</th>
          <th>Qty</th>
          <th>Variants</th>
          <th>Committed</th>
          <th>User Activity</th>
          <th>Sold</th>
          <th>In Stock</th>
          <th></th>
        </tr>
      </thead>
      <tbody> 

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-01.jpg" alt="Product Image">
          </td>
          <td>Coach Swagger</td>
          <td>24541</td>
          <td>27</td>
          <td>1</td>
          <td>2</td>
          <td>
            <div id="tbl-chart-01"></div>
          </td>
          <td>4</td>
          <td>18</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-02.jpg" alt="Product Image">
          </td>
          <td>Toddler Shoes, Gucci Watch</td>
          <td>24542</td>
          <td>18</td>
          <td>7</td>
          <td>5</td>
          <td>
            <div id="tbl-chart-02"></div>
          </td>
          <td>1</td>
          <td>14</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-03.jpg" alt="Product Image">
          </td>
          <td>Hat Black Suits</td>
          <td>24543</td>
          <td>20</td>
          <td>3</td>
          <td>7</td>
          <td>
            <div id="tbl-chart-03"></div>
          </td>
          <td>6</td>
          <td>26</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-04.jpg" alt="Product Image">
          </td>
          <td>Backpack Gents</td>
          <td>24544</td>
          <td>37</td>
          <td>8</td>
          <td>3</td>
          <td>
            <div id="tbl-chart-04"></div>
          </td>
          <td>6</td>
          <td>7</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-05.jpg" alt="Product Image">
          </td>
          <td>Speed 500 Ignite</td>
          <td>24545</td>
          <td>8</td>
          <td>3</td>
          <td>4</td>
          <td>
            <div id="tbl-chart-05"></div>
          </td>
          <td>8</td>
          <td>42</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-06.jpg" alt="Product Image">
          </td>
          <td>Olay</td>
          <td>24546</td>
          <td>19</td>
          <td>6</td>
          <td>6</td>
          <td>
            <div id="tbl-chart-06"></div>
          </td>
          <td>79</td>
          <td>12</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-07.jpg" alt="Product Image">
          </td>
          <td>Ledger Nano X</td>
          <td>24547</td>
          <td>61</td>
          <td>46</td>
          <td>18</td>
          <td>
            <div id="tbl-chart-07"></div>
          </td>
          <td>76</td>
          <td>36</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-08.jpg" alt="Product Image">
          </td>
          <td>Surface Laptop 2</td>
          <td>24548</td>
          <td>33</td>
          <td>56</td>
          <td>89</td>
          <td>
            <div id="tbl-chart-08"></div>
          </td>
          <td>38</td>
          <td>5</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-09.jpg" alt="Product Image">
          </td>
          <td>TIGI Bed Head Superstar Queen</td>
          <td>24549</td>
          <td>3</td>
          <td>9</td>
          <td>15</td>
          <td>
            <div id="tbl-chart-09"></div>
          </td>
          <td>6</td>
          <td>46</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-10.jpg" alt="Product Image">
          </td>
          <td>Wattbike Atom</td>
          <td>24550</td>
          <td>61</td>
          <td>56</td>
          <td>68</td>
          <td>
            <div id="tbl-chart-10"></div>
          </td>
          <td>3</td>
          <td>19</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-11.jpg" alt="Product Image">
          </td>
          <td>Smart Watch</td>
          <td>24551</td>
          <td>19</td>
          <td>76</td>
          <td>38</td>
          <td>
            <div id="tbl-chart-11"></div>
          </td>
          <td>3</td>
          <td>17</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-12.jpg" alt="Product Image">
          </td>
          <td>Magic Bullet Blender</td>
          <td>24552</td>
          <td>12</td>
          <td>30</td>
          <td>14</td>
          <td>
            <div id="tbl-chart-12"></div>
          </td>
          <td>26</td>
          <td>9</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-13.jpg" alt="Product Image">
          </td>
          <td>Kanana rucksack</td>
          <td>24553</td>
          <td>14</td>
          <td>65</td>
          <td>39</td>
          <td>
            <div id="tbl-chart-13"></div>
          </td>
          <td>9</td>
          <td>55</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-14.jpg" alt="Product Image">
          </td>
          <td>Copic Opaque White</td>
          <td>24554</td>
          <td>43</td>
          <td>29</td>
          <td>75</td>
          <td>
            <div id="tbl-chart-14"></div>
          </td>
          <td>7</td>
          <td>15</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>

        <tr>
          <td class="py-0">
            <img src="images/products/products-xs-15.jpg" alt="Product Image">
          </td>
          <td>Headphones</td>
          <td>24555</td>
          <td>17</td>
          <td>6</td>
          <td>7</td>
          <td>
            <div id="tbl-chart-15"></div>
          </td>
          <td>6</td>
          <td>98</td>
          <td>
            <div class="dropdown">
              <a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">
              </a>

              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </td>
        </tr>



     </tbody>
    </table>
      -->

  </div>

    </div>

    
  </div>
</div>


<div class="modal fade" id="modal-add-event" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
      <form>
        <div class="modal-header px-4">
          <h5 class="modal-title" id="exampleModalCenterTitle">Employee</h5>

          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>

        <div class="modal-body px-4">

          <div class="row">
            <div class="col-lg-9">
              <div class="form-group">
                  <label for="Em_Name">Employee Name</label>
                  <input type="text" class="form-control  input_cls" id="Em_Name" value=""  autocomplete="off">
                  <div class="text-danger small mt-1" id="Em_Name_er">  </div>
               </div>
              </div>
           
            <div class="col-lg-3">
              <div class="form-group">
                <label for="Em_Code">Code</label>
                <input type="text" class="form-control  input_cls" value="" id="Em_Code"  autocomplete="off" readonly>
                <div class="text-danger small mt-1" id="Em_Code_er">  </div>
              </div>
            </div>
            
           
          </div>

          <div class="row">
            <div class="col-lg-4">
              <div class="form-group">
                <label for="Em_Br_ID">Branch</label>
                <select class="form-control  input_cls" id="Em_Br_ID"  autocomplete="off" onchange="get_emp_code();">
                  <option value="">-Branch-</option>
                  @foreach($branch as $p)
                  <option value="{{ $p->Br_ID}}" Br_Short="{{ $p->Br_Short}}">{{ $p->Br_Name}}</option>
                   @endforeach
                </select>
                <div class="text-danger small mt-1" id="Em_Br_ID_er">  </div>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group">
                <label for="Em_Place">Place</label>
                <input type="text" class="form-control  input_cls" value="" id="Em_Place"  autocomplete="off">
                <div class="text-danger small mt-1" id="Em_Place_er">  </div>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group">
                <label for="Em_Sec_Id">Section</label>
                <select class="form-control  input_cls" id="Em_Sec_Id"  autocomplete="off">
              
                  @foreach($sec_result as $p)
                  <option value="{{ $p->Sec_ID}}">{{ $p->Sec_Name}}</option>
                   @endforeach
                </select>
                <div class="text-danger small mt-1" id="Em_Sec_Id_er">  </div>
              </div>
            </div>
          </div>
          <div class="row">
            
            <div class="col-lg-12">
              <div class="form-group">
                <label for="EM_Dep_IDS">Department</label>
                <select class="js-example-basic-multiple form-control  input_cls" name="department[]" multiple="multiple" id="EM_Dep_IDS">
               
                  @foreach($dp_result as $p)
                <option value="{{ $p->Dep_ID}}">{{ $p->Dep_Short}}-{{ $p->Dep_Name}}</option>
                 @endforeach
                </select>
                <div class="text-danger small mt-1" id="EM_Dep_IDS_er">  </div> 
              </div>
            </div>
          </div>
  
       
        </div>

        <div class="modal-footer border-top-0 px-4 pt-0">
          <button type="button" class="btn btn-primary btn-pill m-0" id="save_btn" onclick="save_form();">Save</button>
          <button type="button" class="btn btn-success btn-pill m-0" id="edit_btn" onclick="save_form();">Edit</button>
          <input type="hidden" id="hidden_status" value="0">
          <input type="hidden" id="row_id" value="0">
        </div>
      </form>
    </div>
  </div>
</div>
@endsection
@section('script')
<script >
  function clear_form(){
    $('#modal-add-event').modal('hide');
    $('#edit_btn').hide();
$('#hidden_status').val(0);
$('#save_btn').show();
$('.input_cls').val('');
  }


  clear_form();

function remove_form(row_id){
  $('#hidden_status').val(2);
$('#row_id').val(row_id);
save_form();
}
function save_form() {
  EM_Dep_IDS=$('#EM_Dep_IDS').select2('data'); 
  var selectedElements = EM_Dep_IDS.map(function(item) {
    return '#'+item.id+'#';
}).join(''); 
   $.ajax({
          url: "/op_employee",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
             hidden_status:$.trim($('#hidden_status').val()),       
             row_id:$.trim($('#row_id').val()),       
             Em_Name:$.trim($('#Em_Name').val()),       
             Em_Code:$.trim($('#Em_Code').val()),       
             Em_Br_ID:$.trim($('#Em_Br_ID').val()),       
             Em_Place:$.trim($('#Em_Place').val()),       
             Em_Sec_Id:$.trim($('#Em_Sec_Id').val()),       
             EM_Dep_IDS:$.trim(selectedElements),
          },
          success:function(response){
            arr=JSON.parse(response);
            if(arr.flag){
              toaster_fn_set('success',' ',arr.msg,"toast-top-center");
              $("#Em_Name,#Em_Code,#Em_Place,#Em_Br_ID").val('');
              $("#Em_Sec_Id").val('0');
              $("#EM_Dep_IDS").val(null).trigger('change');
              clear_form();
              fetch_view();
            }else{
              toaster_fn_set('error',' ',arr.msg,"toast-top-center");
            }

          },
          error: function(xhr) {
                    if (xhr.status === 422) {
                        var errors = xhr.responseJSON.errors;
                        $.each(errors, function(key, value) {
                            $('#'+key+'_er').text(value[0]);
                            $('#'+key).addClass('border-danger');
                        });
                    }
                }
        });  

 }
 $(document).on('focus','.border-danger',function(){ 
ids=$(this).attr('id')+'_er';
$('#'+ids).html('');
$(this).removeClass('border-danger');
 });

 $('.js-example-basic-multiple').on('select2:open', function(e) {
  ids=$(this).attr('id')+'_er';
$('#'+ids).html('');
$(this).removeClass('border-danger');
            });

            function get_emp_code(){
                        $.ajax({
          url: "/get_emp_code",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",  
             'br_short':$('#Em_Br_ID option:selected').attr('br_short')        
          },
          success:function(response){
            $('#Em_Code').val(response);
          }
        });
                      }

                      fetch_view();
        function fetch_view(){
          $.ajax({
          url: "/form_sp_employee",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",  
             'br_short':$('#Em_Br_ID option:selected').attr('br_short')        
          },
          success:function(response){
            
            thead =Object.keys(response[0]);
            if(response!=''){
              theads='';
              thead_bot='';
              thead_top='';
              tbodys='';
             theads=' <div class="collapse" id="collapse-data-tables">';

              theads+='</div>';
              theads+='<table id="productsTable" class="table table-hover table-product" style="width:100%;  min-heignt:200px !important;" >';
                theads+='<thead><tr><th>SL</th>';
             
                  thead_end='<th></th></tr></thead><tbody>';
              $.each(response, function(index, value) {  //
                /*  console.log(ind); */
                tbodys+='<tr><td>'+(index+1)+'</td>';
                $.each(thead, function(i, thval) { // console.log(thval);  // ind=thead[index];
                  if(i>0){
                
                 if(index==0)    thead_top+='<th>'+thval+'</th>';
                  tbodys+='<td>'+value[thval]+'</td>'; 
                  }else{
                    pkey=value[thval];
                  }
              });
              tbodys+='<td>  <div class="dropdown">'; 
                tbodys+='<a class="dropdown-toggle icon-burger-mini" href="#" role="button" id="dropdownMenuLink"    data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static">'; 
                tbodys+='</a>'; 

                tbodys+=' <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">'; 
                  
                  tbodys+='<a class="dropdown-item " href="javascript:void(0)" onclick="edit_form('+pkey+');"><i class="mdi mdi-square-edit-outline"></i>Edit</a>'; 
                  tbodys+=' <a class="dropdown-item " href="javascript:void(0)" onclick="remove_form('+pkey+');"> <i class="mdi mdi-trash-can-outline"></i> Remove</a>'; 
                
                  tbodys+='</div>'; 
                  tbodys+=' </div></td>';
              tbodys+='</tr>';
          
               
              });
              tbody_end='</tbody>';
              tbody_end+='</table>';
          /*   trextra='<tr role="row"><td>&nbsp;</td><td > </td><td></td><td></td><td></td><td></td><td> </td></tr>';
            trextra+='<tr role="row"><td>&nbsp;</td><td > </td><td></td><td></td><td></td><td></td><td> </td></tr>';
            trextra+='<tr role="row"><td>&nbsp;</td><td > </td><td></td><td></td><td></td><td></td><td> </td></tr>'; */
              $('#card-body-page').html(theads+thead_top+thead_end+tbodys+tbody_end);
            //  alert(1);
              load_datatable();
            }
          }
        });
        }

   function     load_datatable(){
          var productsTable = $("#productsTable");
  if (productsTable.length != 0) {
    var columnCount = productsTable.find('tbody tr td').length;
    productsTable.DataTable({
      info: false,
  
      lengthChange: false,
      lengthMenu: [
        [ 50,100, -1],
        [ 50,100, "All"],
      ],
      scrollX: true,
      order: [[1, "asc"]],
      columnDefs: [
        {
          orderable: false,
          targets: [ 0, 1],
        },
      ],
      language: {
        search: "_INPUT_",
        searchPlaceholder: "Search...",
      },
    });

  }

  var productSale = $("#product-sale");
  if (productSale.length != 0) {
    productSale.DataTable({
      info: false,
      paging: false,
      searching: false,
      scrollX: true,
      order: [[0, "asc"]],
      columnDefs: [
        {
          orderable: false,
          targets: [-1],
        },
      ],
    });
  }

        }
      function edit_form(row_id) {
        $('#modal-add-event').modal('show');
        $('#edit_btn').show();
$('#hidden_status').val(1);
$('#row_id').val(row_id);
$('#save_btn').hide();
$.ajax({
          url: "/edit_employee",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
             row_id:row_id
          },
          success:function(response){ 
            if(response!=''){
             // const myArr = JSON.parse(response);
             // users=myArr['users']; console.log(myArr['users']);
              $('#Em_Name').val(response[0].Em_Name);       
             $('#Em_Code').val(response[0].Em_Code);       
             $('#Em_Br_ID').val(response[0].Em_Br_ID);       
             $('#Em_Place').val(response[0].Em_Place);       
             $('#Em_Sec_Id').val(response[0].Em_Sec_Id);  
var dataArray = response[0].department.split(',');
$('#EM_Dep_IDS').val(dataArray).trigger('change');
 
            }
          }
        }); 
      }

      $('#modal-add-event').on('hidden.bs.modal', function () {
        clear_form();
});
</script>
@endsection
