JezK
Edit File: services-paymentdetails.php
<?php include "sidemenu-start.php"; include dirname(__DIR__) . '/admin/app/adminObject.php'; ?> <?php $serviceId = base64_decode($_GET['service_id']); ?> <div class="container-fluid"> <h1>Payment Details</h1> <div class="row mt-5"> <div class="col-md-4 mx-3"> <form id="getUserDetails"> <div class="mb-3 position-relative"> <label for="userMobile" class="form-label">User Mobile</label> <input type="number" class="form-control" id="userMobile" name="userMobile"> <button class="no-btn serv-icon" type="submit" onclick="return validatePaymentsUserId()"> <img src="./images/arrow.png"></button> </div> <p class="error userMobile_error"></p> </form> <div class="mb-3"> <label for="name" class="form-label">User Id</label> <input type="text" class="form-control" id="detailingId" readonly> </div> <div class="mb-3"> <label for="name" class="form-label">Name</label> <input type="text" class="form-control" id="name" readonly> </div> <div class="mb-3"> <label for="email" class="form-label">Email</label> <input type="email" class="form-control" id="email" readonly> </div> <div class="mb-3"> <label for="address" class="form-label">Address</label> <textarea class="form-control" id="address" rows="3" readonly></textarea> </div> <div class="mb-3"> <input type="hidden" class="form-control" id="checkUserId" name="checkUserId"> </div> </div> <div class="col-md-4 mx-3"> <div class="payments-card"> <div id="itemNamesAndCost"> </div> <div class="hr-line"> <div class="p-row"> <h5>Total</h5> <h5><span id="totalCost"></span> Rs</h5> </div> <form id="couponForm"> <div class="p-row position-relative"> <div class="d-flex flex-column "> <input type="text" id="coupon" placeholder="Enter Coupon" class="coupon afterPayment" name="coupon"> <p class="afterPaymentCoupon d-none">Offer Amount</p> <p class="error coupon_error" style="font-size:13px"></p> </div> <span class="rednote"></span> <button type="submit" class="no-btn coupon-icon afterPayment" onclick="return validatePaymentCoupon()"> <img src="./images/arrow.png"></button> <h5 class="">- <span id="offAmount">0</span> Rs</h5> </div> <input type="button" value="Remove Coupon" id="rcoupon" class="de-btn-small d-block m-auto"> </form> <input type="hidden" id="couponId" value=0> </div> <div class="p-row hr-line"> <h5>Tax Rate</h5> <h5>18% </h5> </div> <div class="p-row "> <h5>Tax</h5> <h5>Rs <span id="tax"></span></h5> </div> <div class="p-row "> <h5>Grand Total</h5> <h5>Rs <span id="grandTotal"></span></h5> </div> <form id="servicePaymentForm"> <button type="submit" class="de-btn-small d-block m-auto" id="approveButton" onclick="return validatePaymentsUserId()">SUBMIT</button> <p class="text-center error payment_error"></p> </form> <p class="d-none" id="approval" style="color:red;"></p> <button type="submit" class="de-btn-small d-block m-auto d-none yes" id="paymentButton" onclick="return subAdminPayment(this.value)">PAYMENT</button> <p class="text-center error payment_error"></p> <button type="button" class="de-btns de-grey-btn d-block m-auto d-none" id="disablePayment">PAYMENT</button> <button type="button" class="no-btn d-block m-auto d-none" id="invoice"><a href="" id="downloadInvoice">Invoice </a> <img src="./images/download.png" /> </button> </div> </div> <!-- <div id="overlay"> <lottie-player src="<?php echo $baseUrl; ?>css/loader.json" background="transparent" speed="1" class="loaderLottie" loop="true" autoplay="true"></lottie-player> </div> --> </div> <h3 style="font-weight:600;margin-left:1rem;">Services</h3> <!-- Seleted Services are Showing --> <div class="row products-list"> <div class="row" id="appendData"> </div> </div> <h3 style="font-weight:600;margin-left:1rem;">Products</h3> <!-- Seleted Products are Showing --> <div class="row products-list"> <div class="row" id="appendSelectedProducts"> <div class="col-lg-2 col-4 d-flex align-items-center"> <div class="card card-plus"> <div class="card-body"> <button data-bs-toggle="modal" data-bs-target="#addproduct" class="no-btn plus">+</button> </div> </div> </div> </div> </div> <!-- Services Modal --> <div class="modal fade" id="addserivices" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-xl modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <h5 class="modal-title" id="exampleModalLabel">Add Services</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="row" id="appendDataServices"> </div> </div> </div> </div> </div> <!-- Products Modal --> <div class="modal fade" id="addproduct" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-xl modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <h5 class="modal-title" id="exampleModalLabel">Add Product</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="row" id="appendProducts"> </div> </div> </form> </div> </div> </div> <?php include "./sidemenu-end.php"; ?> <script> let baseUrl = "<?Php echo $baseUrl ?>"; let serviceId = "<?php echo $serviceId ?>"; let selectedServices = []; let servicesNames = []; let servicesCosts = []; selectedServices.push(serviceId) let selectedProductsIds = []; let selectedProductsNames = []; let selectedProductQuantity = []; function makePageTransparent() { var overlay = document.getElementById('overlay'); overlay.style.display = 'flex'; // Display the overlay overlay.style.justifyContent = 'center'; overlay.style.alignItems = 'center'; var loader = overlay.querySelector('.loaderLottie'); loader.style.width = "30vw"; loader.style.borderRadius = '12px'; loader.style.backgroundColor = 'white'; // Replace 'red' with the desired background color var nameElement = document.createElement('p'); nameElement.style.position = 'absolute'; nameElement.style.color = 'black'; nameElement.style.fontSize = '18px'; nameElement.style.fontWeight = 'bold'; nameElement.style.marginTop = '20px'; nameElement.style.paddingTop = '65px'; nameElement.innerText = 'Waiting For Admin Approval'; // Append the name element to the overlay overlay.appendChild(nameElement); // Disable click events on the overlay overlay.onclick = function() { return false; }; // Disable click events on the entire document document.onclick = function() { return false; }; } $(document).ready(function() { $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { getService: serviceId, itemType: 1 }, success: function(response) { let data = JSON.parse(response) let selectedItem = data.selectedItem let services = data.services let products = data.products let amount = data.selectedServiceDetails.amount let name = data.selectedServiceDetails.name let grandTotal = parseInt(amount) + ((amount * 18) / 100) grandTotal = grandTotal.toFixed(2) $('#appendData').html(selectedItem); $('#appendDataServices').html(services); // Services Modal $('#appendProducts').html(products) // Products Modal $('#itemNamesAndCost').html('<div class="p-row"><h5>' + name + '</h5>' + '<h5 class="service-cost">' + amount + 'Rs' + '</h5><div>') $('#totalCost').html(amount); $('#tax').html((amount * 18) / 100); $('#grandTotal').html(grandTotal); servicesNames.push(name); servicesCosts.push(amount) } }) }) $('#getUserDetails').submit(function(event) { event.preventDefault(); let userMobile = $('#userMobile').val(); $.ajax({ type: 'POST', url: baseUrl + 'admin/app/editUser.php', data: { userMobile: userMobile }, success: function(data) { userDetails = JSON.parse(data); if (userDetails.status == 0) { toastr.warning('Invalid User') } else { $('#name').val(userDetails.user_name) $('#detailingId').val(userDetails.user_id) $('#email').val(userDetails.email) $('#address').val(userDetails.address) $('#checkUserId').val(userDetails.id) } } }) }); // In Modal when click on Selecte or selected updating selectedServices Array function updateSelectedServices(Id, type) { serviceId = Id.match(/\d+/)[0]; // Selected Items if (type == 1) { selectedServices.push(serviceId) } else if (type == 2) { // DeSelected index = selectedServices.indexOf(serviceId); if (index > -1) { selectedServices.splice(index, 1); } } updateModalServices(selectedServices) } // For Updating Modal when click on select and Unselect function updateModalServices(selectedServices) { let selectedServicesIds = JSON.stringify(selectedServices); let selectedProducts = JSON.stringify(selectedProductsIds); let productQuantites = JSON.stringify(selectedProductQuantity); $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { selectedServicesIds: selectedServicesIds, selectedProductsIds: selectedProducts, productQuantity: productQuantites }, success: function(response) { let data = JSON.parse(response) let appendNameAndCost = ''; let totalCost = data.totalCost let offerAmount; $('#appendDataServices').html(data.modal) $('#appendData').html(data.selectedItem); $('#totalCost').html(totalCost); // Checking Offer Amount Before Appending Grand Total offerAmount = $('#offAmount').html() if (parseInt(offerAmount) > 0) { totalCost = totalCost - offerAmount grandTotal = totalCost + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((totalCost * 18) / 100); $('#grandTotal').html(grandTotal); } else { grandTotal = totalCost + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((totalCost * 18) / 100); $('#grandTotal').html(grandTotal); } $('#itemNamesAndCost').html(''); // Showing Service Names And Costs If Any Service Selected if (selectedServices.length > 0) { let row; servicesNames = data.servicesNames; // Assgning Services Names As Array servicesCosts = data.servicesCosts; // Assgning Services Costs As Array for (let i = 0; i < servicesNames.length; i++) { row = '<div class="p-row"><h5>' + servicesNames[i] + '</h5>' + '<h5>' + servicesCosts[i] + 'Rs' + '</h5></div>'; appendNameAndCost = appendNameAndCost + row; } } // Showing Products Names And Costs If Any Service Selected if (selectedProductsIds.length > 0) { let row; productsNames = data.productsNames; // Assgning Products Names As Array productsCosts = data.productsCosts; // Assgning Products Costs As Array productsCount = data.productsCount // Assgning Products Counr As Array for (let i = 0; i < productsNames.length; i++) { row = '<div class="p-row"><h5>' + productsNames[i] + '(' + parseInt(productsCount[i]) + ')' + '</h5>' + '<h5>' + productsCosts[i] + ' Rs' + '</h5></div>'; appendNameAndCost = appendNameAndCost + row; } } $('#itemNamesAndCost').append(appendNameAndCost); } }) } // When Pressing X button in Selected Services Removing Service Id function removeService(serviceId) { let index = selectedServices.indexOf(serviceId.toString()); if (index > -1) { selectedServices.splice(index, 1); } updateModalServices(selectedServices) } // In Modal when click on Selecte or selected updating selected Products Array function updateSelectedProducts(Id, type) { productId = Id.match(/\d+/)[0]; // Selected Items if (type == 1) { selectedProductsIds.push(productId) // Updating ProductId in Products Array // Adding Quantity for selected productId in the index of productId of selectedProductQuantity; let IndexOfproductId = selectedProductsIds.indexOf(productId) selectedProductQuantity[IndexOfproductId] = 1; } else if (type == 2) { // DeSelected index = selectedProductsIds.indexOf(productId); if (index > -1) { selectedProductsIds.splice(index, 1); selectedProductQuantity.splice(index, 1); } } updateModalProduct(selectedProductsIds) } // For Updating Modal when click on select function updateModalProduct(selectedProductsIds) { let selectedServicesIds = JSON.stringify(selectedServices); let selectedProducts = JSON.stringify(selectedProductsIds); let productQuantites = JSON.stringify(selectedProductQuantity); $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { ServicesIds: selectedServicesIds, ProductsIds: selectedProducts, productQuantity: productQuantites }, success: function(response) { let data = JSON.parse(response); let appendNameAndCost = '' let totalCost = data.totalCost $('#appendProducts').html(data.modal) $('#appendSelectedProducts').html(data.selectedItem) $('#totalCost').html(totalCost); // Checking Offer Amount Before Appending Grand Total offerAmount = $('#offAmount').html() if (parseInt(offerAmount) > 0) { totalCost = totalCost - offerAmount grandTotal = totalCost + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((totalCost * 18) / 100); $('#grandTotal').html(grandTotal); } else { grandTotal = totalCost + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((totalCost * 18) / 100); $('#grandTotal').html(grandTotal); } $('#itemNamesAndCost').html(''); // Showing Service Names And Costs If Any Service Selected if (selectedServices.length > 0) { let row; servicesNames = data.servicesNames; // Assgning Services Names As Array servicesCosts = data.servicesCosts; // Assgning Services Costs As Array for (let i = 0; i < servicesNames.length; i++) { row = '<div class="p-row"><h5>' + servicesNames[i] + '</h5>' + '<h5>' + servicesCosts[i] + 'Rs' + '</h5></div>'; appendNameAndCost = appendNameAndCost + row; } } // Showing Products Names And Costs If Any Service Selected if (selectedProductsIds.length > 0) { let row; productsNames = data.productsNames; // Assgning Products Names As Array productsCosts = data.productsCosts; // Assgning Products Costs As Array productsCount = data.productsCount // Assgning Products Counr As Array for (let i = 0; i < productsNames.length; i++) { row = '<div class="p-row"><h5>' + productsNames[i] + '(' + parseInt(productsCount[i]) + ')' + '</h5>' + '<h5>' + productsCosts[i] + ' Rs' + '</h5></div>'; appendNameAndCost = appendNameAndCost + row; } } $('#itemNamesAndCost').append(appendNameAndCost); } }) } // When Pressing X button in Selected Services function removeProduct(productId) { let index = selectedProductsIds.indexOf(productId.toString()); if (index > -1) { selectedProductsIds.splice(index, 1); selectedProductQuantity.splice(index, 1); } updateModalProduct(selectedProductsIds) } $(document).on('click', '.increase', function() { productId = this.value; type = "increase"; updateQuantity(productId, type) }); $(document).on('click', '.decrease', function() { productId = this.value; type = "decrease"; updateQuantity(productId, type) }); function updateQuantity(id, type) { productId = '#quanity' + id; let quantityValue = parseInt($(productId).val()); if (type == "increase") { quantityValue = quantityValue + 1; // Finding Index to update in selectedProductQuantity Array IndexOfproductId = selectedProductsIds.indexOf(id) selectedProductQuantity[IndexOfproductId] = quantityValue } else if (type == "decrease") { if (quantityValue >= 2) { quantityValue = quantityValue - 1; } IndexOfproductId = selectedProductsIds.indexOf(id) selectedProductQuantity[IndexOfproductId] = quantityValue } $(productId).val(quantityValue) updateModalProduct(selectedProductsIds) } $('#couponForm').submit(function(event) { event.preventDefault(); let grandTotal = $('#grandTotal').html(); if (parseInt(grandTotal) > 0) { let coupon = $('#coupon').val(); $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { coupon: coupon }, success: function(response) { data = JSON.parse(response); let checkTotalCost = $('#totalCost').html(); if (checkTotalCost > 0) { let usersLeft = parseInt(data.usercount) - parseInt(data.usedusers); let totalCost = parseInt($('#totalCost').html()); let couponMinBill = data.min_bill let offerAmount = parseInt(data.amount) if (usersLeft > 0 && offerAmount <= totalCost && couponMinBill <= totalCost) { $('#offAmount').html(offerAmount) let grandTotal = totalCost - offerAmount; $('#tax').html((totalCost * 18) / 100); grandTotal = grandTotal + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#grandTotal').html(grandTotal); $('.coupon_error').html(usersLeft + 'Users Left') $('#couponId').val(data.coupon_id) } else if (data.status == 0) { $('.coupon_error').html('Invalid Coupon') $('#offAmount').html('0') $('#couponId').val(0) grandTotal = totalCost + ((totalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((totalCost * 18) / 100); $('#grandTotal').html(grandTotal); } else { if (offerAmount > totalCost) { $('.coupon_error').html('Offer Amount Greather Than Bill Amount'); $('#offAmount').html('0') } else if (couponMinBill > totalCost) { $('.coupon_error').html('Coupon Minimum Balance: ' + couponMinBill); $('#offAmount').html('0') } else { $('.coupon_error').html(usersLeft + ' Users Left') $('#offAmount').html('0') } $('#couponId').val(0) grandTotal = checkTotalCost + ((checkTotalCost * 18) / 100) grandTotal = grandTotal.toFixed(2); $('#tax').html((checkTotalCost * 18) / 100); $('#grandTotal').html(grandTotal) } } else { $('.coupon_error').html('Select Items') } } }) } else { $('.coupon_error').html('Select Items') } }) $('#servicePaymentForm').submit(function(event) { event.preventDefault(); $('#paymentButton').addClass('d-none'); let grandTotal = $('#grandTotal').html(); if (parseInt(grandTotal) > 0) { let selectedServicesIds = JSON.stringify(selectedServices); let productIds = selectedProductsIds.map(Number); productIds = JSON.stringify(selectedProductsIds); let productQuantity = JSON.stringify(selectedProductQuantity); let couponId = $('#couponId').val(); let userId = $('#checkUserId').val(); $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { servicePayment: 'payment', ServicesIds: selectedServicesIds, productIds: productIds, productQuantity: productQuantity, userId: userId, couponId: couponId }, success: function(response) { result = JSON.parse(response) if (result.insert == 1) { $('#approveButton').addClass('d-none'); $('#approval').removeClass('d-none'); $('.afterPayment').addClass('d-none'); $('.afterPaymentCoupon').removeClass('d-none'); let url = baseUrl + 'App/userInvoicepdf.php?allotmentId=' + result.insertedId $('#downloadInvoice').attr("href", url) $('#userMobile').prop('readonly', true) toastr.success('Notification Sent') $('.yes').val(result.insertedId) function redirect() { location.replace('approvals.php'); } setTimeout(redirect, 2000); makePageTransparent() } else { toastr.warning('Unable to Allot') } } }) } else { $('.payment_error').html('Select Items') $('#paymentButton').removeClass('d-none'); } }) function subAdminPayment(id) { let allotmentId = id; $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { subAdminPayment: 'payment', allotmentId: allotmentId }, success: function(response) { if (response == 1) { // $('#paymentButton').addClass('d-none'); $('#approval').addClass('d-none'); // $('#disablePayment').removeClass('d-none'); $('#invoice').removeClass('d-none'); let url = baseUrl + 'App/userInvoicepdf.php?allotmentId=' + allotmentId $('#downloadInvoice').attr("href", url) toastr.success('Items Alloted') } else { toastr.warning('Unable to Allot') } } }) } function statusAllotment() { let allotmentId = $('.yes').val(); if (allotmentId != "") { $.ajax({ type: 'POST', url: baseUrl + 'admin/app/servicesPayments.php', data: { getStatus: 'status', allotmentId: allotmentId }, success: function(response) { let data = JSON.parse(response) let approveStatus = data.approve_status; if (approveStatus == 3) { $('#paymentButton').removeClass('d-none'); $('#approval').addClass('d-none'); overlay = document.getElementById('overlay'); overlay.style.display = 'none'; document.onclick = function() { return true; }; } else if (approveStatus == 5) { $('#approval').html('Admin Rejected'); overlay = document.getElementById('overlay'); overlay.style.display = 'none'; document.onclick = function() { return true; }; } } }) } } setInterval(statusAllotment, 2000); $('#rcoupon').click(function() { let checkTotalCost = document.getElementById('totalCost'); checkTotalCost = checkTotalCost.textContent $('#coupon').val(''); $('.coupon_error').html('') $('#offAmount').html('0') $('#couponId').val(0) grandTotal = parseInt(checkTotalCost) + ((checkTotalCost * 18) / 100) $('#tax').html((checkTotalCost * 18) / 100); $('#grandTotal').html(grandTotal) }) </script>