-
Notifications
You must be signed in to change notification settings - Fork 0
/
quantity_upd.php
81 lines (42 loc) · 2.23 KB
/
quantity_upd.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
error_reporting(1);
include("dbcon.php");
session_start();
if(!isset($_SESSION['user_session'])){
header("location:index.php");
}
$hid_qty = $_POST['hid_qty'];
$upd_qty = $_POST['qty'];
$med_id = $_POST['med_id'];
$med_name = $_POST['med_name'];
$med_cat = $_POST['med_cat'];
$ex_date = $_POST['ex_date'];
$select_sql = "SELECT * from stock where medicine_name = '$med_name' and category = '$med_cat' and expire_date = '$ex_date' ";
$result1 = mysqli_query($con,$select_sql);
while($row=mysqli_fetch_array($result1)){
$amount =$upd_qty * $row['selling_price'];
$profit_amount =$upd_qty * $row['profit_price'];
$quantity = $row['act_remain_quantity'];
}
echo $avai_qty;
if($upd_qty > $quantity){
}else{
$update_sql = "UPDATE stock SET used_quantity = (used_quantity - '$hid_qty') + '$upd_qty' , remain_quantity = (remain_quantity + '$hid_qty')-'$upd_qty' where medicine_name = '$med_name' and category = '$med_cat' and expire_date = '$ex_date' ";
$result = mysqli_query($con,$update_sql);
$update_sql1 = "UPDATE on_hold SET qty = '$upd_qty' , amount = '$amount' , profit_amount = '$profit_amount' where id = '$med_id'";
$result2 = mysqli_query($con,$update_sql1);
$select_sql1= "SELECT remain_quantity from stock where medicine_name = '$med_name' and category = '$med_cat' and expire_date = '$ex_date' ";
$result3 = mysqli_query($con,$select_sql1);
while($row = mysqli_fetch_array($result3)){
$remain_quantity = $row['remain_quantity'];
}
if($remain_quantity <= 0){
$update_quantity_sql = "UPDATE stock set status = 'Unavailable' where medicine_name = '$med_name' and expire_date = '$ex_date' ";//********Updating Unavailable if medicine_qty is zero***********
$update_quantity_query = mysqli_query($con,$update_quantity_sql);
}
if($remain_quantity > 0){
$update_quantity_sql1 = "UPDATE stock set status = 'Available' where medicine_name = '$med_name' and expire_date = '$ex_date'";//********Updating Unavailable if medicine_qty is zero***********
$update_quantity_query1 = mysqli_query($con,$update_quantity_sql1);
}
}
?>