From ce85aeb8b3071374ff8a7204090e30bfe288d685 Mon Sep 17 00:00:00 2001 From: Nguyen Son <152074875+thson58@users.noreply.github.com> Date: Sun, 10 Mar 2024 13:28:02 +0700 Subject: [PATCH 1/5] fix NaN when quantity 0 --- .../order/add-product-into-order.jsp | 104 ++++++------------ 1 file changed, 31 insertions(+), 73 deletions(-) diff --git a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp index 152ed27..0758e02 100644 --- a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp +++ b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp @@ -12,17 +12,17 @@ - - + + - + - +
<%@include file="../../../common/_sidenav.jsp" %>
@@ -46,19 +46,9 @@ Chưa nhập tên sản phẩm. Vui lòng kiểm tra lại.
- - - - - - - + @@ -119,75 +109,42 @@
+ <%@include file="../../../common/_footer.jsp" %> - <%@include file="../../../common/_footer.jsp" %> + <%@include file="../../../common/_goback.jsp" %> - <%@include file="../../../common/_goback.jsp" %> - - - - - - - - + + + + + + - @@ -225,6 +180,9 @@ var quantity = parseInt($('#product-quantity').val()); var price = parseFloat($('#product-price').val().replace(/[^0-9.-]+/g, '')) * 1000; var total = quantity * price; + if(isNaN(total)){ + total = 0; + } $('#product-total-price').val(formatCurrency(total)); } From 4e6640efaf755f065a0d0960722177cc1ff0ec58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20V=C6=B0=C6=A1ng?= Date: Sun, 10 Mar 2024 15:07:55 +0700 Subject: [PATCH 2/5] up to version 0.9.0 --- get_version.sh | 2 +- pom.xml | 2 +- src/main/resources/config.mysql.properties | 2 +- src/main/resources/hibernate.cfg.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/get_version.sh b/get_version.sh index 8bb6b2c..b682fcb 100644 --- a/get_version.sh +++ b/get_version.sh @@ -1,7 +1,7 @@ #!/bin/bash major_version=0 -minor_version=8 +minor_version=9 path_version=0 echo "$major_version.$minor_version.$path_version" diff --git a/pom.xml b/pom.xml index 443b89a..b5a6894 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.hardingadonis saledock - 0.8.0 + 0.9.0 war Sale Dock - v${project.version} diff --git a/src/main/resources/config.mysql.properties b/src/main/resources/config.mysql.properties index 6eee35a..0ae7593 100644 --- a/src/main/resources/config.mysql.properties +++ b/src/main/resources/config.mysql.properties @@ -1,4 +1,4 @@ -config.jdbc.url=database +config.jdbc.url=localhost config.jdbc.database_name=saledock config.jdbc.user=root config.jdbc.password= \ No newline at end of file diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 48e5fbd..1f441f1 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -4,7 +4,7 @@ com.mysql.cj.jdbc.Driver - jdbc:mysql://database:3306/saledock?createDatabaseIfNotExist=true + jdbc:mysql://localhost:3306/saledock?createDatabaseIfNotExist=true root From 58c4b72b344382177aad0ea3598b599d1a09ac8c Mon Sep 17 00:00:00 2001 From: Nguyen Son <152074875+thson58@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:13:40 +0700 Subject: [PATCH 3/5] fix NaN when quantity 0 --- .../order/add-product-into-order.jsp | 102 +++++++++++++----- 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp index 0758e02..6227524 100644 --- a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp +++ b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp @@ -12,17 +12,17 @@ - - + + - + - +
<%@include file="../../../common/_sidenav.jsp" %>
@@ -46,9 +46,19 @@ Chưa nhập tên sản phẩm. Vui lòng kiểm tra lại.
- + + + + + + + @@ -109,42 +119,75 @@
- <%@include file="../../../common/_footer.jsp" %> - <%@include file="../../../common/_goback.jsp" %> + <%@include file="../../../common/_footer.jsp" %> - - - - - - + <%@include file="../../../common/_goback.jsp" %> + + + + + + + + + @@ -183,7 +228,6 @@ if(isNaN(total)){ total = 0; } - $('#product-total-price').val(formatCurrency(total)); } From 874cef857d6efcbb44c6ef8641244bbe0ae87cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20V=C6=B0=C6=A1ng?= Date: Tue, 12 Mar 2024 12:31:07 +0700 Subject: [PATCH 4/5] auto generate customer id when create new customer --- .../customer/AddCustomerServlet.java | 7 +---- .../saledock/model/Customer.java | 9 ++++++ .../hardingadonis/saledock/model/Order.java | 5 ---- .../jsp/management/customer/add-customer.jsp | 29 ++++--------------- 4 files changed, 16 insertions(+), 34 deletions(-) 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!') - - ] }); From b09eab2ca2271987ecea5258a9d0fbc41d8d74c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20V=C6=B0=C6=A1ng?= Date: Tue, 12 Mar 2024 12:40:25 +0700 Subject: [PATCH 5/5] use `disabled` instead of `readonly` in update pages --- .../jsp/management/customer/update-customer.jsp | 4 ++-- .../view/jsp/management/order/update-order.jsp | 14 +++++++------- .../view/jsp/management/product/update-product.jsp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/view/jsp/management/customer/update-customer.jsp b/src/main/webapp/view/jsp/management/customer/update-customer.jsp index 92afa72..a5e235b 100644 --- a/src/main/webapp/view/jsp/management/customer/update-customer.jsp +++ b/src/main/webapp/view/jsp/management/customer/update-customer.jsp @@ -48,7 +48,7 @@
- +
@@ -61,7 +61,7 @@
- +
@@ -88,20 +88,20 @@
- +
- +
- +
@@ -111,10 +111,10 @@ - + - + +
@@ -66,7 +66,7 @@ - +