
@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;
}
.filter-row{
    margin-bottom: 10px;
}
.custom-table td{
padding: 0px;
}
.table th {
    padding: 0.25rem 0.25rem;
    font-size: smaller;
background-color: #34444c;
color: white;
text-align: right;
}
#tab_html .form-control{
    height: 30px;
padding: 0px;
font-size: small;
text-align: center;
}
.com_th{
    width: 60px;
}
</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


<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="#" class="btn add-btn" data-bs-toggle="modal" data-bs-target="#add_employee"><i class="fa fa-plus"></i> Add Branch</a>

</div>
</div>
</div>
<div class="row filter-row">
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus">
<input type="text" class="form-control floating" id="this_month" onchange="check_m_atten();">
<label class="focus-label">Month</label>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus">
<input type="text" class="form-control floating" id="noday">
<label class="focus-label">No. Days</label>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus select-focus focused">
    
</div>
</div>
<div class="col-sm-6 col-md-3">
<a href="javascript:void(0);" class="btn btn-success w-100" onclick="generate_monthly_attn();"> Generate </a>
</div>
</div>

<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-bordered  custom-table table-nowrap mb-0">
<thead>
    <tr>
<th></th>
<th colspan="4">WORKED</th>
<th colspan="3">LEAVES</th>
<th colspan="2">MONTHLY</th>
<th colspan="4">ADD</th>
<th colspan="4">LESS</th>
<th></th>
    </tr>
<tr>

<th style="text-align: left;">Employee</th>
<th class="com_th">Hrs</th>
<th class="com_th">OT. Hrs</th>
<th class="com_th">Day</th>
<th class="com_th">H. Day</th>
<th class="com_th">EL</th>
<th class="com_th">CL</th>
<th class="com_th">PL</th>
<th class="com_th">ABSENT</th>
<th class="com_th">HDAYS</th>
<th class="com_th">OT</th>
<th class="com_th">ALLOWANCE</th>
<th class="com_th">EARNINGS</th>
<th class="com_th">OTHERS</th>
<th class="com_th">LWF</th>
<th class="com_th">PTAX</th>
<th class="com_th">OTHERS</th>
<th class="com_th">LOAN</th>
<th class="com_th">ARREARS</th>

</tr>
</thead>
<tbody id="tab_html">
    
</tbody>
</table>
</div>
</div>
</div>


<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">
<input type="hidden" id="serverValue2" value="">



@endsection




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

//fetch_view_table();
   $(function() {

$( "#toggle_btn" ).trigger( "click" );
    });
set_mn();
set_month();

  $('#this_month').MonthPicker({ Button: false , MonthFormat: 'M, yy', AltFormat: 'yy-mm-dd', // ODBC time stamp.
        AltField: '#serverValue2',
 OnAfterChooseMonth: function() { 
       check_m_atten();
        get_m_atten();
    } 
    });
function set_month() {
  var date = new Date();
  $('#this_month').val(moment(date).format('MMM,YYYY'));
  $('#serverValue2').val(moment(date).format('YYYY-MM')+'-01');
  check_m_atten();
        get_m_atten();
}


function check_m_atten() {
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: $('#serverValue2').val(),
              url1:'prl_check_m_atten.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
$('#noday').val(response.edit[0]['day']);

        }
          
     });  
}
function get_m_atten() {
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                    'CID': "{{ Session::get('CID')}}",
                    'b_id': "{{ Session::get('b_id')}}",
                     row_id: $('#serverValue2').val(),
              url1:'prl_get_m_atten.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
emp_list=response.edit;
tab='';
   noday=$('#noday').val();
$(emp_list).each(function(i,val) {
   rn='';
//absent=   noday-;
   if (val['whr']=='') {  rn='readonly';}
   tab+='<tr id="tr_id'+i+'" count="'+i+'" class="tr_row">';

tab+='<td>'+val['emp_name']+'</td>';

tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select totaltime mtime" autocomplete="off" type="text" id="" value="'+val['totaltime']+'"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select ot mtime" autocomplete="off" type="text" id="" value="'+val['ot']+'"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select days" autocomplete="off" type="text" id="" value="'+val['days']+'"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select hday" autocomplete="off" type="text" id="" value="'+val['hday']+'"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select allownumbers " autocomplete="off" type="text" id="" value=""></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select allownumbers " autocomplete="off" type="text" id="" value=""></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select allownumbers " autocomplete="off" type="text" id="" value=""></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select allownumbers  absent" autocomplete="off" type="text" id="" value="'+val['absent']+'" ></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select allownumbers  hday" autocomplete="off" type="text" id="" value="'+val['hday']+'" ></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt ot_wage" autocomplete="off" type="text" id="" value="'+val['ot_wage']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt allowance" autocomplete="off" type="text" id="" value="'+val['allowance']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt add_erning" autocomplete="off" type="text" id="" value="'+val['add_erning']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt ot_allowance" autocomplete="off" type="text" id="" value="'+val['ot_allowance']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt LWF" autocomplete="off" type="text" id="" value="'+val['LWF']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt PTAX" autocomplete="off" type="text" id="" value="'+val['ptax']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt ot_less" autocomplete="off" type="text" id="" value="'+val['ot_less']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt loan" autocomplete="off" type="text" id="" value="'+val['loan']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select cmn_amt arrears" autocomplete="off" type="text" id="" value="'+val['arrears']+'" onkeypress="return isNumber(event, this.value);"></td>';
tab+='</tr>'; 
});
$('#tab_html').html(tab);
$( ".cmn_amt" ).trigger( "blur" );
        }
          
     });  
}

function generate_monthly_attn() {
  $('.tr_row').each(function(){
    cnt=$(this).attr('count');
  });
}
$(document).on("focus", ".cmn_select", function() {
     $(this).select();
});
$(document).on("blur", ".cmn_amt", function() {
       if(this.value=='' || this.value=='0'){
    this.value='0.00';
    this.select();
   }
});
$(document).on("focus", ".mtime", function() {
  $(this).mask("99:99", {
    reverse: true
  });
});
$('.allownumbers').keyup(function () {
   this.value = this.value.replace(/[^0-9\.]/g,'');
   if(this.value==''){
    this.value=0;
    this.select();
   }
});
</script>
@endsection