-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmove-product.php
More file actions
62 lines (45 loc) · 2.24 KB
/
Copy pathmove-product.php
File metadata and controls
62 lines (45 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
session_start();
include("includes/db_conn.php");
$ErrorProduct = array();
$prod_name = mysqli_real_escape_string($db, $_POST['prod_name']);
$prod_qty = mysqli_real_escape_string($db, $_POST['prod_qty']);
// Check if product exist in warehouse
$get_wh = "SELECT * FROM tbl_warehouse WHERE prod_id = '$prod_name'";
$run_wh = mysqli_query($db, $get_wh);
$row_wh = mysqli_fetch_array($run_wh);
$qty = $row_wh['prod_qty'];
if(mysqli_num_rows($run_wh) > 0)
{
if($qty <= 0)
{
echo "<script>alert('Product selected is out of stock!')</script>";
echo "<script>document.location='move-prod-warehouse.php'</script>";
}
else
{
$username = $_SESSION['admin_username'];
$get_admin = "SELECT * FROM admin_tbl WHERE admin_username = '$username'";
$run_ad = mysqli_query($db, $get_admin);
$row_ad = mysqli_fetch_array($run_ad);
$admin_id = $row_ad['admin_id'];
$query = mysqli_query($db,"select prod_name from product_tbl where prod_id = '$prod_name'")or die(mysqli_error());
$row = mysqli_fetch_array($query);
$product = $row['prod_name'];
$remarks = "moved $prod_qty quantities of $product to store from warehouse";
mysqli_query($db, "INSERT INTO history_log(admin_id, action, log_date)VALUES('$admin_id', '$remarks', NOW())")or die(mysqli_error($db));
// Update product qty in store while reducing qty at the warehouse.
mysqli_query($db, "UPDATE product_tbl SET prod_qty = prod_qty + '$prod_qty' where prod_id = '$prod_name'") or die(mysqli_error($db));
mysqli_query($db, "UPDATE tbl_warehouse SET prod_qty = prod_qty - '$prod_qty' where prod_id = '$prod_name'") or die(mysqli_error($db));
// Insert product to move product table.
mysqli_query($db, "INSERT INTO tbl_warehse_prod_moved(admin_id, prod_id, product_qty, date_moved)VALUES('$admin_id', '$prod_name', '$prod_qty', NOW())")or die(mysqli_error($db));
echo "<script>alert('Product moved to store successfully!')</script>";
echo "<script>document.location='move-prod-warehouse.php'</script>";
}
}
else
{
echo "<script>alert('Product selected not stocked at the warehouse!')</script>";
echo "<script>document.location='move-prod-warehouse.php'</script>";
}
?>