var inexplosiveProModule = (function () {
    
    $('.add-inexplosivePro').on('click',function(){
        
        //var supplierdetails  =   $("#supplierdetails").val();

        var explosiveID,explosiveText,eqty;

        //if(supplierdetails) {
            explosiveID     =   $('#explosivedetails').val();
            explosiveText   =   $('.explosive-select-box option:selected').text();            
            eqty        =   $('.eqty-input').val();
            
            if(explosiveID && explosiveText && eqty) {

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

                trlength = 1;

            } else {

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

            var tripDetails =  '<td class="product_name">'+explosiveText+'<input class="form-control" name="explosiveID[]"  value="'+explosiveID+'" type="hidden"></td>';
            
            tripDetails +='<td>'+eqty+'<input class="form-control" name="explosiveqty[]" type="hidden" value="'+eqty+'" ></td>';

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

            $("#inexplosiveProDetailsAdd tbody").append("<tr id='"+trlength+"'></tr>");
            $("#inexplosiveProDetailsAdd tbody tr:last").append(tripDetails);   
            
            $('.eqty-input').val('');

            } else {
                console.log("Please enter explosive details....!");    
                $('.eqty-input').val('');
            }
        // }
        // else {
        //     //alert("Please Select supplier Details & Remove the explosive details values....!");
        //     console.log("Please select supplier Name & Remove the explosive details values....!");    
        //     $('.eqty-input').val('');
        // }    
    });

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

        console.log("Remove Row:"+$(this).closest('tr').attr('id'));
        var removeTrip = $(this).closest('tr').attr('id');
        $("#"+removeTrip).remove();

    
    });

    $('body').on('change','select.explosive-select-box',function(){
        console.log($(this).val());
        var explosiveid    =   $(this).val();
		//alert(explosiveid);
		
        if(explosiveid) {
            $.ajax({
                 url: base_url+'fetchAjaxData/fetchSelectexplosiveQty.php?explosiveid='+explosiveid,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                    $("#aqty").val('');
                    $("#aqty").val(data[0].explosiveqty);                   
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });
        }
    });





    
    

})();