You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
424 lines
13 KiB
424 lines
13 KiB
<!DOCTYPE html>
|
|
|
|
<html xmlns:th="http://www.thymeleaf.org">
|
|
|
|
<head th:replace="~{fragments/head-admin :: head}"></head>
|
|
|
|
<meta charset="ISO-8859-1">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<style>
|
|
.small-input {
|
|
width: 150px;
|
|
/* Adjust the width as needed */
|
|
}
|
|
|
|
.small-table th,
|
|
.small-table td {
|
|
font-size: 14px;
|
|
/* Adjust font size as needed */
|
|
}
|
|
|
|
/* Reduce padding for table cells */
|
|
.small-table td,
|
|
.small-table th {
|
|
padding: 5px;
|
|
/* Adjust padding as needed */
|
|
}
|
|
</style>
|
|
|
|
<body>
|
|
|
|
<!-- Page Container -->
|
|
<div id="page-container"
|
|
class="sidebar-o sidebar-dark enable-page-overlay side-scroll page-header-fixed page-header-dark">
|
|
<!-- Side Overlay aside (right)-->
|
|
<aside th:replace="~{fragments/aside-right :: aside}"></aside>
|
|
<!-- END Side Overlay (right)-->
|
|
<!-- Sidebar Nav-->
|
|
<nav th:replace="~{fragments/nav-admin :: nav}"></nav>
|
|
<!-- END Sidebar -->
|
|
<!-- Header -->
|
|
<header th:replace="~{fragments/header-admin :: header}"></header>
|
|
<!-- END Header -->
|
|
<!-- Main Container -->
|
|
<main id="main-container">
|
|
<div class="content">
|
|
<div class="block block-rounded">
|
|
<div class="block-header block-header-default">
|
|
<h3 class="block-title"> Discount Range</h3>
|
|
<div class="block-options">
|
|
<button type="button" class="btn-block-option" id="addButton" onclick="adddiscount()"><i
|
|
class="far fa-plus-square"></i> Add New Discount</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Page Content -->
|
|
<div class="content">
|
|
<div class="block block-rounded">
|
|
<div class="block-content p-0">
|
|
<div class="p-sm-4 p-0">
|
|
<div class="table-responsive">
|
|
<table id="discountrangetable"
|
|
class="table table-bordered table-striped table-vcenter js-dataTable-responsive">
|
|
<thead class="thead-light">
|
|
<tr class="table-bordered">
|
|
<th class="text-center no-sort">S.No</th>
|
|
<th class="text-center" width="20%">UserType</th>
|
|
<th class="text-center">DiscountRange</th>
|
|
<th class="text-center"> Cdate</th>
|
|
<th class="text-center">UpdatedBy</th>
|
|
<th class="text-center">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr th:each="discountRange, rowStat : ${discountRanges}">
|
|
|
|
<td class="text-center" th:text="${rowStat.index + 1}"></td>
|
|
<td class="text-center" th:text="${discountRange.usertype}">
|
|
</td>
|
|
<td class="text-center"
|
|
th:text="${discountRange.discountRange}"></td>
|
|
<td class="text-center" th:text="${discountRange.cDate}"></td>
|
|
<td class="text-center" th:text="${discountRange.updtedBy}">
|
|
</td>
|
|
<td class="text-center">
|
|
<a href="javascript:void(0);"
|
|
th:onclick="'openEditModal(' + ${discountRange.id} + ');'"
|
|
data-bs-toggle="tooltip" data-bs-animation="true"
|
|
data-bs-placement="top" title="Edit">
|
|
<i class="far fa-pen-to-square" style="font-size: 18px;"></i>
|
|
</a>
|
|
<a href="javascript:void(0);"
|
|
th:onclick="return callDelete( [[${discountRange.id}]] );"
|
|
data-bs-toggle="tooltip" data-bs-animation="true"
|
|
data-bs-placement="top" title="Delete"><i
|
|
class="far fa-trash-can"
|
|
style="font-size: 18px;"></i></a>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- new Discount -->
|
|
<div class="modal fade" id="saveModal" tabindex="-1" role="dialog"
|
|
aria-labelledby="saveModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="saveModalLabel">Save Discount Range</h5>
|
|
<button type="button" class="btn-block-option" data-bs-dismiss="modal">
|
|
<i class="fa fa-fw fa-times"></i>
|
|
</button>
|
|
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="saveForm">
|
|
<div class="form-group">
|
|
<label for="userType">User Type</label>
|
|
<select class="form-control" id="userType" name="userType" required>
|
|
<option value="">Select</option>
|
|
<option value="PUBLIC">PUBLIC</option>
|
|
<option value="PENSIONER">PENSIONER</option>
|
|
<option value="COUNCILLOR">COUNCILLOR</option>
|
|
<option value="GCC_EMPLOYEE">GCC EMPLOYEE</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="editDiscountRange">Discount Range in Percentage</label>
|
|
<input type="text" class="form-control" id="discountRange"
|
|
name="discountRange" placeholder="Discount Range in %" required>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary"
|
|
data-bs-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="savediscounts">Save</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Edit Form -->
|
|
|
|
<div class="modal fade" id="editModal" tabindex="-1" role="dialog"
|
|
aria-labelledby="editModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="editModalLabel">Edit Discount Range</h5>
|
|
<button type="button" class="btn-block-option" data-bs-dismiss="modal">
|
|
<i class="fa fa-fw fa-times"></i>
|
|
</button>
|
|
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="editForm">
|
|
<input type="hidden" id="editId">
|
|
<div class="form-group">
|
|
<label for="editUsertype">User Type</label>
|
|
<input type="text" class="form-control" id="editUsertype" readonly>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="editDiscountRange">Discount Range in Percentage</label>
|
|
<input type="text" class="form-control" id="editDiscountRange"
|
|
placeholder="Discount Range in %" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="editCDate">Creation Date</label>
|
|
<input type="date" class="form-control" id="editCDate" readonly>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="editUpdatedBy">Updated By</label>
|
|
<input type="text" class="form-control" id="editUpdatedBy" readonly>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary"
|
|
data-bs-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="saveChanges">Save
|
|
changes</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<div th:replace="~{fragments/resetpassword :: div}"></div>
|
|
<footer th:replace="~{fragments/footer2 :: footer}"></footer>
|
|
<script th:replace="~{fragments/loginscript :: script}"></script>
|
|
<script>
|
|
|
|
$(document).ready(
|
|
function () {
|
|
var buttons = [{
|
|
extend: 'pageLength',
|
|
className: 'btn btn-primary'
|
|
}, {
|
|
title: 'Data export',
|
|
extend: 'copyHtml5',
|
|
text: 'Copy',
|
|
className: 'btn btn-primary',
|
|
id: 'copyBtn'
|
|
}, {
|
|
extend: 'excelHtml5',
|
|
text: 'Excel',
|
|
className: 'btn btn-primary',
|
|
id: 'excelBtn'
|
|
}, {
|
|
extend: 'csvHtml5',
|
|
text: 'CSV',
|
|
className: 'btn btn-primary',
|
|
id: 'csvBtn'
|
|
}, {
|
|
extend: 'pdfHtml5',
|
|
text: 'PDF',
|
|
className: 'btn btn-primary',
|
|
id: 'pdfBtn'
|
|
},
|
|
|
|
];
|
|
$('#discountrangetable').DataTable(
|
|
{
|
|
dom: 'Bftip',
|
|
columnDefs: [{
|
|
targets: 'no-sort',
|
|
orderable: false
|
|
}],
|
|
lengthMenu: [
|
|
[50, 100, 200, 500, -1],
|
|
['50 rows', '100 rows', '200 rows',
|
|
'500 rows', 'Show all']],
|
|
scrollY: '50vh',
|
|
fixedColumns: {
|
|
left: 1,
|
|
right: 1
|
|
},
|
|
buttons: [buttons],
|
|
responsive: true,
|
|
searching: true, // Enable search
|
|
select: false,
|
|
processing: false,
|
|
});
|
|
|
|
// Link the search input to DataTable
|
|
$('#searchInput').on('keyup', function () {
|
|
dataTable.search(this.value).draw();
|
|
});
|
|
|
|
});
|
|
function openEditModal(id) {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/victoriahallbooking/admin/api/getDiscountDetails',
|
|
data: {
|
|
'id': id
|
|
},
|
|
success: function (response) {
|
|
$('#editId').val(response.id);
|
|
$('#editUsertype').val(response.usertype);
|
|
$('#editDiscountRange').val(response.discountRange);
|
|
$('#editCDate').val(response.cDate);
|
|
$('#editUpdatedBy').val(response.updtedBy);
|
|
$('#editModal').modal('show');
|
|
}
|
|
});
|
|
}
|
|
|
|
function adddiscount() {
|
|
$('#saveModal').modal('show');
|
|
}
|
|
$('#savediscounts').click(function () {
|
|
var userType = $('#userType').val();
|
|
var discountRange = $('#discountRange').val();
|
|
//console.log('User Type:', userType);
|
|
//console.log('Discount Range:', discountRange);
|
|
if(!userType){
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'No User Type Selected',
|
|
text: 'Please select an usertype to update.',
|
|
});
|
|
return;
|
|
}
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/victoriahallbooking/admin/api/savediscountrange",
|
|
data: {
|
|
userType: userType,
|
|
discountRange: discountRange,
|
|
},
|
|
success: function (data) {
|
|
if (data === 'waiting') {
|
|
Swal.fire(
|
|
'EXISTED!',
|
|
'User type already exists. Update or Delete the usertype',
|
|
'info'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
} else if (data === 'success') {
|
|
Swal.fire(
|
|
'Saved!',
|
|
'Details saved successfully.',
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
Swal.fire(
|
|
'Error!',
|
|
'Failed to update the discount range.',
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
$('#saveChanges').click(function () {
|
|
var id = $('#editId').val();
|
|
var discountRange = $('#editDiscountRange').val();
|
|
|
|
// Log the data to the console for debugging
|
|
|
|
$.ajax({
|
|
type: "PUT",
|
|
url: "/victoriahallbooking/admin/api/updateById/" + id,
|
|
data: {
|
|
'id': id,
|
|
'discountRange': discountRange,
|
|
},
|
|
success: function (data) {
|
|
Swal.fire(
|
|
'Updated!',
|
|
'Discount range ' + id + ' has been updated.',
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error('Error occurred during the PUT request:', xhr.responseText);
|
|
Swal.fire(
|
|
'Error!',
|
|
'Failed to update the discount range ' + id + ': ' + xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
function callDelete(id) {
|
|
Swal.fire({
|
|
title: 'Are you sure you want to delete this?',
|
|
text: "You won't be able to revert this!",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Yes, delete it!'
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "DELETE",
|
|
url: "/victoriahallbooking/admin/api/deleteById/" + id,
|
|
success: function (data) {
|
|
Swal.fire(
|
|
'Deleted!',
|
|
'Entry ' + id + ' has been deleted.',
|
|
'success'
|
|
).then(() => {
|
|
location.reload();
|
|
});
|
|
},
|
|
error: function (xhr, status, error) {
|
|
Swal.fire(
|
|
'Error!',
|
|
'Failed to delete entry ' + id + ': ' + xhr.responseText,
|
|
'error'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
function clearModalFields(modalId) {
|
|
const modal = document.getElementById(modalId);
|
|
if (modal) {
|
|
// Clear text inputs and select elements
|
|
modal.querySelectorAll('input[type="text"], input[type="date"], select').forEach(input => {
|
|
if (input.tagName === 'SELECT') {
|
|
input.selectedIndex = 0; // Reset to default option
|
|
} else {
|
|
input.value = ''; // Clear text inputs
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Clear fields when the saveModal is hidden
|
|
document.getElementById('saveModal').addEventListener('hidden.bs.modal', function () {
|
|
clearModalFields('saveModal');
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|