-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkregisitem.php
153 lines (134 loc) · 4.04 KB
/
checkregisitem.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
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
<?php
require_once('connect.php');
session_start();
if (isset($_POST['regisItemSubmit']) && ($_SESSION['userStatus']=="ADMIN"||$_SESSION['userStatus']=="STAFF")){
?>
<?php
$memberIdToRegis= $_POST['memberIdInput'];
$useMember = $_POST['useMember'];
echo "userMemberCheckBOx:".$useMember."<br>";
echo "MemberId:".$memberIdToRegis."<br>";
$staffId = $_SESSION['staffId'];
$varObtainService =0;
$varItemsId= array();
$varItemsName= array();
$varItemsPrice= array();
$varItemQuantity=array();
$countItemsRow = 0;
$totalPrice =0;
$q="select * from item";
$result=$mysqli->query($q);
if(!$result){
echo "Select failed. Error: ".$mysqli->error ;
}
while($row=$result->fetch_array()){ ?>
<?php $varItemsName[$countItemsRow] = $row['itemName'];
$varItemsId[$countItemsRow] = $row['itemId'];
$varItemsPrice[$countItemsRow] = $row['price'];
$varItemQuantity[$countItemsRow] = $_POST[($row['itemName']."Vol")];
$countItemsRow+=1;
?>
<?php } ?>
<?php
for ($y = 0; $y < $countItemsRow; $y++) {
if($varItemQuantity[$y]>0){
$varObtainService =1;
}
}
?>
<?php
$varObtainMemberId=0;
if($useMember == "1"){
echo "Placed";
$q = "SELECT * FROM `member` WHERE memberId='".$memberIdToRegis."'";
if ($res = $mysqli->query($q))
{
if (mysqli_num_rows($res) == 1)
{
$row = $res->fetch_array();
$varObtainMemberId=1;
}
}
}
elseif ($useMember == "0") {
$varObtainMemberId=1;
echo "failed";
}
else {
$varObtainMemberId=0;
}
?>
<?php
if ($varObtainService==1 && $varObtainMemberId==1) {
$q = "SELECT `generateServiceId`() AS `generateServiceId`";
if ($res = $mysqli->query($q))
{
if (mysqli_num_rows($res) == 1)
{
$row = $res->fetch_array();
$servideId = $row['generateServiceId'];
}
}
// echo "Staff ID : ".$_SESSION['staffId'];
echo "<br>";
echo "ServiceId is :".$servideId;
echo "<br>";
for ($x = 0; $x < $countItemsRow; $x++) {
if($varItemQuantity[$x]>0){
echo "ItemId: ".$varItemsId[$x];
echo " ";
echo "ItemName: ".$varItemsName[$x];
echo " ";
echo "ItemPrice: ".$varItemsPrice[$x];
echo " ";
echo "ItemQuantity: ".$varItemQuantity[$x];
echo " ";
echo "<br>";
$itemQuantity = $varItemQuantity[$x];
$itemId = $varItemsId[$x];
if($useMember=="0"){
$memberIdToRegis = 9999;
$q="INSERT INTO `regisitem` (`memberId`,`staffId`,`serviceId`,`itemId`,`quantity`) VALUES ('$memberIdToRegis','$staffId','$servideId','$itemId','$itemQuantity')";
$result=$mysqli->query($q);
if(!$result){
echo "INSERT failed. Error: ".$mysqli->error ;
}
}
else {
$q="INSERT INTO `regisitem` (`memberId`,`staffId`,`serviceId`,`itemId`,`quantity`) VALUES ('$memberIdToRegis','$staffId','$servideId','$itemId','$itemQuantity')";
$result=$mysqli->query($q);
if(!$result){
echo "INSERT failed. Error: ".$mysqli->error ;
}
}
$totalPrice = $totalPrice+($varItemsPrice[$x]*$varItemQuantity[$x]);
}
}
$q="SELECT curdate() as currentDate";
$currentDate = 0;
if ($res = $mysqli->query($q))
{
if (mysqli_num_rows($res) == 1)
{
$row = $res->fetch_array();
$currentDate=$row['currentDate'];
}
}
$q ="INSERT INTO `laundryservice` (`serviceId`,`staffId`,`memberId`,`dateIn`,`dateOut`,`serviceStatus`,`totalPrice`) VALUES('$servideId','$staffId','$memberIdToRegis','$currentDate','-','NF','$totalPrice')";
$result=$mysqli->query($q);
if(!$result){
echo "INSERT failed. Error: ".$mysqli->error ;
}
header("Refresh: 1; url=regisItem.php");
echo "<h1>Done.</h1>";
}
elseif($varObtainMemberId==0){
header("Refresh: 1; url=regisItem.php");
echo "<h1>Member id not found </h1>";
}
else{
header("Refresh: 1; url=regisItem.php");
echo "<h1>No item to register </h1>";
}
}
?>