var collectionModule = (function () { 


    $('.supplierName-select-box').on('change',function(){
//alert("hi");
        var cid = $(this).val();
        if(cid) {
			
            $.ajax({
				
                url: base_url+'fetchAjaxData/fetchpurpaymentPending.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/fetchpurchaseBillList.php?cid='+cid,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                                      
                    $("#pend_bill_list option").remove();
                    var selected = '<option value="">Select purchase Bill </option>';
                    $(data).each(function(index,value) {
                      selected =selected+"<option value='"+this.purchaseBillNo+"'>"+this.purchaseBillNo+"</option> ";
                    });
                    $("#pend_bill_list").append(selected);
                   
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });
        }

    });

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

        var purchaseid = $(this).val();
       // if(purchaseid>0) {
            $.ajax({
                url: base_url+'fetchAjaxData/fetchpaypurchaseBillAmt.php?purchaseid='+purchaseid,
                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();
        }

    });

})();