var collectionModule = (function () { 


    $('.customerName-select-box').on('change',function(){

        var cid = $(this).val();
        if(cid) {
            $.ajax({
                url: base_url+'fetchAjaxData/fetchCollectionPending.php?cid='+cid,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                   $("#pamount").val(data[0].pamount.toFixed(2));
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });
            $.ajax({
                url: base_url+'fetchAjaxData/fetchSaleBillList.php?cid='+cid,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                                      
                    $("#pend_bill_list option").remove();
                    var selected = '<option>Select sale Bill </option>';
                    $(data).each(function(index,value) {
                      selected =selected+"<option value='"+this.saleBillNo+"'>"+this.saleBillNo+"</option> ";
                    });
                    $("#pend_bill_list").append(selected);
                   
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });
        }

    });

    $('#pend_bill_list').on("click",function(){

        var saleid = $(this).val();
        //if(saleid>0) {
            $.ajax({
                url: base_url+'fetchAjaxData/fetchCollectionpendBillAmt.php?saleid='+saleid,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                    console.log(data[0].pbillamount);
                   $("#pbillamount").val(data[0].pbillamount.toFixed(2));
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });


      //  }

    });

    //paymentreference
    $('.collect-paymenttype').on('change',function(){

        console.log('paymenttype :'+$(this).val());
        var paymentType = $(this).val();
        if(paymentType == 'cash') {
            $('.paymentreference').hide();
        } else {
            $('.paymentreference').show();
        }

    });

})();