diff --git a/WebContent/WEB-INF/classes/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml b/WebContent/WEB-INF/classes/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
index 090effa..f9d68d3 100644
--- a/WebContent/WEB-INF/classes/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
+++ b/WebContent/WEB-INF/classes/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
@@ -1510,6 +1510,9 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
COALESCE(SR.incoterms, '') AS INCOTERMS
FROM PROJECT_MGMT AS T
LEFT JOIN sales_registration SR ON T.PROJECT_NO = SR.project_no
+
+ AND SR.sale_no = #{saleNo}
+
LEFT JOIN CONTRACT_MGMT CM ON CM.OBJID::VARCHAR = T.CONTRACT_OBJID
WHERE T.PROJECT_NO = #{orderNo}
@@ -1727,35 +1730,12 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
#{shippingMethod}, #{salesUnitPrice}::numeric, #{salesSupplyPrice}::numeric,
#{salesVat}::numeric, #{salesTotalAmount}::numeric, #{salesCurrency},
- #{salesExchangeRate}::numeric, #{manager}, #{incoterms}, #{serialNo},
+ #{salesExchangeRate}::numeric, #{managerUserId}, #{incoterms}, #{serialNo},
#{parentSaleNo}::integer, #{cretEmpNo}
)
-
-
-
-
-
-
-
+
/* salesNcollectMgmt.updateSalesQuantityFromShipmentLog - shipment_log 합계로 sales_quantity 업데이트 */
UPDATE sales_registration
@@ -1782,6 +1762,28 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
WHERE sale_no = #{saleNo}
+
+
+
+
+
+
+
+
+ /* salesNcollectMgmt.saveTransactionStatement - 거래명세서 저장 */
+ INSERT INTO NSWOS100_TBL (
+ SuVndCd /* 업체코드 */
+ ,IssueDt /* 작성일자 */
+ ,IssueNo /* 거래명세서번호 */
+ ,IsNo /* 순번 */
+ ,ProdCd /* 기종코드 */
+ ,OdOrderNo /* 발주번호 */
+ ,ImItemId /* 품번 */
+ ,RmDueDt /* 납기일자 */
+ ,RmOrderQty /* 발주수량 */
+ ,RmRcptQty /* 입고처리수량 */
+ ,RmRemQty /* 잔량 */
+ ,IsDt /* 납기일자 */
+ ,IsQty /* 납품수량 */
+ ,IsPrice /* 납품단가 */
+ ,IsAmount /* 납품금액 */
+ ) VALUES (
+ #{suVndCd} /* 업체코드 */
+ ,#{issueDt} /* 작성일자 */
+ ,#{issueNo}::integer /* 거래명세서번호 */
+ ,#{isNo}::integer /* 순번 */
+ ,COALESCE(#{prodCd}, '') /* 기종코드 */
+ ,COALESCE(#{odOrderNo}, '') /* 발주번호 */
+ ,COALESCE(#{imItemId}, '') /* 품번 */
+ ,COALESCE(#{rmDueDt}, '') /* 납기일자 */
+ ,COALESCE(#{rmOrderQty}, 0)::integer /* 발주수량 */
+ ,COALESCE(#{rmRcptQty}, 0)::integer /* 입고처리수량 */
+ ,COALESCE(#{rmRemQty}, 0)::integer /* 잔량 */
+ ,COALESCE(#{isDt}, '') /* 납기일자 */
+ ,COALESCE(#{isQty}, 0)::integer /* 납품수량 */
+ ,COALESCE(#{isPrice}, 0)::numeric /* 납품단가 */
+ ,COALESCE(#{isAmount}, 0)::numeric /* 납품금액 */
+ ) ON CONFLICT (SuVndCd, IssueDt, IssueNo, IsNo) DO
+ UPDATE SET
+ ProdCd = COALESCE(#{prodCd}, '')
+ ,OdOrderNo = COALESCE(#{odOrderNo}, '')
+ ,ImItemId = COALESCE(#{imItemId}, '')
+ ,RmDueDt = COALESCE(#{rmDueDt}, '')
+ ,RmOrderQty = COALESCE(#{rmOrderQty}, 0)::integer
+ ,RmRcptQty = COALESCE(#{rmRcptQty}, 0)::integer
+ ,RmRemQty = COALESCE(#{rmRemQty}, 0)::integer
+ ,IsDt = COALESCE(#{isDt}, '')
+ ,IsQty = COALESCE(#{isQty}, 0)::integer
+ ,IsPrice = COALESCE(#{isPrice}, 0)::numeric
+ ,IsAmount = COALESCE(#{isAmount}, 0)::numeric
+
+
+
+
+
diff --git a/WebContent/WEB-INF/view/salesmgmt/salesMgmt/salesMgmtList.jsp b/WebContent/WEB-INF/view/salesmgmt/salesMgmt/salesMgmtList.jsp
index 5bb0437..9ba6457 100644
--- a/WebContent/WEB-INF/view/salesmgmt/salesMgmt/salesMgmtList.jsp
+++ b/WebContent/WEB-INF/view/salesmgmt/salesMgmt/salesMgmtList.jsp
@@ -174,6 +174,11 @@
}
}
+ // 그리드 데이터를 localStorage에 저장
+ console.log("=== 거래명세서 출력 - 선택된 데이터 ===");
+ console.log(selectedData);
+ localStorage.setItem('transactionStatementData', JSON.stringify(selectedData));
+
// 프로젝트 번호들을 수집
var projectNos = selectedData.map(function(row) {
return row.PROJECT_NO;
diff --git a/WebContent/WEB-INF/view/salesmgmt/salesMgmt/transactionStatementForm.jsp b/WebContent/WEB-INF/view/salesmgmt/salesMgmt/transactionStatementForm.jsp
index cbc17d0..e2f63a6 100644
--- a/WebContent/WEB-INF/view/salesmgmt/salesMgmt/transactionStatementForm.jsp
+++ b/WebContent/WEB-INF/view/salesmgmt/salesMgmt/transactionStatementForm.jsp
@@ -329,42 +329,54 @@ $(document).ready(function(){
});
function fn_loadData() {
- var projectNos = "${param.projectNos}";
console.log("=== 거래명세서 데이터 로드 ===");
- console.log("프로젝트 번호:", projectNos);
- if(!projectNos || projectNos === "") {
- alert("프로젝트 번호가 없습니다.");
+ // localStorage에서 그리드 데이터 가져오기
+ var gridDataJson = localStorage.getItem('transactionStatementData');
+ if(!gridDataJson) {
+ alert("선택된 데이터가 없습니다.");
return;
}
- $.ajax({
- url: "/salesMgmt/getTransactionStatementData.do",
- type: "POST",
- data: { projectNos: projectNos },
- dataType: "json",
- success: function(data) {
- console.log("=== 서버 응답 데이터 ===");
- console.log("전체 데이터:", JSON.stringify(data, null, 2));
- console.log("success:", data.success);
- console.log("customerName:", data.customerName);
- console.log("items:", data.items);
- console.log("supplierName:", data.supplierName);
-
- if(data && data.success) {
- fn_fillData(data);
- } else {
- alert("데이터 조회 실패: " + (data.message || "알 수 없는 오류"));
- }
- },
- error: function(xhr, status, error) {
- console.log("=== AJAX 에러 ===");
- console.log("status:", status);
- console.log("error:", error);
- console.log("responseText:", xhr.responseText);
- alert("데이터 조회 중 오류 발생");
- }
- });
+ var gridData = JSON.parse(gridDataJson);
+ console.log("그리드 데이터:", gridData);
+
+ // 그리드 데이터를 거래명세서 형식으로 변환
+ var firstItem = gridData[0];
+ var statementData = {
+ success: true,
+ customerName: firstItem.CUSTOMER,
+ supplierName: "㈜압피에스",
+ supplierRegNo: "314-81-75146",
+ supplierAddress: "대전광역시 유성구 국제과학10로 8",
+ supplierBusiness: "제조",
+ supplierType: "금속절삭가공기계의",
+ supplierContact: "TEL:042-602-3300/FAX:042-672",
+ note: "아래와 같이 공급합니다.",
+ items: []
+ };
+
+ // 각 그리드 행을 품목으로 변환
+ for(var i = 0; i < gridData.length; i++) {
+ var row = gridData[i];
+ statementData.items.push({
+ productName: row.PRODUCT_NAME,
+ spec: row.PRODUCT_NO,
+ quantity: row.SALES_QUANTITY || 0,
+ unitPrice: row.SALES_UNIT_PRICE || 0,
+ supplyPrice: row.SALES_SUPPLY_PRICE || 0,
+ vat: row.SALES_VAT || 0
+ });
+ }
+
+ console.log("=== 변환된 거래명세서 데이터 ===");
+ console.log(statementData);
+
+ // 데이터 채우기
+ fn_fillData(statementData);
+
+ // localStorage 정리
+ localStorage.removeItem('transactionStatementData');
}
function fn_fillData(data) {
diff --git a/src/com/pms/salesmgmt/controller/SalesNcollectMgmtController.java b/src/com/pms/salesmgmt/controller/SalesNcollectMgmtController.java
index 5e32102..50f3e6f 100644
--- a/src/com/pms/salesmgmt/controller/SalesNcollectMgmtController.java
+++ b/src/com/pms/salesmgmt/controller/SalesNcollectMgmtController.java
@@ -525,16 +525,16 @@ public class SalesNcollectMgmtController {
Map resultMap = new HashMap();
try {
- // 거래명세서는 차수 관리가 불필요하므로 단순히 성공 응답만 반환
- // 실제로는 PDF 생성 또는 로그 기록 등의 작업을 수행할 수 있음
-
- System.out.println("=== 거래명세서 저장 ===");
+ System.out.println("=== 거래명세서 저장 Controller ===");
System.out.println("프로젝트 번호: " + paramMap.get("projectNos"));
System.out.println("납품일: " + paramMap.get("deliveryDate"));
System.out.println("비고: " + paramMap.get("noteContent"));
+ System.out.println("품목 개수: " + ((List)paramMap.get("items")).size());
- resultMap.put("success", true);
- resultMap.put("message", "저장되었습니다.");
+ // Service 호출하여 DB에 저장
+ resultMap = salesNcollectMgmtService.saveTransactionStatement(paramMap);
+
+ System.out.println("저장 결과: " + resultMap.get("success"));
} catch (Exception e) {
e.printStackTrace();
diff --git a/src/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml b/src/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
index 8cd44a6..f9d68d3 100644
--- a/src/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
+++ b/src/com/pms/salesmgmt/mapper/salesNcollectMgmt.xml
@@ -887,30 +887,18 @@
COALESCE(SR.sales_vat, 0) AS SALES_VAT,
COALESCE(SR.sales_total_amount, 0) AS SALES_TOTAL_AMOUNT,
COALESCE(SR.sales_total_amount, 0) AS SALES_TOTAL_AMOUNT_KRW,
- -- 잔량 계산: 수주수량 - 모든 분할 출하의 합계
+ -- 잔량 계산: 수주수량 - shipment_log의 split_quantity 합계
COALESCE(T.QUANTITY::numeric, 0) - COALESCE(
- (SELECT SUM(
- CASE
- WHEN sales_quantity IS NULL THEN 0
- WHEN TRIM(CAST(sales_quantity AS TEXT)) = '' THEN 0
- ELSE CAST(sales_quantity AS NUMERIC)
- END
- )
- FROM sales_registration
- WHERE project_no LIKE T.PROJECT_NO || '%'),
+ (SELECT SUM(COALESCE(split_quantity, 0))
+ FROM shipment_log
+ WHERE target_objid = T.PROJECT_NO),
0
) AS REMAINING_QUANTITY,
- -- 잔량원화총액 계산: (수주수량 - 모든 분할 출하 합계) * 판매단가
+ -- 잔량원화총액 계산: (수주수량 - shipment_log 합계) * 판매단가
(COALESCE(T.QUANTITY::numeric, 0) - COALESCE(
- (SELECT SUM(
- CASE
- WHEN sales_quantity IS NULL THEN 0
- WHEN TRIM(CAST(sales_quantity AS TEXT)) = '' THEN 0
- ELSE CAST(sales_quantity AS NUMERIC)
- END
- )
- FROM sales_registration
- WHERE project_no LIKE T.PROJECT_NO || '%'),
+ (SELECT SUM(COALESCE(split_quantity, 0))
+ FROM shipment_log
+ WHERE target_objid = T.PROJECT_NO),
0
)) * COALESCE(SR.sales_unit_price, 0) AS REMAINING_AMOUNT_KRW,
COALESCE(SR.sales_currency, T.CONTRACT_CURRENCY) AS SALES_CURRENCY,
@@ -1522,6 +1510,9 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
COALESCE(SR.incoterms, '') AS INCOTERMS
FROM PROJECT_MGMT AS T
LEFT JOIN sales_registration SR ON T.PROJECT_NO = SR.project_no
+
+ AND SR.sale_no = #{saleNo}
+
LEFT JOIN CONTRACT_MGMT CM ON CM.OBJID::VARCHAR = T.CONTRACT_OBJID
WHERE T.PROJECT_NO = #{orderNo}
@@ -1739,11 +1730,38 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
#{shippingMethod}, #{salesUnitPrice}::numeric, #{salesSupplyPrice}::numeric,
#{salesVat}::numeric, #{salesTotalAmount}::numeric, #{salesCurrency},
- #{salesExchangeRate}::numeric, #{manager}, #{incoterms}, #{serialNo},
+ #{salesExchangeRate}::numeric, #{managerUserId}, #{incoterms}, #{serialNo},
#{parentSaleNo}::integer, #{cretEmpNo}
)
+
+
+ /* salesNcollectMgmt.updateSalesQuantityFromShipmentLog - shipment_log 합계로 sales_quantity 업데이트 */
+ UPDATE sales_registration
+ SET sales_quantity = (
+ SELECT COALESCE(SUM(split_quantity), 0)
+ FROM shipment_log
+ WHERE target_objid = #{projectNo}
+ ),
+ sales_supply_price = (
+ SELECT COALESCE(SUM(sales_supply_price), 0)
+ FROM shipment_log
+ WHERE target_objid = #{projectNo}
+ ),
+ sales_vat = (
+ SELECT COALESCE(SUM(sales_vat), 0)
+ FROM shipment_log
+ WHERE target_objid = #{projectNo}
+ ),
+ sales_total_amount = (
+ SELECT COALESCE(SUM(sales_total_amount), 0)
+ FROM shipment_log
+ WHERE target_objid = #{projectNo}
+ )
+ WHERE sale_no = #{saleNo}
+
+
+
+
+ /* salesNcollectMgmt.saveTransactionStatement - 거래명세서 저장 */
+ INSERT INTO NSWOS100_TBL (
+ SuVndCd /* 업체코드 */
+ ,IssueDt /* 작성일자 */
+ ,IssueNo /* 거래명세서번호 */
+ ,IsNo /* 순번 */
+ ,ProdCd /* 기종코드 */
+ ,OdOrderNo /* 발주번호 */
+ ,ImItemId /* 품번 */
+ ,RmDueDt /* 납기일자 */
+ ,RmOrderQty /* 발주수량 */
+ ,RmRcptQty /* 입고처리수량 */
+ ,RmRemQty /* 잔량 */
+ ,IsDt /* 납기일자 */
+ ,IsQty /* 납품수량 */
+ ,IsPrice /* 납품단가 */
+ ,IsAmount /* 납품금액 */
+ ) VALUES (
+ #{suVndCd} /* 업체코드 */
+ ,#{issueDt} /* 작성일자 */
+ ,#{issueNo}::integer /* 거래명세서번호 */
+ ,#{isNo}::integer /* 순번 */
+ ,COALESCE(#{prodCd}, '') /* 기종코드 */
+ ,COALESCE(#{odOrderNo}, '') /* 발주번호 */
+ ,COALESCE(#{imItemId}, '') /* 품번 */
+ ,COALESCE(#{rmDueDt}, '') /* 납기일자 */
+ ,COALESCE(#{rmOrderQty}, 0)::integer /* 발주수량 */
+ ,COALESCE(#{rmRcptQty}, 0)::integer /* 입고처리수량 */
+ ,COALESCE(#{rmRemQty}, 0)::integer /* 잔량 */
+ ,COALESCE(#{isDt}, '') /* 납기일자 */
+ ,COALESCE(#{isQty}, 0)::integer /* 납품수량 */
+ ,COALESCE(#{isPrice}, 0)::numeric /* 납품단가 */
+ ,COALESCE(#{isAmount}, 0)::numeric /* 납품금액 */
+ ) ON CONFLICT (SuVndCd, IssueDt, IssueNo, IsNo) DO
+ UPDATE SET
+ ProdCd = COALESCE(#{prodCd}, '')
+ ,OdOrderNo = COALESCE(#{odOrderNo}, '')
+ ,ImItemId = COALESCE(#{imItemId}, '')
+ ,RmDueDt = COALESCE(#{rmDueDt}, '')
+ ,RmOrderQty = COALESCE(#{rmOrderQty}, 0)::integer
+ ,RmRcptQty = COALESCE(#{rmRcptQty}, 0)::integer
+ ,RmRemQty = COALESCE(#{rmRemQty}, 0)::integer
+ ,IsDt = COALESCE(#{isDt}, '')
+ ,IsQty = COALESCE(#{isQty}, 0)::integer
+ ,IsPrice = COALESCE(#{isPrice}, 0)::numeric
+ ,IsAmount = COALESCE(#{isAmount}, 0)::numeric
+
+
+
+
+ /* salesNcollectMgmt.getNextTransactionStatementNo - 거래명세서 번호 생성 */
+ SELECT COALESCE(MAX(IssueNo), 0) + 1 AS nextNo
+ FROM NSWOS100_TBL
+ WHERE SuVndCd = #{suVndCd}
+ AND IssueDt = #{issueDt}
+
+
diff --git a/src/com/pms/salesmgmt/service/SalesNcollectMgmtService.java b/src/com/pms/salesmgmt/service/SalesNcollectMgmtService.java
index d4e08b3..4480698 100644
--- a/src/com/pms/salesmgmt/service/SalesNcollectMgmtService.java
+++ b/src/com/pms/salesmgmt/service/SalesNcollectMgmtService.java
@@ -10,7 +10,9 @@
package com.pms.salesmgmt.service;
import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -1175,4 +1177,165 @@ public Map saveSaleRegistration(HttpServletRequest request, Map<
return resultMap;
}
+
+ /**
+ * 거래명세서 저장 (NSWOS100_TBL)
+ */
+ public Map saveTransactionStatement(Map paramMap) {
+ SqlSession sqlSession = null;
+ Map resultMap = new HashMap();
+
+ try {
+ sqlSession = SqlMapConfig.getInstance().getSqlSession();
+
+ System.out.println("=== 거래명세서 저장 시작 ===");
+ System.out.println("paramMap: " + paramMap);
+
+ // 업체코드 (고객 정보에서 추출 필요 - 임시로 '0001' 사용)
+ String suVndCd = "0001";
+
+ // 작성일자 (오늘 날짜)
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+ String issueDt = sdf.format(new Date());
+
+ // 납품일자 포맷 변환 (한글 날짜 또는 YYYY-MM-DD → YYYYMMDD)
+ String deliveryDate = "";
+ if(paramMap.get("deliveryDate") != null && !paramMap.get("deliveryDate").equals("")) {
+ String deliveryDateStr = String.valueOf(paramMap.get("deliveryDate"));
+
+ // 한글 날짜 형식인 경우 (예: "목요일, 11월 13, 2025")
+ // 오늘 날짜로 대체
+ if(deliveryDateStr.contains("월") || deliveryDateStr.contains("일")) {
+ deliveryDate = issueDt; // 작성일자와 동일하게 설정
+ System.out.println("납품일자 변환 (한글): " + deliveryDateStr + " → " + deliveryDate + " (오늘 날짜 사용)");
+ }
+ // YYYY-MM-DD 형식인 경우
+ else if(deliveryDateStr.contains("-")) {
+ deliveryDate = deliveryDateStr.replaceAll("-", ""); // "2025-11-13" → "20251113"
+ System.out.println("납품일자 변환 (하이픈): " + deliveryDateStr + " → " + deliveryDate);
+ }
+ // 이미 YYYYMMDD 형식인 경우
+ else if(deliveryDateStr.length() == 8) {
+ deliveryDate = deliveryDateStr;
+ System.out.println("납품일자 변환 (8자리): " + deliveryDateStr + " → " + deliveryDate);
+ }
+ // 그 외의 경우 오늘 날짜 사용
+ else {
+ deliveryDate = issueDt;
+ System.out.println("납품일자 변환 (기타): " + deliveryDateStr + " → " + deliveryDate + " (오늘 날짜 사용)");
+ }
+ }
+
+ // 거래명세서 번호 생성
+ Map noParam = new HashMap();
+ noParam.put("suVndCd", suVndCd);
+ noParam.put("issueDt", issueDt);
+ Integer issueNo = sqlSession.selectOne("salesNcollectMgmt.getNextTransactionStatementNo", noParam);
+
+ System.out.println("업체코드: " + suVndCd);
+ System.out.println("작성일자: " + issueDt);
+ System.out.println("거래명세서번호: " + issueNo);
+
+ // 품목 정보 저장
+ List