<?php

include 'load.php';

?>

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

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard">
    <meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard">
    <meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard">
    <meta name="robots" content="noindex, nofollow">

    <title>Product List | Eat More Resturant   | Pos & Invetory System | Dashboard</title>

<?php
require_once 'headercss.php';
?>

</head>

<body>

    <div class="main-wrapper">
<?php
require_once 'header.php';
?>

        <?php
require_once 'navbar.php';
?>

        <div class="page-wrapper">
            <div class="content">
                <div class="page-header">
                    <div class="page-title">
                        <h4>Product List</h4>
                        <h6>Manage your products</h6>
                    </div>




                    <div class="page-btn">
                        <a href="addproduct.php" class="btn btn-added"><img src="assets/img/icons/plus.svg" alt="img"
                                class="me-1">Add New Product</a>
                    </div>
                </div>

                <div class="card">
                    <div class="card-body">
                        <div class="table-top">


                        </div>
						
						<div class="card mb-0" id="filter_inputs" style="display:block;">
							<div class="card-body pb-0">
								<div class="row">
									<div class="col-lg-12 col-sm-12">
										<form method="GET" enctype="multipart/form-data">
											<div class="row">
                        <div class="col-md-6">
                            <select class="form-control select2" name="supplier" required>
                                <option value="">Select Supplier</option>
                                <?php 
				
					$sql = "SELECT * FROM mobilesuppliers";
					$result = $conn->query($sql);

					if ($result->num_rows > 0) {
						while($row = $result->fetch_assoc()) { ?>
                                <option value="<?php echo $row['spid']; ?>"><?php echo $row['spname']; ?></option>
                                <?php }
					}
				?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <button class="btn btn-success btn-sm btn-block" type="submit" name="submit" style="width:100%;">Search</button>
                            </form>
                        </div>
                        <div class="col-md-3">
                        <button onclick="deleteSelectedRows()" class="btn btn-danger btn-sm btn-block" style="width:100%;">Delete Selected Rows</button>

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

									</div>
								</div>
							</div>
						</div>
		
<?php 
	if(isset($_GET['supplier'])){
		$supplier = $_GET['supplier'];

		$search = "AND supplier='$supplier'";
	}else{
		$search = "";
	}
?>

<hr>
		
                        <div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="selectall">
  <label class="form-check-label" for="flexCheckDefault">
    Select All
  </label>
</div>
                        <div class="table-responsive">
<table class="table" id="betable">
                                <thead>
                                    <tr>
                                        <th>#</th>
										<th>ID</th>
                                        <th>Action</th>
                                        <th>Status</th>
                                        <th>Type</th>
                                        <th>Product Code</th>
                                        <th>Barcode/Item/Room Code</th>
                                        <th>Product</th>
                                        <th>Category</th>
                                        <th>Sub Category</th>
                                        <th>Brand</th>
                                        <th>Supplier</th>
                                        <th>Unit</th>
										<th>Minimum Qty</th>
                                        <th>Qty</th>
                                        <th>Discount</th>
                                        <th>Tax</th>
                                        <th>Cost Price</th>
										<th>Market Price</th>
										<th>Profit</th>
										<th>Sell Price</th>
                                        <th>Add Date</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php

										$count=0;
										
										$dis=0;
										$taxx=0;
										$totalrowqty=0;
										$totalrowdis=0;
										$totalrowtaxx=0;
										$totalrowprice=0;
										$totalrowmarket_price=0;
										$totalrowprofitmargin=0;
										$totalrowsellprice=0;
										
										$stmt = $DB_con->prepare('SELECT * FROM mobileproducts WHERE prid != 0 '.$search.' ORDER BY prid');

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);
										
										$totalrowqty=$totalrowqty+$row["qty"];
										$totalrowdis=$totalrowdis+$dis;
										$totalrowtaxx=$totalrowtaxx+$taxx;
										$totalrowprice=$totalrowprice+$row["price"];
										$totalrowmarket_price=$totalrowmarket_price+$row["market_price"];
										$totalrowprofitmargin=$totalrowprofitmargin+$row["profitmargin"];
										$totalrowsellprice=$totalrowsellprice+$row["sellprice"];
										
										$count++;

										?>
                                    <tr>
                                        <td><input type="checkbox" class="delete-checkbox"
                                                value="<?php echo $row["prid"]; ?>"></td>
                                        <td><?php echo number_format($count,0); ?></td>
                                        <td>

                                            <a href="editproduct.php?prid=<?php echo $row["prid"]; ?>"
                                                class="btn btn-block btn-outline-primary active btn-sm text-white"><i
                                                    class="fa fa-edit" data-bs-toggle="tooltip" title=""
                                                    data-bs-original-title="fa fa-edit" aria-label="fa fa-edit"></i></a>
                                            <a href="deleteproduct.php?prid=<?php echo $row["prid"]; ?>"
                                                class="btn btn-block btn-outline-danger active btn-sm text-white"><i
                                                    class="fa fa-trash" data-bs-toggle="tooltip" title=""
                                                    data-bs-original-title="fa fa-trash"
                                                    aria-label="fa fa-trash"></i></a>

                                        </td>
                                        <td><?php 
						
														if($row['status'] == "1"){

														echo '<a class="btn btn-success btn-sm text-white">Active</a>';

													    }else if($row['status'] == "0"){

														echo '<a class="btn btn-danger btn-sm text-white">Deactive</a>';

														}
						
												
											  ?></td>
                                        <td><?php echo $row['producttype']; ?></td>
                                        <td><a href="javascript:void(0);"><?php echo $row['prcode']; ?></a></td>
                                        <td><?php echo $row['itemcode']; ?></td>
                                        <td><?php echo $row['proname']; ?></td>
                                        <td><?php
if($row['category'] == "0"){
													
												}else{	
												$id = $row['category'];  

												$query = $DB_con->prepare('SELECT catename FROM mobilecategory WHERE ctid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['catename'];
}
												?></td>
                                        <td><?php
if($row['subcategory'] == "0"){
													
												}else{	
												$id = $row['subcategory'];  

												$query = $DB_con->prepare('SELECT subname FROM mobilesubcategory WHERE sbid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['subname'];
}
												?></td>
                                        <td>
                                            <?php 
if($row['brand_id']){
$brand_id = $row['brand_id']; 
$brand= mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobile_brand WHERE brand_id='$brand_id'"));

echo $brand['brand_name'];
}
?>

                                        </td>






                                        <td><?php
if($row['supplier'] == "0"){
													
												}else{	
												$id = $row['supplier'];  

												$query = $DB_con->prepare('SELECT spname FROM mobilesuppliers WHERE spid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['spname'];
}
												?></td>
                                        <td><?php
if($row['unit'] == "0"){
													
												}else{	
												$id = $row['unit'];  

												$query = $DB_con->prepare('SELECT unit_name FROM unit WHERE unit_id='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['unit_name'];
}
												?></td>
										<td><?php echo number_format((int)$row['mqty']); ?></td>
                                        <td><?php echo number_format((int)$row['qty']); ?></td>
                                        <td>Rs.<?php 
                                         if($row['discount_type1']==1){
                                            $dis = $row['discount1']."%";
                                        }else{
                                            $dis = $row['discount1'];
                                        }
                                        
                                        echo $dis; ?></td>
                                        <td>Rs.<?php 
                                        if($row['tax_type1']==1){
											$taxx = $row['tax1']."%";
										}else{
											$taxx = $row['tax1'];
										}
                                        
                                        echo $taxx; ?></td>
                                        <td>Rs.<?php echo number_format((float)$row['price'],2); ?></td>
                                        <td>Rs.<?php echo number_format((float)$row['market_price'],2); ?></td>
										<td>Rs.<?php echo number_format((float)$row['profitmargin'],2); ?></td>
										<td>Rs.<?php echo number_format((float)$row['sellprice'],2); ?></td>
                                        <td>
										<?php echo date_format(date_create($row['add_date']), "M d, Y | h:i:s "); ?>
										</td>
                                    </tr> 
                                    <?php 
} 
}
?>
                                </tbody>
								<tfoot style="background-color:#008b0b;color:#ffffff;">
									<tr>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
									    <th><strong>All Total</strong></th>
										<th><?php echo number_format((float)$totalrowqty,2); ?></th>
										<th><?php echo number_format((float)$totalrowdis=$totalrowdis+$dis,2); ?></th>
										<th><?php echo number_format((float)$totalrowtaxx=$totalrowtaxx+$taxx,2); ?></th>
										<th>Rs.<?php echo number_format((float)$totalrowprice,2); ?></th>
										<th>Rs.<?php echo number_format((float)$totalrowmarket_price,2); ?></th>
										<th>Rs.<?php echo number_format((float)$totalrowprofitmargin,2); ?></th>
										<th>Rs.<?php echo number_format((float)$totalrowsellprice,2); ?></th>
										<th></th>
									</tr>
								</tfoot>
                            </table>
                        </div>
                       
                    </div>
                </div>
            </div>
        </div>

    </div>
    </div>
    </div>
	
<?php require_once 'footerjs2.php'; ?>

</body>
</html>