$(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 modeTrans = $("#modeTrans").val();
      //var timeFrom = $("#timefrom").val();
      //var timeTo = $("#timeto").val();
      //var tktFrom = $("#tktfrom").val();
        var vehicle = $("#vehicle").val();
        $.ajax({
          type: "POST",
          url: "ajaxreport1/fetch_purchase_report.php",
          dataType:"json",
          data: { customer: customer, tod: tod, fromd: fromd, product: product,vehicle:vehicle,modetrans:modeTrans},
          success: function (data) {
            console.log(data);
            data.map((list)=>{
                reportValue.push(list);
           });
          let limitedReport= data.splice(0,1000);
         console.log(data);
        var tbodyValue ="";
        limitedReport.map((data,index)=>{
                tbodyValue +=`<tr><td>${index+1}</td><td>${data.ticket}</td><td>${data.tripno}</td><td>${data.purchasecode}</td><td>${data.date}</td><td>${data.vehicleno}</td><td>${data.customername}</td><td>${data.empty}</td><td>${data.load}</td><td>${data.net}</td><td>${data.productname}</td><td>${data.tonn}</td><td>${data.netqty}</td><td>${data.price}</td><td>${data.totalamount}</td><td>${data.mode}</td><td>${data.delivery}</td><td>${data.process}</td><td>${data.bata}</td><td>${data.operator}</td><td>${data.remark}</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();
    });
    $("#excel").click(function(){
        JSONToCSVConvertor(reportValue, "Purchase-Report", true);
       });
  });
  