JezK
Edit File: approvals.php
<?php include "sidemenu-start.php"; ?> <div class="container-fluid"> <div class="row"> <div class="col-md-6"> <h1>Approvals</h1> </div> </div> <div class="row mt-3"> <div class="col-md-12"> <table class="table" id="approvalTable"> <thead> <tr> <th>S.no</th> <th>Date</th> <th>Phone Number</th> <th>Status</th> <th>Amount</th> <th>Actions</th> </tr> </thead> <tbody> <!-- Table content goes here --> </tbody> </table> </div> </div> </div> <!-- View Modal --> <div class="modal fade" id="viewModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body" id="appendAllotmentDetails"> </div> </div> </div> </div> <!-- Approve Modal --> <!-- <div class="modal fade" id="approveModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <h1 class="modal-title text-center" id="exampleModalLabel">Do You want to Approve?</h1> </div> <div class="modal-footer"> <button type="button" class="de-btn-small approveYes" name="submit" onclick="approve(this.value)">Yes</button> <button type="button" class="close-btn" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div> --> <!-- Reject Modal --> <!-- <div class="modal fade" id="rejectModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <h1 class="modal-title text-center" id="exampleModalLabel">Do You want to Reject?</h1> </div> <div class="modal-footer"> <button type="button" class="de-btn-small rejectYes" name="submit" onclick="reject(this.value)">Yes</button> <button type="button" class="close-btn" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div> --> <?php include "sidemenu-end.php"; ?> <script> let datatable; $(document).ready(function() { notification(); datatable = $('#approvalTable').DataTable({ "processing": true, //Feature control the processing indicator. "serverSide": true, //Feature control DataTables' servermside processing mode. //"order": [], //Initial no order. "searching": true, "iDisplayLength": 10, "orderable": false, "ajax": { "url": 'app/getApproval.php', "type": "POST", "dataType": "json", "dataSrc": function(jsonData) { return jsonData.data; } }, "language": { searchPlaceholder: "Search", "search": '<div class="form user"><i class="fa fa-search"></i></div>', "paginate": { "previous": '<i class="angles fa fa-angle-left"></i>', "next": '<i class="angles fa fa-angle-right"></i>' } } }); }); function getapprove(Id) { $('.approveYes').val(Id) } function getreject(Id) { $('.rejectYes').val(Id) } function approve(id) { $.ajax({ type: 'POST', url: 'app/approvals.php', data: { approve: 'approve', allotmentId: id, }, success: function(data) { if (data == 1) { toastr.success('Approved'); datatable.draw(); } else { toastr.warning('Unable To Approve'); } $('#approveModal').modal('toggle') $('#viewModal').modal('toggle') } }) } function approveUserPurchase (id) { $.ajax({ type: 'POST', url: 'app/approvals.php', data: { userApprove: 'userApprove', allotmentId: id, }, success: function(data) { if (data == 1) { toastr.success('Approved'); datatable.draw(); } else { toastr.warning('Unable To Approve'); } $('#approveModal').modal('toggle') $('#viewModal').modal('toggle') } }) } function reasonValidate(id){ let reason = document.getElementById('reason').value; if(reason == ""){ $('.reason_error').html("Please Enter Reason."); }else{ reject(id) } } function reject(id) { event.preventDefault(); let reason = $('#reason').val(); $.ajax({ type: 'POST', url: 'app/approvals.php', data: { reject: 'reject', allotmentId: id, reason:reason }, success: function(data) { if (data == 1) { toastr.success('Rejected'); datatable.draw(); } else { toastr.warning('Unable To Reject'); } $('#rejectModal').modal('toggle') $('#viewModal').modal('toggle') } }) } function details(id) { $.ajax({ type: 'POST', url: 'app/approvals.php', data: { details: 'details', allotmentId: id }, success: function(data) { $('#appendAllotmentDetails').html(data) $("#reasonBox").hide(); $("#reject").click(function() { $("#reasonBox").show(); document.getElementById("approve").disabled = true; const myButton = document.getElementById("approve"); myButton.style.backgroundColor = "Gray"; }) $("#clsrbox").click(function(){ $("#reasonBox").hide(); document.getElementById("approve").disabled = false; const myButton = document.getElementById("approve"); myButton.style.backgroundColor = "#008069"; }) } }) } function notification() { $.ajax({ type: 'POST', url: 'app/approvals.php', data: { notificationss: 'notification', }, success: function(data) { } }) } function handleDelete(approvalId) { $.ajax({ url: 'app/deleteApproval.php', method: 'POST', // or 'GET', 'PUT', etc. depending on your needs data: { approvalId: approvalId }, success: function(response) { if (response == 1) { toastr.success('Deleted Successfully..!'); datatable.draw(); } else { toastr.warning('Unable To Delete'); } }, error: function(xhr, status, error) { // Handle error } }); } </script>