잔량 거래명세서데이터베이스저장완료 출하일눌렀을대 보임
This commit is contained in:
@@ -525,16 +525,16 @@ public class SalesNcollectMgmtController {
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
<if test="saleNo != null and saleNo != ''">
|
||||
AND SR.sale_no = #{saleNo}
|
||||
</if>
|
||||
LEFT JOIN CONTRACT_MGMT CM ON CM.OBJID::VARCHAR = T.CONTRACT_OBJID
|
||||
WHERE T.PROJECT_NO = #{orderNo}
|
||||
</select>
|
||||
@@ -1739,11 +1730,38 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
</choose>
|
||||
#{shippingMethod}, #{salesUnitPrice}::numeric, #{salesSupplyPrice}::numeric,
|
||||
#{salesVat}::numeric, #{salesTotalAmount}::numeric, #{salesCurrency},
|
||||
#{salesExchangeRate}::numeric, #{manager}, #{incoterms}, #{serialNo},
|
||||
#{salesExchangeRate}::numeric, #{managerUserId}, #{incoterms}, #{serialNo},
|
||||
#{parentSaleNo}::integer, #{cretEmpNo}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- sales_registration의 수량을 shipment_log 합계로 업데이트 -->
|
||||
<update id="updateSalesQuantityFromShipmentLog" parameterType="map">
|
||||
/* 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}
|
||||
</update>
|
||||
|
||||
<!-- PROJECT_MGMT의 OBJID 조회 (shipment_log의 target_objid로 사용) -->
|
||||
<select id="getProjectObjid" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getProjectObjid - PROJECT_MGMT의 OBJID 조회 */
|
||||
@@ -1752,21 +1770,18 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
|
||||
<!-- 출하일 상세 내역 조회 (모든 분할 출하 포함) -->
|
||||
<select id="getShippingDetailList" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getShippingDetailList - 모든 분할 출하 포함 */
|
||||
/* salesNcollectMgmt.getShippingDetailList - shipment_log에서 모든 분할 출하 조회 */
|
||||
SELECT
|
||||
COALESCE(TO_CHAR(SR.shipping_date, 'YYYY-MM-DD'), '미등록') AS shipping_date,
|
||||
COALESCE(SR.sales_quantity, 0) AS shipping_quantity,
|
||||
COALESCE(SR.shipping_order_status, '미등록') AS shipping_order_status,
|
||||
COALESCE(SR.serial_no, '-') AS serial_no,
|
||||
SR.project_no,
|
||||
CASE
|
||||
WHEN SR.project_no = #{projectNo} THEN '최초 출하'
|
||||
ELSE '분할 출하 ' || SUBSTRING(SR.project_no FROM LENGTH(#{projectNo}) + 2)
|
||||
END AS source
|
||||
FROM sales_registration SR
|
||||
WHERE SR.project_no LIKE #{projectNo} || '%'
|
||||
|
||||
ORDER BY shipping_date DESC, project_no
|
||||
COALESCE(TO_CHAR(SL.shipping_date, 'YYYY-MM-DD'), '미등록') AS shipping_date,
|
||||
COALESCE(SL.split_quantity, 0) AS shipping_quantity,
|
||||
COALESCE(SL.shipping_status, '미등록') AS shipping_order_status,
|
||||
COALESCE(SL.serial_no, '-') AS serial_no,
|
||||
SL.target_objid AS project_no,
|
||||
'분할 출하 ' || SL.log_id AS source,
|
||||
TO_CHAR(SL.reg_date, 'YYYY-MM-DD HH24:MI:SS') AS reg_date
|
||||
FROM shipment_log SL
|
||||
WHERE SL.target_objid = #{projectNo}
|
||||
ORDER BY SL.shipping_date DESC, SL.log_id DESC
|
||||
</select>
|
||||
|
||||
<!-- 거래명세서 - 고객 정보 조회 -->
|
||||
@@ -1799,5 +1814,64 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
WHERE PM.PROJECT_NO = #{projectNo}
|
||||
</select>
|
||||
|
||||
<!-- 거래명세서 저장 - NSWOS100_TBL 테이블 사용 -->
|
||||
<insert id="saveTransactionStatement" parameterType="map">
|
||||
/* 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
|
||||
</insert>
|
||||
|
||||
<!-- 거래명세서 번호 생성 -->
|
||||
<select id="getNextTransactionStatementNo" parameterType="map" resultType="int">
|
||||
/* salesNcollectMgmt.getNextTransactionStatementNo - 거래명세서 번호 생성 */
|
||||
SELECT COALESCE(MAX(IssueNo), 0) + 1 AS nextNo
|
||||
FROM NSWOS100_TBL
|
||||
WHERE SuVndCd = #{suVndCd}
|
||||
AND IssueDt = #{issueDt}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -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<String, Object> saveSaleRegistration(HttpServletRequest request, Map<
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래명세서 저장 (NSWOS100_TBL)
|
||||
*/
|
||||
public Map<String, Object> saveTransactionStatement(Map<String, Object> paramMap) {
|
||||
SqlSession sqlSession = null;
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
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<String, Object> noParam = new HashMap<String, Object>();
|
||||
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<Map<String, Object>> items = (List<Map<String, Object>>) paramMap.get("items");
|
||||
if(items != null && items.size() > 0) {
|
||||
int seqNo = 1;
|
||||
for(Map<String, Object> item : items) {
|
||||
Map<String, Object> insertParam = new HashMap<String, Object>();
|
||||
insertParam.put("suVndCd", suVndCd);
|
||||
insertParam.put("issueDt", issueDt);
|
||||
insertParam.put("issueNo", issueNo);
|
||||
insertParam.put("isNo", seqNo);
|
||||
|
||||
// 품목 정보
|
||||
insertParam.put("prodCd", ""); // 기종코드
|
||||
|
||||
// 발주번호 (프로젝트번호) - VARCHAR(15) 제한
|
||||
String projectNos = String.valueOf(paramMap.get("projectNos"));
|
||||
if(projectNos.length() > 15) {
|
||||
projectNos = projectNos.substring(0, 15); // 15자로 자르기
|
||||
}
|
||||
insertParam.put("odOrderNo", projectNos);
|
||||
|
||||
// 품번 - VARCHAR(15) 제한
|
||||
String spec = String.valueOf(item.get("spec"));
|
||||
if(spec != null && spec.length() > 15) {
|
||||
spec = spec.substring(0, 15); // 15자로 자르기
|
||||
}
|
||||
insertParam.put("imItemId", spec);
|
||||
|
||||
insertParam.put("rmDueDt", ""); // 납기일자
|
||||
|
||||
// 수량 정보
|
||||
String quantityStr = String.valueOf(item.get("quantity"));
|
||||
quantityStr = quantityStr.replaceAll(",", "").replaceAll("[^0-9]", "");
|
||||
int quantity = 0;
|
||||
try {
|
||||
quantity = Integer.parseInt(quantityStr);
|
||||
} catch(Exception e) {
|
||||
quantity = 0;
|
||||
}
|
||||
insertParam.put("rmOrderQty", quantity); // 발주수량
|
||||
insertParam.put("rmRcptQty", 0); // 입고처리수량
|
||||
insertParam.put("rmRemQty", 0); // 잔량
|
||||
insertParam.put("isDt", deliveryDate); // 납기일자 (포맷 변환된 값)
|
||||
insertParam.put("isQty", quantity); // 납품수량
|
||||
|
||||
// 금액 정보
|
||||
String unitPriceStr = String.valueOf(item.get("unitPrice"));
|
||||
unitPriceStr = unitPriceStr.replaceAll(",", "").replaceAll("[^0-9.]", "");
|
||||
double unitPrice = 0;
|
||||
try {
|
||||
unitPrice = Double.parseDouble(unitPriceStr);
|
||||
} catch(Exception e) {
|
||||
unitPrice = 0;
|
||||
}
|
||||
|
||||
String supplyPriceStr = String.valueOf(item.get("supplyPrice"));
|
||||
supplyPriceStr = supplyPriceStr.replaceAll(",", "").replaceAll("[^0-9.]", "");
|
||||
double supplyPrice = 0;
|
||||
try {
|
||||
supplyPrice = Double.parseDouble(supplyPriceStr);
|
||||
} catch(Exception e) {
|
||||
supplyPrice = 0;
|
||||
}
|
||||
|
||||
insertParam.put("isPrice", unitPrice); // 납품단가
|
||||
insertParam.put("isAmount", supplyPrice); // 납품금액
|
||||
|
||||
System.out.println("품목 " + seqNo + " 저장: " + item.get("productName"));
|
||||
System.out.println(" - 품번: " + item.get("spec"));
|
||||
System.out.println(" - 수량: " + quantity);
|
||||
System.out.println(" - 단가: " + unitPrice);
|
||||
System.out.println(" - 금액: " + supplyPrice);
|
||||
|
||||
sqlSession.insert("salesNcollectMgmt.saveTransactionStatement", insertParam);
|
||||
seqNo++;
|
||||
}
|
||||
}
|
||||
|
||||
sqlSession.commit();
|
||||
|
||||
resultMap.put("success", true);
|
||||
resultMap.put("message", "거래명세서가 저장되었습니다.");
|
||||
resultMap.put("issueNo", issueNo);
|
||||
|
||||
System.out.println("=== 거래명세서 저장 완료 ===");
|
||||
|
||||
} catch (Exception e) {
|
||||
if(sqlSession != null) {
|
||||
sqlSession.rollback();
|
||||
}
|
||||
System.out.println("=== 거래명세서 저장 실패 ===");
|
||||
e.printStackTrace();
|
||||
resultMap.put("success", false);
|
||||
resultMap.put("message", "저장 중 오류가 발생했습니다: " + e.getMessage());
|
||||
} finally {
|
||||
if (sqlSession != null) {
|
||||
sqlSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user