var accLabourModule = (function () {
    $('.accLabourSubmit').hide();

    $("input.add-accLabour").on('click',function(){
        if($('#accLabourDetailsAdd tbody tr').length>0){
            $('.accLabourSubmit').show();
        }         
    });

    

    $('.add-accLabour').on('click',function(){
        
        var labouremployeenameID,shifttypeID,extraworkinghrs,labouremployeenameText,shifttypeText,advancesalary;

            labouremployeenameID     =   $('#labouremployeename').val();
            labouremployeenameText    =   $('#labouremployeename option:selected').text();
            shifttypeID     =   $('#shifttype').val();
            shifttypeText    =   $('#shifttype option:selected').text();
            extraworkinghrs       =   ($('#extraworkinghrs').val()>0) ? $('#extraworkinghrs').val() : 0 ;
            //advancesalary       =   ($('#advancesalary').val()>0) ? $('#advancesalary').val() : 0 ;

            //console.log("details count :-    "+$('#accLabourDetailsAdd tbody tr').length);

            if(labouremployeenameID>0 && shifttypeID ) {

                var trlength    =   $('#accLabourDetailsAdd tbody tr:last').length;
                
            if(trlength == 0) {

                trlength = 1;

            } else {

                trlength = $('#accLabourDetailsAdd tbody tr:last').attr('id');
                
                trlength = parseInt(trlength)+parseInt(1);
            }

            $("#tripcount").val("1");
            var tripDetails =  '<td class="product_name">'+labouremployeenameText+'<input class="form-control labouremployeenameID" name="labouremployeenameID[]"  value="'+labouremployeenameID+'" type="hidden"></td>';
            
            tripDetails +='<td>'+shifttypeText+'<input class="form-control shifttypeID" name="shifttypeID[]" type="hidden" value="'+shifttypeID+'" ></td>';
            
            tripDetails +='<td>'+extraworkinghrs+'<input class="form-control extraworkinghrs" name="extraworkinghrs[]" type="hidden" value="'+extraworkinghrs+'" ></td>';

            //tripDetails +='<td>'+advancesalary+'<input class="form-control advancesalary" name="advancesalary[]" type="hidden" value="'+advancesalary+'" ></td>';

            tripDetails +='<td><input type="button" class="btn btn-default removeTripDetails" id="removeTripDetails" value="-"></td>';

            $("#accLabourDetailsAdd tbody").append("<tr id='"+trlength+"'></tr>");
            $("#accLabourDetailsAdd tbody tr:last").append(tripDetails);    
            
            $('#labouremployeename').val('0');
            //$('.product-select-box option[value="'+productID+'"],option:not([value])').remove();

            $('#labouremployeename option[value="'+labouremployeenameID+'"],option:not([value])').attr("disabled","disabled");
            $('.accLabourSubmit').show();

            } else {
                alert("Please enter Labour details values....!");    
            }
        
    });

 

    $('body').on('click', 'input.removeTripDetails', function(){

        //console.log("Remove Row:"+$(this).closest('tr').attr('id'));
        var removeTrip = $(this).closest('tr').attr('id');
        $("#"+removeTrip).remove();
        
        var labouremployeenameID = $(this).closest('td').prev().prev().prev().find('.labouremployeenameID').val();
        alert(labouremployeenameID);

        $('#labouremployeename option[value="'+labouremployeenameID+'"],option:not([value])').removeAttr("disabled");
        //$('.product-select-box option[value="'+productid+'"],option:not([value])').("disabled");
        if($('#accLabourDetailsAdd tbody tr').length == 0){            
            //removeAttr
            $('.accLabourSubmit').hide();
        }      
    });

    $('body').on('change','select.select-labour-employee',function(){ 

        //alert($(this).val());
        // var labourID    =   $(this).val();
        // if(quality_type1) {
        //     $.ajax({
        //         url: base_url+'fetchAjaxData/fetchlabourshiftextra_amt.php?labourID='+labourID,
        //         dataType: "json",
        //         type: 'GET',        
        //         success: function(data) {
        //             $("#aqty").val('');
        //             $("#aqty").val(data[0].Aoilqty); 
        //         },
        //         error: function() {
        //             console.log('An error has occurred');
        //         }                
        //     });
        // }


    });

})();