File "addproduct.php"

Full path: /home/atrmarke/public_html/atrdemolive.site/bshop/log/addproduct.php
File size: 0.02 KB (18.21 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?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'];
}

// Retrieve products from the database
$products_query = "SELECT * FROM products";
$products_result = $connection->query($products_query);

if($_GET){
    $id = $_GET["id"];
    $del_query = mysqli_query($connection,"delete FROM products where id = '$id'
    ");
        echo "<script type='text/javascript'>window.location.href = 'addproduct.php';</script>";
}
ob_end_flush();
?>



<!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>Product Management</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" />
  
</head>

<style>
 #product-container-wrapper {
    max-height: 700px; /* Adjust the maximum height as needed */
    overflow-y: auto; /* Enable vertical scroll when content overflows */
}
/* Custom styles for sidebar */
 #table-container-wrapper {
    max-height: 500px; /* 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, #3C2F23);
        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: #503F2E;
    }

    /* 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(270deg, #060606, #3C2F23);
        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: #503F2E;
        color: #fff;
        border: 1px solid #503F2E;
    }

    .btn-dark:hover {
        background: #fff;
        color: #503F2E;
        border: 1px solid #503F2E;
    }

    .bg-dark2 {
        background: #503F2E;
        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);
        }
    }

	
		
		        #searchResults {
            position: absolute;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            max-height: 200px;
            overflow-y: auto;
            width: 85%;
            display: none;
        }
        #searchResults div {
            padding: 10px;
            cursor: pointer;
        }
        #searchResults div:hover {
            background-color: #f1f1f1;
        }
</style>

<body>

<?php
if(isset($msg)){
	
	echo $msg;
	}
?>
<?php include("common/hd.php"); ?>
<!-- Sidebar -->
<?php include("common/sd.php"); ?>
<div class="main-content">
<div class="container">
<div class="row">
<div class="col-sm-7">
<h3 style="color:#212529;"> Product Management</h3>

</div>
<div class="col-sm-5" style="border:1px solid #CCCCCC; padding:7px; border-radius:4px;">
<div class="search-container">
    <input type="text" id="search-input" class="form-control" placeholder="Search Product by Name:-" />
    <div class="search-icon">
      
    </div>
  </div>

</div>
</div>

</div>

<div class="contanier">
<div class="row">
<?php
/*$total_e = mysqli_query($connection,"select SUM(total_amount)  AS qty from products");
$t = mysqli_fetch_array($total_e);
*/
?>
<div class="col-sm-3" >
<?php    
/*
$qty = $t["qty"];
$final =  $qty;
echo "Total Amount of Inventory :".'  Rs '.number_format($final, 2);*/
?>
</div>
<div class="col-sm-5"></div>
<div class="col-sm-4"></div>

</div>
</div>

<br />
    <div class="container text-center">
      <div class="row">
        <div class="col-sm-10" id="product-container-wrapper">
            <div class="row text-center" id="products-container" >
<?php
// Fetch products from database
$sql = "SELECT * FROM products";
$result = $connection->query($sql);

if ($result->num_rows > 0) {
    echo '<table id="productTable" class="table table-stripped table-hover table-sm">';
    echo '<tr style="color:#fff; background:#212529; font-size:14px;">';
    echo '<th>Sr#</th>';
    echo '<th>Item Code</th>';
     echo '<th>R.~ Qty ~</th>';
    echo '<th>Supplier</th>';
     echo '<th>Class</th>';
    echo '<th>Company</th>';
    echo '<th>Product</th>';
    echo '<th>Retail Price(Rs)</th>';
    echo '<th>Total Amount(Rs)</th>';
    echo '<th>Update</th>';
    echo '<th>Delete</th>';
    echo '</tr>';
$sr_no = 1;
    while ($row = $result->fetch_assoc()) {
        // Check if quantity is less than 5
        $rowStyle = $row["quantity"] < 5 ? 'background-color: red; color: white;' : '';

        echo '<tr style="font-size:14px; ' . $rowStyle . '" class="product-row" data-category="'.$row["company"].'">';
        echo '<td style="font-weight:600;">' . $sr_no++ . '</td>';
        echo '<td style="font-weight:600;">' . $row["product_id"] . '</td>';
        echo '<td style="font-weight:600;">' . $row["quantity"] . '</td>';
        echo '<td style="font-weight:600; text-transform:capitalize;">' . $row["supplier"] . '</td>';
        echo '<td class="text-capitalize" style="font-weight:600;">' . $row["size"] . '</td>';
        echo '<td class="text-capitalize" style="font-weight:600;">' . $row["company"] . '</td>';
        echo '<td style="font-weight:700;">' . $row["product_name"] . '</td>';
        echo '<td class="text-capitalize"> ' . $row["retail_price"] . ' </td>';
        echo '<td> ' . $row["total_amount"] . ' </td>';
        echo '<td><a href="product_update.php?id=' . $row["id"] . '"><button type="button" class="btn btn-dark btn-sm"><i class="fas fa-clipboard-check"></i></button></a></td>';
        echo '<td><a href="addproduct.php?id=' . $row["id"] . '"><button type="button" class="btn btn-danger btn-sm">x</button></a></td>';
        echo '</tr>';
    }

    echo '</table>';
} else {
    echo "No products found";
}
?>

                </div>
        </div>
        
        <div class="col-sm-2" >
		<?php
        
        
        if ($connection->connect_error) {
            die("Connection failed: " . $connection->connect_error);
        }
        
        $sql12 = "SELECT DISTINCT company FROM products";
        $result12 = $connection->query($sql12);
        
        $categories = [];
        if ($result12->num_rows > 0) {
            while ($row12 = $result12->fetch_assoc()) {
                $categories[] = $row12['company'];
            }
        }
        ?>
     <input type="text" id="searchInput" autocomplete="off" class="form-control" placeholder="Search Company">
     <div id="searchResults"></div>

            <br />
        <a href="addproducts.php"><button type="button" class="btn btn-dark form-control" data-toggle="modal" data-target="#addProductModal">
               Existing Stock
            </button></a>
        
<br />

      <!-- <a href="checkqr.php"> <button type="button" class="btn btn-dark form-control" style="margin-top:14px;">Check Barcode</button></a>-->
       
  <a href="purchase_n.php"><button type="button" class="btn btn-dark form-control"  style="margin-top:14px;">
            Existing Purchase
            </button></a>
            
             
       
 <a href="new_product.php"><button type="button" class="btn btn-dark form-control"  style="margin-top:14px;">
             New Product
            </button></a>
        </div>    
       </div>
    </div>
    
    
</div>    
</body>
 <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.addEventListener("DOMContentLoaded", function () {
    const products = document.querySelectorAll('.product-row');
    let currentIndex = -1;

    // Function to handle up and down arrow keys
    document.addEventListener("keydown", function(event) {
        if (event.key === "ArrowDown" || event.key === "ArrowUp") {
            event.preventDefault();
            if (currentIndex === -1) {
                currentIndex = 0;
            } else {
                currentIndex += event.key === "ArrowDown" ? 1 : -1;
            }
            if (currentIndex < 0) currentIndex = 0;
            if (currentIndex >= products.length) currentIndex = products.length - 1;
            products[currentIndex].focus();
            products[currentIndex].scrollIntoView({ behavior: 'smooth', block: 'center' });
        }
    });

    // Set tabindex and index for each row
    products.forEach((row, index) => {
        row.setAttribute('tabindex', '0');
        row.dataset.index = index;
        row.addEventListener('focus', function() {
            currentIndex = parseInt(row.dataset.index);
        });
    });
});
document.addEventListener("DOMContentLoaded", function () {
    const categories = <?php echo json_encode($categories); ?>;
    const searchInput = document.getElementById('searchInput');
    const searchResults = document.getElementById('searchResults');
    const products = document.querySelectorAll('.product-row');

    searchInput.addEventListener('input', function () {
        const query = this.value.trim().toLowerCase();
        if (query === '') {
            searchResults.style.display = 'none';
            showAllProducts();
            return;
        }
        const filteredCategories = categories.filter(category => category.toLowerCase().includes(query));
        renderResults(filteredCategories);
        filterProducts(filteredCategories);
    });

    searchInput.addEventListener('blur', function () {
        setTimeout(() => {
            searchResults.style.display = 'none';
        }, 200); // Delay hiding dropdown to allow click event on dropdown items
    });

    function renderResults(results) {
        let html = '';
        results.forEach(result => {
            html += `<div>${result}</div>`;
        });
        searchResults.innerHTML = html;
        searchResults.style.display = 'block';
    }

    function filterProducts(filteredCategories) {
        products.forEach(function (product) {
            const category = product.getAttribute('data-category');
            if (!filteredCategories.includes(category)) {
                product.style.display = 'none';
            } else {
                product.style.display = 'table-row';
            }
        });
    }

    function showAllProducts() {
        products.forEach(function (product) {
            product.style.display = 'table-row';
        });
    }

    searchResults.addEventListener('click', function (event) {
        const clickedItem = event.target;
        if (clickedItem.tagName === 'DIV') {
            searchInput.value = clickedItem.innerText;
            searchResults.style.display = 'none';
            filterProducts([clickedItem.innerText]);
        }
    });
});
 
 document.addEventListener("DOMContentLoaded", function() {
    document.getElementById("search-input").addEventListener("input", function() {
        var searchText = this.value.toLowerCase();
        var rows = document.querySelectorAll(".product-row");

        rows.forEach(function(row) {
            var productName = row.querySelector("td:nth-child(8)").textContent.toLowerCase();
            if (productName.includes(searchText)) {
                row.style.display = "table-row";
            } else {
                row.style.display = "none";
            }
        });
    });
});



   
    // Function to toggle submenu
    function toggleSubMenu(element) {
        $(element).next('.sub-menu').slideToggle();
    }
</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>