Skip to content

Commit

Permalink
Admin approval/rejection, Add to cart and admin remarks added
Browse files Browse the repository at this point in the history
  • Loading branch information
khyati18 committed Nov 25, 2020
1 parent 1cc4634 commit d537bd9
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 50 deletions.
74 changes: 74 additions & 0 deletions admin/request_manage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

include '../config/db_connection.php';

$conn = OpenCon();
echo $conn->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 "<script>alert('Order Approved'); window.location.href='./requests.php';</script>";
}
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 "<script>alert('Order Rejected'); window.location.href='./requests.php';</script>";
}
?>
31 changes: 12 additions & 19 deletions admin/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<th>Admin Remarks</th>
<th>Approve</th>
<th>Reject</th>
<th>Order Status</th>
</tr>

<tbody id="myTable">
Expand All @@ -41,49 +42,41 @@
$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())
{
$id = $row['UserId'];
$sql1 = "SELECT email from Users where id='$id'";
$result1 = $conn->query($sql1);
$count++;

$order = $row['OrderId'];

echo "<tr>";
echo "<td>" . $row['OrderId'] . "</td>";
echo "<td>" . $row['UserId'] . "</td>";
echo "<td>" . $result1->fetch_assoc()['email'] . "</td>";
echo "<td>" . $row['OrderDetails'] . "</td>";
echo "<td>" . $row['Remarks'] . "</td>";
// echo "<td><textarea style='width:200px; height:40px'></textarea></td>";

echo "<td><input type='text' style='margin:0; background-color: white;' placeholder='thank you for ordering'></td>";
echo '<td><input type="submit" name="approve" value="Approve"/></td>';
echo '<td><input type="submit" name="reject" value="Reject"/></td>';
echo "<td><a href='request_manage.php?var=1&order=$order'>Approve</a></td>";
echo "<td><a href='request_manage.php?var=0&order=$order'>Reject</a></td>";
echo "<td>" . $row['Status'] . "</td>";
echo "</tr>";
}
}
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);
}

}
?>

</tbody>
</table>

Expand Down
78 changes: 66 additions & 12 deletions database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -48,8 +71,8 @@ CREATE TABLE `Items` (

INSERT INTO `Items` (`id`, `name`, `company`, `quantity`, `price`) VALUES
(1, '<a href=\"https://en.wikipedia.org/wiki/Acetylacetone\" target=\"_blank\">Acetylacetone</a>', 'Alfa Aeser', 100, 50),
(2, '<a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a>', 'SDFCL', 200, 50),
(3, '<a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a>', 'Sigma-Aldrich', 300, 50),
(2, '<a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a>', 'SDFCL', 194, 50),
(3, '<a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a>', 'Sigma-Aldrich', 291, 50),
(4, '<a href=\"https://en.wikipedia.org/wiki/Camphorsulfonic_acid\" target=\"_blank\">Camphorsulfonic Acid</a>', 'Sigma-Aldrich', 300, 50),
(5, '<a href=\"https://en.wikipedia.org/wiki/Docusate\" target=\"_blank\">Dioctyl sulfosuccinate sodium salt</a>', 'Sigma-Aldrich', 300, 50),
(6, '<a href=\"https://en.wikipedia.org/wiki/Ethylene_glycol\" target=\"_blank\">Ethanediol</a>', 'SDFCL', 400, 50),
Expand All @@ -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: <a href=\"https://en.wikipedia.org/wiki/Camphorsulfonic_acid\" target=\"_blank\">Camphorsulfonic Acid</a> quantity: 3 price: 50', 'Remarks...', 'Rejected', 'Your order is rejected. Please order again after 10 days.'),
(18, 1, 'chemicalId: <a href=\"https://en.wikipedia.org/wiki/Docusate\" target=\"_blank\">Dioctyl sulfosuccinate sodium salt</a> quantity: 2 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
(19, 1, 'chemicalId: <a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a> quantity: 1 price: 50', 'Remarks...', 'Rejected', 'Your order is rejected. Please order again after 10 days.'),
(20, 1, 'chemicalId: <a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a> quantity: 1 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
(21, 1, 'chemicalId: 2 name: <a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a> quantity: 2 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
(22, 1, 'chemicalId: 3 name: <a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a> quantity: 1 price: 50', 'Remarks...', 'Approved', 'Thanks for Ordering'),
(23, 1, 'chemicalId: 3 name: <a href=\"https://en.wikipedia.org/wiki/Benzoic_acid\" target=\"_blank\">Benzoic Acid</a> 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', '[email protected]', '2020-11-01 22:17:05','9876543212'),
(2, 'Jai', 'Luthra', '[email protected]', '2020-11-01 22:17:32','9182736456');
INSERT INTO `Users` (`id`, `firstname`, `lastname`, `email`, `reg_date`, `contact`, `Address`) VALUES
(1, 'Khyati', 'Agarwal', '[email protected]', '2020-11-25 18:12:08', '9876543212', 'Flat no. 312, Sector 83, Faridabad, Haryana'),
(2, 'Jai', 'Luthra', '[email protected]', '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`
--
Expand All @@ -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`
--
Expand All @@ -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`
Expand Down
38 changes: 25 additions & 13 deletions user/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,36 @@

if(isset($_POST["check_row_$count"]))
{
$cart .= "chemicalId: " . $row['name'] . " quantity: " . $_POST["quantity_$count"] . " price: " . $row['price'] . "<br>";

echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $_POST["quantity_$count"] . "</td>";
echo "<td>" . $row['price'] . "</td>";
$items ++;
$total += $row['price'] * $_POST["quantity_$count"];
echo "</tr>";

$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'] . "<br>";


echo "<tr>";
echo "<td>" . $row['ChemName'] . "</td>";
echo "<td>" . $row['Quantity'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
$items ++;
$total += $row['Price'] * $row["Quantity"];
echo "</tr>";
}
}
}

echo "</table>";

Expand Down
3 changes: 2 additions & 1 deletion user/inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
</table>

<div>
<button type="submit" class="button" name="submit">Go To Cart</button>
<button type="submit" class="button" name="submit">Add To Cart</button>
<button class='button' onclick="window.location.href='cart.php'">Go To Cart</button>
</div>

</form>
Expand Down
6 changes: 3 additions & 3 deletions user/orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,8 +60,8 @@
echo "<td>" . $row['UserId'] . "</td>";
echo "<td>" . $row['OrderId'] . "</td>";
echo "<td>" . $row['OrderDetails'] . "</td>";
echo "<td>Approval Pending</td>";
echo "<td>Your request will be approved soon</td>";
echo "<td>" . $row['Status'] . "</td>";
echo "<td>" . $row['Admin_Remarks'] . "</td>";
}
}
else
Expand Down
Loading

0 comments on commit d537bd9

Please sign in to comment.