
@extends('layouts.admin')
@section('pageTitle', 'Vega Soft')
@section('page-content')



<style>
#dynamic_ajax_table_length ,.dt-buttons ,#dynamic_ajax_table_filter{
    //float: left;
}
.custom-design-modal{
max-width:70%;
}
.dt-buttons{
    height: 34px;
}
.tick_print{


  color: red !important;
  font-weight:bold;
  background :none;
  border:none;
}


.btn-info:hover{

  background:none !important;
}

.btn_tick{
  background:white;
color:black;

}





.btn-info.active:not(:disabled):not(.disabled), .btn-info:active:not(:disabled):not(.disabled){

background :none;
border:none;

}




</style>
   <input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"  active_mn="<?= $rows->root;?>"  active_mnt="<?= $rows->menu_type;?>">
    @if ($rows->sedp != "")
  @foreach(explode(',', $rows->sedp) as  $z=>$info) 
     @if ($info == "1" && $z==1)
       <input type="hidden" class="additional_btns" btn_icon="fa fa-pencil" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm btn-dtbl" col_width="30" >
     @endif 
     @if ($info == "1" && $z==2)
        <input type="hidden" class="additional_btns" btn_icon="fa fa-trash-o " btn_text="Remove" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm btn-dtbl" col_width="40"  >
     @endif 
     @if ($info == "1" && $z==3)
          <input type="hidden" class="additional_btns" btn_icon="fa fa-print" btn_text="Print" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm btn-dtbl" col_width="40"  >
     @endif
  @endforeach
@endif
<input type="hidden" id="ev" class="additional_btns_td" btn_icon="fa fa-print" btn_text="Details" btn_click_function="employee_view" btn_class="btn btn-warning  btn-sm btn-dtbl" col_width="40"  >
<input type="hidden" id="cp" class="additional_btns_td" btn_icon="fa fa-print" btn_text="<i class='las la-check'></i>" btn_click_function="tick_print" btn_class="btn btn-info  btn-sm btn-dtbl btn_tick" col_width="40"  >

<div class="page-header">
<div class="row align-items-center">
<div class="col">
<h3 class="page-title"><?= $rows->menu_name;?></h3>
</div>
<div class="col-auto float-end ms-auto">

<a href="javascript:void(0)" class="btn add-btn" id="code_print" onclick="generate_bcode();"><i class="fa fa-print"></i> CODE</a>
<a href="javascript:void(0)" class="btn add-btn" data-bs-toggle="modal" data-bs-target="#add_employee"><i class="fa fa-plus"></i> Add EMployee</a>

</div>
</div>
</div>


<div class="row filter-row">




</div>

<div class="row">
<div class="col-md-12">
<div class="table-responsive" id="table_result">
    
</div>
</div>
</div>
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">





<div id="add_employee" class="modal custom-modal fade add_main_modal" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-lg custom-design-modal" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= $rows->menu_name;?></h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="row">


<div class="col-md-6">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control input_text" id="emp_name">
</div>
<div class="form-group">
<label>
Husband / Father's Name</label>
<input type="text" class="form-control input_text" id="guardian">
</div>
<div class="form-group">
<label class="d-block">Gender:</label>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="gender_male" value="1" checked>
<label class="form-check-label" for="gender_male">Male</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="gender_female" value="2">
<label class="form-check-label" for="gender_female">Female</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="gender_trans" value="3">
<label class="form-check-label" for="gender_trans">Transgender</label>
</div>
</div>
<div class="form-group">
<label>Address</label>
<textarea rows="4" cols="5" class="form-control input_text" id="addres"></textarea>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Country
</label>
<select id="country" class="form-control" onchange="get_state();"></select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>State</label>

<select id="state" class="form-control" onchange="get_district();"></select>
</div>
</div>
</div>

</div>
<div class="col-md-6" >

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Employee Code</label>
<input type="text" class="form-control input_text" id="emp_code">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Serial No</label>
<input type="text" class="form-control input_text" id="serial_no">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Machine Code
</label>
<input type="text" class="form-control input_text" id="mach_code">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Branch Name</label>
<select class="form-control" id="branch_id" > 
         <option value="0">Select Branch</option>
           @foreach($brn as  $z=>$det) 
           <option value="{{$det->BranchID}}">{{$det->BranchName}}</option>
           @endforeach
        </select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>BloodGroup
</label>
<select id="blood" name="blood" class="form-control"> 
         <option value="">Select</option>
         <option value="A+">A+</option>
         <option value="A-">A-</option>
         <option value="B+">B+</option>
         <option value="B-">B-</option>
         <option value="AB+">AB+</option>
         <option value="AB-">AB-</option>
         <option value="O+">O+</option>
         <option value="O-">O-</option>
        </select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Date Of Birth</label>
<input type="text" id="dob" class="form-control input_text mdate">

</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Religion</label>
<select id="religion" name="" class="form-control input_text"> 
           <option value="">Select</option>
         <option value="Hindu">Hindu</option>
         <option value="Muslim">Muslim</option>
         <option value="Christian">Christian</option>
         <option value="Sikh">Sikh</option>
         <option value="Buddhist">Buddhist</option>
         <option value="Others">Others</option>
        </select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Date OF Join</label>
<input type="text" id="doj" class="form-control input_text mdate">

</div>
</div>
</div>

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Phone
</label>
<input type="text" id="phone1"  class="form-control input_text">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Phone2</label>
<input type="text"  id="phone2" class="form-control input_text ">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>District</label>
<select id="district" class="form-control" onchange="get_district();"></select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Pincode</label>
<input type="text" id="pin" class="form-control">
</div>
</div>
</div>
</div>


</div>
<div class="submit-section">

<button type="button" id="add_btn" class="btn btn-info btn-lg" onclick="submit_form();">Save</button>
<button type="button" id="edit_btn" class="btn btn-success btn-lg" onclick="submit_form();">Edit</button>
<button type="button" class="btn btn-danger btn-lg">Reset</button>
</div>
</form>
</div>
</div>
</div>
</div>



<div id="printTable" style="white-space: break-spaces;">

</div>

@endsection




@section('page-script')
<script src="{{ asset('project-js\vega-front-scripts.js')}}"></script>
<script type="text/javascript">
$( document ).ready(function() {
    set_mn();


$("#branch_id").val("{{ Session::get('b_id')}}");
$("#branch_id").prop('disabled',true);

    $('#code_print').hide();
     get_country();
    fetch_view_table();
});







function submit_form() {
 status=0;
 if($.trim($('#emp_name').val())==''){
    alert('Enter Employee Name');
    $('#emp_name').focus();
    status==1;
    return;
 }
 if($.trim($('#emp_code').val())==''){
    alert('Enter Employee Code');
    $('#emp_code').focus();
    status==1;
    return;
 }
 if($.trim($('#branch_id').val())=='0'){
    alert('Enter Employee Branch');
    $('#branch_id').focus();
    status==1;
    return;
 }
 if($.trim($('#phone1').val())==''){
    alert('Enter Employee Phone');
    $('#phone1').focus();
    status==1;
    return;
 }

 if (status==0) {
Save_form();
 }
}
//http://192.168.18.128/prl_api/ij/prl_branch_edit.php

function call_edit_modal(row_id) {
$('#add_btn').hide();
$('#edit_btn').show();

    $('#row_id').val(row_id);
    $('#hidden_status').val(1);
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: row_id,
              url1:'prl_desg_edit.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
 datas=response.edit;

          
              $('.add_main_modal').modal('show');
            $('#desg_name').val(datas[0]['desg_name']); 
            $('#grade').val(datas[0]['grade']); 
            
   
            
       // start_focus();   
        }
          
     });  
}

  function Save_form() {
  arr={
              'cid':"{{ Session::get('cid')}}",
              'hidden_status':$.trim($('#hidden_status').val()),
              'row_id':$.trim($('#row_id').val()),
              'emp_name':$.trim($('#emp_name').val()),
              'guardian':$.trim($('#guardian').val()),
              'addres':$.trim($('#addres').val()),
              'country':$.trim($('#country').val()),
              'state':$.trim($('#state').val()),
              'district':$.trim($('#district').val()),
              'emp_code':$.trim($('#emp_code').val()),
              'serial_no':$.trim($('#serial_no').val()),
              'mach_code':$.trim($('#mach_code').val()),
              'phone':$.trim($('#phone').val()),
              'blood':$.trim($('#blood').val()),
              'dob':$.trim($('#dob').val()),
              'religion':$.trim($('#religion').val()),
              'doj':$.trim($('#doj').val()),
              'pin':$.trim($('#pin').val()),
              'phone2':$.trim($('#phone2').val()),
              'branch_id':$.trim($('#branch_id').val()),
              'gender':$.trim($('input[name="gender"]:checked').val()),
              'company_id':"{{ Session::get('CID')}}",
              'added_by':"{{ Session::get('user_id')}}",
};
           $.ajax({
          url: "/store_data",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              json_data: JSON.stringify(arr),
              url1:'prl_employee_save.php'
             
          },
          success:function(response){
            
            console.log(response);
            if (response) {
              alert(response['msg']);
            
               $('.add_main_modal').modal('hide');
               fetch_view_table();
            }else{

            }
          },
          error: function(response) {
          }
         });
  }

  $( ".add_main_modal" ).on('hidden.bs.modal', function(){ $('#add_btn').show();
$('#edit_btn').hide();
 $('#hidden_status').val(0);
 $('.add_main_modal .form-control').val('');
});



function get_country() {
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: 'X',
              url1:'prl_get_country.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) { 
                    country=response;
$('#country').html("<option val='0'>-Select Country-</option>");
 $(country).each(function (i,val){
$('#country').append("<option value='"+val['country_id']+"'>"+val['country_name']+"</option>");
 });
$('#country').val(103);
get_state();
        }
          
     });  
}


function get_state() {
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: $('#country').val(),
              url1:'prl_get_state.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
$('#state').html("<option val='0'>-Select State-</option>");
 $(response).each(function (i,val){
$('#state').append("<option value='"+val['state_id']+"'>"+val['state_name']+"</option>");
 });
$('#state').val(10);
get_district();
        }
          
     });  
}


function get_district() {
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: $('#state').val(),
              url1:'prl_get_district.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
$('#district').html("<option val='0'>-Select District-</option>");
 $(response).each(function (i,val){
$('#district').append("<option value='"+val['district_id']+"'>"+val['district_name']+"</option>");
 });

$('#district').val(4);
        }
          
     });  
}
function employee_view(epl_id) {
    window.location.href='/viw_employee/'+epl_id;
}
function tick_print(epl_id) { 

if($("#cp"+epl_id).hasClass('tick_print')){
  $("#cp"+epl_id).removeClass('tick_print');
}else{
    $("#cp"+epl_id).addClass('tick_print');
}
if($('.tick_print').length>0){
       $('#code_print').show();
   }else{
       $('#code_print').hide();
   }
}



function printData()
{
   var divToPrint=document.getElementById("printTable");
   newWin= window.open("", '_blank', 'width=500,left=150,top=100');
   newWin.document.write(divToPrint.outerHTML);
   newWin.print();
   newWin.close();
}



function generate_bcode(){
// 

arr=[];

$(".tick_print").each(function(){

arr.push($(this).attr('row_id'));

});





$.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: arr,
                 
                      CID: "{{ Session::get('CID')}}",
              url1:'generate_barcode.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
               
 datas=response.edit;
 console.log(datas)
         $("#printTable").html(datas);
          printData();
//  time_stamp = new Date().getTime(); 
// var w = window.open('/barcode', '_blank', 'width=500,left=150,top=100');
// w.print();
// setTimeout(function () { w.print(); }, 500);
            
     
        }
          
     });





}









//generate_bcode();




// function generate_bcode(){




  



// }








</script>
@endsection