diff --git a/src/main/java/io/hardingadonis/saledock/controller/management/customer/AddCustomerServlet.java b/src/main/java/io/hardingadonis/saledock/controller/management/customer/AddCustomerServlet.java index 609db90..48de933 100644 --- a/src/main/java/io/hardingadonis/saledock/controller/management/customer/AddCustomerServlet.java +++ b/src/main/java/io/hardingadonis/saledock/controller/management/customer/AddCustomerServlet.java @@ -27,15 +27,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); - String code = request.getParameter("code"); String address = request.getParameter("address"); String email = request.getParameter("email"); try { - if (name.length() > 0 && code.length() > 0 && address.length() > 0 && email.length() > 0) { + if (name.length() > 0 && address.length() > 0 && email.length() > 0) { Customer customer = new Customer(); customer.setName(name); - customer.setCode(code); customer.setAddress(address); customer.setEmail(email); Singleton.customerDAO.save(customer); @@ -48,9 +46,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) customer.setName(name); customer.setAddress(address); StringBuilder message = new StringBuilder("Tạo khách hàng không thành công: "); - if (e.getMessage().contains(code)) { - message.append("Không được trùng mã khách hàng."); - } if (e.getMessage().contains(email)) { message.append("Không được trùng email."); } diff --git a/src/main/java/io/hardingadonis/saledock/model/Customer.java b/src/main/java/io/hardingadonis/saledock/model/Customer.java index 1a2b29b..599a4cb 100644 --- a/src/main/java/io/hardingadonis/saledock/model/Customer.java +++ b/src/main/java/io/hardingadonis/saledock/model/Customer.java @@ -2,6 +2,8 @@ import jakarta.persistence.*; import java.time.*; +import java.util.*; + import lombok.*; @Entity(name = "Customer") @@ -38,6 +40,7 @@ public class Customer { @PrePersist protected void onCreate() { + this.code = generateRandomCustomerCode(); this.createdAt = LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh")); } @@ -45,4 +48,10 @@ protected void onCreate() { protected void onUpdate() { this.updatedAt = LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh")); } + + private static String generateRandomCustomerCode() { + UUID uuid = UUID.randomUUID(); + + return uuid.toString().toUpperCase().replace("-", "").substring(0, 7); + } } diff --git a/src/main/java/io/hardingadonis/saledock/model/Order.java b/src/main/java/io/hardingadonis/saledock/model/Order.java index 2d5f839..2cb18e0 100644 --- a/src/main/java/io/hardingadonis/saledock/model/Order.java +++ b/src/main/java/io/hardingadonis/saledock/model/Order.java @@ -87,9 +87,4 @@ private static String generateRandomOrderCode() { return uuid.toString().toUpperCase().replace("-", "").substring(0, 15); } - - public String getTotalToString() { - DecimalFormat decimalFormat = new DecimalFormat("#,###.#"); - return decimalFormat.format(this.total); - } } diff --git a/src/main/webapp/view/jsp/management/customer/add-customer.jsp b/src/main/webapp/view/jsp/management/customer/add-customer.jsp index 036c25e..4fc61a7 100644 --- a/src/main/webapp/view/jsp/management/customer/add-customer.jsp +++ b/src/main/webapp/view/jsp/management/customer/add-customer.jsp @@ -42,29 +42,15 @@
-
+
+
- -
- "> - -
-
-
-
-
- -
- - -
+ "> +
-
@@ -122,11 +108,8 @@ formGroupSelector: '.form-group', rules: [ Validator.isRequired('#name-customer', 'Vui lòng nhập tên khách hàng!'), - Validator.isRequired('#code-customer', 'Vui lòng nhập mã khách hàng!'), Validator.isRequired('#address-customer', 'Vui lòng nhập địa chỉ khách hàng!'), Validator.isRequired('#email-customer', 'Vui lòng nhập email khách hàng!') - - ] });