Skip to content

Commit c4f1998

Browse files
authored
Merge pull request #112 from SRATRC/dev
gave akshay option to revoke late checkout fees
2 parents 3f9f6ba + 6321690 commit c4f1998

2 files changed

Lines changed: 130 additions & 104 deletions

File tree

admin/room/lateCheckOutFeeReport.html

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,6 @@
2323
</script>
2424

2525
<link rel="stylesheet" href="../../style/css/styles.css" />
26-
<style>
27-
.modal {
28-
display: none;
29-
position: fixed;
30-
z-index: 9999;
31-
padding-top: 100px;
32-
left: 0;
33-
top: 0;
34-
width: 100%;
35-
height: 100%;
36-
overflow: auto;
37-
background-color: rgba(0,0,0,0.4);
38-
}
39-
40-
.modal-content {
41-
background-color: #fff;
42-
margin: auto;
43-
padding: 20px;
44-
border: 1px solid #888;
45-
width: 50%;
46-
border-radius: 5px;
47-
}
48-
49-
.modal-header {
50-
font-weight: bold;
51-
margin-bottom: 10px;
52-
}
53-
54-
.modal-actions {
55-
text-align: right;
56-
margin-top: 15px;
57-
}
58-
59-
.modal-actions button {
60-
margin-left: 10px;
61-
}
62-
</style>
6326
</head>
6427
<body>
6528
<div class="header">
@@ -82,42 +45,44 @@ <h1>Late Checkout Fees Report</h1>
8245

8346
<div class="form">
8447
<div id="alert" class="alert" style="display:none;"></div>
85-
<form id="reportForm">
86-
<div class="form-group">
87-
<label for="payment_type">Payment Type:</label>
88-
<select id="payment_type" name="payment_type" class="form-control" required>
89-
<option value="payment_pending" data-type="room">Late Checkout Fee Payment Pending</option>
90-
<option value="payment_done" data-type="flat">Late Checkout Fee Payment Done</option>
91-
</select>
92-
</div>
48+
49+
<!-- Remove the form tag or move it to only wrap the select -->
50+
<div class="form-group">
51+
<label for="payment_type">Payment Type:</label>
52+
<select id="payment_type" name="payment_type" class="form-control" required>
53+
<option value="payment_pending">Payment Pending</option>
54+
<option value="payment_done">Payment Done</option>
55+
<option value="fees_revoked">Fees Revoked</option>
56+
</select>
57+
</div>
9358

94-
95-
<div class="table-responsive">
96-
<input type="text" id="tableSearch" class="form-control search-box" placeholder="Search...">
97-
<table id="reportTable" class="table table-striped table-bordered">
98-
<thead>
99-
<tr>
100-
<th></th>
101-
<th>Late Checkout Fees</th>
102-
<th>Booking Id</th>
103-
<th>Guest Name</th>
104-
<th>Mobile No.</th>
105-
<th>Room No</th>
106-
<th>Room Type</th>
107-
<th>Check-in</th>
108-
<th>Check-out</th>
109-
<th>Nights</th>
110-
</tr>
111-
</thead>
112-
<tbody id="reportTableBody">
113-
<!-- JS will populate -->
114-
</tbody>
115-
</table>
59+
<div class="table-responsive">
60+
<input type="text" id="tableSearch" class="form-control search-box" placeholder="Search...">
61+
<table id="reportTable" class="table table-striped table-bordered">
62+
<thead>
63+
<tr>
64+
<th>#</th>
65+
<th>Late Checkout Fees</th>
66+
<th>Action</th>
67+
<th>Booking Id</th>
68+
<th>Guest Name</th>
69+
<th>Mobile No.</th>
70+
<th>Room No</th>
71+
<th>Room Type</th>
72+
<th>Check-in</th>
73+
<th>Check-out</th>
74+
<th>Nights</th>
75+
</tr>
76+
</thead>
77+
<tbody id="reportTableBody">
78+
<!-- JS will populate -->
79+
</tbody>
80+
</table>
81+
</div>
11682
</div>
11783
</div>
11884
</div>
11985
</div>
12086
</div>
121-
122-
</body>
123-
</html>
87+
</body>
88+
</html>

admin/room/lateCheckOutFeeReport.js

Lines changed: 95 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,119 @@ document.addEventListener("DOMContentLoaded", () => {
55

66
async function loadReport() {
77
const payment_type = paymentTypeSelect.value;
8+
9+
console.log(`Loading report for payment_type: ${payment_type}`);
810

9-
const res = await fetch(
10-
`${CONFIG.basePath}/stay/late-checkout-fees?payment_type=${payment_type}`,
11-
{
12-
method: 'GET',
13-
headers: {
14-
'Content-Type': 'application/json',
15-
Authorization: `Bearer ${sessionStorage.getItem('token')}`
11+
try {
12+
const res = await fetch(
13+
`${CONFIG.basePath}/stay/late-checkout-fees?payment_type=${payment_type}`,
14+
{
15+
headers: {
16+
Authorization: `Bearer ${sessionStorage.getItem("token")}`
17+
}
1618
}
17-
}
18-
);
19+
);
1920

20-
const json = await res.json();
21-
if (!json.success) return;
21+
const json = await res.json();
22+
23+
console.log('Response:', json);
24+
25+
if (!json.success) {
26+
console.error('Failed to load report:', json.message);
27+
alert(json.message || 'Failed to load report');
28+
return;
29+
}
2230

23-
renderTable(json.data);
31+
console.log(`Loaded ${json.data.length} records`);
32+
renderTable(json.data, payment_type);
33+
} catch (error) {
34+
console.error('Error loading report:', error);
35+
alert('Error loading report. Please check console.');
36+
}
2437
}
2538

26-
function renderTable(rows) {
39+
function renderTable(rows, payment_type) {
2740
tableBody.innerHTML = "";
2841

42+
if (rows.length === 0) {
43+
tableBody.innerHTML = '<tr><td colspan="11" class="text-center">No records found</td></tr>';
44+
return;
45+
}
46+
47+
console.log(`Rendering ${rows.length} rows for payment_type: ${payment_type}`);
48+
2949
rows.forEach((row, index) => {
30-
const tr = document.createElement("tr");
50+
let actionBtn = "—";
3151

52+
// Use row.id (this is the primary key from the database)
53+
if (payment_type === "payment_pending") {
54+
actionBtn = `<button type="button" class="btn btn-danger btn-sm" onclick="toggleRevoke(${row.id},'admin cancelled')">Revoke</button>`;
55+
}
56+
57+
if (payment_type === "fees_revoked") {
58+
actionBtn = `<button type="button" class="btn btn-success btn-sm" onclick="toggleRevoke(${row.id},'cash pending')">Restore</button>`;
59+
}
60+
61+
const tr = document.createElement("tr");
3262
tr.innerHTML = `
3363
<td>${index + 1}</td>
34-
<td>₹${row.amount}</td>
35-
<td>${row.bookingid}</td>
36-
<td>${row.guest_name}</td>
37-
<td>${row.mobile}</td>
38-
<td>${row.roomno}</td>
39-
<td>${row.roomtype}</td>
40-
<td>${formatDate(row.checkin)}</td>
41-
<td>${formatDate(row.checkout)}</td>
42-
<td>${row.nights}</td>
64+
<td>₹${row.amount || 0}</td>
65+
<td>${actionBtn}</td>
66+
<td>${row.bookingid || '-'}</td>
67+
<td>${row.guest_name || '-'}</td>
68+
<td>${row.mobile || '-'}</td>
69+
<td>${row.roomno || '-'}</td>
70+
<td>${row.roomtype || '-'}</td>
71+
<td>${row.checkin ? formatDate(row.checkin) : '-'}</td>
72+
<td>${row.checkout ? formatDate(row.checkout) : '-'}</td>
73+
<td>${row.nights || '-'}</td>
4374
`;
44-
4575
tableBody.appendChild(tr);
4676
});
4777

48-
// Reapply table enhance (sort, search, filters)
4978
enhanceTable("reportTable", "tableSearch");
5079
}
5180

52-
// Auto load on page load
53-
loadReport();
81+
window.toggleRevoke = async (transactionId, status) => {
82+
console.log(`toggleRevoke called with: transactionId=${transactionId}, status=${status}`);
83+
84+
if (!confirm(`Are you sure you want to change the status to "${status}"?`)) {
85+
return;
86+
}
5487

55-
// Change when payment type dropdown changes
56-
paymentTypeSelect.addEventListener("change", loadReport);
88+
try {
89+
const res = await fetch(
90+
`${CONFIG.basePath}/stay/late-checkout-fees/revoke`,
91+
{
92+
method: "PUT",
93+
headers: {
94+
"Content-Type": "application/json",
95+
Authorization: `Bearer ${sessionStorage.getItem("token")}`
96+
},
97+
body: JSON.stringify({ transactionId, status })
98+
}
99+
);
57100

58-
// Re-search
59-
searchInput.addEventListener("input", () => {
60-
enhanceTable("reportTable", "tableSearch");
61-
});
62-
});
101+
const json = await res.json();
102+
103+
console.log('Update response:', json);
104+
105+
if (json.success) {
106+
alert('Transaction updated successfully');
107+
loadReport(); // Reload the table
108+
} else {
109+
alert(json.message || "Failed to update transaction");
110+
}
111+
} catch (error) {
112+
console.error('Error updating transaction:', error);
113+
alert("An error occurred. Please check console for details.");
114+
}
115+
};
116+
117+
// Initial load
118+
loadReport();
119+
120+
// Event listeners
121+
paymentTypeSelect.addEventListener("change", loadReport);
122+
searchInput.addEventListener("input", () => enhanceTable("reportTable", "tableSearch"));
123+
});

0 commit comments

Comments
 (0)