<?php
include("db/cn.php");
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'];
}
//$cr_id = $_GET["cr_id"];
@$supplier_name = $_GET["supplier_name"];
//echo $cr_nickname;
$rec =  mysqli_query($connection,"select * from purchases where supplier_name = '$supplier_name' && paid_by = 'credit' ");
$row1 = mysqli_fetch_array($rec);
//echo $row1["order_id"];
//@$order_id = $row1["order_id"];


$date_time1 = date("Y-m-d");
$rec10 = mysqli_query($connection, "SELECT supplier_name, sum(total_amount) AS total_credit FROM purchases WHERE supplier_name = '$supplier_name'  AND paid_by = 'credit' GROUP BY supplier_name ");
//&& user_name = '$userName' AND user_role = '$userRole'
if ($rec10) {
    $total_sales = 0;
    while ($row3 = mysqli_fetch_array($rec10)) {
        $total_sales += $row3['total_credit'];
    }
    echo "";
    if (mysqli_num_rows($rec10) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
$date_time21 = date("Y-m-d");
$cash_out = mysqli_query($connection, "SELECT SUM(supplier_amount) AS total_amount FROM supplier_paid where user_name = '$userName' && user_role = '$userRole' && supplier_name = '$supplier_name'   ");
if ($cash_out) {
    $cash_outdata = mysqli_fetch_array($cash_out);
    if ($cash_outdata && isset($cash_outdata['total_amount'])) {
        $totalAmount = $cash_outdata['total_amount'];
        echo "";
    } else {
        echo ".";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}


$cash_purchase = mysqli_query($connection, "SELECT SUM(total_amount) AS total_amount FROM purchases where user_name = '$userName' && user_role = '$userRole' && supplier_name = '$supplier_name' && paid_by = 'cash'  ");
if ($cash_purchase) {
    $cash_purchase_data = mysqli_fetch_array($cash_purchase);
    if ($cash_purchase_data && isset($cash_purchase_data['total_amount'])) {
        $totalAmount_cash = $cash_purchase_data['total_amount'];
        echo "";
    } else {
        echo ".";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}

//-------------------------------------------------------------
$cash_purchases_r = mysqli_query($connection, "SELECT * FROM purchases_r where user_name = '$userName' && user_role = '$userRole' && supplier_name = '$supplier_name' && paid_by = 'credit' && date_time = '$date_time21'  ");
if ($cash_purchases_r) {
    $cash_purchase_data_r = mysqli_fetch_array($cash_purchases_r);
    if ($cash_purchase_data_r && isset($cash_purchase_data_r['total_amount'])) {
        $totalAmount_cash_r = $cash_purchase_data_r['total_amount'];
        echo "";
    } else {
        echo ".";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}

//--------------------------------------------------------------

$supplier_out = mysqli_query($connection, "SELECT SUM(open_amount) AS total_amount FROM supplier_opening_amount where user_name = '$userName' && user_role = '$userRole' && supplier_name = '$supplier_name'   ");
if ($supplier_out) {
    $supplier_outdata = mysqli_fetch_array($supplier_out);
    if ($supplier_outdata && isset($supplier_outdata['total_amount'])) {
        $totalAmount_supplier = $supplier_outdata['total_amount'];
        echo "";
    } else {
        echo ".";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}



if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["supplier_paid"])){
$date_time = $_POST["date_time"];
	$supplier = $_POST["supplier_name"];
	$amount = $_POST["supplier_amount"];
	$status = $_POST["status"];
	
	
	 mysqli_query($connection,"insert into supplier_paid(supplier_name,supplier_amount,status,date_time,user_name,user_role,outlet_name,outlet_address)
values('".$supplier."','".$amount."','".$status."','".$date_time."','".$userName."','".$userRole."','".$outlet_name."','".$outlet_address."')");

}

if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["supplier_open"])){
$date_time32 = date("Y-m-d");
			$supplier_name = $_POST["supplier_name"];
			$open_amount = $_POST["open_amount"];
			 
			 mysqli_query($connection,"insert into supplier_opening_amount(supplier_name,open_amount,date_time,user_name,user_role,outlet_name,outlet_address)
			 values('".$supplier_name."','".$open_amount."','".$date_time32."','".$userName."','".$userRole."','".$outlet_name."','".$outlet_address."');");
}

if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["supplier_close"])){
	
	// Check connection
if ($connection->connect_error) {
  die("Connection failed: " . $connection->connect_error);
}

// Retrieve values from $_POST
$supplier_name = $_POST['supplier_name'];
$opening_cash = $_POST['opening_cash'];
$cash_purchase = $_POST['cash_purchase'];
$cash_paid = $_POST["cash_paid"];
$credit_purchase = $_POST['credit_purchase'];
$closing_balance = $_POST["closing_balance"];
$date_time211 = date("Y-m-d");

// Calculate closing balance
//$closing_balance = $opening_cash - $cash_purchase - $credit_purchase;

// Prepare SQL query
$sql = "INSERT INTO supplier_closing(supplier_name, opening_cash, cash_purchase, credit_purchase, cash_paid, closing_balance, user_name, user_role, outlet_name, outlet_address, date_time) VALUES ('$supplier_name', '$opening_cash', '$cash_purchase', '$credit_purchase', '$cash_paid', '$closing_balance', '$userName', '$userRole', '$outlet_name', '$outlet_address', '$date_time211')";

// Execute SQL query
if ($connection->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $connection->error;
}
	
	}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Supplier - Detail</title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<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 -->
    <script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
</head>

<style>
 #table-container-wrapper {
    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-color: #060606;
        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-color: #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);
        }
    }	
		/* Basic styling */
    .tab {
        display: none;
        padding: 20px;
    }
    .active {
        display: block;
    }
    .tab-buttons {
        display: flex;
    }
    .tab-button {
        cursor: pointer;
        padding: 10px 10px;
        background-color: #ffff;
        border: 1px solid #0A5064;
        border-radius: 5px 5px 0 0;
        margin-right: 5px;
		color:#212529;
    }
    .tab-button.active {
        background-color: #212529;
		color:#fff;
    }

    /* Background colors for tab content */
    #tab1 {
        background-color: #fff;
		color:#212529;
		padding:20px;
    }
    #tab2 {
        color:#212529;
		background-color: ;
    }
    #tab3 {
		color:#212529;
        background-color: ;
    }
</style>

<body> 

<?php include("common/hd.php");?>
<!-- Sidebar -->
<?php include("common/sd.php"); ?>
<div class="main-content">
<br />
<div class="container">
<div class="row">
<div class="col-sm-9">
<h3 style="color:#212529;">Supplier Detail</h3>
</div>
<div class="col-sm-3">
<a href="supplier.php"><button type="button" class="btn btn-dark "><i class="fa fa-arrow-left"></i></button></a>
<button type="button" class="btn btn-dark btn-sm" data-toggle="modal" data-target="#addPurchaseModal">
               Paid
            </button>
             <button type="button" class="btn btn-dark btn-sm" data-toggle="modal" data-target="#addopenPurchaseModal">
              Add Open
            </button>
</div>
</div>
<br />
<div class="container">
<div class="row">
<div class="col-sm-3  text-dark text-capitalize" >
<span style="padding:10px; border-radius:7px; font-size:18px; border:1px solid #0A5064;"><?php echo $supplier_name; ?></span></div>
<div class="col-sm-9"></div>

</div>
</div>
<br /><br />
<div class="container">
<div class="tab-buttons">
    <div class="tab-button active" onclick="openTab(event, 'tab1')">Overview</div>
    <div class="tab-button" onclick="openTab(event, 'tab2')">Purchase</div>
    <div class="tab-button" onclick="openTab(event, 'tab4')">Purchase Return</div>
    <div class="tab-button" onclick="openTab(event, 'tab3')">Cash Paid</div>
</div>
<?php
$close_balance1 =  $total_sales + @$totalAmount_supplier;
$close = $close_balance1 - @$totalAmount - @$totalAmount_cash_r;

?>
<div class="tab-container">
    <div id="tab1" class="tab active">
    <h4>Overview</h4>
    <form method="post" action="supplier_detail.php?supplier_name=<?php echo $supplier_name; ?>">
    <input type="hidden" value="<?php echo $supplier_name; ?>" name="supplier_name"  />
    <div class="container ">
        <div class="row" style="padding:20px;background:#fff; box-shadow: 0px 0px 5px 2px #CCC; border-radius:10px;">
            <div class="col-sm-12" style="padding:20px;">
            <table class="table table-hover"  >
            <tr style="color:#8A1218;padding:20px;">
            <td style="font-weight:600;">Opening Cash</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($totalAmount_supplier) ? "Rs ".$totalAmount_supplier."" : ""; ?>
      <input type="hidden" value="<?php echo isset($totalAmount_supplier) ? "Rs ".$totalAmount_supplier."" : ""; ?>" name="opening_cash"  />
			</td>
            
            </tr>
            <tr>
            <td style="font-weight:600;">Cash Purchase</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($totalAmount_cash) ? "Rs ".$totalAmount_cash."" : ""; ?>
       <input type="hidden" value="<?php echo isset($totalAmount_cash) ? "Rs ".$totalAmount_cash."" : ""; ?>" name="cash_purchase"  />
			</td>
            </tr>
            
            <tr>
            <td style="font-weight:600;">Credit Purchase</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($total_sales) ? "Rs ".$total_sales."" : ""; ?>
     <input type="hidden" value="<?php echo isset($total_sales) ? "Rs ".$total_sales."" : ""; ?>" name="credit_purchase"  />
			</td>
            </tr>
            <tr>
            <td style="font-weight:600;">Purchase Return</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($totalAmount_cash_r) ? "Rs ".$totalAmount_cash_r."" : ""; ?>
       <input type="hidden" value="<?php echo isset($totalAmount_cash_r) ? "Rs ".$totalAmount_cash_r."" : ""; ?>" name="cash_purchases_r"  />
			</td>
            </tr>
            <tr>
            <td style="font-weight:600;">Cash Paid</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($totalAmount) ? "Rs ".$totalAmount."" : ""; ?>
        <input type="hidden" value="<?php echo isset($totalAmount) ? "Rs ".$totalAmount."" : ""; ?>" name="cash_paid"  />
			</td>
            </tr> 

            <tr>
            <td style="font-weight:600;">Closing Balance</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
            <?php echo isset($close) ? "Rs ".$close."" : ""; ?>
      <input type="hidden" value="<?php echo isset($close) ? "Rs ".$close."" : ""; ?>" name="closing_balance"  />
			</td>
            </tr>
                     
            </table>
            <button style="submit" class="btn btn-dark btn-sm" name="supplier_close">Save</button>
            </div>
            
            
        </div>
        <br />
        
        
    </div>
     </form>
    <p></p>
</div>
    <div id="tab2" class="tab">
        <h4>Purchase</h4>
        <div class="container">
           <div class="row">
              
    
            <br />
            </div>
            
           
        
             <div class="col-sm-12" id="table-container-wrapper">
               <table class="table table-stripped table-sm text-center">
                <tr style="background:#212529; color:#fff;">
                <td>Date</td>
                <td>Amount</td>
                <td>Method</td>
                <td> By</td>
                </tr>
               <?php  
			   $rec3 = mysqli_query($connection,"select * from purchases  where supplier_name = '$supplier_name'    ");
			   while($row3 = mysqli_fetch_array($rec3)){
			   ?>
              <tr>
              <td><?php echo $row3['date_time']; ?></td>
              <td>Rs. <?php echo $row3['total_amount']; ?></td>
              <td class="text-capitalize"><?php echo $row3["paid_by"];?></td>
              <td style="text-transform:capitalize;"><?php echo $row3['user_name']; ?></td>
              </tr>
              <?php }?>
               </table>
             </div>
           </div>
          </div>
          <div id="tab4" class="tab">
        <h4>Purchase</h4>
        <div class="container">
           <div class="row">
              
    
            <br />
            </div>
            
           
        
             <div class="col-sm-12" id="table-container-wrapper">
               <table class="table table-stripped table-sm text-center">
                <tr style="background:#212529; color:#fff;">
                <td>Date</td>
                <td>Amount</td>
                <td>Method</td>
                <td> By</td>
                </tr>
               <?php  
			   $rec3 = mysqli_query($connection,"select * from purchases_r  where supplier_name = '$supplier_name'     ");
			   while($row3 = mysqli_fetch_array($rec3)){
			   ?>
              <tr>
              <td><?php echo $row3['date_time']; ?></td>
              <td>Rs. <?php echo $row3['total_amount']; ?></td>
              <td class="text-capitalize"><?php echo $row3["paid_by"];?></td>
              <td style="text-transform:capitalize;"><?php echo $row3['user_name']; ?></td>
              </tr>
              <?php }?>
               </table>
             </div>
           </div>
          </div>
    </div>
    <div id="tab3" class="tab">
        <h4>Cash Paid</h2>
        <div class="container ">
           <div class="row">
       
            </div>
           
           <br />
             <div class="col-sm-12" id="table-container-wrapper">
               <table class="table table-stripped table-sm text-center text-capitalize">
                <tr style="background:#212529; color:#fff;">
                
                <td>Date</td>
                
                <td>Amount</td>
                <td>Method</td>
                <td>By</td>
                </tr>
              <?php 
			  
			  
			  $rec1 = mysqli_query($connection,"select * from supplier_paid where  supplier_name = '$supplier_name' ");
			  while($row2 = mysqli_fetch_array($rec1)){
			  
			  ?>
              <tr>
              
              <td><?php echo $row2["date_time"];?></td>
              
              <td>Rs <?php echo $row2["supplier_amount"]; ?> </td>
              <td><?php echo $row2["status"]; ?></td>
              <td> <?php echo $row2["user_name"];?></td>
              </tr>
              <?php } ?>
              </table>
             </div>
           </div>
          </div>
    </div>

<div class="modal fade" id="addopenPurchaseModal" tabindex="-1" role="dialog" 
            aria-labelledby="addPurchaseopenModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title text-capitalize" id="addPurchaseopenModalLabel">Add Opening Amount</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <!-- Form for adding purchase -->
                            <form method="post" action="supplier_detail.php?supplier_name=<?php echo $supplier_name; ?>" enctype="multipart/form-data">
                            
                                <input type="hidden" value="<?php echo $supplier_name; ?>" name="supplier_name" placeholder="Name" class="form-control" />
                             
                                <input type="text" name="open_amount" placeholder="Amount" class="form-control" />
                               <br />
                               <!-- <input class="form-control" type="date" name="date_time"  />
                                <br />-->
                                <button type="submit" name="supplier_open"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

<div class="modal fade" id="addPurchaseModal" tabindex="-1" role="dialog" 
            aria-labelledby="addPurchaseModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title text-capitalize" id="addPurchaseModalLabel">Supplier Paid</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <!-- Form for adding purchase -->
                            <form method="post" action="supplier_detail.php?supplier_name=<?php echo $supplier_name; ?>" enctype="multipart/form-data">
                            
                                <input type="text" name="supplier_name" placeholder="Supplier Name" class="form-control" />
                                <br />
                                <input type="text" name="supplier_amount" placeholder="Amount" class="form-control" />
                               <br />
                                <select name="status" class="form-control">
                                <option value="">Select Method</option>                                
                                    <option value="cash">Cash</option>
                                    <option value="bank">Bank</option>
                                    <option value="other">Other</option>
                                </select>
                                <br />
                                <input type="date" name="date_time" class="form-control" />
                                <br />
                                <button type="submit" name="supplier_paid"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

</div>

   
</div>    
</body>

<script>
 // Function to switch between tabs
    function openTab(evt, tabName) {
        // Get all elements with class="tab" and hide them
        var tabs = document.getElementsByClassName("tab");
        for (var i = 0; i < tabs.length; i++) {
            tabs[i].style.display = "none";
        }

        // Get all elements with class="tab-button" and remove the class "active"
        var tabButtons = document.getElementsByClassName("tab-button");
        for (var i = 0; i < tabButtons.length; i++) {
            tabButtons[i].classList.remove("active");
        }

        // Show the current tab, and add an "active" class to the button that opened the tab
        document.getElementById(tabName).style.display = "block";
        evt.currentTarget.classList.add("active");
    }
   
   
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);
});
 
   
   
	</script>
<!-- jQuery library -->
<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>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

</html>