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

$id = $_GET["id"];
$rec = mysqli_query($connection,"select * from products where id = '$id'");
$row = mysqli_fetch_array($rec); 

// Handle purchase addition
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit2"])) {
    $product_id = $_POST["product_id"]; // Use the product ID retrieved from the previous page
    $name1 = $_POST["name1"];
    $category1 = $_POST["category1"];
    $stock_qty1 = $_POST["stock_qty1"];
    $unit_pr1 = $_POST["price1"];
    $date_time1 = date("Y-m-d");
    $supplier_name = $_POST["supplier_name"];
    $number_unit = $_POST["number_unit"];
    $company_category = $_POST["company_category"];
    @$retail_price = $_POST["retail_price"];
    @$percentage = $_POST["percentage"];
    $total_amount = $_POST["total_amount"];
    $trade_price = $_POST["trade_price"];
    $expiry = $_POST["expiry"];
    $rack_no = $_POST["rack_no"];
    $batch_no = $_POST["batch_no"];
    $total_quantity = $_POST["total_quantity"];
	$lose_qty = $_POST["lose_qty"];
	$tp_per_unit = $_POST["tp_per_unit"];
     // Assuming you're passing the ID through a hidden field in the form

    // Update purchase information in the database
    $productSql = "UPDATE products 
                   SET name = '".$name1."', 
                       product_id = '".$product_id."', 
                       total_quantity = '".$total_quantity."', 
                       price = '".$retail_price."', 
                       stock_qty = '".$stock_qty1."',
					   lose_qty = '".$lose_qty."', 
                       number_unit = '".$number_unit."', 
                       percentage = '".$percentage."', 
                       trade_price = '".$trade_price."',
					   tp_per_unit = '".$tp_per_unit."', 
                       total_amount = '".$total_amount."', 
                       supplier_name = '".$supplier_name."', 
                       category = '".$category1."', 
                       company_category = '".$company_category."', 
                       unit_pr = '".$unit_pr1."', 
                       batch_no = '".$batch_no."', 
                       expiry = '".$expiry."', 
                       rack_no = '".$rack_no."', 
                       date_time = '".$date_time1."', 
                       login_user = '".$userName."', 
                       user_role = '".$userRole."', 
                       outlet_name = '".$outlet_name."', 
                       outlet_address = '".$outlet_address."' 
                   WHERE id = '".$id."'";


    if ($connection->query($productSql) === TRUE) {
        // Purchase added successfully
        header("location:addproduct.php");
    } else {
        echo "Error adding purchase: " . $productSql . "<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>Opening</title>
<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>
 #product-container-wrapper {
    max-height: 700px; /* 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;
    }
}

/* Custom styles for sidebar */    /* 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(270deg, #060606, #0A5064);
        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 + padding */
      margin-left: 100px; /* Width of sidebar */
      padding-top: 30px; /* Height of fixed header */
    }
	/* Custom styles for search bar */
    .search-container {
      display: flex;
      align-items: center;
      width: 300px;
      margin: 2px auto;
    }
    .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);
            }
        }
		label{font-size:12px; font-weight:600;}
		</style>
<body>

<?php include("common/hd.php"); ?>
<!-- Sidebar -->
<?php include("common/sd.php"); ?>
<div class="main-content">
<?php // echo $id; ?>

<?php
// Fetch supplier data
$rec1236 = mysqli_query($connection, "SELECT * FROM supplier 
                                    WHERE user_name = '$userName' 
                                    AND user_role = '$userRole' 
                                    AND outlet_name = '$outlet_name' 
                                    AND outlet_address = '$outlet_address'");
?>
<div class="container">
<div class="row">
<div class="col-sm-9">
<h3 style="color:#212529;">Update Product</h3>
</div>
<div class="col-sm-3">
<a href="addproduct.php"><button type="button" class="btn btn-dark" style="float:left;"><i class="fa fa-arrow-left"></i></button></a>
</div>
</div>

</div><br />
<div class="container">
<div class="row">

<div class="col-sm-4">

   <form method="post" action="products_up.php?id=<?php echo $id;?>" enctype="multipart/form-data">
                
                    <div class="form-group">
                    <label>Supplier</label>
                        <input type="text" class="form-control"  name="supplier_name" value="<?php echo $row["supplier_name"];?>"  >
                       
                        
                    </div>
                    <div class="form-group">
                     <label>Company</label>
                    <input type="text" name="category1"  class="form-control" value="<?php echo $row["category"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Category</label>
                     <input type="text" name="company_category" class="form-control" value="<?php echo $row["company_category"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Product</label>
                    <input type="text" name="name1"  class="form-control" value="<?php echo $row["name"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Product ID</label>
                    <input type="text" name="product_id"  class="form-control" value="<?php echo $row["product_id"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Pack Quantity</label>
                    <input type="text" name="stock_qty1" 
                     class="form-control" value="<?php echo $row["stock_qty"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Lose Quantity</label>
                    <input type="text" name="lose_qty" 
                     id="retail_price" class="form-control" value="<?php echo $row["lose_qty"];?>"   />
                    </div>
                    
                    
                    
                    </div>
                    <div class="col-sm-4">
                     <div class="form-group">
                    <label>Retail Price Per Pack</label>
                    <input type="text" name="retail_price" 
                     id="retail_price" class="form-control" value="<?php echo $row["price"];?>"   />
                    </div>
                    <div class="form-group">
                    
                    <label>% Apply</label>
                    <input type="text" name="percentage" 
                    class="form-control" value="<?php echo $row["percentage"];?>"  />
                    </div>
                    <div class="form-group">
                    
                    <label>% Extra</label>
                    <input type="text" name="percentage" 
                    class="form-control" value="<?php echo $row["extra_percentage"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Trade Price Per Pack</label>
                    <input type="text" name="trade_price" 
                    class="form-control"  value="<?php echo $row["trade_price"];?>"  />
                    </div>
                    
                    <div class="form-group">
                    <label>No Of Unit Per Pack</label>
                    <input type="text" name="number_unit"  
                    class="form-control" value="<?php echo $row["number_unit"];?>"  />
                    </div>
                     <div class="form-group">
                    <label>T.P Per Unit</label>
                    <input type="text" name="tp_per_unit" class="form-control" value="<?php echo $row["tp_per_unit"];?>"    />
                    </div>
                    <div class="form-group">
                    <label>R.P Per Unit</label>
                    <input type="text" name="price1" class="form-control" value="<?php echo $row["unit_pr"];?>"    />
                    </div>
                   
                   
                    
                   
                   
                   </div>
                    <div class="col-sm-4">
                     <div class="form-group">
                    <label>Total Quantity</label>
                    <input type="text" class="form-control" name="total_quantity" value="<?php echo $row["total_quantity"];?>"    />
                    </div>
                     <div class="form-group">
                    <label>Total Amount</label>
                    <input type="text" name="total_amount"   class="form-control" value="<?php echo $row["total_amount"];?>"  />
                    </div>
                     <div class="form-group">
                    <label>Rack No</label>
                    <input type="text" name="rack_no"   class="form-control" value="<?php echo $row["rack_no"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Batch No</label>
                    <input type="text" name="batch_no"   class="form-control" value="<?php echo $row["batch_no"];?>"  />
                    </div>
                    <div class="form-group">
                    <label>Expiry Date</label>
                    <input type="date" name="expiry"   class="form-control" value="<?php echo $row["expiry"];?>"  />
                    </div>
                    
                    <button type="submit" name="submit2" class="btn btn-dark form-control">Enter</button>
     
                </form>
  </div>
  <div class="col-sm-1">
    
  </div>
     </div>
     </div>           
 </div>               
</body>
<script>


        function toggleSidebar() {
      document.getElementById("sidebar").classList.toggle("hide");
    }
    // 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>
