Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Sale Dock - Release v0.7.0 #140

Merged
merged 47 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ff82af1
Update add order
htnghia1423 Feb 21, 2024
3667469
update add order
htnghia1423 Feb 21, 2024
b9c37e3
Update add product into order
htnghia1423 Feb 22, 2024
7770b22
update add order
htnghia1423 Feb 22, 2024
cf6cdb6
Update add order
htnghia1423 Feb 23, 2024
93a98bf
Update add order
htnghia1423 Feb 24, 2024
279528b
Update add order
htnghia1423 Feb 24, 2024
fcffb84
Update add order
htnghia1423 Feb 25, 2024
0386f09
Update-customer
yuhtnguyen Feb 25, 2024
afbd4cc
Update add order
htnghia1423 Feb 25, 2024
e9f4823
Update add order
htnghia1423 Feb 26, 2024
bec2554
Update add order and more
htnghia1423 Feb 26, 2024
34ba3b2
Update currency symbol
htnghia1423 Feb 26, 2024
387b917
Update add order
htnghia1423 Feb 26, 2024
c6e475a
Update add order
htnghia1423 Feb 26, 2024
fc0ce32
Update jquery-ui.css
htnghia1423 Feb 26, 2024
f67f22f
Delete jquery-ui.css
htnghia1423 Feb 27, 2024
14fded5
Delete jquery-ui.min.js
htnghia1423 Feb 27, 2024
d56b2b9
Delete jquery-3.5.1.min.js
htnghia1423 Feb 27, 2024
ed9096c
up to version 0.7.0
hardingadonis Feb 27, 2024
1a8fe82
Update add order
htnghia1423 Feb 28, 2024
50ba75d
Merge branch 'nghia-add-order-page' of https://github.com/hardingadon…
htnghia1423 Feb 28, 2024
f05a7e6
Update confirm-popup.js
htnghia1423 Feb 28, 2024
3e8c840
update add order
htnghia1423 Feb 29, 2024
2c5c8c7
Merge branch 'nghia-add-order-page' of https://github.com/hardingadon…
htnghia1423 Feb 29, 2024
33656a5
Merge pull request #133 from hardingadonis/dev
htnghia1423 Feb 29, 2024
b41c5f3
Update order
htnghia1423 Feb 29, 2024
d69ab2a
Merge pull request #129 from hardingadonis/nghia-add-order-page
bakaqc Feb 29, 2024
f2b4207
Merge pull request #127 from hardingadonis/Thuy-Edit-a-customer
bakaqc Feb 29, 2024
165de83
remove `Tải báo cáo` button
hardingadonis Feb 29, 2024
4c5ee6b
Implement paging for customer page(completed)
yuhtnguyen Feb 29, 2024
98baf57
completed paging for product page
bakaqc Feb 29, 2024
9374ece
optimize code for paging of product page
bakaqc Feb 29, 2024
a6449fc
add navigate to its manager page with each badge
hardingadonis Feb 29, 2024
dfa48ed
Merge pull request #137 from hardingadonis/dev
bakaqc Mar 1, 2024
241e943
fix err 404 and set constrain for list product
bakaqc Mar 1, 2024
d9436fe
add excel util and its dependencies
hardingadonis Mar 1, 2024
fa9e43d
add download servlet and button to download
hardingadonis Mar 1, 2024
11fbe10
optimize code of paging servlet
bakaqc Mar 1, 2024
71fd941
Add paging for list order
htnghia1423 Mar 3, 2024
a7eadb6
update column for table list product
bakaqc Mar 3, 2024
b4f2104
Merge pull request #136 from hardingadonis/chuong-paging-product-page
hardingadonis Mar 3, 2024
97021e1
Merge pull request #138 from hardingadonis/vuong-download-data-as-excel
bakaqc Mar 3, 2024
cadb1df
Update format currency in list order
htnghia1423 Mar 3, 2024
c2b66fb
Merge pull request #139 from hardingadonis/nghia-paging-for-order-page
hardingadonis Mar 3, 2024
70f763e
Merge pull request #135 from hardingadonis/Thuy-paging-for-customer-page
bakaqc Mar 3, 2024
91038e2
prepare for release
hardingadonis Mar 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ server/*.war
# IntelliJ IDEA
.idea/

.history/
.history/

*.xlsx
2 changes: 1 addition & 1 deletion get_version.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

major_version=0
minor_version=6
minor_version=7
path_version=0

echo "$major_version.$minor_version.$path_version"
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.hardingadonis</groupId>
<artifactId>saledock</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<packaging>war</packaging>

<name>Sale Dock - v${project.version}</name>
Expand All @@ -16,7 +17,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jakartaee>10.0.0</jakartaee>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
Expand Down Expand Up @@ -85,6 +86,16 @@
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package io.hardingadonis.saledock.controller.error;

import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import jakarta.servlet.http.*;
import java.io.*;

@WebServlet(name = "ErrorPageServlet", urlPatterns = {"/error-404"})
public class ErrorPageServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/view/jsp/error/404.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

List<Customer> customers = Singleton.customerDAO.getAll();
Integer customerCount = Singleton.customerDAO.count();
request.setAttribute("customerCount", customerCount);
int pageNumber = 1;
int pageSize = 10;

// Get the requested page number
String pageStr = request.getParameter("page");
if (pageStr != null) {
pageNumber = Integer.parseInt(pageStr);
}

List<Customer> customers = Singleton.customerDAO.pagination((pageNumber - 1) * pageSize, pageSize);

int totalPages = Singleton.customerDAO.totalPages(pageSize);

request.setAttribute("pageSize", pageSize);

request.setAttribute("customerCount", Singleton.customerDAO.count());
request.setAttribute("customers", customers);
request.setAttribute("currentPage", pageNumber);
request.setAttribute("totalPages", totalPages);
request.setAttribute("pageSize", pageSize);
request.setAttribute("page", "customer");


request.getRequestDispatcher("/view/jsp/management/customer/customer.jsp").forward(request, response);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
package io.hardingadonis.saledock.controller.management.customer;

import io.hardingadonis.saledock.model.Customer;
import io.hardingadonis.saledock.utils.Singleton;
import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import jakarta.servlet.http.*;

import java.io.*;
import java.util.Optional;

@WebServlet(name = "UpdateCustomerServlet", urlPatterns = {"/update-customer"})
public class UpdateCustomerServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.setAttribute("page", "customer");

String id = request.getParameter("id");
if (id == null) {
response.sendError(404);
return;
}

Integer id_customer = Integer.valueOf(id);
Optional<Customer> customer = Singleton.customerDAO.getByID(id_customer);

if (customer.isPresent()) {
var cus = customer.get();

request.setAttribute("cus", cus);
request.getRequestDispatcher("/view/jsp/management/customer/update-customer.jsp").forward(request, response);
} else {
response.sendRedirect(request.getContextPath() + "/customer");
}
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

System.out.println("hhhh");
String name = request.getParameter("nameCus");
String address = request.getParameter("addressCus");

String id = request.getParameter("id");
if (id == null) {
response.sendError(404);
return;
}


Integer id_customer = Integer.valueOf(id);
Customer customer = Singleton.customerDAO.getByID(id_customer).get();
if (!name.isEmpty()) {
customer.setName(name);
}
if (!address.isEmpty()) {
customer.setAddress(address);
}
Singleton.customerDAO.save(customer);
response.sendRedirect(request.getContextPath() + "/customer-detail?id="+id);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.hardingadonis.saledock.controller.management.order;

import com.mysql.cj.util.StringUtils;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import jakarta.servlet.http.*;
import java.io.*;
import java.util.*;

@WebServlet(name = "AddOrderServlet", urlPatterns = {"/add-order"})
public class AddOrderServlet extends HttpServlet {
Expand All @@ -16,50 +18,152 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

List<Customer> customers = Singleton.customerDAO.getAll();
List<Product> products = Singleton.productDAO.getAll();

String action = request.getParameter("action");
String customerIdParam = request.getParameter("customerId");

if (customerIdParam != null && !customerIdParam.isEmpty()) {
try {
Integer customerId = Integer.parseInt(customerIdParam);
request.setAttribute("customerId", customerId);
} catch (NumberFormatException e) {
e.printStackTrace();
response.sendRedirect("./error-404");
return;
}
}

if (action != null) {
switch (action) {
case "delete":
deleteProductFromOrder(request, response);
break;
case "goBack":
SessionUtil.getInstance().removeValue(request, "productMap");
response.sendRedirect("./order");
return;
default:
response.sendRedirect("./add-order");
}
}

Map<Integer, Integer> productMap = getProductMap(request);

double totalCost = calculateTotalCost(productMap, Singleton.productDAO.getAll());

request.setAttribute("customers", customers);
request.setAttribute("products", products);
request.setAttribute("productMap", productMap);
request.setAttribute("totalCost", totalCost);

request.setAttribute("page", "order");

RequestDispatcher requestDispatcher = request.getRequestDispatcher("/view/jsp/management/order/add-order.jsp");
requestDispatcher.forward(request, response);
request.getRequestDispatcher("/view/jsp/management/order/add-order.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String customerID = request.getParameter("customerID");
String productID = request.getParameter("productID");
String quantity = request.getParameter("quantity");

if (customerID == null || productID == null || quantity == null) {
response.sendError(404, "Please provide Customer ID, Product ID and Quantity");
String customerIdParam = request.getParameter("customerId");
if (customerIdParam == null || customerIdParam.isEmpty()) {
response.sendRedirect("./add-order?message=customerNotExist");
return;
}
try {
Integer customerId = Integer.parseInt(customerIdParam);
String note = request.getParameter("note");
Employee employee = (Employee) SessionUtil.getInstance().getValue(request, "employee");

Optional<Customer> customer = Singleton.customerDAO.getByID(customerId);

if (customer.isPresent()) {
Order order = new Order();

Integer id_customer = Integer.valueOf(customerID);
Integer id_product = Integer.valueOf(productID);
order.setCustomer(customer.get());
order.setEmployee(employee);
order.setNote(note);

Customer customer = Singleton.customerDAO.getByID(id_customer).orElse(null);
Product product = Singleton.productDAO.getByID(id_product).orElse(null);
HttpSession session = request.getSession();
Employee employee = (Employee) session.getAttribute("employee");
Map<Integer, Integer> productMap = getProductMap(request);

// Check if an employee is logged in
if (employee == null) {
response.sendRedirect(request.getContextPath() + "/login?message=notLoggedIn");
if (productMap.isEmpty()) {
response.sendRedirect("./add-order?customerId=" + customerId + "&message=emptyProduct");
return;
} else {
for (Integer productId : productMap.keySet()) {
Optional<Product> product = Singleton.productDAO.getByID(productId);

if (product.isPresent()) {
order.addProduct(product.get(), productMap.get(productId));
} else {
response.sendRedirect("./add-order?customerId=" + customerId + "&message=productNotExist");
return;
}
}
}
Order saveOrder = Singleton.orderDAO.save(order);
SendEmailUtil.sendOrderMessage(customer.get().getEmail(), "Slae Dock - Đặt hàng thành công", saveOrder);
SessionUtil.getInstance().removeValue(request, "productMap");
response.sendRedirect("./order?message=orderSuccess");
} else {
response.sendRedirect("./add-order?message=customerNotExist");
}
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("./error-404");
return;
}

if (customer == null || product == null) {
response.sendError(404, "Please provide correct Customer ID and Product ID");
return;
}

private void deleteProductFromOrder(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String productIdParam = request.getParameter("productId");

if (productIdParam != null) {
try {
int productId = Integer.parseInt(productIdParam);

Map<Integer, Integer> productMap = getProductMap(request);

productMap.remove(productId);

double totalCost = calculateTotalCost(productMap, Singleton.productDAO.getAll());
request.setAttribute("totalCost", totalCost);

SessionUtil.getInstance().putValue(request, "productMap", productMap);

} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}

Order order = new Order();
order.setCustomer(customer);
order.setEmployee(employee);
private Map<Integer, Integer> getProductMap(HttpServletRequest request) {
Map<Integer, Integer> productMap = (Map<Integer, Integer>) SessionUtil.getInstance().getValue(request, "productMap");
if (productMap == null) {
productMap = new HashMap<>();
SessionUtil.getInstance().putValue(request, "productMap", productMap);
}
return productMap;
}

order.addProduct(product, Integer.valueOf(quantity));
private double calculateTotalCost(Map<Integer, Integer> productMap, List<Product> allProducts) {
double totalCost = 0;

for (Map.Entry<Integer, Integer> entry : productMap.entrySet()) {
int productId = entry.getKey();
int quantity = entry.getValue();

for (Product product : allProducts) {
if (product.getID() == productId) {
totalCost += product.getPrice() * quantity;
break;
}
}
}

Singleton.orderDAO.save(order);
response.sendRedirect(request.getContextPath() + "/order");
return totalCost;
}
}
Loading
Loading