diff --git a/admin/request_manage.php b/admin/request_manage.php
new file mode 100644
index 0000000..ab07454
--- /dev/null
+++ b/admin/request_manage.php
@@ -0,0 +1,74 @@
+error;
+
+ // echo $_GET['var'];
+ $order = $_GET['order'];
+
+ $q_details = "SELECT OrderDetails FROM Orders WHERE OrderId=$order";
+ $details = $conn->query($q_details);
+
+ $item_id = "";
+ $quantity = "";
+
+ if ($details->num_rows > 0)
+ {
+ while($row = $details->fetch_assoc())
+ {
+ echo $row['OrderDetails'];
+ $pieces = explode(": ", $row['OrderDetails']);
+
+ $item_id_ = explode(" ", $pieces[1]);
+ $quantity_ = explode(" ", $pieces[3]);
+
+ $item_id = $item_id_[0];
+ $quantity = $quantity_[0];
+
+ echo $item_id;
+ echo $quantity;
+ }
+ }
+
+ $q_sel = "SELECT Id, quantity from Items WHERE Id=$item_id";
+ $q_sel_res = $conn->query($q_sel);
+ $prev_quan = "";
+
+ if ($q_sel_res->num_rows > 0)
+ {
+ while($row = $q_sel_res->fetch_assoc())
+ {
+ $prev_quan = $row['quantity'];
+ }
+ }
+
+ echo $prev_quan;
+
+ $final_quan = number_format($prev_quan)-number_format($quantity);
+
+ if($_GET['var']=='1')
+ {
+ $sql = "UPDATE Orders SET Status='Approved' WHERE OrderId=$order";
+ $result = $conn->query($sql);
+
+ $sql2 = "UPDATE Orders SET Admin_Remarks='Thanks for Ordering' WHERE OrderId=$order";
+ $result2 = $conn->query($sql2);
+
+ $update_inv = "UPDATE Items SET quantity=$final_quan WHERE Id=$item_id";
+ $update_inv_res = $conn->query($update_inv);
+
+ echo "";
+ }
+ else if($_GET['var']=='0')
+ {
+ $sql = "UPDATE Orders SET Status='Rejected' WHERE OrderId=$order";
+ $result = $conn->query($sql);
+
+ $sql2 = "UPDATE Orders SET Admin_Remarks='Your order is rejected. Please order again after 10 days.' WHERE OrderId=$order";
+ $result2 = $conn->query($sql2);
+
+ echo "";
+ }
+?>
\ No newline at end of file
diff --git a/admin/requests.php b/admin/requests.php
index e6a6ee4..cf27c31 100644
--- a/admin/requests.php
+++ b/admin/requests.php
@@ -31,6 +31,7 @@
Admin Remarks |
Approve |
Reject |
+ Order Status |
@@ -41,12 +42,11 @@
$conn = OpenCon();
echo $conn->error;
- $sql = "SELECT OrderId,UserId, OrderDetails, Remarks FROM Orders WHERE Status is NULL";
+ $sql = "SELECT OrderId, UserId, OrderDetails, Status, Remarks FROM Orders";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
- // output data of each row
$count = 0;
while($row = $result->fetch_assoc())
{
@@ -54,36 +54,29 @@
$sql1 = "SELECT email from Users where id='$id'";
$result1 = $conn->query($sql1);
$count++;
+
+ $order = $row['OrderId'];
+
echo "";
echo "" . $row['OrderId'] . " | ";
echo "" . $row['UserId'] . " | ";
echo "" . $result1->fetch_assoc()['email'] . " | ";
echo "" . $row['OrderDetails'] . " | ";
echo "" . $row['Remarks'] . " | ";
- // echo " | ";
+
echo " | ";
- echo ' | ';
- echo ' | ';
+ echo "Approve | ";
+ echo "Reject | ";
+ echo "" . $row['Status'] . " | ";
+ echo "
";
}
}
else
{
echo "Database Error";
- }
-
-
- if (isset($_POST['approve']))
- {
- $sql = "UPDATE Orders SET Status='Approved' WHERE OrderId=$val";
- $result = $conn->query($sql);
- }
- else if (isset($_POST['reject']))
- {
- $sql = "UPDATE Orders SET Status='Rejected' WHERE OrderId=$val";
- $result = $conn->query($sql);
- }
-
+ }
?>
+
diff --git a/database.sql b/database.sql
index 480000f..1b9edee 100644
--- a/database.sql
+++ b/database.sql
@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
--- Generation Time: Nov 16, 2020 at 05:30 AM
+-- Generation Time: Nov 25, 2020 at 11:50 PM
-- Server version: 10.3.25-MariaDB-0ubuntu0.20.04.1
-- PHP Version: 7.0.33-29+ubuntu18.04.1+deb.sury.org+1
@@ -22,18 +22,41 @@ SET time_zone = "+00:00";
-- Database: `inventory`
--
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `inventory` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
+
+USE `inventory`;
+
+
+
-- --------------------------------------------------------
--
--- Table structure for table `Items`
+-- Table structure for table `Cart`
--
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `inventory` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
-USE `inventory`;
+DROP TABLE IF EXISTS `Cart`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+
+CREATE TABLE `Cart` (
+ `CartId` int(11) NOT NULL,
+ `UserId` int(11) NOT NULL,
+ `Quantity` int(11) NOT NULL,
+ `Price` int(11) NOT NULL,
+ `ChemName` text NOT NULL,
+ `ChemId` int(11) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `Items`
+--
DROP TABLE IF EXISTS `Items`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
+
CREATE TABLE `Items` (
`id` int(11) NOT NULL,
`name` varchar(1000) CHARACTER SET utf8 NOT NULL,
@@ -48,8 +71,8 @@ CREATE TABLE `Items` (
INSERT INTO `Items` (`id`, `name`, `company`, `quantity`, `price`) VALUES
(1, 'Acetylacetone', 'Alfa Aeser', 100, 50),
-(2, 'Benzoic Acid', 'SDFCL', 200, 50),
-(3, 'Benzoic Acid', 'Sigma-Aldrich', 300, 50),
+(2, 'Benzoic Acid', 'SDFCL', 194, 50),
+(3, 'Benzoic Acid', 'Sigma-Aldrich', 291, 50),
(4, 'Camphorsulfonic Acid', 'Sigma-Aldrich', 300, 50),
(5, 'Dioctyl sulfosuccinate sodium salt', 'Sigma-Aldrich', 300, 50),
(6, 'Ethanediol', 'SDFCL', 400, 50),
@@ -63,46 +86,71 @@ INSERT INTO `Items` (`id`, `name`, `company`, `quantity`, `price`) VALUES
--
-- Table structure for table `Orders`
--
+
DROP TABLE IF EXISTS `Orders`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
+
CREATE TABLE `Orders` (
`OrderId` int(11) NOT NULL,
`UserId` int(11) NOT NULL,
`OrderDetails` text NOT NULL,
`Remarks` text NOT NULL,
- `Status` text
+ `Status` text DEFAULT NULL,
+ `Admin_Remarks` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+--
+-- Dumping data for table `Orders`
+--
+
+INSERT INTO `Orders` (`OrderId`, `UserId`, `OrderDetails`, `Remarks`, `Status`, `Admin_Remarks`) VALUES
+(17, 1, 'chemicalId: Camphorsulfonic Acid quantity: 3 price: 50', 'Remarks...', 'Rejected', 'Your order is rejected. Please order again after 10 days.'),
+(18, 1, 'chemicalId: Dioctyl sulfosuccinate sodium salt quantity: 2 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
+(19, 1, 'chemicalId: Benzoic Acid quantity: 1 price: 50', 'Remarks...', 'Rejected', 'Your order is rejected. Please order again after 10 days.'),
+(20, 1, 'chemicalId: Benzoic Acid quantity: 1 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
+(21, 1, 'chemicalId: 2 name: Benzoic Acid quantity: 2 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
+(22, 1, 'chemicalId: 3 name: Benzoic Acid quantity: 1 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
+(23, 1, 'chemicalId: 3 name: Benzoic Acid quantity: 1 price: 50', 'Remarks...', 'Approval pending', 'Your request will be approved soon');
+
-- --------------------------------------------------------
--
-- Table structure for table `Users`
--
+
DROP TABLE IF EXISTS `Users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
+
CREATE TABLE `Users` (
`id` int(11) NOT NULL,
`firstname` varchar(30) NOT NULL,
`lastname` varchar(30) NOT NULL,
`email` varchar(50) DEFAULT NULL,
`reg_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
- `contact` varchar(15) NOT NULL
+ `contact` varchar(15) NOT NULL,
+ `Address` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `Users`
--
-INSERT INTO `Users` (`id`, `firstname`, `lastname`, `email`, `reg_date`, `contact`) VALUES
-(1, 'Khyati', 'Agarwal', 'test@gmail.com', '2020-11-01 22:17:05','9876543212'),
-(2, 'Jai', 'Luthra', 'test2@gmail.com', '2020-11-01 22:17:32','9182736456');
+INSERT INTO `Users` (`id`, `firstname`, `lastname`, `email`, `reg_date`, `contact`, `Address`) VALUES
+(1, 'Khyati', 'Agarwal', 'test@gmail.com', '2020-11-25 18:12:08', '9876543212', 'Flat no. 312, Sector 83, Faridabad, Haryana'),
+(2, 'Jai', 'Luthra', 'test2@gmail.com', '2020-11-01 22:17:32', '9182736456', '');
--
-- Indexes for dumped tables
--
+--
+-- Indexes for table `Cart`
+--
+ALTER TABLE `Cart`
+ ADD PRIMARY KEY (`CartId`);
+
--
-- Indexes for table `Items`
--
@@ -125,6 +173,12 @@ ALTER TABLE `Users`
-- AUTO_INCREMENT for dumped tables
--
+--
+-- AUTO_INCREMENT for table `Cart`
+--
+ALTER TABLE `Cart`
+ MODIFY `CartId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
+
--
-- AUTO_INCREMENT for table `Items`
--
@@ -135,7 +189,7 @@ ALTER TABLE `Items`
-- AUTO_INCREMENT for table `Orders`
--
ALTER TABLE `Orders`
- MODIFY `OrderId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
+ MODIFY `OrderId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;
--
-- AUTO_INCREMENT for table `Users`
diff --git a/user/cart.php b/user/cart.php
index 4de2f1f..eb035ca 100755
--- a/user/cart.php
+++ b/user/cart.php
@@ -60,24 +60,36 @@
if(isset($_POST["check_row_$count"]))
{
- $cart .= "chemicalId: " . $row['name'] . " quantity: " . $_POST["quantity_$count"] . " price: " . $row['price'] . "
";
-
- echo "";
- echo "" . $row['name'] . " | ";
- echo "" . $_POST["quantity_$count"] . " | ";
- echo "" . $row['price'] . " | ";
- $items ++;
- $total += $row['price'] * $_POST["quantity_$count"];
- echo "
";
+
+ $sql_cart_insert = "INSERT INTO Cart (UserId, ChemName, Quantity, Price, ChemId) VALUES ('1','".$row['name']."', '".$_POST["quantity_$count"]."', '".$row['price']."', '".$row['id']."')";
+ $result_cart = $conn->query($sql_cart_insert);
+
}
}
}
- else
+
+ $sql_cart = "SELECT UserId, Quantity, Price, ChemName, ChemId FROM Cart";
+ $result_cart = $conn->query($sql_cart);
+
+ if ($result_cart->num_rows > 0)
{
- echo "Database Error";
- }
+ while($row = $result_cart->fetch_assoc())
+ {
+ if($row['UserId']=='1')
+ {
+
+ $cart .= "chemicalId: " . $row['ChemId'] . " name: " . $row['ChemName'] . " quantity: " . $row["Quantity"] . " price: " . $row['Price'] . "
";
-
+ echo "";
+ echo "" . $row['ChemName'] . " | ";
+ echo "" . $row['Quantity'] . " | ";
+ echo "" . $row['Price'] . " | ";
+ $items ++;
+ $total += $row['Price'] * $row["Quantity"];
+ echo "
";
+ }
+ }
+ }
echo "";
diff --git a/user/inventory.php b/user/inventory.php
index a4a9325..69097bb 100755
--- a/user/inventory.php
+++ b/user/inventory.php
@@ -88,7 +88,8 @@
-
+
+
diff --git a/user/orders.php b/user/orders.php
index 2e7fe45..2a9e3a1 100644
--- a/user/orders.php
+++ b/user/orders.php
@@ -45,7 +45,7 @@
$conn = OpenCon();
echo $conn->error;
- $sql = "SELECT Orders.UserId,Orders.OrderId,Orders.OrderDetails FROM Orders WHERE Orders.UserId=1";
+ $sql = "SELECT Orders.UserId,Orders.OrderId,Orders.OrderDetails,Orders.Status,Orders.Admin_Remarks FROM Orders WHERE Orders.UserId=1";
$result = $conn->query($sql);
$count = 0;
@@ -60,8 +60,8 @@
echo "" . $row['UserId'] . " | ";
echo "" . $row['OrderId'] . " | ";
echo "" . $row['OrderDetails'] . " | ";
- echo "Approval Pending | ";
- echo "Your request will be approved soon | ";
+ echo "" . $row['Status'] . " | ";
+ echo "" . $row['Admin_Remarks'] . " | ";
}
}
else
diff --git a/user/send_order.php b/user/send_order.php
index e9730a6..a46d84e 100644
--- a/user/send_order.php
+++ b/user/send_order.php
@@ -5,6 +5,9 @@
$conn = OpenCon();
echo $conn->error;
+ $cart_delete = "DELETE FROM Cart WHERE UserId=1";
+ $cart_q = $conn->query($cart_delete);
+
$details = $_GET['cart'];
$remarks = $_POST['remark'];
// echo $details;
@@ -13,7 +16,7 @@
foreach ($a as $b){
if($b != "")
{
- $insert_q = "INSERT INTO Orders (UserId, OrderDetails, Remarks) VALUES (1 , '".$b."' , '".$remarks."')";
+ $insert_q = "INSERT INTO Orders (UserId, OrderDetails, Remarks, Status, Admin_Remarks) VALUES (1 , '".$b."' , '".$remarks."', 'Approval pending', 'Your request will be approved soon')";
$result_insert = $conn->query($insert_q);
}
}
diff --git a/user/user_profile.php b/user/user_profile.php
index 5935c2b..a73d254 100644
--- a/user/user_profile.php
+++ b/user/user_profile.php
@@ -33,7 +33,7 @@
$conn = OpenCon();
echo $conn->error;
- $sql = "SELECT id, firstname, lastname, email, reg_date, contact FROM Users WHERE id=1";
+ $sql = "SELECT id, firstname, lastname, email, reg_date, contact, Address FROM Users WHERE id=1";
$result = $conn->query($sql);
if ($result->num_rows > 0)
@@ -43,10 +43,12 @@
{
echo "
";
echo "" . $row['firstname'] ." ".$row['lastname'] . "
";
+ echo "
";
echo "Email : " . "" . $row['email'] . "
";
echo "UserId : " . "" . $row['id'] . "" . "
";
echo "
Contact : " . "" . $row['contact'] . "";
echo "
Reg. Date : " . "" . $row['reg_date'] . "" . "
";
+ echo "Address : " . "" . $row['Address'] . "" . "
";
echo "
";
}
}