<div class="row ">
    <?php
	session_start();
	require_once 'db_connection.php'; ?>
    <script src="process.js"></script>
    <?php

	$searchbarcode = $_POST['searchbarcode'];

	$sql1 = "SELECT itemcode,status FROM mobileproducts WHERE itemcode='$searchbarcode' AND status=1 LIMIT 1";
	$result1 = $conn->query($sql1);
	if ($result1->num_rows > 0) {
		$productinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT prid,itemcode,status FROM mobileproducts WHERE itemcode='$searchbarcode' AND status=1 LIMIT 1"));
		$prid = $productinfo['prid'];
		echo "<script>addProductById(" . $prid . ")</script>";
	}


	if ($searchbarcode) {
		$sql = "SELECT * FROM mobileproducts WHERE itemcode='$searchbarcode' OR proname LIKE '%$searchbarcode%'  AND status=1";
	} else {
		$sql = "SELECT * FROM mobileproducts WHERE status=1";
	}
	$result = $conn->query($sql);

	if ($result->num_rows > 0) {
		// output data of each row
		while ($row = $result->fetch_assoc()) {

			$prid = $row["prid"];
			$proname = $row["proname"];
			$discount = $row["discount"];
			$price = $row["sellprice"];
			$qty = $row["qty"];
			$cover = $row["cover"];
			$mqty = $row["mqty"];
			$itemcode = $row["itemcode"];

			$user_qury_02 = mysqli_query($conn, "SELECT * FROM tbl_user_branch WHERE user_id='" . $_SESSION['user_id'] . "'");
			$user_res = mysqli_fetch_assoc($user_qury_02);
			$user_branch = $user_res['branch_id'];

			$user_qury_03 = mysqli_query($conn, "SELECT * FROM tbl_stock WHERE prid = '$prid' AND branch_id='$user_branch'");
			$user_res1 = mysqli_fetch_assoc($user_qury_03);
			$sqty = $user_res1['qty'];

	?>
    <div class="div_wrap" onclick="addProductById(<?php echo $row['prid']; ?>);">
        <div class="fix_textnps">
            <div class="image_images">
                <?php if ($cover == "") {
							$pro_img = "images/eimage.png";
						} else {
							$pro_img = "images/products/cover/" . $cover;
						} ?><img src="<?php echo $pro_img; ?>" alt="">
                <h6>
                    <?php echo $proname; ?>
                </h6>
            </div>
            <p>
                <?php echo $itemcode; ?>
            </p>
            <?php if ($user_res1['qty'] < $mqty) { ?>
            <h6 class="text-primary">
                Qty Low <?php if ($user_res1['qty'] != 0) : ?> | <?php echo $user_res1['qty'];
																			endif; ?>
            </h6>
            <?php } else { ?>
            <h6 class="text-primary">Qty : <?php echo $user_res1['qty']; ?></h6>
            <?php } ?>

            <h6 class="btn btn-block btn-sm btn-outline-dark active text-white">
                Rs.
                <?php echo number_format((float) $price, 2);
						if ($discount > 0) {
							echo "  (" . $discount . "%)";
						} ?>
            </h6>
        </div>
    </div>
    <?php

		}
	} else {
		echo "   Not Found Any Products..";
	}

	?>
</div>