var stockreportCollectionModule = (function () { 

    $("#fromDate").on("select change blur",function(){
        $('.supplierStock').val("");
        
        console.log("Start Date :"+$(this).val());
    });
    $("#toDate").on("select change blur",function(){
        $('.supplierStock').val("");
         console.log("End Date :"+$(this).val());
     });

    $('.supplierStock').on('change',function(){

        //console.log("supplierStock"+$(this).val());
        
        var cID       = $(this).val();
        var startDate = $("#fromDate").val();
        var endDate   = $("#toDate").val();
        // console.log(startDate);
        // console.log(endDate);

        
        if(startDate!= '' && endDate!= '' && cID>0 ) {

            $('#stockCollectionDashboard').show();


            var purchasepdf = $('.purchase-stockreport-pdf').attr("href");
      
            $('.purchase-stockreport-pdf').attr("href",'');
            $('.purchase-stockreport-pdf').attr("href",purchasepdf+'?startDate='+startDate+'&endDate='+endDate+'&supplierID='+cID);

            
           
            var dataTable =  $('#stockCollectionDashboard').DataTable({
                responsive: {
                    details: {
                        renderer: function ( api, rowIdx ) {
                            var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                                var header = $( api.column( cell.column ).header() );
                                return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                            } ).toArray().join('');

                            return data ?    $('<table/>').append( data ) :    false;
                        }
                    }
                },
                processing: true,
                serverSide: true,
                destroy: true,
                ajax: {
                    url : "./stockpaymentgriddata.php",
                    type: 'POST',
                    data:  {
                        userpermissionPrint: 1,
                        supplierID  : cID,
                        startDate   : startDate,
                        endDate     : endDate
                    }
                }
            });  
                  
        }
      
    });

    $('.datewise-submit-collection').on('click',function(){

        //console.log("supplierStock"+$(this).val());
        
        var cID       = '';
        var startDate = $("#fromDate").val();
        var endDate   = $("#toDate").val();
        // console.log(startDate);
        // console.log(endDate);

        
        if(startDate!= '' && endDate!= '' ) {

            $('.supplierStock').val("");

            $('.purchase-stockreport-pdf').show();
        //console.log($('.purchase-stockreport-pdf').attr("href"));
        var purchasepdf = $('.purchase-stockreport-pdf').attr("href");

        $('.purchase-stockreport-pdf').attr("href",'');
        $('.purchase-stockreport-pdf').attr("href",purchasepdf+'?startDate='+startDate+'&endDate='+endDate+'&supplierID='+cID);

            
           
            var dataTable =  $('#stockCollectionDashboard').DataTable({
                responsive: {
                    details: {
                        renderer: function ( api, rowIdx ) {
                            var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                                var header = $( api.column( cell.column ).header() );
                                return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                            } ).toArray().join('');

                            return data ?    $('<table/>').append( data ) :    false;
                        }
                    }
                },
                processing: true,
                serverSide: true,
                destroy: true,
                ajax: {
                    url : "./stockpaymentgriddata.php",
                    type: 'POST',
                    data:  {
                        userpermissionPrint: 1,
                        supplierID  : cID,
                        startDate   : startDate,
                        endDate     : endDate
                    }
                }
            });  
                  
        }
      
    });



})();