$(document).ready(function () {
    var reportValue=[];
    $("#calender").click(function () {
      $(".spindis").show();
      var fromd = $("#input_from").val();
      var tod = $("#input_to").val();
      var customer = $("#customer").val();
      var product = $("#product").val();
      //var timeFrom = $("#timefrom").val();
      //var timeTo = $("#timeto").val();
      //var tktFrom = $("#tktfrom").val();
        var vehicle = $("#vehicle").val();
        var modeTrans = $("#modeTrans").val();
        $.ajax({
          type: "POST",
          url: "ajaxreport1/fetch_sales_Return_report.php",
          dataType:"json",
          data: { customer: customer, tod: tod, fromd: fromd, product: product,vehicle:vehicle,modetrans:modeTrans},
          success: function (data) {
            console.log(data);
            data.products.map((list)=>{
                reportValue.push(list);
           });
           data.Cummulative.map((list)=>{
             reportValue.push(list);
           })
          let limitedReport= data.products.splice(0,1000);
         console.log(limitedReport);
        var tbodyValue ="";
        limitedReport.map((data,index)=>{
                tbodyValue +=`<tr><td>${index+1}</td><td>${data.invoicecode}</td><td>${data.invoicedate}</td><td>${data.tripno}</td><td>${data.customername}</td><td>${data.productname}</td><td>${data.capacity}</td><td>${data.netqty}</td><td>${data.price}</td><td>${data.totalamount}</td><td>${data.mode}</td><td>${data.delivery}</td><td>${data.remark}</td><td>${data.employee}</td></tr>`;
            });
            $("#tbodyReport").append(tbodyValue);
            $(".spindiv").hide();
             $("#input_from").val("");
            $("#input_to").val("");
           $("#customer").val(null).trigger("change");
            $("#product").val(null).trigger("change");
            $("#timefrom").val("");
           $("#timeto").val("");
           $("#tktfrom").val(null).trigger("change");
           $("#vehicle").val("");
          },
        });
        $("#modaldis").click();
        console.log(reportValue);
    });
    $("#excel").click(function(){
        JSONToCSVConvertor(reportValue, "Sales_Return-Report", true);
       });
  });
  