我很难在特定日期范围内获得总销售额。我想显示销售报告过滤日期的总销售额数据。
This my retrieve sales report html
这是我的html代码
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Sales Report</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-
widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove">
<i class="fa fa-remove"></i></button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="box-body">
<!-- Date and time range -->
<div class="form-group">
<label>Date and time range:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-clock-o"></i>
</div>
<input type="text" class="form-control pull-right" id="reservationtime">
</div>
<!-- /.input group -->
</div>
</div>
</div>
</div>
<div class="box box-success">
<table id="example1" class="table table-bordered table-striped"
style="color: black;">
<thead>
<tr>
<th>Brand</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
<tfoot>
<tr>
<td colspan="3">Total</td>
<td id="payment"></td>
</tr>
</tfoot>
</table>
这是我的JavaScript代码
//=============== Start of Total Sales ========================
var rootRef = firebase.database().ref();
var rootreq = rootRef.child("sales");
rootreq.on('value',getReq);
function getReq(snap){
var t1 = 0;
snap.forEach(keyReq => {
var total = keyReq.val().total;
var t = parseInt(total);
t1 += t;
document.getElementById("payment").innerText = t1;
});
// // $("#tr_count").valueOf(t1);
// console.log(t1);
}
//======================== End of Total Sales ==============================
$(document).ready(function() {
var brandsRef = firebase.database().ref().child("sales");
brandsRef.on("child_added", snap=> {
// var pic = snap.child("pic").val(); //This is the image src
var brand = snap.child("product").val();
var price = snap.child("price").val();
var quantity =snap.child("quantity").val();
var total =snap.child("total").val();
var $row = $('<tr></tr>').appendTo('#tableBody');
//$('<td></td>').appendTo($row).append($('<img />').attr('src', pic));
$('<td></td>').appendTo($row).text(brand);
$('<td></td>').appendTo($row).text(price);
$('<td></td>').appendTo($row).text(quantity);
$('<td></td>').appendTo($row).text(total);
$('<td><a class="label label-primary"
href="view_product_orders.html">View</button></td>').appendTo($row);
})
});
这是我的Firebase数据
[ null, {
"date_delivered" : "09-19-18",
"date_ordered" : "09-18-18",
"price" : 54,
"product" : "Century Tuna",
"quantity" : 10,
"total" : 10050
}, {
"data_delivered" : "09-04-18",
"date_ordered" : "09-03-18",
"price" : 15,
"product" : "Bearbrand",
"quantity" : 30,
"total" : 500
}, {
"date_delivered" : "09-08-18",
"date_ordered" : "09-07-18",
"price" : 12,
"product" : "Noodles",
"quantity" : 30,
"total" : 309
}, {
"date_delivered" : "09-09-18",
"date_ordered" : "09-08-18",
"price" : 65,
"product" : "Milk Tea",
"quantity" : 58,
"total" : 5000
} ]
请为我的学校论文真的需要帮助。