

<?php $__env->startSection('pageTitle', 'Vega Soft'); ?>
<?php $__env->startSection('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  , .table thead td  {
    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: right;
}
.com_th{
    //width: 60px;
}
.cmn_th{
width: 4%;
}
.disabled-links {
    pointer-events: none;
}
.com_th .form-control{
    height: 25px;
}
.fsl{
    width: 2%;
}
</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;?>">
    <?php if($rows->sedp != ""): ?>
  <?php $__currentLoopData = explode(',', $rows->sedp); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $z=>$info): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
     <?php 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" >
     <?php endif; ?> 
     <?php 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"  >
     <?php endif; ?> 
     <?php 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"  >
     <?php endif; ?>
  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php 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">


</div>
</div>
</div>
<div class="row filter-row">
<div class="col-sm-4 col-md-2">
<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-3 col-md-2">
<div class="form-group form-focus">

<label class="focus-label">Select Category <span class="mandatory">*</span></label>
</div>
</div> -->

<div class="col-sm-3 col-md-2">
<div class="form-group form-focus">
<input type="text" class="form-control floating" id="noday" readonly onkeyup="set_wrkng_dy_val(this.value);">
<label class="focus-label">Total Days  <span class="mandatory">*</span></label>
</div>
</div>


<div class="col-sm-3 col-md-2">
<div class="form-group form-focus">
<input type="text" class="form-control floating" id="tot_hday" onkeypress="return isNumber(event, this.value);">
<label class="focus-label">Holidays <span class="mandatory">*</span></label>
</div>
</div>
<div class="col-sm-6 col-md-1">
<div class="form-group form-focus focused">
<input type="text" class="form-control floating" id="wday" value="0" readonly="">
<label class="focus-label"> Working Day</label>
</div>
</div>
<div class="col-sm-6 col-md-2">
<div class="form-group form-focus select-focus focused">
    
</div>
</div>
<div class="col-sm-6 col-md-2">
<button type="button" class="btn btn-success w-100 sv_btn" onclick="save_monthly_attens();">Save</button>

<!-- <a href="javascript:void(0);" class="btn btn-success w-100" onclick="save_monthly_attens();"> Save </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 " id="m_tbl">
<thead>
<!--     <tr>
<th style="width: 167px;"></th>
<th ></th>
<th colspan="5">WORKED</th>
<th colspan="4">MONTHLY</th>


    </tr> -->
<tr>
<th class="fsl">SL</th>
<th style="text-align: left; width: 15%;">Employee</th>
<!-- <th class="com_th cmn_th">Emp Work days</th> -->
<th class="com_th cmn_th">Full Day</th>
<th class="com_th cmn_th">Half Day</th>
<th class="com_th cmn_th">Total</th>
<th class="com_th cmn_th">Holiday </th>
<th class="com_th cmn_th">Holiday Wage</th>
<th class="com_th cmn_th">Esi. Leave</th>
<th class="com_th cmn_th">OT Pay</th>
<th class="com_th cmn_th">L.W.F</th>
<th class="com_th cmn_th">Tax Ded.</th>
<th class="com_th cmn_th">Additional</th>
<th class="com_th cmn_th">Other Ded.</th>

<!-- <th class="com_th">ABSENT</th>
<th class="com_th">CL</th>
<th class="com_th">PL</th> -->


</tr>
<tr>
<td class="fsl"></td>
<td style="text-align: left; width: 15%;"></td>
<!-- <td class="com_th cmn_th"></td> -->
<!-- <th class="com_th cmn_th">Emp Work days</th> -->
<td class="com_th cmn_th"><input class="form-control focusable auto_fills" autocomplete="off" type="text" id=""  onkeypress="return isNumber(event, this.value);"></td>
<td class="com_th cmn_th"><input class="form-control focusable auto_fills" autocomplete="off" type="text" id=""  onkeypress="return isNumber(event, this.value);"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"><input class="form-control focusable auto_fills" autocomplete="off" type="text" id=""  onkeypress="return isNumber(event, this.value);"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>
<td class="com_th cmn_th"></td>

<!-- <th class="com_th">ABSENT</th>
<th class="com_th">CL</th>
<th class="com_th">PL</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="">



<?php $__env->stopSection(); ?>




<?php $__env->startSection('page-script'); ?>
<script src="<?php echo e(asset('project-js\vega-front-scripts.js')); ?>"></script>
<script type="text/javascript">

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

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

set_mn();
set_month();

 



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();
}


$('#this_month').MonthPicker({ Button: false , MonthFormat: 'M, yy', AltFormat: 'yy-mm-dd',
        AltField: '#serverValue2',
 OnAfterChooseMonth: function() { 


  $(".sv_btn").prop('disabled',false);
      get_m_atten();
    } 
    });



$("#cat_id").on('change',function(){
  $("#noday").val($('option:selected',this).attr('md'));

check_m_atten();
get_m_atten();




});





$('.focusable').keydown(function (e) {

   if (e.which === 13) {
 
     
var index = $('.focusable').index(this) + 1;

       $('.focusable').eq(index).focus();

   }
});







function check_m_atten() {
//         $.ajax({
//               type: 'POST',
//                async: false,
//                 url: '/get_data',
//                 data: {
//                      '_token': "<?php echo e(csrf_token()); ?>",
//                     'cid':"<?php echo e(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() {


  if( $('#serverValue2').val()==""){
    var date = new Date();
    row_id= moment(date).format('YYYY-MM')+'-01'
  }else{

    row_id=$('#serverValue2').val();
  }

  arr={
               
               'cat_id':0,
                     'row_id': row_id,
};

        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "<?php echo e(csrf_token()); ?>",
                    'cid':"<?php echo e(Session::get('cid')); ?>",
                    'CID': "<?php echo e(Session::get('CID')); ?>",
                    'b_id': "<?php echo e(Session::get('b_id')); ?>",
             
                    'row_id':JSON.stringify(arr),
              url1:'prl_get_mnthly_attns.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
emp_list=response.edit;
tab='';
$('#noday').val(response.ndays);
$('#tot_hday').val(response.week_count);
$('#wday').val((response.ndays-response.week_count));
   noday=$('#wday').val();
$(emp_list).each(function(i,val) {
   rn='';
//absent=   noday-;
rd='';

if(val['t_wrking_dys']!=0){
  noday=val['t_wrking_dys'];
}

if(val['flg']!=0){
  rd='readonly';
$(".sv_btn").prop('disabled',true);

}

tr_id="'tr_id"+i+"'";


emp_id="'"+val['emp_id']+"'";
   tab+='<tr id="tr_id'+i+'" count="'+i+'" class="tr_row" emp_id='+emp_id+'>';

tab+='<td >'+(i+1)+'</td>';
tab+='<td >'+val['emp_name']+'</td>';
/*tab+='<td style="text-align:right;" class="t_wrkng_d">'+noday+'</td>';
tab+='<td style="text-align:right;" class="e_wrkng_d"><input class="form-control td_rt focusable vmn_row'+i+' cmn_select emp_wrk_dy " autocomplete="off"  type="text" id="" value="'+val['emp_mx']+'" onkeypress="return isNumber(event, this.value);" '+rd+' ></td>';*/

tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select full_day td_rt" autocomplete="off" onkeyup="month_calc('+tr_id+');" type="text" id="" value="'+val['full_day']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select half_day td_rt" autocomplete="off"  onkeyup="month_calc('+tr_id+');" type="text" id="" value="'+val['half_day']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select total td_rt" autocomplete="off" type="text" readonly id="" value="'+val['total']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select holi_days td_rt" autocomplete="off" type="text" id="" value="'+val['holi_days']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select holi_wage td_rt" autocomplete="off" type="text" id="" value="'+val['holi_wage']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select esi_leave td_rt" autocomplete="off" type="text" id="" value="'+val['esi_leave']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select ot_wage td_rt" autocomplete="off" type="text" id="" value="'+val['ot_wage']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select lwf_wage td_rt" autocomplete="off" type="text" id="" value="'+val['lwf_wage']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select tax_ded td_rt" autocomplete="off" type="text" id="" value="'+val['tax_ded']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select additional td_rt" autocomplete="off" type="text" id="" value="'+val['additional']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></td>';
tab+='<td><input class="form-control focusable vmn_row'+i+' cmn_select other_ded td_rt" autocomplete="off" type="text" id="" value="'+val['other_ded']+'" onkeypress="return isNumber(event, this.value);" '+rd+'></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();
});




function month_calc(tr_id){
 //   $('.tr_row').each(function() {
   
     full_day=$('#'+tr_id).find('.full_day').val();
     half_day=$('#'+tr_id).find('.half_day').val();
     ot_days=$('#'+tr_id).find('.ot_days').val();
   
    if(full_day=='') full_day=0;
     if(half_day=='') half_day=0;
     if(ot_days=='') ot_days=0;

     half_day=(half_day/2);

total=parseFloat(full_day)+parseFloat(half_day)+parseFloat(ot_days);
    
     $('#'+tr_id).find('.total').val(total.toFixed(2));


     
   // })
}










function  save_monthly_attens(){

status=0;


if($("#tot_hday").val()==""){
  alert("holiday Cant be empty");
  status=1;
  return;
}
if($("#noday").val()==""||$("#noday").val()==0){
  alert("Working Days is mandatory");
  status=1;
  return;
}

if(status==0){


save_form();

}

}


function save_form() { 
      /*  tarray={
            
              'emp_id':$(this).attr('emp_id'),
             
              'emp_wrk_dys':$(this).find('.emp_wrk_dy').val(),
              'full_day':$(this).find('.full_day').val(),
              'half_day':$(this).find('.half_day').val(),
              'ot_days':$(this).find('.ot_days').val(),
              'total':$(this).find('.total').val(),
              'absent':$(this).find('.absent').val(),
              'CL':$(this).find('.CL').val(),
              'PL':$(this).find('.PL').val()
          }*/
       allo=[];
          $(".tr_row").each(function(){
           tarray={
            
              'emp_id':$(this).attr('emp_id'),
             
              'emp_wrk_dys':$(this).find('.emp_wrk_dy').val(),
              'full_day':$(this).find('.full_day').val(),
              'half_day':$(this).find('.half_day').val(),
              'total':$(this).find('.total').val(),
              'holi_days':$(this).find('.holi_days').val(),
              'holi_wage':$(this).find('.holi_wage').val(),
              'esi_leave':$(this).find('.esi_leave').val(),
              'ot_wage':$(this).find('.ot_wage').val(),
              'lwf_wage':$(this).find('.lwf_wage').val(),
              'tax_ded':$(this).find('.tax_ded').val(),
              'additional':$(this).find('.additional').val(),
              'other_ded':$(this).find('.other_ded').val()
          }
          allo.push(tarray);
      });
     arr={
               
               'cid':"<?php echo e(Session::get('cid')); ?>",
              'b_id': "<?php echo e(Session::get('b_id')); ?>",
              'CID':"<?php echo e(Session::get('CID')); ?>",
              'added_by':"<?php echo e(Session::get('user_id')); ?>",

              'sal_month':$.trim($('#this_month').val()),
              'sal_tot_day':$.trim($('#noday').val()),
              'tot_hday':$.trim($('#tot_hday').val()),
              'cat_id':$.trim($('#cat_id').val()),
            
              'allo':allo
};


 $.ajax({

          url: "/store_data",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              json_data: JSON.stringify(arr),
              url1:'prl_save_mnthly_attn.php'
             
          },
          success:function(response){
            
            console.log(response);
            if (response) {
              alert(response['msg']);
            
               $('.modal').modal('hide');
               fetch_view_table();
            }else{

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

}







$(document).on('keyup','.auto_fills',function(){
 var $this = $(this);
fillvalue=$(this).val();
  // First, get the index of the td.
  var cellIndex = $this.parent('td').index(); 
  $('#tab_html > tr >td:nth-child('+(cellIndex+1)+')').find('input').val(fillvalue);
  
});




function set_wrkng_dy_val(val){

//alert(val)

}











</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\payroll\resources\views/month_atten_hp.blade.php ENDPATH**/ ?>