<script type="text/javascript">

    function getDetailsByUser(event,minute_id,user_id)
	{

		event.preventDefault();
        
		var route = "{{route('user.payrolldetails')}}";

		showLoader();
		$.post(route,{minute_id:minute_id,user_id:user_id,_token:token},function(data,status)
		{
        
    		$('#update_payroll_detail_model').html(data);

        $('.user_id').val(user_id);

        $('.minute_id').val(minute_id);


    		$('#md_update_payroll_detail').modal('show');


    		removeLoader();
  		})
  		  .fail(function(data) {

          messageToaster('error','Required form validation.','Failed');
         
          removeLoader();
    
        });
	}

    // AJAX REQUEST TO STORE INSTALLMENT PLAN 
  function updatePayrollDetail(event,obj)
  {
      event.preventDefault();

      var obj = $('#form_update_payroll_detail');
      var route = obj.attr('action');     
      var formdata = obj.serialize();
                   
      showLoader();

      $.post(route, formdata, function(result)
      {
          if(result)
          {
              // Reload the current page without the browser cache
              messageToaster('success','Payroll detail has been updated.','Success');

              location.reload(true);
                  
          }
      removeLoader();


      },'json')
      .fail(function(data) {

          messageToaster('error','Required form validation.','Failed');
          
          ajax_show_error(data,obj,$('#md_update_payroll_detail'));

         
          removeLoader();
    
        });    
  }


  function calculateGross(event,key_element)

  {
    event.preventDefault();

    var allowance_sum = 0;
    var deduction_sum = 0;
    var gross_salary  = 0;

    var basic_salary = $('.basic_salary').val();


     $('.allowance_'+key_element).each(function(){


        allowance_sum += isDefaulter(parseInt($(this).val()));  

      }); 


      $('.deduction_'+key_element).each(function(){


       deduction_sum +=  isDefaulter(parseInt($(this).val()));  

      });



      
      gross_salary += isDefaulter((isDefaulter(basic_salary) + isDefaulter(allowance_sum)) - isDefaulter((deduction_sum)));

     
     $('.deduction_sum').val(deduction_sum);
     $('.allowance_sum').val(allowance_sum);
     $('.gross_salary').val(gross_salary);

  }

     function getCurrentAllowance(event,obj)
    {
         event.preventDefault();
    
          value = $(obj).val();
          if(value < 0)
          {
            messageToaster('warning','Invalid Input Field','Invalid Allowance Amount');
           field_unsuccess($(obj),'Allowance amount is invalid');
        
        return false;
          }

          field_refersh($(obj));


    }

    function getCurrentDeduction(event,obj)
    {
         event.preventDefault();
    
          value = $(obj).val();
          if(value < 0)
          {
            messageToaster('warning','Invalid Input Field','Invalid Deduction Amount');
           field_unsuccess($(obj),'Deduction amount is invalid');
        
        return false;
          }

          field_refersh($(obj));


    }

   function selectAllPayroll(event,obj)
  {
    event.preventDefault();
    
    obj = $(obj);

     $('.checked_payroll').each(function(event)
     {
          check_box = $(this);

          var counter = 0;

          if(obj.prop('checked'))
          {

             $(this).prop('checked',true);

    

                  check_box.closest('tr').find('.payment_mode').removeAttr('disabled');
                  obj.closest('tr').find('.user_instrument').removeAttr('disabled');

      
             counter ++;


          }
          else
          {
             $(this).prop('checked',false);
        

             check_box.closest('tr').find('.payment_mode').attr('disabled',true);
           


          }
          if(counter > 0)
          {
               $('.cls_post').show();
          }
          else
          {
               $('.cls_post').hide();
          }
         
     });

     


  }

  function verifyCheckBoxList(obj)
  {
      obj = $(obj);

     $('.employee_salary_mode :selected').text();
          
      var counter = 0;

      if(obj.prop('checked'))
      {

         obj.prop('checked',true);
      
     
            obj.closest('tr').find('.payment_mode').removeAttr('disabled');
            obj.closest('tr').find('.user_instrument').removeAttr('disabled');

    
       
       
         counter ++;



      }
      else
      {
         obj.prop('checked',false);

      
                   obj.closest('tr').find('.payment_mode').attr('disabled',true);
                   obj.closest('tr').find('.user_instrument').attr('disabled',true);

         



      }
           if(counter > 0)
          {
               $('.cls_post').show();
          }
          else
          {
               $('.cls_post').hide();
          }
         
  }

  function showModeDiv(event,obj)
  {
   

    event.preventDefault();
    
    obj = $(obj);


      if(obj.prop('checked'))
      {

        $('.mode_tr').hide();
        $('.mode_td').hide();
        $('.instrument_tr').hide();
        $('.instrument_td').hide();


      }
      else
      {
         $('.mode_tr').show();
         $('.mode_td').show();
         $('.instrument_tr').show();
         $('.instrument_td').show();

      }
    


  }

</script>