var stockreportexpenseModule = (function () { 

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

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

        //console.log("customerStock"+$(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 ) {

            var salepdf = $('.sale-stockreport-pdf').attr("href");
            $('.sale-stockreport-pdf').attr("href",'');
            $('.sale-stockreport-pdf').attr("href",salepdf+'?startDate='+startDate+'&endDate='+endDate+'&eid='+cID);
            

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

            
           
            var dataTable =  $('#stockExpenseDashboard').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 : "./stockExpensegriddata.php",
                    type: 'POST',
                    data:  {
                        userpermissionPrint: 1,
                        customerID  : cID,
                        startDate   : startDate,
                        endDate     : endDate
                    }
                }
            });  
                  
        }
      
    });

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

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

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

            $('#stockExpenseDashboard').show();
            $('.sale-stockreport-pdf').show();

            var salepdf = $('.sale-stockreport-pdf').attr("href");
            $('.sale-stockreport-pdf').attr("href",'');
            $('.sale-stockreport-pdf').attr("href",salepdf+'?startDate='+startDate+'&endDate='+endDate+'&eid='+cID);

            
           
            var dataTable =  $('#stockExpenseDashboard').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 : "./stockExpensegriddata.php",
                    type: 'POST',
                    data:  {
                        userpermissionPrint: 1,
                        customerID  : cID,
                        startDate   : startDate,
                        endDate     : endDate
                    }
                }
            });  
                  
        }
      
    });


   



})();