<?php
include 'includes/config.php';
session_start();

if (!$_SESSION['email']) {
    header('location:login.php');
}

if (isset($_POST['submit_bank'])) {
    $bank_name = $_POST['bank_name'];
    $start_bank_date = $_POST['start_bank_date'];
    $account_number = $_POST['account_number'];
    $start_bank_balance = $_POST['start_bank_balance'];
    $description = $_POST['description'];

    try {
        $sql = "INSERT INTO banks (bank_name, start_bank_date, account_number, start_bank_balance, description) 
                VALUES (:bank_name, :start_bank_date, :account_number, :start_bank_balance, :description)";

        $stmt = $conn->prepare($sql);

        $stmt->bindParam(':bank_name', $bank_name);
        $stmt->bindParam(':start_bank_date', $start_bank_date);
        $stmt->bindParam(':account_number', $account_number);
        $stmt->bindParam(':start_bank_balance', $start_bank_balance);
        $stmt->bindParam(':description', $description);

        // Execute the query
        $stmt->execute();

        header('Location: list_banks.php');
        exit();
    } catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
}

try {
    $sql = "
   SELECT b.id, b.bank_name, b.start_bank_date, b.account_number, b.description, b.start_bank_balance,
       COALESCE(SUM(cd.amount), 0) AS total_deposit,
       COALESCE(SUM(bd.amount), 0) AS total_debit
FROM banks b
LEFT JOIN (
    SELECT bank_id, SUM(amount) AS amount
    FROM cash_deposit
    GROUP BY bank_id
) cd ON b.id = cd.bank_id 
LEFT JOIN (
    SELECT bank_id, SUM(amount) AS amount
    FROM bank_debit_amount
    GROUP BY bank_id
) bd ON b.id = bd.bank_id
GROUP BY b.id, b.bank_name, b.start_bank_date, b.account_number, b.description, b.start_bank_balance;
";
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $banks = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}
?>
<?php
if (isset($_POST['submit_money'])) {
    $date_deposit = $_POST['date_deposit'] ?? null;
    $bank_id = $_POST['bank_id'] ?? null;
    $amount = $_POST['amount'] ?? null;
    $payment_status = $_POST['payment_status'] ?? null;

    if ($date_deposit && $bank_id && $amount && $payment_status) {
        try {
            $conn->beginTransaction();

            $query = "INSERT INTO `cash_deposit` (`bank_id`, `amount`, `payment_status`, `date_deposit`) 
                      VALUES (:bank_id, :amount, :payment_status, :date_deposit)";
            $stmt = $conn->prepare($query);

            $stmt->bindParam(':bank_id', $bank_id, PDO::PARAM_INT);
            $stmt->bindParam(':amount', $amount);
            $stmt->bindParam(':payment_status', $payment_status);
            $stmt->bindParam(':date_deposit', $date_deposit);

            if ($stmt->execute()) {
                $conn->commit();

                $bankQuery = "SELECT `bank_name` FROM `banks` WHERE `id` = :bank_id";
                $bankStmt = $conn->prepare($bankQuery);
                $bankStmt->bindParam(':bank_id', $bank_id, PDO::PARAM_INT);
                $bankStmt->execute();
                $bank = $bankStmt->fetch(PDO::FETCH_ASSOC);

                if ($bank) {
                    $bank_name = $bank['bank_name'];

                    header("Location: print/print_voucher.php?bank_name=" . urlencode($bank_name) . "&amount=" . urlencode($amount) . "&payment_status=" . urlencode($payment_status) . "&date_deposit=" . urlencode($date_deposit));
                    exit;
                } else {
                    echo "<script>alert('Bank name not found.');</script>";
                }
            } else {
                echo "<script>alert('Data insertion failed.');</script>";
            }
        } catch (PDOException $e) {
            // Rollback transaction if there is an error
            $conn->rollBack();
            die("Insertion failed: " . $e->getMessage());
        }
    } else {
        echo "<script>alert('Please fill in all required fields.');</script>";
    }
}
?>

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>List Banks</title>
    <!-- Favicon -->
    <link rel="shortcut icon" href="images/favicon.ico" />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Typography CSS -->
    <link rel="stylesheet" href="css/typography.css">
    <!-- Style CSS -->
    <link rel="stylesheet" href="css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="css/responsive.css">
    <script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
    <script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
    <style>
        ion-icon {
            font-size: 20px;
            margin-bottom: -5px;
        }

        .search-container {
            margin-bottom: 20px;
            text-align: center;
        }

        .search-input {
            width: 50%;
            padding: 10px;
            font-size: 16px;
            border: 2px solid #ddd;
            border-radius: 4px;
            outline: none;
            transition: all 0.3s ease;
        }

        .search-input:focus {
            border-color: #007bff;
        }
    </style>
</head>

<body>
    <!-- loader Start -->
    <div id="loading">
        <div id="loading-center">
        </div>
    </div>
    <!-- loader END -->
    <!-- Wrapper Start -->
    <div class="wrapper">
        <!-- Sidebar  -->
        <?php
        include 'includes/sidebar.php';
        ?>
        <!-- TOP Nav Bar -->
        <?php include 'includes/header.php'; ?>
        <!-- TOP Nav Bar END -->
        <!-- Page Content  -->
        <div id="content-page" class="content-page">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="iq-card">
                            <div class="iq-card-header d-flex justify-content-between row">
                                <div class="iq-header-title col-lg-6">
                                    <h4 class="card-title"><a href="list_expense_category.php">Bank & Cash Accounts</a> > List Bank
                                    </h4>
                                </div>
                                <div class="col-lg-6">
                                    <button type="button" class="btn btn-primary" data-toggle="modal"
                                        data-target="#exampleModalCenter" style="float:inline-end;">
                                        <ion-icon name="add-outline" style="font-size:20px; margin-bottom:-4px;color:white">
                                        </ion-icon>Add Bank
                                    </button>
                                    <button type="button" class="btn btn-secondary mr-3" data-toggle="modal"
                                        data-target="#moneyModalCenter" style="float:inline-end;">
                                        <ion-icon name="add-outline" style="font-size:20px; margin-bottom:-4px;color:white">
                                        </ion-icon>New Income
                                    </button>
                                    <!-- Bootstrap Modal for Withdraw -->
<!-- Bootstrap Modal for Withdraw -->
<!-- Bootstrap Modal for Withdraw -->
<div class="modal fade" id="withdrawModal" tabindex="-1" aria-labelledby="withdrawModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="withdrawModalLabel">Withdraw</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <form id="withdrawForm">
          <!-- Bank Selection -->
          <div class="mb-3">
            <label for="bankSelect" class="form-label">Select Bank:</label>
            <select id="bankSelect" class="form-select" required>
              <option value="">Select a Bank</option>
              <!-- Options will be populated dynamically -->
            </select>
          </div>

          <!-- Remaining Amount -->
          <div class="mb-3">
            <label for="remainingAmount" class="form-label">Remaining Amount:</label>
            <input type="text" id="remainingAmount" class="form-control" readonly>
          </div>

          <!-- Withdrawal Amount -->
          <div class="mb-3">
            <label for="withdrawAmount" class="form-label">Amount to Withdraw:</label>
            <input type="number" id="withdrawAmount" class="form-control" required min="1">
            <div id="error-message" style="color: red; display: none;">Amount exceeds available balance!</div>
          </div>

          <!-- Note -->
          <div class="mb-3">
            <label for="note" class="form-label">Note:</label>
            <textarea id="note" class="form-control" rows="3"></textarea>
          </div>

          <!-- Date -->
          <div class="mb-3">
            <label for="withdrawDate" class="form-label">Date:</label>
            <input type="date" id="withdrawDate" class="form-control" required>
          </div>

          <button type="button" id="submitBtn" class="btn btn-primary" onclick="submitWithdrawal()">Submit</button>
        </form>
      </div>
    </div>
  </div>
</div>

<!-- Withdraw Button -->
<button class="btn btn-warning" id="withdrawBtn" onclick="openWithdrawPopup()">Withdraw</button>

<!-- Include Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>

<script>
// Open the withdraw pop-up modal
function openWithdrawPopup() {
    // Fetch available banks and populate the bank select dropdown
    fetch('get_banks.php')
        .then(response => response.json())
        .then(data => {
            const bankSelect = document.getElementById('bankSelect');
            bankSelect.innerHTML = '<option value="">Select a Bank</option>';  // Reset options

            data.forEach(bank => {
                const option = document.createElement('option');
                option.value = bank.id;
                option.textContent = bank.bank_name;
                bankSelect.appendChild(option);
            });
        })
        .catch(error => console.error("Error fetching banks:", error));

    // Show the modal
    const withdrawModal = new bootstrap.Modal(document.getElementById('withdrawModal'));
    withdrawModal.show();
}

// Event listener for when the user selects a bank
document.getElementById('bankSelect').addEventListener('change', function() {
    const bankId = this.value;

    if (bankId) {
        // Fetch the remaining amount for the selected bank
        fetch(`get_remaining_amount_bank.php?bank_id=${bankId}`)
            .then(response => response.json())
            .then(data => {
                // Display the remaining amount in the input field
                document.getElementById('remainingAmount').value = data.remaining_amount;
            })
            .catch(error => console.error("Error fetching remaining amount:", error));
    } else {
        document.getElementById('remainingAmount').value = '';
    }
});

document.getElementById('withdrawAmount').addEventListener('input', function() {
    const withdrawAmount = parseFloat(this.value);
    const remainingAmount = parseFloat(document.getElementById('remainingAmount').value);

    if (withdrawAmount > remainingAmount) {
        document.getElementById('error-message').style.display = 'block';
        document.getElementById('submitBtn').disabled = true;
    } else {
        document.getElementById('error-message').style.display = 'none';
        document.getElementById('submitBtn').disabled = false;
    }
});

// Submit withdrawal
function submitWithdrawal() {
    const bankId = document.getElementById('bankSelect').value;
    const withdrawAmount = document.getElementById('withdrawAmount').value;
    const note = document.getElementById('note').value;
    const date = document.getElementById('withdrawDate').value;

    if (bankId && withdrawAmount && note && date) {
        const requestData = {
            bank_id: bankId,
            amount: withdrawAmount,
            note: note,
            date: date
        };

        fetch('insert_withdrawal.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(requestData)
        })
        .then(response => response.json())
        .then(data => {
            if (data.status === 'success') {
                // Redirect to the voucher print page with the withdrawal ID as a URL parameter
                window.location.href = `print_voucher_withdraw.php?id=${data.withdrawal_id}`;
            } else {
                alert(data.message);
            }
        });
    } else {
        alert('Please fill out all fields correctly.');
    }
}


</script>


                                    <!-- <button type="button" class="btn btn-info mr-3" data-toggle="modal"
                                        data-target="#exampleModalCenter" style="float:inline-end;">
                                            <ion-icon name="send-outline" style="font-size:20px; margin-bottom:-4px;color:white">
                                            </ion-icon>Transfer Money
                                    </button> -->
                                </div>
                                <!-- add variation -->
                                <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog"
                                    aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                    <div class="modal-dialog modal-dialog-centered" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="modal-title" id="exampleModalCenterTitle">Add New Account</h5>
                                                <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <form method="POST" action="">

                                                <div class="modal-body">
                                                    <div class="form-group">
                                                        <label for="" class="control-label">Bank Name *</label>
                                                        <input type="text" name="bank_name" class="form-control" placeholder="Bank Name" required>
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="" class="control-label">Opening Date *</label>
                                                        <input type="date" name="start_bank_date" class="form-control" required>
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="" class="control-label">Account Number</label>
                                                        <input type="text" name="account_number" class="form-control" placeholder="Account Number" id="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="" class="control-label">Opening Balance *</label>
                                                        <input type="text" name="start_bank_balance" class="form-control" placeholder="Opening Balance" required>
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="" class="control-label">Description</label>
                                                        <input type="text" name="description" class="form-control" placeholder="Description" id="">
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-secondary"
                                                        data-dismiss="modal">Close</button>
                                                    <button type="submit" name="submit_bank" class="btn btn-primary">Save</button>
                                                </div>
                                        </div>
                                        </form>
                                    </div>
                                </div>
                                <!-- add variation end -->
                            </div>

                            <!------------------------------Add money---------------------------------------->
                            <!-- add variation -->
                            <div class="modal fade" id="moneyModalCenter" tabindex="-1" role="dialog"
                                aria-labelledby="moneyModalCenterTitle" aria-hidden="true">
                                <div class="modal-dialog modal-dialog-centered" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="moneyModalCenterTitle">Add New Income</h5>
                                            <button type="button" class="close" data-dismiss="modal"
                                                aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <form method="POST" action="">

                                            <div class="modal-body">
                                                <div class="form-group">
                                                    <label for="" class="control-label">Date *</label>
                                                    <input type="date" name="date_deposit" class="form-control" required>
                                                </div>
                                                <div class="form-group">
                                                    <label for="" class="control-label">Account *</label>
                                                    <?php

                                                    try {
                                                        $query = "SELECT `id`, `bank_name` FROM `banks`";
                                                        $stmt = $conn->query($query);
                                                        $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
                                                    } catch (PDOException $e) {
                                                        die("Query failed: " . $e->getMessage());
                                                    }
                                                    ?>

                                                    <select name="bank_id" class="form-control">
                                                        <option value="">Plz Select Account</option>
                                                        <?php foreach ($datas as $data): ?>
                                                            <option value="<?= htmlspecialchars($data['id']) ?>">
                                                                <?= htmlspecialchars($data['bank_name']) ?>
                                                            </option>
                                                        <?php endforeach; ?>
                                                    </select>

                                                </div>

                                                <div class="form-group">
                                                    <label for="" class="control-label">Amount</label>
                                                    <input type="text" name="amount" class="form-control" placeholder="Enter Amount" id="">
                                                </div>

                                                <div class="form-group">
                                                    <label for="" class="control-label">Description</label>
                                                    <input type="text" name="payment_status" class="form-control" placeholder="Description" id="">
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary"
                                                    data-dismiss="modal">Close</button>
                                                <button type="submit" name="submit_money" class="btn btn-primary">Save</button>
                                            </div>
                                    </div>
                                    </form>
                                </div>
                            </div>

                            <!----------------------------------------End Add Money pop up------------------------->

                            <!----------Updated model---------->
                            <!-- Modal for Editing Bank Details -->
                            <div class="modal" 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 Bank Details</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="closeEditModal()">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body">
                                            <!-- Edit Form -->
                                            <form action="update_bank.php" method="POST">
                                                <input type="hidden" id="edit-bank_id" name="id">
                                                <div class="form-group">
                                                    <label for="edit-bank_name">Bank Name</label>
                                                    <input type="text" class="form-control" id="edit-bank_name" name="bank_name" required>
                                                </div>
                                                <div class="form-group">
                                                    <label for="edit-start_bank_date">Opening Date</label>
                                                    <input type="date" class="form-control" id="edit-start_bank_date" name="start_bank_date" required>
                                                </div>
                                                <div class="form-group">
                                                    <label for="edit-account_number">Account Number</label>
                                                    <input type="text" class="form-control" id="edit-account_number" name="account_number" required>
                                                </div>
                                                <div class="form-group">
                                                    <label for="edit-start_bank_balance">Opening Balance</label>
                                                    <input type="text" class="form-control" id="edit-start_bank_balance" name="start_bank_balance">
                                                </div>
                                                <div class="form-group">
                                                    <label for="edit-description">Description</label>
                                                    <textarea class="form-control" id="edit-description" name="description"></textarea>
                                                </div>
                                                <button type="submit" class="btn btn-primary">Update</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <script>
                                function openEditModal(id, bankName, openingDate, accountNumber, openingBalance, description) {
                                    document.getElementById('edit-bank_id').value = id;
                                    document.getElementById('edit-bank_name').value = bankName;
                                    document.getElementById('edit-start_bank_date').value = openingDate;
                                    document.getElementById('edit-account_number').value = accountNumber;
                                    document.getElementById('edit-start_bank_balance').value = openingBalance;
                                    document.getElementById('edit-description').value = description;

                                    $('#editModal').modal('show');
                                }

                                function closeEditModal() {
                                    $('#editModal').modal('hide');
                                }
                            </script>

                            <!-----End Update model---------->
                            <!-- search bar -->
                            <!-- <form action="">
                                <div class="row mt-5" style="width:95%;margin:0 auto;">
                                    <div class="col-lg-5">
                                        <input type="search" name="" placeholder="Search" class="form-control" id="">
                                    </div>
                          
                                    <div class="col-lg-2">
                                        <button style="width:100%;" class="btn btn-primary p-2">Search</button>
                                    </div>
                                </div>
                            </form> -->
                            <!-- searchbar end -->
                            <!-- buttons for export -->
                            <div class="row mt-5">
                                <div class="col-lg-2"></div>
                                <!-- <div class="col-lg-8">
                                    <button class="btn btn-primary">
                                        <ion-icon name="document-outline"></ion-icon>Export to CSV
                                    </button>
                                    <button class="btn btn-info">
                                        <ion-icon name="document-outline"></ion-icon>Export to Excel
                                    </button>
                                    <button class="btn btn-warning">
                                        <ion-icon name="print-outline"></ion-icon>Print
                                    </button>
                                    <button class="btn btn-danger">
                                        <ion-icon name="stop-outline"></ion-icon>Column Visibility
                                    </button>
                                    <button class="btn btn-dark">
                                        <ion-icon name="document-outline"></ion-icon>Export to PDF
                                    </button>
                                </div> -->
                            </div>
                            <!-- buttons for export end -->
                            <div class="iq-card-body" style="overflow:auto;">

                                <div class="search-container">
                                    <input type="text" id="searchInput" class="search-input" placeholder="Search by Bank Name, Account Number or Description..." onkeyup="filterTable()">
                                </div>

                                <table class="table table-hover table-bordered" id="bankTable">
                                    <thead>
                                        <tr>
                                            <th>Bank Name</th>
                                            <th>Opening Date</th>
                                            <th>Account Number</th>
                                            <th>Description</th>
                                            <!-- <th>Available Balance</th>  -->
                                            <th colspan="2">Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if (!empty($banks)): ?>
                                            <?php foreach ($banks as $bank): ?>
                                                <?php
                                                // Calculate the available balance: start_bank_balance + total_deposit - total_debit
                                                $available_balance = $bank['start_bank_balance'] + $bank['total_deposit'] - $bank['total_debit'];
                                                ?>
                                               <tr 
    <?php 
        $bankName = strtolower($bank['bank_name']);
        $bgColor = '';

        if (strpos($bankName, 'nadeem meezan bank') !== false || 
            strpos($bankName, 'nadeem easypaisa/jazzcash') !== false || 
            strpos($bankName, 'nadeem raast id') !== false) {
            $bgColor = 'background-color: green; color: white;';
        } elseif (strpos($bankName, 'babar meezan bank') !== false || 
                  strpos($bankName, 'babar alfalah bank') !== false) {
            $bgColor = 'background-color: orange; color: white;';
        } elseif (strpos($bankName, 'cash') !== false) {
            $bgColor = 'background-color: #f0f0f0;'; // light gray
        } elseif (strpos($bankName, 'credit') !== false) {
            $bgColor = 'background-color: #cce5ff;'; // light blue
        }

        echo $bgColor ? 'style="' . $bgColor . '"' : '';
    ?>
>
                                                    <td><?php echo htmlspecialchars($bank['bank_name']); ?></td>
                                                    <td><?php echo htmlspecialchars($bank['start_bank_date']); ?></td>
                                                    <td><?php echo htmlspecialchars($bank['account_number']); ?></td>
                                                    <td><?php echo htmlspecialchars($bank['description']); ?></td>
                                                    <!-- <td><?php echo number_format($available_balance, 2); ?> </td>  -->
                                                    <td>
                                                        <!-- Edit Button -->
                                                        <span class="edit-btn" onclick="openEditModal(<?php echo $bank['id']; ?>, '<?php echo addslashes($bank['bank_name']); ?>', '<?php echo addslashes($bank['start_bank_date']); ?>', '<?php echo addslashes($bank['account_number']); ?>', '<?php echo addslashes($bank['start_bank_balance']); ?>', '<?php echo addslashes($bank['description']); ?>')">
                                                            <ion-icon name="create-outline"></ion-icon>
                                                        </span>
                                                        <a href="bank_ledger.php?bank_id=<?php echo $bank['id']; ?>" class="view-ledger-btn">
                                                            <ion-icon name="eye-outline"></ion-icon>
                                                        </a>
                                                        <!-- Delete Button -->
                                                        <a href="action/delete_bank.php?id=<?php echo $bank['id']; ?>" class="delete-btn" onclick="return confirm('Warning: Deleting this bank record will also remove all related transactions, deposits, debit amounts, and payment records. This action cannot be undone. Are you sure you want to delete this bank and all associated data?');">
                                                            <ion-icon name="trash-outline"></ion-icon>
                                                        </a>

                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php else: ?>
                                            <tr>
                                                <td colspan="6">No banks found.</td>
                                            </tr>
                                        <?php endif; ?>
                                    </tbody>
                                </table>


                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    </div>
    <script>
        function filterTable() {
            var input = document.getElementById("searchInput");
            var filter = input.value.toLowerCase();

            // Get the table and rows
            var table = document.getElementById("bankTable");
            var rows = table.getElementsByTagName("tr");

            for (var i = 1; i < rows.length; i++) {
                var cells = rows[i].getElementsByTagName("td");
                var matchFound = false;

                for (var j = 0; j < cells.length; j++) {
                    var cell = cells[j];
                    if (cell) {
                        if (cell.textContent.toLowerCase().indexOf(filter) > -1) {
                            matchFound = true;
                            break;
                        }
                    }
                }

                if (matchFound) {
                    rows[i].style.display = "";
                } else {
                    rows[i].style.display = "none";
                }
            }
        }
    </script>

    <!-- Wrapper END -->
    <!-- Footer -->
    <?php include 'includes/footer.php'; ?>
    <nav class="iq-float-menu">
        <input type="checkbox" href="#" class="iq-float-menu-open" name="menu-open" id="menu-open" />
        <label class="iq-float-menu-open-button" for="menu-open">
            <span class="lines line-1"></span>
            <span class="lines line-2"></span>
            <span class="lines line-3"></span>
        </label>
        <button class="iq-float-menu-item bg-info" data-toggle="tooltip" data-placement="top" title="Direction Mode"
            data-mode="rtl"><i class="ri-text-direction-r"></i></button>
        <button class="iq-float-menu-item bg-danger" data-toggle="tooltip" data-placement="top" title="Color Mode"
            id="dark-mode" data-active="true"><i class="ri-sun-line"></i></button>
        <button class="iq-float-menu-item bg-warning" data-toggle="tooltip" data-placement="top" title="Comming Soon"><i
                class="ri-palette-line"></i></button>
    </nav>
    <!-- Footer END -->
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="js/jquery.min.js"></script>
    <!-- Rtl and Darkmode -->
    <script src="js/rtl.js"></script>
    <script src="js/customizer.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- Appear JavaScript -->
    <script src="js/jquery.appear.js"></script>
    <!-- Countdown JavaScript -->
    <script src="js/countdown.min.js"></script>
    <!-- Counterup JavaScript -->
    <script src="js/waypoints.min.js"></script>
    <script src="js/jquery.counterup.min.js"></script>
    <!-- Wow JavaScript -->
    <script src="js/wow.min.js"></script>
    <!-- Apexcharts JavaScript -->
    <script src="js/apexcharts.js"></script>
    <!-- Slick JavaScript -->
    <script src="js/slick.min.js"></script>
    <!-- Select2 JavaScript -->
    <script src="js/select2.min.js"></script>
    <!-- Owl Carousel JavaScript -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- Magnific Popup JavaScript -->
    <script src="js/jquery.magnific-popup.min.js"></script>
    <!-- Smooth Scrollbar JavaScript -->
    <script src="js/smooth-scrollbar.js"></script>
    <!-- lottie JavaScript -->
    <script src="js/lottie.js"></script>
    <!-- Chart Custom JavaScript -->
    <script src="js/chart-custom.js"></script>
    <!-- Custom JavaScript -->
    <script src="js/custom.js"></script>
</body>

</html>