Merge pull request '견적요청서 생성 오류 수정' (#155) from V20260210 into main
Reviewed-on: #155
This commit was merged in pull request #155.
This commit is contained in:
@@ -1082,107 +1082,110 @@ function fn_save() {
|
||||
|
||||
// 견적요청서 생성
|
||||
function fn_createQuotationRequest() {
|
||||
// 체크된 행 가져오기
|
||||
var checkedRows = [];
|
||||
$('.rowCheck:checked').each(function() {
|
||||
var row = $(this).closest('.tabulator-row');
|
||||
var rowData = _tabulGrid.getRow(row.attr('data-row')).getData();
|
||||
checkedRows.push(rowData);
|
||||
});
|
||||
|
||||
// 체크된 항목이 없으면 전체 데이터 사용
|
||||
if(checkedRows.length === 0) {
|
||||
checkedRows = _tabulGrid.getData();
|
||||
}
|
||||
|
||||
if(checkedRows.length === 0) {
|
||||
Swal.fire({
|
||||
title: '알림',
|
||||
text: '견적요청서를 생성할 데이터가 없습니다.',
|
||||
icon: 'warning'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 공급업체/가공업체가 입력된 항목 분류
|
||||
var supplyItems = []; // 공급업체가 입력된 항목
|
||||
var processingItems = []; // 가공업체가 입력된 항목
|
||||
|
||||
checkedRows.forEach(function(item) {
|
||||
var vendorPm = item.VENDOR_PM || '';
|
||||
var processingVendor = item.PROCESSING_VENDOR || '';
|
||||
var originalObjids = item.ORIGINAL_OBJIDS || item.OBJID;
|
||||
|
||||
if(vendorPm && vendorPm !== '') {
|
||||
supplyItems.push({
|
||||
originalObjids: originalObjids,
|
||||
vendorObjid: vendorPm,
|
||||
partNo: item.PART_NO,
|
||||
partName: item.PART_NAME
|
||||
});
|
||||
}
|
||||
|
||||
if(processingVendor && processingVendor !== '') {
|
||||
processingItems.push({
|
||||
originalObjids: originalObjids,
|
||||
vendorObjid: processingVendor,
|
||||
partNo: item.PART_NO,
|
||||
partName: item.PART_NAME
|
||||
// 서버 API에서 견적요청서 생성 가능 항목 직접 조회 (메인 리스트와 동일한 패턴)
|
||||
$.ajax({
|
||||
url: "/salesMng/getPurchaseListForQuotation.do",
|
||||
type: "POST",
|
||||
data: { SALES_REQUEST_MASTER_OBJID: salesRequestMasterObjid },
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
if(response.resultFlag === "S" && response.list && response.list.length > 0) {
|
||||
fn_processQuotationRequestFromServer(response.list);
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: '알림',
|
||||
text: '견적요청서를 생성할 대상이 없습니다.\n(이미 생성된 견적요청서이거나, 공급업체/가공업체가 입력된 항목이 필요합니다)',
|
||||
icon: 'warning'
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("구매리스트 조회 오류:", error);
|
||||
Swal.fire({
|
||||
title: '오류',
|
||||
text: '구매리스트 조회 중 오류가 발생했습니다.',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if(supplyItems.length === 0 && processingItems.length === 0) {
|
||||
Swal.fire({
|
||||
title: '알림',
|
||||
text: '공급업체 또는 가공업체가 입력된 항목이 없습니다.\n업체를 먼저 입력해주세요.',
|
||||
icon: 'warning'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 업체별로 그룹화
|
||||
}
|
||||
|
||||
function fn_processQuotationRequestFromServer(purchaseList) {
|
||||
var supplyVendorGroups = {};
|
||||
var processingVendorGroups = {};
|
||||
|
||||
supplyItems.forEach(function(item) {
|
||||
if(!supplyVendorGroups[item.vendorObjid]) {
|
||||
supplyVendorGroups[item.vendorObjid] = [];
|
||||
|
||||
purchaseList.forEach(function(item) {
|
||||
var vendorPm = (item.VENDOR_PM || item.vendor_pm || '').toString();
|
||||
var processingVendor = (item.PROCESSING_VENDOR || item.processing_vendor || '').toString();
|
||||
var originalObjids = (item.ORIGINAL_OBJIDS || item.original_objids || item.OBJID || item.objid || '').toString();
|
||||
var vendorName = (item.VENDOR_NAME || item.vendor_name || '').toString();
|
||||
var processingVendorName = (item.PROCESSING_VENDOR_NAME || item.processing_vendor_name || '').toString();
|
||||
var canCreateSupply = (item.CAN_CREATE_SUPPLY || item.can_create_supply || '').toString();
|
||||
var canCreateProcessing = (item.CAN_CREATE_PROCESSING || item.can_create_processing || '').toString();
|
||||
|
||||
if(vendorPm !== '' && canCreateSupply === 'Y') {
|
||||
if(!supplyVendorGroups[vendorPm]) {
|
||||
supplyVendorGroups[vendorPm] = { vendorName: vendorName, parts: [] };
|
||||
}
|
||||
supplyVendorGroups[vendorPm].parts.push(originalObjids);
|
||||
}
|
||||
supplyVendorGroups[item.vendorObjid].push(item.originalObjids);
|
||||
});
|
||||
|
||||
processingItems.forEach(function(item) {
|
||||
if(!processingVendorGroups[item.vendorObjid]) {
|
||||
processingVendorGroups[item.vendorObjid] = [];
|
||||
|
||||
if(processingVendor !== '' && canCreateProcessing === 'Y') {
|
||||
if(!processingVendorGroups[processingVendor]) {
|
||||
processingVendorGroups[processingVendor] = { vendorName: processingVendorName, parts: [] };
|
||||
}
|
||||
processingVendorGroups[processingVendor].parts.push(originalObjids);
|
||||
}
|
||||
processingVendorGroups[item.vendorObjid].push(item.originalObjids);
|
||||
});
|
||||
|
||||
// 생성할 견적요청서 목록 표시
|
||||
|
||||
var supplyCount = Object.keys(supplyVendorGroups).length;
|
||||
var processingCount = Object.keys(processingVendorGroups).length;
|
||||
var totalCount = supplyCount + processingCount;
|
||||
|
||||
var confirmMsg = '견적요청서를 생성하시겠습니까?\n\n';
|
||||
|
||||
if(totalCount === 0) {
|
||||
Swal.fire({
|
||||
title: '알림',
|
||||
text: '견적요청서를 생성할 대상이 없습니다.\n(이미 생성된 견적요청서이거나, 공급업체/가공업체가 입력된 항목이 필요합니다)',
|
||||
icon: 'warning'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var confirmHtml = '<div style="text-align:left; margin-top:10px;">';
|
||||
if(supplyCount > 0) {
|
||||
confirmMsg += '- 공급업체: ' + supplyCount + '개 업체\n';
|
||||
confirmHtml += '<p><strong>공급업체:</strong> ' + supplyCount + '개 업체</p>';
|
||||
for(var vendorId in supplyVendorGroups) {
|
||||
confirmHtml += '<span style="margin-left:20px; color:#1976d2;">- ' + supplyVendorGroups[vendorId].vendorName + ' (' + supplyVendorGroups[vendorId].parts.length + '건)</span><br/>';
|
||||
}
|
||||
}
|
||||
if(processingCount > 0) {
|
||||
confirmMsg += '- 가공업체: ' + processingCount + '개 업체\n';
|
||||
confirmHtml += '<p><strong>가공업체:</strong> ' + processingCount + '개 업체</p>';
|
||||
for(var vendorId in processingVendorGroups) {
|
||||
confirmHtml += '<span style="margin-left:20px; color:#388e3c;">- ' + processingVendorGroups[vendorId].vendorName + ' (' + processingVendorGroups[vendorId].parts.length + '건)</span><br/>';
|
||||
}
|
||||
}
|
||||
confirmMsg += '\n총 ' + totalCount + '개의 견적요청서가 생성됩니다.';
|
||||
|
||||
confirmHtml += '</div>';
|
||||
|
||||
Swal.fire({
|
||||
title: '견적요청서 생성',
|
||||
text: confirmMsg,
|
||||
html: '<p>총 <strong>' + totalCount + '개</strong>의 견적요청서가 생성됩니다.</p>' + confirmHtml,
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: '생성',
|
||||
cancelButtonText: '취소'
|
||||
cancelButtonText: '취소',
|
||||
width: '500px'
|
||||
}).then((result) => {
|
||||
if(result.isConfirmed) {
|
||||
fn_executeCreateQuotationRequest(supplyVendorGroups, processingVendorGroups);
|
||||
// 기존 fn_executeCreateQuotationRequest에 맞게 변환
|
||||
var supplyGroups = {};
|
||||
for(var vendorId in supplyVendorGroups) {
|
||||
supplyGroups[vendorId] = supplyVendorGroups[vendorId].parts;
|
||||
}
|
||||
var processingGroups = {};
|
||||
for(var vendorId in processingVendorGroups) {
|
||||
processingGroups[vendorId] = processingVendorGroups[vendorId].parts;
|
||||
}
|
||||
fn_executeCreateQuotationRequest(supplyGroups, processingGroups);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5499,14 +5499,14 @@ ORDER BY V.PATH2
|
||||
CASE WHEN G.VENDOR_PM IS NOT NULL AND G.VENDOR_PM != '' AND NOT EXISTS (
|
||||
SELECT 1 FROM QUOTATION_REQUEST_DETAIL QRD
|
||||
INNER JOIN QUOTATION_REQUEST_MASTER QRM ON QRD.QUOTATION_REQUEST_MASTER_OBJID = QRM.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID = G.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID::VARCHAR = G.OBJID
|
||||
AND QRM.VENDOR_TYPE = 'SUPPLY'
|
||||
AND QRM.VENDOR_OBJID::VARCHAR = G.VENDOR_PM
|
||||
) THEN 'Y' ELSE 'N' END AS CAN_CREATE_SUPPLY,
|
||||
CASE WHEN G.PROCESSING_VENDOR IS NOT NULL AND G.PROCESSING_VENDOR != '' AND NOT EXISTS (
|
||||
SELECT 1 FROM QUOTATION_REQUEST_DETAIL QRD
|
||||
INNER JOIN QUOTATION_REQUEST_MASTER QRM ON QRD.QUOTATION_REQUEST_MASTER_OBJID = QRM.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID = G.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID::VARCHAR = G.OBJID
|
||||
AND QRM.VENDOR_TYPE = 'PROCESSING'
|
||||
AND QRM.VENDOR_OBJID::VARCHAR = G.PROCESSING_VENDOR
|
||||
) THEN 'Y' ELSE 'N' END AS CAN_CREATE_PROCESSING
|
||||
@@ -5515,7 +5515,7 @@ ORDER BY V.PATH2
|
||||
(G.VENDOR_PM IS NOT NULL AND G.VENDOR_PM != '' AND NOT EXISTS (
|
||||
SELECT 1 FROM QUOTATION_REQUEST_DETAIL QRD
|
||||
INNER JOIN QUOTATION_REQUEST_MASTER QRM ON QRD.QUOTATION_REQUEST_MASTER_OBJID = QRM.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID = G.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID::VARCHAR = G.OBJID
|
||||
AND QRM.VENDOR_TYPE = 'SUPPLY'
|
||||
AND QRM.VENDOR_OBJID::VARCHAR = G.VENDOR_PM
|
||||
))
|
||||
@@ -5523,7 +5523,7 @@ ORDER BY V.PATH2
|
||||
(G.PROCESSING_VENDOR IS NOT NULL AND G.PROCESSING_VENDOR != '' AND NOT EXISTS (
|
||||
SELECT 1 FROM QUOTATION_REQUEST_DETAIL QRD
|
||||
INNER JOIN QUOTATION_REQUEST_MASTER QRM ON QRD.QUOTATION_REQUEST_MASTER_OBJID = QRM.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID = G.OBJID
|
||||
WHERE QRD.SALES_REQUEST_PART_OBJID::VARCHAR = G.OBJID
|
||||
AND QRM.VENDOR_TYPE = 'PROCESSING'
|
||||
AND QRM.VENDOR_OBJID::VARCHAR = G.PROCESSING_VENDOR
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user