JezK
Edit File: careClub-paymentdetails.php
<?php include "sidemenu-start.php"; include '../admin/app/adminObject.php'; $careClubId = base64_decode($_GET['careClub_id']); $packageDetails = $admin->getSingleCareClub(['id' => $careClubId]); ?> <div class="container-fluid"> <h1>Payment Details</h1> <div class="row mt-5"> <div class="col-md-3 mx-3"> <form id="getUserDetails"> <div class="mb-3 position-relative"> <label for="userid" class="form-label">User Mobile</label> <input type="number" class="form-control" id="userMobile" name="userMobile"> <button class="no-btn useridicon" 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-3 mx-3"> <div class="mb-3"> <label for="vehicletype" class="form-label">Vehicle Type</label> <input type="text" class="form-control" id="vehicletype" name="vehicletype"> <p class="error vehicletype_error"></p> </div> <div class="mb-3"> <label for="vehiclenumber" class="form-label">Vehicle Number</label> <input type="text" class="form-control" id="vehiclenumber" name="vehiclenumber" oninput="convertToUpperCase()"> <p class="error vehiclenumber_error"></p> </div> <div class="mb-3"> <label for="model" class="form-label">Model</label> <input type="text" class="form-control" id="model" name="model"> <p class="error model_error"></p> </div> </div> <div class="col-md-4 mx-3"> <div class="payments-card"> <div class="p-row"> <h5><?php echo $packageDetails['name'] ?></h5> </div> <div class="d-flex justify-content-space-around align-items-baseline"> <div style="width:35%;font-weight: bold; font-size: 15px;">Select Branch</div> <select class="form-select" id="branchFilter" style="font-weight: bold; border-color: #00adef; width: 50%;"> <option value="">Select Branch </option> <?php $branches = $admin->getBrachesByCareClub($careClubId); foreach ($branches as $branch) { ?> <option value="<?php echo $branch['branch_id']; ?>"><?php echo $branch['name']; ?></option> <?php } ?> </select> </div> <div class="d-flex justify-content-space-around align-items-baseline pt-2"> <div style="width:35%;font-weight: bold; font-size: 15px;">Select Car Type</div> <select class="form-select" id="carTypeFilter" style="font-weight: bold; border-color: #00adef; width: 50%;"> <option value="0">Select Car</option> <option value="4">Hatchback</option> <option value="1">Sedan</option> <option value="3">MUV</option> <option value="2">SUV</option> </select> </div> <div class="d-flex justify-content-space-around align-items-baseline pt-2"> <div style="font-weight: bold; width:35%; font-size: 15px;">Select Plan</div> <select class="form-select" id="planFilter" style="font-weight: bold; border-color: #00adef; width: 50%;"> <option value="0">Select Plan</option> <option value="1"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 1 Year</option> <option value="2"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 2 Years</option> <option value="3"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 3 Years</option> <option value="4"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 4 Years</option> <option value="5"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 5 Years</option> </select> </div> <div > </div> <ul id="itemNamesAndCost"> </ul> <div class="hr-line"> <div class="p-row"> <h5>Total</h5> <h5>Rs <span id="totalCost"></span></h5> </div> <form id="couponForm"> <div class="p-row "> <div class="d-flex flex-column position-relative"> <input type="text" id="coupon" placeholder="Enter Coupon" class="coupon afterPayment" name="coupon"> <p class="afterPaymentCoupon d-none">Offer Amount</p> <button class="no-btn coupon-icon" type="submit" onclick="return validatePaymentCoupon()" id="couponButton"> <img src="./images/arrow.png"></button> <p class="error coupon_error" style="font-size:13px"></p> </div> <span class="rednote"></span> <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"> <h5>Tax Rate</h5> <h5>18% </h5> </div> <div class="p-row "> <h5>Tax</h5> <h5 id="tax">Rs 0.00</h5> </div> <div class="p-row "> <h5>Grand Total</h5> <h5 id ="grandTotal">Rs 0.00</h5> </div> <form id="paymentForm"> <button type="submit" class="de-btn-small d-block m-auto" onclick="return validatePackagePaymentFrom()" id="paymentButton">PAYMENT</button> <button type="button" class="de-btns de-grey-btn d-block m-auto d-none" id="disablePayment">Payment</button> </form> <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> </div> <?php include "./sidemenu-end.php"; ?> <script> let baseUrl = "<?php echo $baseUrl ?>"; let careClubId = "<?php echo $careClubId ?>"; $('#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 if (userDetails.status == 2) { toastr.warning('User Account Deleted') } else { $('#name').val(userDetails.user_name) $('#detailingId').val(userDetails.user_id) $('#email').val(userDetails.email) $('#address').val(userDetails.address) $('#checkUserId').val(userDetails.id) } } }) }); $('#carTypeFilter,#planFilter,#branchFilter').change(function() { let carType = $('#carTypeFilter').val(); let planType = $('#planFilter').val(); let branchType = $('#branchFilter').val(); if(branchType == 0){ alert("Please select branch"); return false; } if(carType == 0){ alert("Please select car type"); return false; } if(planType == 0){ alert("Please select plan"); return false; } $.ajax({ type: 'POST', url: baseUrl + 'admin/app/careClub.php', data: { carType: carType, planType: planType, branchId: branchType, careClubId: careClubId, action: "getBranchCarPlanPrice" }, success: function(response) { result = JSON.parse(response); $('#itemNamesAndCost').html(result.service_details); let totalCost = result.amount; let tax = (totalCost * 18) / 100; let grandTotal = parseFloat(totalCost) + parseFloat(tax); $('#totalCost').html(totalCost); $('#tax').html(tax); $('#grandTotal').html(grandTotal); } }) }); $('#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/careClubPayment.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 couponType = data.cpn_type; let offerAmount; if(couponType == 1) { offerAmount = parseInt(data.amount) } else { offerAmount = (checkTotalCost * (data.percent/100)).toFixed(2); } if (usersLeft > 0 && offerAmount < totalCost && couponMinBill <= totalCost) { $('#offAmount').html(offerAmount) let grandTotal = totalCost - offerAmount; finalTotal = grandTotal + ((grandTotal*18)/100) grandTotal = grandTotal.toFixed(2); $('#grandTotal').html(finalTotal) $('#tax').html((grandTotal * 18) / 100); $('.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 = checkTotalCost + ((checkTotalCost * 18) / 100) $('#tax').html((checkTotalCost * 18) / 100); grandTotal = grandTotal.toFixed(2) $('#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) $('#tax').html((checkTotalCost * 18) / 100); grandTotal = grandTotal.toFixed(2) $('#grandTotal').html(grandTotal) } } else { $('.coupon_error').html('Select Items') } } }) } else { $('.coupon_error').html('Select Items') } }); $('#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) }) $('#paymentForm').submit(function(event) { event.preventDefault(); let vehicletype = $('#vehicletype').val(); let vehiclenumber = $('#vehiclenumber').val(); let model = $('#model').val(); let userId = $('#checkUserId').val(); let branchType = $('#branchFilter').val(); $('#paymentButton').addClass('d-none'); $.ajax({ type: 'POST', url: baseUrl + '/admin/app/careClubPayment.php', data: { vehicletype: vehicletype, vehiclenumber: vehiclenumber, model: model, userId: userId, careClubId: careClubId, branchId: branchType, // amount: amount, carType: $('#carTypeFilter').val(), planType: $('#planFilter').val(), couponId: $('#couponId').val() }, success: function(response) { result = JSON.parse(response) if (result.insert == 1) { $('#paymentButton').addClass('d-none'); $('#disablePayment').removeClass('d-none'); $('#invoice').removeClass('d-none'); let url = baseUrl + 'App/userInvoicepdf.php?allotmentId=' + result.insertedId $('#downloadInvoice').attr("href", url) toastr.success('Package Allocated') $('#userMobile').prop('readonly', true) } else { toastr.warning('Unable to Allot') $('#paymentButton').removeClass('d-none'); } } }) }) function convertToUpperCase() { var inputField = document.getElementById("vehiclenumber"); inputField.value = inputField.value.toUpperCase(); } </script>