-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.php
More file actions
211 lines (206 loc) · 8.4 KB
/
customer.php
File metadata and controls
211 lines (206 loc) · 8.4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Customer Details </title>
</head>
<body style="background-color:skyblue">
<hr />
<center> <h2> Customer Details </h2> </center>
<hr />
<center>
<form #action="details.php" method = "post">
<br />
<table>
<tr>
<td><br />Customer ID.       </td>
<td><br /><input type="name" name="cid" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />First Name       </td>
<td><br /><input type="name" name="fname" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />Middle Name       </td>
<td><br /><input type="name" name="mname" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />Last Name       </td>
<td><br /><input type="name" name="lname" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />Age       </td>
<td><br /><input type="name" name="age" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br /> Sex       </td>
<td><br /><input type="name" name="sex" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />Meicine Name       </td>
<td><br /><input type="name" name="name" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br />Store id       </td>
<td><br /><input type="name" name="sid" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<tr>
<td><br /> Buying Date       </td>
<td><br /><input type="name" name="date" /><font color="RED" SIZE="2">*(yyyy-mm-dd)</font>            </td>
</tr>
<tr>
<td><br />Quantity       </td>
<td><br /><input type="name" name="qty" /><font color="RED" SIZE="2">*</font>            </td>
</tr>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("Connection Failed");
}
if(!(mysql_select_db("medical_inventory", $con)))
{
die ("Database Not Selected");
}
if (isset($_POST['cid']) && isset($_POST['fname']) && isset($_POST['mname']) && isset($_POST['lname']) && isset($_POST['age']) && isset($_POST['sex']))
{
$query = "INSERT INTO customer(CID,Fname,Mname,Lname,Age,Sex) VALUES ('$_POST[cid]','$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[age]','$_POST[sex]')";
}
if (isset ($query))
$sql = mysql_query($query,$con);
if (isset($sql))
{
$cmp = $_POST['date'];
$query12 = "SELECT Batchno,Name FROM medicines WHERE ExpiryDate < '$cmp'";
if(isset($query12))
{
$sql12 = mysql_query($query12,$con);
}
if(isset($sql12))
{
$store = $_POST['sid'];
while($row = mysql_fetch_array($sql12))
{
$name = $row['Name'];
$batch = $row['Batchno'];
$query13 = "DELETE FROM contains WHERE Medname='$name' AND Medbatchno = '$batch' AND SSID = '$store'";
$query14 = "DELETE FROM medicines WHERE Name='$name' AND Batchno = '$batch'";
if(isset($query13))
mysql_query($query13,$con);
if(isset($query14))
mysql_query($query14,$con);
}
}
$ssid = $_POST['sid'];
$query = "SELECT * FROM contains WHERE SSID ='$ssid'";
if(isset($query))
{
$sql = mysql_query($query,$con);
}
$row = mysql_fetch_array($sql);
if(empty($row))
echo "<script>alert('Store does not contain this medicine!');</script>";
else
{
$query = "SELECT SUM(Qty) FROM contains GROUP BY '$ssid'";
$sql = mysql_query($query,$con);
$row = mysql_fetch_array($sql);
if(empty($row))
echo "<script>alert('Store does not contain this medicine!');</script>";
else
{
if($row['SUM(Qty)'] >= $_POST['qty'])
{
if (isset($_POST['cid']) && isset($_POST['name']) && isset($_POST['sid']) && isset($_POST['qty']) && isset($_POST['date']))
{ $query = "select * from contains JOIN medicines on contains.Medname=medicines.Name AND contains.Medbatchno=medicines.Batchno where Medname like '%".$_POST['name']."%' and SSID = ".$_POST['sid']." and Qty = ".$_POST['qty'].";";
$sql = mysql_query($query,$con);
$row = mysql_fetch_array($sql);
if($row)
{
/*calculate price*/
$cid = $_POST['cid'];
$name = $_POST['name'];
$qty = $_POST['qty'];
$date = $_POST['date'];
$price = $row['Price'] * $qty;
mysql_query("insert into customermedicine(CCID,Medname,MedBatchno,Qty,Price,SSID,Buyingdate) values('$cid','$name','$row[Medbatchno]','$qty','$price','$row[SSID]','$date');",$con);
mysql_query("delete from contains where Medname like '%".$_POST['name']."%' and SSID = ".$_POST['sid']." and Qty = ".$_POST['qty'].";",$con);
mysql_query("DELETE FROM medicines WHERE Name LIKE '%".$_POST['name']."%' AND Batchno=".$row['Medbatchno'].";",$con);
///////// write medicine code
}
else
{
$flag = "1";
$query = "select * from contains JOIN medicines on contains.Medname=medicines.Name AND contains.Medbatchno=medicines.Batchno where Medname like '%".$_POST['name']."%' and SSID = ".$_POST['sid'].";";
$sql = mysql_query($query,$con);
while($row = mysql_fetch_array($sql))
{
$cid = $_POST['cid'];
$name = $_POST['name'];
$qty = $_POST['qty'];
$date = $_POST['date'];
//echo "djh";
if($flag)
{
$new = $row['Qty'];
$new = $new - $_POST['qty'];
if($new > "0")
{
$price = $row['Price'] * $qty;
mysql_query("insert into customermedicine(CCID,Medname,MedBatchno,Qty,Price,SSID,Buyingdate) values('$cid','$name','$row[Medbatchno]','$qty','$price','$row[SSID]','$date');",$con);
mysql_query("UPDATE contains set Qty = $new WHERE Medname LIKE '%".$_POST['name']."%' AND Medbatchno=".$row['Medbatchno'].";",$con);
$flag = "0";
}
else if($new < "0")
{
$price = $row['Price'] * $row['Qty'];
mysql_query("insert into customermedicine(CCID,Medname,MedBatchno,Qty,Price,SSID,Buyingdate) values('$cid','$name','$row[Medbatchno]','$row[Qty]','$price','$row[SSID]','$date');",$con);
mysql_query("DELETE FROM contains WHERE Medname LIKE '%".$_POST['name']."%' AND Medbatchno=".$row['Medbatchno'].";",$con);
mysql_query("DELETE FROM medicines WHERE Name LIKE '%".$_POST['name']."%' AND Batchno=".$row['Medbatchno'].";",$con);
$_POST['qty'] = $_POST['qty'] - $row['Qty'];
}
else if($new == "0")
{
$price = $row['Price'] * $row['Qty'];
mysql_query("insert into customermedicine(CCID,Medname,MedBatchno,Qty,Price,SSID,Buyingdate) values('$cid','$name','$row[Medbatchno]','$row[Qty]','$price','$row[SSID]','$date');",$con);
mysql_query("DELETE FROM contains WHERE Medname LIKE '%".$_POST['name']."%' AND Medbatchno=".$row['Medbatchno'].";",$con);
mysql_query("DELETE FROM medicines WHERE Name LIKE '%".$_POST['name']."%' AND Batchno=".$row['Medbatchno'].";",$con);
$flag ="0";
}
}
}
}
}
}
else
{
echo "<script>alert('Store does not contain required amount of medicine!');</script>";
$query = "select * from contains JOIN medicines on contains.Medname=medicines.Name AND contains.Medbatchno=medicines.Batchno where Medname like '%".$_POST['name']."%' and SSID = ".$_POST['sid'].";";
$sql = mysql_query($query,$con);
$cid = $_POST['cid'];
$name = $_POST['name'];
$date = $_POST['date'];
while($row = mysql_fetch_array($sql))
{
$price = $row['Price'] * $row['Qty'];
mysql_query("insert into customermedicine(CCID,Medname,MedBatchno,Qty,Price,SSID,Buyingdate) values('$cid','$name','$row[Medbatchno]','$row[Qty]','$price','$row[SSID]','$date');",$con);
mysql_query("DELETE FROM contains WHERE Medname LIKE '%".$_POST['name']."%' AND Medbatchno=".$row['Medbatchno'].";",$con);
mysql_query("DELETE FROM medicines WHERE Name LIKE '%".$_POST['name']."%' AND Batchno=".$row['Medbatchno'].";",$con);
}
//$flag ="0";
}
header ("Location:option.php");
}
}
}
else
{
echo "<br /> <font size='2' color='red'>*Required Fields are Mandotary</font>";
}
?>
</table>
<br /><br /><input type ="submit" value="Submit">
</center>
</form>
</body>
</html>