여러 품목(프로젝트) 거래명세서 동시 생성 시 생성한 품목 모두에 표시되도록.
This commit is contained in:
@@ -939,10 +939,10 @@
|
||||
T.OBJID::VARCHAR AS SALE_NO,
|
||||
'ORIGINAL' AS RECORD_TYPE,
|
||||
'' AS SPLIT_LOG_ID,
|
||||
-- 거래명세서 존재 여부
|
||||
-- 거래명세서 존재 여부 (LinkedProjectObjids에 해당 프로젝트 OBJID 포함 여부)
|
||||
CASE WHEN EXISTS(
|
||||
SELECT 1 FROM NSWOS100_TBL
|
||||
WHERE OdOrderNo = T.PROJECT_NO
|
||||
SELECT 1 FROM NSWOS100_TBL
|
||||
WHERE T.OBJID::VARCHAR = ANY(STRING_TO_ARRAY(LinkedProjectObjids, ','))
|
||||
) THEN 'Y' ELSE 'N' END AS HAS_TRANSACTION_STATEMENT
|
||||
FROM PROJECT_MGMT AS T
|
||||
LEFT JOIN sales_registration SR ON T.PROJECT_NO = SR.project_no
|
||||
@@ -2022,6 +2022,7 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
,IsQty /* 납품수량 */
|
||||
,IsPrice /* 납품단가 */
|
||||
,IsAmount /* 납품금액 */
|
||||
,LinkedProjectObjids /* 연결된 프로젝트 OBJID 목록 */
|
||||
) VALUES (
|
||||
#{suVndCd} /* 업체코드 */
|
||||
,#{issueDt} /* 작성일자 */
|
||||
@@ -2038,6 +2039,7 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
,COALESCE(#{isQty}, 0)::integer /* 납품수량 */
|
||||
,COALESCE(#{isPrice}, 0)::numeric /* 납품단가 */
|
||||
,COALESCE(#{isAmount}, 0)::numeric /* 납품금액 */
|
||||
,#{linkedProjectObjids} /* 연결된 프로젝트 OBJID 목록 */
|
||||
) ON CONFLICT (SuVndCd, IssueDt, IssueNo, IsNo) DO
|
||||
UPDATE SET
|
||||
ProdCd = COALESCE(#{prodCd}, '')
|
||||
@@ -2051,6 +2053,7 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
,IsQty = COALESCE(#{isQty}, 0)::integer
|
||||
,IsPrice = COALESCE(#{isPrice}, 0)::numeric
|
||||
,IsAmount = COALESCE(#{isAmount}, 0)::numeric
|
||||
,LinkedProjectObjids = #{linkedProjectObjids}
|
||||
</insert>
|
||||
|
||||
<!-- 거래명세서 번호 생성 -->
|
||||
@@ -2078,7 +2081,7 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
|
||||
<select id="getSavedTransactionStatement" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getSavedTransactionStatement - 저장된 거래명세서 조회 */
|
||||
SELECT
|
||||
SELECT
|
||||
SuVndCd,
|
||||
IssueDt,
|
||||
IssueNo,
|
||||
@@ -2093,9 +2096,10 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
IsDt,
|
||||
IsQty,
|
||||
IsPrice,
|
||||
IsAmount
|
||||
IsAmount,
|
||||
LinkedProjectObjids
|
||||
FROM NSWOS100_TBL
|
||||
WHERE OdOrderNo = #{projectNo}
|
||||
WHERE #{projectObjid} = ANY(STRING_TO_ARRAY(LinkedProjectObjids, ','))
|
||||
ORDER BY IsNo
|
||||
</select>
|
||||
|
||||
|
||||
@@ -1488,15 +1488,30 @@ public Map<String, Object> saveSaleRegistration(HttpServletRequest request, Map<
|
||||
String suVndCd = "0001";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
// 발주번호 (프로젝트번호) - VARCHAR(15) 제한
|
||||
String projectNos = String.valueOf(paramMap.get("projectNos"));
|
||||
if(projectNos.length() > 15) {
|
||||
projectNos = projectNos.substring(0, 15);
|
||||
// 납품일자 포맷 변환
|
||||
String deliveryDate = "";
|
||||
String defaultIssueDt = sdf.format(new Date());
|
||||
if(paramMap.get("deliveryDate") != null && !paramMap.get("deliveryDate").equals("")) {
|
||||
String deliveryDateStr = String.valueOf(paramMap.get("deliveryDate"));
|
||||
if(deliveryDateStr.contains("월") || deliveryDateStr.contains("일")) {
|
||||
deliveryDate = defaultIssueDt;
|
||||
} else if(deliveryDateStr.contains("-")) {
|
||||
deliveryDate = deliveryDateStr.replaceAll("-", "");
|
||||
} else if(deliveryDateStr.length() == 8) {
|
||||
deliveryDate = deliveryDateStr;
|
||||
} else {
|
||||
deliveryDate = defaultIssueDt;
|
||||
}
|
||||
}
|
||||
|
||||
// 기존 거래명세서 확인 → 있으면 기존 IssueDt/IssueNo 재사용
|
||||
// 연결된 프로젝트 OBJID 목록 (콤마 구분)
|
||||
String linkedProjectObjids = paramMap.get("projectObjids") != null
|
||||
? String.valueOf(paramMap.get("projectObjids")) : "";
|
||||
|
||||
// 첫 번째 프로젝트 OBJID로 기존 거래명세서 확인
|
||||
String firstObjid = linkedProjectObjids.split(",")[0].trim();
|
||||
Map<String, Object> checkParam = new HashMap<String, Object>();
|
||||
checkParam.put("projectNo", projectNos);
|
||||
checkParam.put("projectObjid", firstObjid);
|
||||
List<Map<String, Object>> existingData = sqlSession.selectList("salesNcollectMgmt.getSavedTransactionStatement", checkParam);
|
||||
|
||||
String issueDt;
|
||||
@@ -1506,9 +1521,14 @@ public Map<String, Object> saveSaleRegistration(HttpServletRequest request, Map<
|
||||
Map<String, Object> first = existingData.get(0);
|
||||
issueDt = String.valueOf(first.get("issuedt"));
|
||||
issueNo = Integer.parseInt(String.valueOf(first.get("issueno")));
|
||||
System.out.println("기존 거래명세서 업데이트: IssueDt=" + issueDt + ", IssueNo=" + issueNo);
|
||||
// 기존 거래명세서 업데이트 시 DB에 저장된 LinkedProjectObjids 유지
|
||||
String existingLinked = String.valueOf(first.get("linkedprojectobjids"));
|
||||
if(existingLinked != null && !existingLinked.isEmpty() && !"null".equals(existingLinked)) {
|
||||
linkedProjectObjids = existingLinked;
|
||||
}
|
||||
System.out.println("기존 거래명세서 업데이트: IssueDt=" + issueDt + ", IssueNo=" + issueNo + ", LinkedObjids=" + linkedProjectObjids);
|
||||
} else {
|
||||
issueDt = sdf.format(new Date());
|
||||
issueDt = defaultIssueDt;
|
||||
Map<String, Object> noParam = new HashMap<String, Object>();
|
||||
noParam.put("suVndCd", suVndCd);
|
||||
noParam.put("issueDt", issueDt);
|
||||
@@ -1516,26 +1536,13 @@ public Map<String, Object> saveSaleRegistration(HttpServletRequest request, Map<
|
||||
System.out.println("신규 거래명세서 생성: IssueDt=" + issueDt + ", IssueNo=" + issueNo);
|
||||
}
|
||||
|
||||
// 납품일자 포맷 변환
|
||||
String deliveryDate = "";
|
||||
if(paramMap.get("deliveryDate") != null && !paramMap.get("deliveryDate").equals("")) {
|
||||
String deliveryDateStr = String.valueOf(paramMap.get("deliveryDate"));
|
||||
if(deliveryDateStr.contains("월") || deliveryDateStr.contains("일")) {
|
||||
deliveryDate = issueDt;
|
||||
} else if(deliveryDateStr.contains("-")) {
|
||||
deliveryDate = deliveryDateStr.replaceAll("-", "");
|
||||
} else if(deliveryDateStr.length() == 8) {
|
||||
deliveryDate = deliveryDateStr;
|
||||
} else {
|
||||
deliveryDate = issueDt;
|
||||
}
|
||||
// OdOrderNo용 첫 번째 프로젝트번호 (기존 호환)
|
||||
String firstProjectNo = String.valueOf(paramMap.get("projectNos")).split(",")[0].trim();
|
||||
if(firstProjectNo.length() > 50) {
|
||||
firstProjectNo = firstProjectNo.substring(0, 50);
|
||||
}
|
||||
|
||||
System.out.println("업체코드: " + suVndCd);
|
||||
System.out.println("작성일자: " + issueDt);
|
||||
System.out.println("거래명세서번호: " + issueNo);
|
||||
|
||||
// 품목 정보 저장 (ON CONFLICT DO UPDATE로 UPSERT)
|
||||
// 거래명세서 1건만 저장 (모든 품목 포함)
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) paramMap.get("items");
|
||||
if(items != null && items.size() > 0) {
|
||||
int seqNo = 1;
|
||||
@@ -1545,76 +1552,53 @@ public Map<String, Object> saveSaleRegistration(HttpServletRequest request, Map<
|
||||
insertParam.put("issueDt", issueDt);
|
||||
insertParam.put("issueNo", issueNo);
|
||||
insertParam.put("isNo", seqNo);
|
||||
|
||||
// 품목 정보 - 수기 입력 품명을 ProdCd에 저장
|
||||
|
||||
String productName = item.get("productName") != null ? String.valueOf(item.get("productName")) : "";
|
||||
if(productName.length() > 15) {
|
||||
productName = productName.substring(0, 15);
|
||||
if(productName.length() > 50) {
|
||||
productName = productName.substring(0, 50);
|
||||
}
|
||||
insertParam.put("prodCd", productName);
|
||||
|
||||
// 발주번호 (프로젝트번호) - 이미 선언된 projectNos 재사용
|
||||
insertParam.put("odOrderNo", projectNos);
|
||||
|
||||
// 품번 - VARCHAR(15) 제한
|
||||
insertParam.put("odOrderNo", firstProjectNo);
|
||||
insertParam.put("linkedProjectObjids", linkedProjectObjids);
|
||||
|
||||
String spec = String.valueOf(item.get("spec"));
|
||||
if(spec != null && spec.length() > 15) {
|
||||
spec = spec.substring(0, 15); // 15자로 자르기
|
||||
if(spec != null && spec.length() > 50) {
|
||||
spec = spec.substring(0, 50);
|
||||
}
|
||||
insertParam.put("imItemId", spec);
|
||||
|
||||
insertParam.put("rmDueDt", ""); // 납기일자
|
||||
|
||||
// 수량 정보
|
||||
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); // 납품수량
|
||||
|
||||
// 금액 정보
|
||||
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;
|
||||
}
|
||||
|
||||
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); // 납품금액
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user