<?php include("../db/cn.php"); ob_start(); if(isset($_SESSION['user_name']) && isset($_SESSION['user_role']) && isset($_SESSION['outlet_name']) && isset($_SESSION['outlet_address'])) { $userName = $_SESSION['user_name']; $userRole = $_SESSION['user_role']; $outlet_address = $_SESSION['outlet_address']; $outlet_name = $_SESSION['outlet_name']; // Fetch sale history data $saleHistoryResult = mysqli_query($connection, "SELECT * FROM log_user_sales where outlet_name = '$outlet_name' && login_user = '$userName' && user_role = '$userRole' && outlet_address = '$outlet_address' ORDER BY date_time DESC "); // Fetch sale hold data $saleHoldResult = mysqli_query($connection, "SELECT product_id, order_id, date_time, product_quantity, product_name, product_price, customer_name, customer_phone, product_total, tax_amount, discount_amount, total_amount, discounted FROM m_order where outlet_name = '$outlet_name' && login_user = '$userName' && user_role = '$userRole' && outlet_address = '$outlet_address'"); // Fetch sale refund data $saleRefundResult = mysqli_query($connection, "SELECT * FROM order_detail "); // Group sale history data by order ID $saleHistoryData = array(); while ($row = mysqli_fetch_assoc($saleHistoryResult)) { $saleHistoryData[] = $row; } $orderGroups = groupDataByOrderId($saleHistoryData); // Group sale hold data by order ID $saleHoldData = array(); while ($row = mysqli_fetch_assoc($saleHoldResult)) { $saleHoldData[] = $row; } $saleHoldGroups = groupDataByOrderId($saleHoldData); // Group sale refund data by order ID $saleRefundData = array(); while ($row = mysqli_fetch_assoc($saleRefundResult)) { $saleRefundData[] = $row; } $refundGroups = groupDataByOrderId($saleRefundData); } // Close database connection mysqli_close($connection); // Function to group data by order ID function groupDataByOrderId($data) { $groups = array(); foreach ($data as $item) { $orderId = $item['order_id']; if (!isset($groups[$orderId])) { $groups[$orderId] = array(); } $groups[$orderId][] = $item; } return $groups; } ob_end_flush(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Order Detail</title> <!-- Latest compiled and minified CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link rel="stylesheet" href="css/custom_css.css" /> <!-- QRCode.js --> </head><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Order Detail</title> <!-- Latest compiled and minified CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link rel="stylesheet" href="css/custom_css.css" /> <!-- QRCode.js --> </head> <style> #table-container-single { max-height: 460px; /* Adjust the maximum height as needed */ overflow-y: auto; /* Enable vertical scroll when content overflows */ } @media (max-width: 880px) { .col-4 { width: 33.33% !important; } .fa-wifi { display: none !important; } .col-6 { width: 50% !important; } } @media (min-width: 880px) { .sidebar { width: 100%; /* Change sidebar width to 100% on mobile */ max-width: 120px; /* Set maximum width for the sidebar */ } } @media (min-width: 880px) { .main-content { margin-left: ; /* Width of the sidebar */ } } /* Added new class to control overlay */ .overlay { position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(0, 0, 0, 0.6); z-index: 999; display: none; /* Initially hidden */ } /* Custom styles for sidebar */ .sidebar { width: 100px; background: linear-gradient(360deg, #060606, #0A5064); position: fixed; bottom: 0; top: 60px; transition: transform 0.3s ease-in-out; transform: translateX(0); z-index: 1; height: 100%; border-radius: 0px; transition: transform 0.3s ease-in-out, width 0.3s ease-in-out; } .sidebar.hide { transform: translateX(-100px); /* Move sidebar out of the viewport when it is hidden */ } .sidebar .nav-item { padding: 10px 0; text-align: center; position: relative; font-size: 12px; } .sidebar .nav-link { color: #fff; position: relative; /* Ensure icon and text are positioned relative to the nav link */ z-index: 2; /* Ensure the text and icon are above the hover background */ } .sidebar .nav-link i { margin-bottom: 5px; /* Adjust the margin of the icon */ } /* Custom styles for hover effect */ .sidebar .nav-item:hover:after { background-color: #fff; content: ''; position: absolute; left: 0; bottom: 0; width: 100%; height: 100%; z-index: 1; /* Ensure the hover background is below the text and icon */ } .sidebar .nav-item:hover .nav-link { color: #0A5064; } /* Custom styles for divider */ .sidebar .nav-item:after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 1px; background-color: #fff; transition: height 0.3s ease-in-out; /* Transition effect for smooth animation */ } /* Custom styles for header */ .header { background: linear-gradient(90deg, #0A5064, #060606); color: #fff; padding: 10px; position: fixed; top: 0; width: 100%; z-index: 2; height: 69px; box-shadow: #FFF 2px 0px 0px 0px; /* Ensure header appears above sidebar */ } .header .navbar-toggler { color: #fff; } .header .navbar-toggler-icon { color: #fff; /* Set the color of the toggle button to white */ } .header .navbar-toggler.white { color: #fff !important; /* Ensure the toggle button is white */ } .header .navbar-brand { color: #fff; /* Set navbar brand text color to white */ } .header .nav-item .nav-link { color: #fff; /* Set nav link text color to white */ } .main-content { margin-top: 50px; /* Height of fixed header */ margin-left: 100px; /* Initially, set margin-left to 0 */ padding-top: 30px; /* Height of fixed header */ transition: margin-left 0.3s ease-in-out; /* Add transition for smoother animation */ } /* Custom styles for search bar */ .search-container { display: flex; align-items: center; width:100%; margin: 2px auto; float:left; } /* Updated hide class to apply to the overlay */ .sidebar.hide, .overlay.hide { transform: translateX(-100%); } .search-input { width: 100%; padding: 10px 30px 10px 10px; /* Adjust padding to accommodate the icon */ border: 1px solid #ccc; border-radius: 20px; font-size: 16px; } .search-icon { position: relative; left: -25px; /* Adjust the position of the icon */ color: #aaa; } .search-icon i { position: absolute; top: 50%; transform: translateY(-50%); } .btn-dark { background: #0A5064; color: #fff; border: 1px solid #0A5064; } .btn-dark:hover { background: #fff; color: #0A5064; border: 1px solid #0A5064; } .bg-dark2 { background: #8A1218; color: #fff; } .modal-content { animation: modal-animation 0.5s; } @keyframes modal-animation { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } } </style> <body> <?php include("common/hd.php");?> <?php include("common/sd.php");?> <!-- Main content --> <div class="main-content"> <br /> <div class="container-fluid" style="text-transform:capitalize;"> <div class="row"> <div class="col-sm-6"> <!-- Tab navigation --> <ul class="nav nav-tabs" id="myTabs"> <li class="nav-item"> <a class="nav-link active text-dark" id="saleHistory-tab" data-toggle="tab" href="#saleHistory" role="tab" aria-controls="saleHistory" aria-selected="true">Sale History</a> </li> <!-- <li class="nav-item"> <a class="nav-link text-dark" id="saleHold-tab" data-toggle="tab" href="#saleHold" role="tab" aria-controls="saleHold" aria-selected="false"> Sale Modify</a> </li>--> <li class="nav-item"> <a class="nav-link text-dark" id="refund-tab" data-toggle="tab" href="#refund" role="tab" aria-controls="refund" aria-selected="false">Refund</a> </li> </ul> <!-- Tab content --> <div class="tab-content" id="myTabContent"> <!-- Sale History tab content --> <div class="tab-pane fade show active" id="saleHistory" role="tabpanel" aria-labelledby="saleHistory-tab"> <div style="max-height: 700px; overflow-y: auto;"> <br> <!-- Filter controls --> <div class="form-group row"> <label for="saleOrderID" class="col-sm-2 col-form-label">Search by :</label> <div class="col-sm-8"> <input type="text" class="form-control" id="saleOrderID" placeholder=""> </div> </div> <br> <table class="table table-sm text-center" style="width: 100%; font-size:14px; "> <!-- Table header --> <thead style="border-radius:8px;"> <!-- Table header rows --> <tr style="background:#212529; color:#fff;"> <th>Date</th> <th>name</th> <th>Cell</th> <th>Order </th> <th>Amount</th> <th>Refund</th> <!--<th>Modify</th> <th>Print</th>--> <!-- Add more table columns here as needed --> </tr> </thead> <!-- Table body --> <tbody id="saleHistoryTableBody" > <!-- Sale history data rows --> <?php foreach ($orderGroups as $orderId => $group): ?> <tr class="sale-history-row" data-order-id="<?php echo $orderId; ?>" > <td style="font-weight:700;"><?php echo $group[0]['date_time']; ?></td> <td><?php echo $group[0]['customer_name']; ?></td> <td><?php echo $group[0]['customer_phone']; ?></td> <td style="color:#8A1218; font-weight:700; font-size:11px;"><?php echo $orderId; ?></td> <!-- <td><?php echo $group[0]['product_name']; ?></td> <td><span style="width:50px;height:20px; padding:7px; border-radius:20px; color:#fff; background:#8A1218;"> <?php echo $group[0]['product_quantity']; ?></span></td>--> <td style="font-weight:700;">Rs<?php echo " ".$group[0]['discount_amount']."/-"; ?></td> <td><a href="orderrefund.php?order_id=<?php echo $orderId; ?>"><button type="button" class="btn btn-dark btn-sm btn-circle"><i class="fas fa-box fa-1x"></i></button></a></td> <!--<td><a href="order_m.php?order_id=<?php echo $orderId; ?>"><button type="button" class="btn btn-dark btn-sm btn-circle"><i class="fas fa-chart-pie fa-1x"></i></button></a></td> <td> <a href="print_invoice_o.php?order_id=<?php echo $orderId; ?>" target="_blank" style="border-radius:20px;" class="btn btn-dark btn-sm print-invoice form-control"><i class="fas fa-print"></i></a></td> <!-- Add more table columns here as needed --> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <!-- Sale Hold tab content <div class="tab-pane fade" id="saleHold" role="tabpanel" aria-labelledby="saleHold-tab"> <div style="max-height: 700px; overflow-y: auto;"><br> <div class="form-group row"> <label for="holdOrderID" class="col-sm-2 col-form-label">Search by:</label> <div class="col-sm-8"> <input type="text" class="form-control" id="holdOrderID" placeholder=""> </div> </div><br> <table class="table table-sm text-center" style="width: 100%; font-size:14px; "> <!-- Table header <thead style="border-radius:8px;"> <!-- Table header rows <tr style="background:#212529; color:#fff;"> <th>Date</th> <th>name</th> <th>Cell</th> <th>Order </th> <th>Amount</th> <th>Action</th> <!--<th>Print</th>--> <!-- Add more table columns here as needed </tr> </thead> <!-- Table body <tbody id="saleHoldTableBody" > <!-- Sale history data rows <?php foreach ($saleHoldGroups as $orderId => $group): ?> <tr class="sale-hold-row" data-order-id="<?php echo $orderId; ?>" > <td><?php echo $group[0]['date_time']; ?></td> <td><?php echo $group[0]['customer_name']; ?></td> <td><?php echo $group[0]['customer_phone']; ?></td> <td style="color:#8A1218; font-weight:700; font-size:11px;"><?php echo $orderId; ?></td> <!-- <td><?php echo $group[0]['product_name']; ?></td> <td><span style="width:50px;height:20px; padding:7px; border-radius:20px; color:#fff; background:#8A1218;"> <?php echo $group[0]['product_quantity']; ?></span></td> <td>Rs<?php echo " ".$group[0]['discount_amount']."/-"; ?></td> <td> <a href="print_invoice.php?order_id=<?php echo $orderId; ?>" target="_blank" style="border-radius:20px;" class="btn btn-dark btn-sm print-invoice form-control"><i class="fas fa-print"></i></a></td> <!-- Add more table columns here as needed </tr> <?php endforeach; ?> </tbody> </table> </div> </div>--> <!-- Refund tab content --> <div class="tab-pane fade" id="refund" role="tabpanel" aria-labelledby="refund-tab"> <div style="max-height: 700px; overflow-y: auto;"> <br> <!-- Filter controls --> <div class="form-group row "> <label for="refundOrderID" class="col-sm-2 col-form-label">Search By:</label> <div class="col-sm-8"> <input type="text" class="form-control" id="refundOrderID" placeholder=""> </div> </div><br> <table class="table text-center table-sm" style="width: 100%;font-size:14px;"> <!-- Table header --> <thead> <!-- Table header rows --> <tr style="background:#212529; color:#fff;"> <th>Date</th> <th>Name</th> <th>Order </th> <th>Amount</th> <th>Status</th> <th>Action</th> <!-- Add more table columns here as needed --> </tr> </thead> <!-- Table body --> <tbody id="refundTableBody" > <!-- Sale refund data rows --> <?php foreach ($refundGroups as $orderId => $group): ?> <tr class="refund-row" data-order-id="<?php echo $orderId; ?>"> <td><?php echo $group[0]['date_time']; ?></td> <td><?php echo $group[0]['customer_name']; ?></td> <td style="color:#8A1218; font-weight:700; font-size:12px;"><?php echo $orderId; ?></td> <td>Rs <?php echo $group[0]['total_amount']; ?> /-</td> <td><?php echo $group[0]['order_status']; ?></td> <td> <a href="print_invoice_r.php?order_id=<?php echo $orderId; ?>" target="_blank" style="border-radius:20px;" class="btn btn-dark btn-sm print-invoice form-control"><i class="fas fa-print"></i></a></td> <!--<td><?php echo $group[0]['product_name']; ?></td> <td><?php echo $group[0]['product_quantity']; ?></td>--> <!-- Add more table columns here as needed --> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> <!-- Single view column --> <div class="col-sm-6"> <br> <div id="singleView" style="display: ;"> <!-- Single view content will be displayed here --> </div> </div> </div> </div> </div> <!-- Sale History Modal --> <!-- <div class="modal fade" id="saleHistoryModal" tabindex="-1" aria-labelledby="saleHistoryModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="saleHistoryModalLabel">Sale History Details</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body" id="saleHistoryModalBody"> <!-- Sale history data will be inserted here </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div>--> <!-- Sale Hold Modal --> <!--<div class="modal fade" id="saleHoldModal" tabindex="-1" aria-labelledby="saleHoldModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="saleHoldModalLabel">Sale Hold Details</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body" id="saleHoldModalBody"> <!-- Sale hold data will be inserted here </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div>--> <!-- Refund Modal --> <!-- <div class="modal fade" id="refundModal" tabindex="-1" aria-labelledby="refundModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="refundModalLabel">Refund Details</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body" id="refundModalBody"> <!-- Refund data will be inserted here </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div>--> <!-- Your JavaScript and Bootstrap scripts --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <script> document.addEventListener("DOMContentLoaded", function () { var sidebar = document.getElementById("sidebar"); var overlay = document.createElement("div"); overlay.classList.add("overlay"); document.body.appendChild(overlay); function toggleSidebar() { sidebar.classList.toggle("hide"); overlay.classList.toggle("hide"); var mainContent = document.querySelector(".main-content"); if (sidebar.classList.contains("hide")) { mainContent.style.marginLeft = "0"; } else { mainContent.style.marginLeft = "100px"; // Width of the sidebar } } overlay.addEventListener("click", function () { toggleSidebar(); }); // Add toggle functionality to navbar toggler var navbarToggler = document.querySelector(".navbar-toggler"); navbarToggler.addEventListener("click", function () { toggleSidebar(); }); // Automatically hide sidebar on all screen sizes // sidebar.classList.add("hide"); // overlay.classList.add("hide"); // Add class to body to prevent scrolling when sidebar is open // document.body.classList.add("noscroll"); // Check if screen size is larger than a certain threshold (e.g., 768px for desktop screens) function checkScreenSize() { if (window.innerWidth > 768) { sidebar.classList.remove("hide"); overlay.classList.remove("hide"); } else { sidebar.classList.add("hide"); overlay.classList.add("hide"); } } // Check screen size on initial load and whenever the window is resized checkScreenSize(); window.addEventListener("resize", checkScreenSize); }); $(document).ready(function() { // Function to filter table by any text function filterTable(tableBody, searchText) { $(tableBody + ' tr').each(function() { var row = $(this).text().toLowerCase(); if (row.indexOf(searchText.toLowerCase()) === -1) { $(this).hide(); } else { $(this).show(); } }); } // Event listener for sale history search $('#saleOrderID').keyup(function() { var searchText = $(this).val(); filterTable('#saleHistoryTableBody', searchText); }); // Event listener for sale hold search $('#holdOrderID').keyup(function() { var searchText = $(this).val(); filterTable('#saleHoldTableBody', searchText); }); // Event listener for refund search $('#refundOrderID').keyup(function() { var searchText = $(this).val(); filterTable('#refundTableBody', searchText); }); }); $(document).ready(function() { // Function to populate Single View function populateSingleView(orderId, products, sales) { // Calculate subtotal var subtotal = 0; products.forEach(function(productss) { subtotal += parseFloat(productss.product_price); }); // Construct HTML for product details var detailsHTML = '<div class="single-view-content">'; detailsHTML += '<h5 style="font-size:15px;"> <span class="order-id" style="border:1px solid #353535;padding:8px; border-radius:7px; font-size:16px;">' + orderId + '</span></h5><br>'; detailsHTML += '<p class="order-date"><i class="fa fa-calendar-check" style="color:#524C42;font-size:20px;"></i>&nbsp;' + sales[0].date_time + '</p>'; detailsHTML += '<div id="table-container-single"><table class="table table-stripped text-center table-sm">'; detailsHTML += '<thead><tr><th>Product</th><th>L(F)</th><th>W(F)</th><th>L(I)</th><th>W(I)</th><th>Area</th><th>Piece</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr></thead>'; detailsHTML += '<tbody>'; var subtotal = 0; // Initialize subtotal // Loop through each product and calculate subtotal for each products.forEach(function(product) { var productSubtotal = product.product_price * product.product_quantity; subtotal += productSubtotal; // Accumulate subtotal detailsHTML += '<tr style="height:35px;margin-top:20px;text-transform:capitalize;">'; detailsHTML += '<td style="font-size:12px; font-weight:600;">' + product.product_name + '</td>'; detailsHTML += '<td>' + product.l_feet + '</td>'; detailsHTML += '<td>' + product.w_feet + '</td>'; detailsHTML += '<td>' + product.l_inch + '</td>'; detailsHTML += '<td>' + product.w_inch + '</td>'; detailsHTML += '<td>' + product.area + '</td>'; detailsHTML += '<td>' + product.piece + '</td>'; detailsHTML += '<td><span class="bg-dark2" style="width:50px;height:20px;border-radius:20px;font-size:12px;padding:4px;">' + product.product_quantity + '</span></td>'; detailsHTML += '<td>' + product.product_price + '</td>'; detailsHTML += '<td style="font-weight:700;">' + productSubtotal.toFixed(2) + '</td>'; // Display product subtotal detailsHTML += '</tr>'; }); detailsHTML += '</tbody></table></div>'; detailsHTML += '<div class="order-summary text-center" style="font-weight:500;">'; // Display calculated subtotal instead of sales[0].total_amount detailsHTML += '<div class="row total-amount"><div class="col-sm-6">Sub:</div><div class="col-sm-6">Rs ' + subtotal.toFixed(2) + '</div></div>'; detailsHTML += '<div class="row total-amount"><div class="col-sm-6">Labour:</div><div class="col-sm-6"> Rs ' + sales[0].labour_amount + '</div></div>'; detailsHTML += '<div class="row total-amount"><div class="col-sm-6">Disc:</div><div class="col-sm-6"> Rs ' + sales[0].discounted + '</div></div>'; var totalAmount = Number(subtotal) - Number(sales[0].discounted); var toTal = totalAmount + Number(sales[0].labour_amount); detailsHTML += '<div class="row total-amount"><div class="col-sm-6">Total:</div><div class="col-sm-6"> Rs ' + toTal + '</div></div>'; // Show total after discount detailsHTML += '</div>'; detailsHTML += '<div class="order-actions">'; detailsHTML += '<a href="" style="border-radius:20px;" class=""></a><br>'; detailsHTML += '</div>'; detailsHTML += '</div>'; // Set HTML content to singleView div and show it $('#singleView').html(detailsHTML).show(); } // Function to handle click event on table rows $(document).on('click', '.sale-history-row, .sale-hold-row, .refund-row', function() { var orderId = $(this).data('order-id'); var products, sales; // Determine the tab and get data accordingly if ($(this).hasClass('sale-history-row')) { products = <?php echo json_encode($orderGroups); ?>[orderId]; sales = <?php echo json_encode($orderGroups); ?>[orderId]; } else if ($(this).hasClass('sale-hold-row')) { products = <?php echo json_encode($saleHoldGroups); ?>[orderId]; sales = <?php echo json_encode($saleHoldGroups); ?>[orderId]; } else if ($(this).hasClass('refund-row')) { products = <?php echo json_encode($refundGroups); ?>[orderId]; sales = <?php echo json_encode($refundGroups); ?>[orderId]; } // Populate single view populateSingleView(orderId, products, sales); }); $(document).on('click', '.print-invoice', function() { // Get the content of #singleView div var content = $('#singleView').clone(); // Clone the content to keep the original intact // Remove any buttons or interactive elements content.find('.order-actions').remove(); content.find('.refund-invoice').remove(); // Get the invoice items content var itemsContent = content.find('.invoice-items').html(); // Create data object var data = []; content.find('.invoice-items tbody tr').each(function() { var item = { product_name: $(this).find('td:eq(0)').text(), product_price: $(this).find('td:eq(1)').text(), product_quantity: $(this).find('td:eq(2)').text() }; data.push(item); }); // Debugging: check the collected data console.log(data); // Open a new window for printing // Debugging: check the printWindow object // Debugging: check if the content is written to the new window console.log(printWindow.document.body.innerHTML); }); // Function to handle printing when the "Refund Invoice" button is clicked $(document).on('click', '.refund-invoice', function() { // Implement refund invoice functionality if necessary }); }); document.addEventListener('DOMContentLoaded', function() { // Sample sales data const sales = [ { discount_amount: 100, // Change this value to test different scenarios } ]; let detailsHTML = ''; // Function to check if the current tab is the refund tab function isRefundTab() { // Placeholder logic for checking if it's the refund tab // You can replace this with your actual logic, e.g., checking an element's ID or class return document.body.classList.contains('refund-tab'); } // Check if sales array has elements and discount_amount is valid if (sales.length > 0 && sales[0].discount_amount && !isRefundTab()) { detailsHTML += '<div class="row tax-amount"><div class="col-sm-6">Discount:</div><div class="col-sm-6">Rs ' + sales[0].discount_amount + '</div></div>'; } // Insert the generated HTML into the page document.getElementById('order-details').innerHTML = detailsHTML; }); </script> </body> </html>