$(document).ready(function () {
    var reportValue=[];
    $("#calender").click(function () {
      $(".spindis").show();
      var fromd = $("#input_from").val();
      var tod = $("#input_to").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_quotation_report.php",
          dataType:"json",
          data: { tod: tod, fromd: fromd},
          success: function (data) {
            console.log(data);
			let sumofprice=0;
			let sumoftotal=0;
			let sumofmode=0;
            data.products.map((list)=>{
                reportValue.push(list);
				sumofprice+=Number(list.Total);
           });
			
			reportValue.push({Sno:"",InDate:"",InTime:"",ExitDate:"",ExitTime:"",VehNo:"",InvoiceNo:"",Cust:"",GSTNo:"",Prod:"",Qty:"",CusPrice:"",Grossprice:"",Gross:"",tax:"",CGST:"",SGST:"TOTAL",Total:sumofprice,Mode:"",Delivery:"",Remarks:"",Employee:""});
			reportValue.push({Sno:"S.No",InDate:"Mode",InTime:"Amount",ExitDate:"Load",ExitTime:"",VehNo:"",InvoiceNo:"",Cust:"",GSTNo:"",Prod:"",Qty:"",CusPrice:"",Grossprice:"",Gross:"",tax:"",CGST:"",SGST:"",Total:"",Mode:"",Delivery:"",Remarks:"",Employee:""});
			
			data.Cummulative.map((list)=>{
             reportValue.push(list);
			 sumoftotal+=Number(list.tamt);
			 sumofmode+=Number(list.modeno);
			      
           })
		  
		   reportValue.push({sno:"",modeof:"TOTAL",tamt:sumoftotal,modeno:sumofmode});
          
          let limitedReport= data.products.splice(0,1000);
         console.log(limitedReport);
        var tbodyValue ="";
        limitedReport.map((data,index)=>{
                tbodyValue +=`<tr><td>${index+1}</td><td>${data.Indate}</td><td>${data.Intime}</td><td>${data.Exitdate}</td><td>${data.Exittime}</td><td>${data.Vehno}</td><td>${data.InvoiceCode}</td><td>${data.Cust}</td><td>${data.GSTNo}</td><td>${data.Prod}</td><td>${data.Qty}</td><td>${data.CusPrice}</td><td>${data.Grossprice}</td><td>${data.Gross}</td><td>${data.tax}</td><td>${data.cgst}</td><td>${data.sgst}</td><td>${data.igst}</td><td>${data.Total}</td><td>${data.Mode}</td><td>${data.Delivery}</td><td>${data.Remarks}</td><td>${data.Employee}</td></tr>`;
            });
		
		
		
		tbodyValue +=`<tr><td colspan="10">Total</td><td>${sumofprice}</td></tr>`;
		 
		
			  console.log(tbodyValue);
		
            $("#tbodyReport").append(tbodyValue);
            $(".spindiv").hide();
             $("#input_from").val("");
            $("#input_to").val("");
          
          },
        });
        $("#modaldis").click();
        console.log(reportValue);
    });
    $("#excel").click(function(){
        JSONToCSVConvertor(reportValue, "Sales-Report", true);
       });
  });
  