diff --git a/src/main/java/com/no1/wms/in/InController.java b/src/main/java/com/no1/wms/in/InController.java index 8397990..735abc3 100644 --- a/src/main/java/com/no1/wms/in/InController.java +++ b/src/main/java/com/no1/wms/in/InController.java @@ -6,6 +6,7 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -78,8 +79,10 @@ public class InController { @PostMapping("/create_process") @ResponseBody - public boolean createProcess(InDto dto) { - return inService.chechAndUpdateOrCreateProcess(dto); + public int createProcess(InDto dto) { + boolean create = inService.chechAndUpdateOrCreateProcessForCreate(dto); + + return 0; } @PostMapping("/read") @@ -109,13 +112,9 @@ public class InController { // 수정 - Ajax @PutMapping("/update_process") @ResponseBody - public boolean update_process(InDto dto) { - int i = inService.updateById(dto); - if (i == 1) { - return true; - } else { - return false; - } + public boolean updateProcess(InDto dto) { + return inService.chechAndUpdateProcess(dto); + } @@ -200,7 +199,11 @@ public class InController { return mav; } - + @DeleteMapping("/delete") + @ResponseBody + public boolean delete(String id) { + return inService.deactivateById(id); + } diff --git a/src/main/java/com/no1/wms/in/InMapper.java b/src/main/java/com/no1/wms/in/InMapper.java index 750bd8c..e204958 100644 --- a/src/main/java/com/no1/wms/in/InMapper.java +++ b/src/main/java/com/no1/wms/in/InMapper.java @@ -16,5 +16,10 @@ public interface InMapper { int checkIfExistsStock(InDto dto); int updateStockProcess(InDto dto); int createStockProcess(InDto dto); - + int currntStockQuantity(InDto dto); + int currntInQuantity(InDto dto); + int updateStockProcessForUpdate(InDto dto); + int deactivateById(String id); + String selectWarehouseQuantity(String warehouseId); + int updateWarehouseQuantity(Map m); } diff --git a/src/main/java/com/no1/wms/in/InService.java b/src/main/java/com/no1/wms/in/InService.java index 4c84faa..0540d73 100644 --- a/src/main/java/com/no1/wms/in/InService.java +++ b/src/main/java/com/no1/wms/in/InService.java @@ -59,14 +59,17 @@ public class InService { } //createProcess - public boolean chechAndUpdateOrCreateProcess(InDto dto) { + public boolean chechAndUpdateOrCreateProcessForCreate(InDto dto) { + + + int j = mapper.checkIfExistsStock(dto); if(j == 1) { int k = mapper.updateStockProcess(dto); if(k == 1) { int i = mapper.createProcess(dto); if(i == k) { - System.out.println("달라서 새로만듬"); + //System.out.println("같아서 합침"); return true; }else { return false; @@ -80,7 +83,7 @@ public class InService { if(k == 1) { int i = mapper.createProcess(dto); if(i == k) { - System.out.println("같아서 합침"); + //System.out.println("달라서 새로만듬"); return true; }else { return false; @@ -93,7 +96,68 @@ public class InService { } } + //updateProcess + public boolean chechAndUpdateProcess(InDto dto) { + int j = mapper.checkIfExistsStock(dto);//재고에 동일한 창고, 제품이 있는지 + if(j == 1) {//재고에 동일한 창고, 제품이 있다면 + int currentStockQuantity = mapper.currntStockQuantity(dto);//현재 재고의 개수 + int changeInQuantity = Integer.parseInt(dto.getQuantity());//변경된 입고의 개수 + int currentInQuantity = mapper.currntInQuantity(dto);//기존의 입고의 개수 + int modifiedStockQuantity = currentStockQuantity + changeInQuantity - currentInQuantity;//수정된 재고의 개수 + if(currentStockQuantity == modifiedStockQuantity) {//현재 재고의 개수와 변한 재고의 개수가 같다면 + int i = mapper.updateById(dto);//재고는 놔두고 입고만 업데이트 한다 + if(i == 1) { + return true; + }else { + return false; + } + }else{//현재 재고의 개수보다 변한 재고의 개수가 더 크거나 작다면 + int i = mapper.updateById(dto); // 입고를 먼저 업데이트하고 + dto.setQuantity(modifiedStockQuantity+"");// 변경 개수를 적용하여 + int k = mapper.updateStockProcessForUpdate(dto); // 재고테이블에 반영한다. + if (i == k) { + return true; + }else { + return false; + } + }//else + }else {// 재고에 동일 재품 동일 창고가 없다면 오류발생. + return false; + } + + } + public boolean deactivateById(String id) { + InDto dto = mapper.selectById(id); + int j = mapper.checkIfExistsStock(dto);//재고에 동일한 창고, 제품이 있는지 + if(j == 1) { + int currentStockQuantity = mapper.currntStockQuantity(dto);//스톡의 재고수 + int deactivateInQuantity = Integer.parseInt(dto.getQuantity());//in의 재고수 + if(currentStockQuantity >= deactivateInQuantity) {//스톡의 재고수가 in의 재고수보다 많을 때 + mapper.deactivateById(id);// 입고 비활성화 + int modifiedStockQuantity = currentStockQuantity - deactivateInQuantity; + dto.setQuantity(modifiedStockQuantity+"");// 변경 개수를 적용하여 + int k = mapper.updateStockProcessForUpdate(dto); // 재고테이블에 반영한다. + return true; + }else { + return false; + } + + }else { + return false; + } + + } + //사용하지 않음. + public void updateWarehouse(InDto dto) { + String warehouseId = dto.getId(); + String updateValue = mapper.selectWarehouseQuantity(warehouseId); + Map m = new HashMap(); + m.put("warehouseId", warehouseId); + m.put("updateValue", updateValue); + mapper.updateWarehouseQuantity(m); + + } diff --git a/src/main/resources/mappers/InMapper.xml b/src/main/resources/mappers/InMapper.xml index f375410..1637777 100644 --- a/src/main/resources/mappers/InMapper.xml +++ b/src/main/resources/mappers/InMapper.xml @@ -38,11 +38,14 @@ - INSERT INTO product_in (id, product_id, in_date, quantity, warehouse_id, manager_id, note, activation) - VALUES (UUID(), #{product_id}, #{in_date}, #{quantity}, #{warehouse_id}, #{manager_id}, #{note}, 1) + INSERT INTO product_in (id, product_id, in_date, quantity, warehouse_id, manager_id, note, activation) + VALUES (UUID(), #{product_id}, #{in_date}, #{quantity}, #{warehouse_id}, #{manager_id}, #{note}, 1) - + + INSERT INTO stock (id, warehouse_id, product_id, quantity, activation) + VALUES (UUID(), #{warehouse_id}, #{product_id}, #{quantity}, 1) + @@ -52,13 +55,30 @@ warehouse_id = #{warehouse_id}, manager_id = #{manager_id}, note = #{note} WHERE id = #{id} - - - - + + UPDATE product_in + SET activation = 0 + WHERE id = #{id} + + + + UPDATE stock + SET quantity = #{quantity} + WHERE warehouse_id = #{warehouse_id} AND product_id = #{product_id} and activation = 1 + + + + UPDATE stock + SET quantity = quantity + #{quantity} + WHERE warehouse_id = #{warehouse_id} AND product_id = #{product_id} and activation = 1 + + + + update warehouse set current_capacity = #{updateValue} where id = #{warehouseId} and activation = 1 + + - SELECT COUNT(*) FROM stock - WHERE warehouse_id = #{warehouse_id} AND product_id = #{product_id} + WHERE warehouse_id = #{warehouse_id} AND product_id = #{product_id} and activation = 1 - - UPDATE stock - SET quantity = quantity + #{quantity} - WHERE warehouse_id = #{warehouse_id} AND product_id = #{product_id} - - - INSERT INTO stock (id, warehouse_id, product_id, quantity, activation) - VALUES (UUID(), #{warehouse_id}, #{product_id}, #{quantity}, 1) - + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/category/list.jsp b/src/main/webapp/WEB-INF/views/category/list.jsp index e65beb7..a60ed48 100644 --- a/src/main/webapp/WEB-INF/views/category/list.jsp +++ b/src/main/webapp/WEB-INF/views/category/list.jsp @@ -68,7 +68,7 @@
- + ms-excel @@ -101,25 +101,10 @@
-
- - - - - - - - -
- -
-
-
-
- -
-
+ +
+
diff --git a/src/main/webapp/WEB-INF/views/category/read.jsp b/src/main/webapp/WEB-INF/views/category/read.jsp index 7e9a3ee..f675c76 100644 --- a/src/main/webapp/WEB-INF/views/category/read.jsp +++ b/src/main/webapp/WEB-INF/views/category/read.jsp @@ -110,7 +110,7 @@ alert("삭제되었습니다."); $(location).attr("href", "/category/list"); } else { - alert("정상적으로 삭제되지 않았습니다.."); + alert("정상적으로 삭제되지 않았습니다."); } }).fail(function() { alert("오류가 발생했습니다."); @@ -127,8 +127,6 @@ $("#yesNoModalBodyTextDiv").text(yesNoModal.body); yesNoModal.yesFunction = deleteCategoryFunction; yesNoModalBootStrap.show(); - - } diff --git a/src/main/webapp/WEB-INF/views/in/create.jsp b/src/main/webapp/WEB-INF/views/in/create.jsp index 214f44c..58e1a18 100644 --- a/src/main/webapp/WEB-INF/views/in/create.jsp +++ b/src/main/webapp/WEB-INF/views/in/create.jsp @@ -138,6 +138,10 @@ var in_date = $("#in_date").val(); var manager_id = $("#manager_id").val(); var note = $("#note").val(); + var quantity = parseInt($("#quantity").val(), 10); + var remainingcapacity = parseInt($("#remainingcapacity").val(), 10); + + if(!product_id){ alert("제품을 선택해야합니다."); @@ -153,6 +157,12 @@ alert("창고을 선택해야합니다."); return false; } + if (quantity > remainingcapacity) { + alert("적재 할 재고량이 잔여 용량을 넘을 수 없습니다."); + $("#quantity").focus(); + return false; + } + if(!in_date){ in_date = new Date(); in_date = in_date.toISOString(); diff --git a/src/main/webapp/WEB-INF/views/in/read.jsp b/src/main/webapp/WEB-INF/views/in/read.jsp index a3e21e7..aa484d9 100644 --- a/src/main/webapp/WEB-INF/views/in/read.jsp +++ b/src/main/webapp/WEB-INF/views/in/read.jsp @@ -113,8 +113,41 @@ });//ready + function deleteInFunction(){ + var id = $("#id").val(); + $.ajax({ + url: "/in/delete", + type: "delete", + data: { + "id": id + }, + datatype:"json" + }).done(function(data) { + if (data == true) { + alert("삭제되었습니다."); + $(location).attr("href", "/in/list"); + } else { + alert("정상적으로 삭제되지 않았습니다."); + } + }).fail(function() { + alert("오류가 발생했습니다."); + }).always(function() { + // + }); + + }//deleteInFunction + function goDelete(){ + yesNoModalTextDefine("입고 삭제", "해당 입고를 삭제하시겠습니까?"); + $("#yesNoModalLabel").text(yesNoModal.title); + $("#yesNoModalBodyTextDiv").text(yesNoModal.body); + yesNoModal.yesFunction = deleteInFunction; + yesNoModalBootStrap.show(); + + + } + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/in/update.jsp b/src/main/webapp/WEB-INF/views/in/update.jsp index 3a79e20..0c95de9 100644 --- a/src/main/webapp/WEB-INF/views/in/update.jsp +++ b/src/main/webapp/WEB-INF/views/in/update.jsp @@ -28,7 +28,7 @@ - +
@@ -52,7 +52,7 @@
수량 + value="${dto.quantity}">
@@ -63,7 +63,7 @@ - +
@@ -145,11 +145,11 @@ var in_date = $("#in_date").val(); var manager_id = $("#manager_id").val(); var note = $("#note").val(); - if(!name){ - alert("제품명을 입력해야 합니다."); - $("#name").focus(); - return false; - } + var id = $("#id").val(); + var quantityAdjustment = parseInt($("#quantityAdjustment").val(), 10); + var remainingcapacity = parseInt($("#remainingcapacity").val(), 10); + + if(!product_id){ alert("제품을 선택해야합니다."); return false; @@ -164,6 +164,12 @@ alert("창고을 선택해야합니다."); return false; } + if (quantityAdjustment > remainingcapacity) { + alert("적재 할 재고량이 재고량 한도를 넘을 수 없습니다."); + $("#quantityAdjustment").focus(); + return false; + } + if(!in_date){ in_date = new Date(); in_date = in_date.toISOString(); @@ -178,9 +184,10 @@ in_date : in_date, manager_id : manager_id, warehouse_id : warehouse_id, - note : note + note : note, + id : id } - + console.log(data); $.ajax({ url: "/in/update_process", type: "put", @@ -208,6 +215,7 @@ } else { alert("입고 수정에 실패하였습니다."); + console.log(data); } }).fail(function() { alert("오류가 발생했습니다.");