Dựa trên mã nguồn được cung cấp, tôi sẽ giúp bạn tạo một trang hiển thị thông tin hóa đơn tương tự như trang Report/Rent nhưng dành cho hóa đơn. Đây là giải pháp đề xuất:
jsx Copy code
// pages/Admin/Report/Invoice/index.js
import React from "react";
function Invoice() {
return (
<div className="col-md-12 col-sm-12 col-xs-12">
<div className="x_panel">
<div className="x_title">
<h2 style={{ display: 'inline-block' }}>
<strong>Danh sách hóa đơn</strong>
</h2>
<div className="clearfix"></div>
</div>
<div className="x_content">
<form data-parsley-validate className="form-horizontal form-label-left">
{/* Form Filters */}
<div className="form-group">
<label className="col-fhd-1 col-xlg-1 col-md-1 col-sm-12 col-xs-1">Trạng thái</label>
<div className="col-fhd-2 col-xlg-2 col-md-2 col-sm-12 col-xs-2">
<select style={{ width: '100%' }} id="statusInvoice" className="form-control">
<option value="-1">Tất cả</option>
<option value="0">Chưa thanh toán</option>
<option value="1">Đã thanh toán</option>
</select>
</div>
<div className="col-fhd-3 col-xlg-3 col-md-3 col-sm-12 col-xs-1" style={{ float: 'right' }}>
<button className="btn btn-warning" type="button" id="watchButton">
<i className="fa fa-search"></i> Xem
</button>
<div id="exportExcel" style={{ display: 'inline-block' }}></div>
</div>
</div>
{/* Table */}
<div className="form-group">
<table
id="invoiceTable"
className="table table-striped table-bordered dt-responsive nowrap"
cellSpacing="0"
width="100%"
>
<thead>
<tr>
<th>ID</th>
<th>Tổng tiền (VNĐ)</th>
<th>Ngày tạo</th>
<th>Phòng</th>
<th>Trạng thái</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</form>
</div>
</div>
</div>
);
}
export default Invoice;
javascript Copy code
// pages/Admin/Report/Invoice/invoiceReport.js
var table;
$(function () {
//#region load table
var loadTable = function (status) {
table = $('#invoiceTable').DataTable({
"processing": true,
"serverSide": true,
"paging": true,
"ordering": true,
"info": true,
"responsive": true,
"searching": true,
"autoWidth": false,
"language": {
"url": languageDatatable
},
"ajax": {
"url": "/invoices", // API endpoint từ InvoicesController
"type": "GET",
"data": function(d) {
d.status = status;
}
},
"columns": [
{ "data": "id", "name": "id" },
{
"data": "total",
"name": "[Redacted Person]",
"class": "dt-body-right",
"render": $.fn.dataTable.render.number(',', '.', 0, '')
},
{
"data": "createdAt",
"name": "createdAt",
"render": function(data) {
return moment(data).format("DD/MM/YYYY");
}
},
{ "data": "room.name", "name": "room" },
{
"data": "status",
"name": "status",
"render": function(data) {
return data === 0 ? "Chưa thanh toán" : "Đã thanh toán";
}
}
],
"drawCallback": function() {
var api = this.api();
if (api.rows().data().length > 0) {
var sumTotal = api.column(1).data().sum();
$("<tr><td colspan='1' class='dt-body-center'><strong>Tổng cộng</strong></td>" +
"<td class='dt-body-right'><strong>" + $.number(sumTotal) + "</strong></td>" +
"<td colspan='3'></td></tr>")
.insertAfter($(this[0]).find("tr:last"));
}
}
});
}
//#endregion
//#region event handlers
$("#statusInvoice").select2();
$("#watchButton").click(function() {
if ($.fn.DataTable.isDataTable('#invoiceTable'))
table.destroy();
loadTable($("#statusInvoice").val());
});
//#endregion
});