Files
wace_plm/WebContent/WEB-INF/view/partMng/structureBomCopyFormPopup.jsp
2025-11-25 15:15:20 +09:00

775 lines
20 KiB
Plaintext

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.pms.common.utils.*"%>
<%@ page import="java.util.*" %>
<%@include file= "/init.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=Constants.SYSTEM_NAME%></title>
<link href="/css/tabulator/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="/js/tabulator/tabulator.min.js"></script>
<style>
::-webkit-scrollbar {
width: 10px;
height: 15px;
}
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
/* 상단 입력 영역 */
.top-input-section {
padding: 15px 20px;
background: #f9f9f9;
border-bottom: 2px solid #ddd;
}
.input-table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.input-table td {
padding: 5px 8px;
vertical-align: middle;
}
.input-table label {
font-weight: bold;
display: block;
white-space: nowrap;
}
.input-table input[type="text"] {
padding: 6px 8px;
border: 1px solid #ddd;
border-radius: 3px;
width: 100%;
box-sizing: border-box;
}
.bom-select-table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
table-layout: fixed;
}
.bom-select-table td {
padding: 5px 8px;
vertical-align: middle;
}
.bom-select-table label {
font-weight: bold;
display: block;
white-space: nowrap;
}
.bom-select-table input[type="text"] {
padding: 6px 8px;
border: 1px solid #ddd;
border-radius: 3px;
width: 100%;
box-sizing: border-box;
}
/* 하단 버튼 영역 */
.bottom-button-section {
padding: 15px 20px;
background: #f9f9f9;
border-top: 2px solid #ddd;
text-align: center;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 100;
}
/* 그리드 영역 */
#structureTableWrap1 {
padding: 15px 20px;
height: calc(100vh - 260px);
overflow: auto;
padding-bottom: 80px;
}
#structureName {
margin-bottom: 10px;
font-weight: bold;
padding: 8px 0;
border-bottom: 1px solid #eee;
}
#structureName2 {
margin-bottom: 10px;
font-size: 12px;
color: #666;
}
/* Tabulator 커스텀 스타일 */
.tabulator-row.level-1 { background-color: #fde9d9 !important; }
.tabulator-row.level-2 { background-color: #daeef3 !important; }
.tabulator-row.level-3 { background-color: #e4dfec !important; }
.tabulator-row.level-4 { background-color: #ebf1de !important; }
.tabulator-row.level-5 { background-color: #f2f2f2 !important; }
.tabulator-row.level-6 { background-color: #f2dcdb !important; }
.tabulator-row.level-7 { background-color: #eeece1 !important; }
.tabulator-row.level-8 { background-color: #dce6f1 !important; }
.tabulator-row.level-9 { background-color: #FFFFEB !important; }
.tabulator-row.level-10 { background-color: #ffffff !important; }
</style>
<script>
var _tabulGrid;
var selectedRowData = null;
var selectedBomObjId = null; // 선택된 BOM의 OBJID
var selectedBomType = null; // 'EBOM' 또는 'MBOM'
var bomGridData = []; // BOM 그리드 데이터
$(function(){
// Select2 초기화
$('.select2').select2();
// 페이지 로드 시 품번/품명 자동 입력
// 우선순위: urlParamInfo(POST 파라미터) > projectInfo(DB 조회)
<c:choose>
<c:when test="${not empty urlParamInfo}">
// POST 파라미터로 전달된 품번/품명 사용
$("#COPY_PART_NO").val("${urlParamInfo.PART_NO}");
$("#COPY_PART_NAME").val("${urlParamInfo.PART_NAME}");
</c:when>
<c:when test="${not empty projectInfo}">
// DB에서 조회한 프로젝트 정보 사용
$("#COPY_PART_NO").val("${projectInfo.PART_NO}");
$("#COPY_PART_NAME").val("${projectInfo.PART_NAME}");
// Machine이 아닌 경우, 동일 품번의 기존 M-BOM 확인 및 자동 로드
var productCode = "${projectInfo.PRODUCT}";
var isMachine = productCode && (productCode === '0001807' || productCode.toUpperCase().indexOf('MACHINE') >= 0);
if(!isMachine && "${projectInfo.PART_NO}" !== "") {
fn_checkExistingMbom("${projectInfo.PART_NO}");
}
</c:when>
</c:choose>
// 담기 버튼 - 선택한 BOM을 복사 대상으로 설정
$("#btnAddItem").click(function(){
var partNo = $("#COPY_PART_NO").val().trim();
var partName = $("#COPY_PART_NAME").val().trim();
if(!partNo || !partName) {
Swal.fire('품번과 품명을 입력해주세요.');
return;
}
// 선택된 BOM이 있는지 확인
if(!selectedBomObjId) {
Swal.fire('E-BOM 또는 M-BOM을 먼저 선택해주세요.');
return;
}
Swal.fire({
title: '담기 완료',
text: '선택한 BOM이 복사 대상으로 설정되었습니다.',
icon: 'success'
});
});
// 저장 버튼 - E-BOM을 M-BOM으로 복사
$("#btnSaveItem").click(function(){
fn_saveBomCopy();
});
// E-BOM 셀렉트박스 변경 이벤트
$("#EBOM_SELECT").change(function(){
var selectedObjId = $(this).val();
if(!selectedObjId) {
// 선택 해제 시 M-BOM 셀렉트박스 활성화 및 그리드 초기화
$("#MBOM_SELECT").prop("disabled", false);
_tabulGrid.clearData();
$("#bomPartName").text("");
return;
}
// E-BOM 선택 시 M-BOM 셀렉트박스 비활성화
$("#MBOM_SELECT").val("").prop("disabled", true);
// 선택된 E-BOM으로 미리보기 로드
fn_loadBomPreviewByObjId(selectedObjId, 'EBOM');
});
// M-BOM 셀렉트박스 변경 이벤트
$("#MBOM_SELECT").change(function(){
var selectedObjId = $(this).val();
if(!selectedObjId) {
// 선택 해제 시 E-BOM 셀렉트박스 활성화 및 그리드 초기화
$("#EBOM_SELECT").prop("disabled", false);
_tabulGrid.clearData();
$("#bomPartName").text("");
return;
}
// M-BOM 선택 시 E-BOM 셀렉트박스 비활성화
$("#EBOM_SELECT").val("").prop("disabled", true);
// 선택된 M-BOM으로 미리보기 로드
fn_loadBomPreviewByObjId(selectedObjId, 'MBOM');
});
// Excel 다운로드 버튼
$("#btnExcel").click(function() {
fn_excel();
});
// 도면 업로드 버튼 클릭
$("#btnDrawingUpload").click(function() {
$("#drawingFiles").click();
});
// 파일 선택 이벤트
$("#drawingFiles").change(function() {
fn_uploadDrawingFiles(this.files);
});
// 초기 그리드 생성 (빈 그리드)
fn_initGrid([], 3);
});
// 기존 M-BOM 확인 (Machine 이외 제품용)
function fn_checkExistingMbom(partNo) {
$.ajax({
url: "/productionplanning/getLatestMbomByPartNo.do",
type: "POST",
data: { partNo: partNo },
dataType: "json",
success: function(response) {
console.log("getLatestMbomByPartNo 응답:", response);
if(response && response.MBOM_PART_NO) {
// 기존 M-BOM이 있는 경우 사용자에게 알림
Swal.fire({
title: '기존 M-BOM 발견',
html: '동일 품번(' + partNo + ')의 M-BOM이 이미 존재합니다.<br>' +
'M-BOM 품번: ' + response.MBOM_PART_NO + '<br>' +
'저장일: ' + response.SAVE_DATE + '<br><br>' +
'기존 M-BOM을 자동으로 불러오시겠습니까?',
icon: 'question',
showCancelButton: true,
confirmButtonText: '자동 불러오기',
cancelButtonText: '새로 생성'
}).then((result) => {
if(result.isConfirmed) {
// M-BOM 자동 로드
$("#MBOM_PART_NO").val(response.MBOM_PART_NO);
fn_loadBomPreview(response.MBOM_PART_NO, 'MBOM');
}
});
} else {
console.log("기존 M-BOM이 없습니다.");
}
},
error: function(xhr, status, error) {
console.error("getLatestMbomByPartNo 에러:", xhr, status, error);
}
});
}
// BOM 미리보기 로드 (품번으로)
function fn_loadBomPreview(partNo, bomType) {
console.log("fn_loadBomPreview 호출:", partNo, bomType);
// 먼저 품번으로 BOM OBJID 조회
$.ajax({
url: "/partMng/getBomObjIdByPartNo.do",
type: "POST",
data: { partNo: partNo },
dataType: "json",
success: function(response) {
console.log("getBomObjIdByPartNo 응답:", response);
if(response && response.OBJID) {
$("#bomPartName").text(partNo);
// 전역 변수에 저장
selectedBomObjId = response.OBJID;
selectedBomType = bomType;
// BOM 트리 데이터 로드
fn_loadBomTree(response.OBJID);
} else {
console.error("BOM OBJID를 찾을 수 없음:", response);
Swal.fire('해당 품번의 BOM을 찾을 수 없습니다.');
}
},
error: function(xhr, status, error) {
console.error("getBomObjIdByPartNo 에러:", xhr, status, error);
Swal.fire('BOM 조회 중 오류가 발생했습니다.');
}
});
}
// BOM 미리보기 로드 (OBJID로 직접)
function fn_loadBomPreviewByObjId(objId, bomType) {
console.log("fn_loadBomPreviewByObjId 호출:", objId, bomType);
// 전역 변수에 저장
selectedBomObjId = objId;
selectedBomType = bomType;
// 셀렉트박스에서 선택된 텍스트를 품명으로 표시
var selectBox = bomType === 'EBOM' ? $("#EBOM_SELECT") : $("#MBOM_SELECT");
var selectedText = selectBox.find("option:selected").text();
$("#bomPartName").text(selectedText);
// BOM 트리 데이터 로드
fn_loadBomTree(objId);
}
// BOM 트리 데이터 로드
function fn_loadBomTree(bomObjId) {
console.log("fn_loadBomTree 호출:", bomObjId);
$.ajax({
url: "/partMng/getStructureTreeJson.do",
type: "POST",
data: {
objId: bomObjId,
bomReportObjid: bomObjId,
search_type: "working"
},
dataType: "json",
success: function(response) {
console.log("getStructureTreeJson 응답:", response);
if(response && response.length > 0) {
var maxLevel = response[0].MAX_LEVEL || 3;
// Level 필드 생성
var processedData = [];
response.forEach(function(item) {
for(var i = 1; i <= maxLevel; i++) {
item['LEVEL_' + i] = (item.LEVEL == i) ? '*' : '';
}
processedData.push(item);
});
// 전역 변수에 저장
bomGridData = processedData;
fn_initGrid(processedData, maxLevel);
} else {
console.warn("BOM 트리 데이터가 비어있음");
bomGridData = [];
fn_initGrid([], 3);
}
},
error: function(xhr, status, error) {
console.error("getStructureTreeJson 에러:", xhr, status, error);
Swal.fire('BOM 트리 조회 중 오류가 발생했습니다.');
}
});
}
// 도면 파일 업로드
function fn_uploadDrawingFiles(files) {
if(!files || files.length === 0) {
Swal.fire('파일을 선택해주세요.');
return;
}
Swal.fire('도면 다중 업로드 기능은 구현 예정입니다.');
}
// Tabulator 그리드 초기화
function fn_initGrid(data, maxLevel) {
maxLevel = maxLevel || 3; // 기본 3레벨
// 데이터에서 최대 레벨 계산
if(data && data.length > 0) {
data.forEach(function(row) {
if(row.LEVEL && row.LEVEL > maxLevel) {
maxLevel = row.LEVEL;
}
});
}
// 컬럼 정의
var columns = [
{
headerHozAlign: 'center',
hozAlign: 'center',
width: 60,
headerSort: false,
title: '선택',
field: 'RADIO',
formatter: function(cell) {
var rowData = cell.getData();
return '<input type="radio" name="checkedPartNo" value="' + (rowData.CHILD_OBJID || '') + '">';
},
cellClick: function(e, cell) {
var radio = $(e.target);
if(radio.is(':radio')) {
selectedRowData = cell.getData();
$('input[name=checkedPartNo]').not(radio).prop('checked', false);
}
}
}
];
// 수준 컬럼 그룹
var levelColumns = [];
for(var i = 1; i <= maxLevel; i++) {
levelColumns.push({
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 30,
title: i,
field: 'LEVEL_' + i,
formatter: function(cell) {
return cell.getValue() === '*' ? '*' : '';
}
});
}
columns.push({
title: '수준',
headerHozAlign: 'center',
columns: levelColumns
});
// 나머지 컬럼 추가
columns.push(
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 220,
title: '품번',
field: 'PART_NO'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
// width: 200,
title: '품명',
field: 'PART_NAME'
},
{
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 60,
title: '수량',
field: 'QTY_TEMP'
},
{
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 80,
title: '항목 수량',
field: 'ITEM_QTY'
},
{
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 60,
title: '3D',
field: 'CU01_CNT',
formatter: function(cell) {
var rowData = cell.getData();
var iconClass = (rowData.CU01_CNT && rowData.CU01_CNT > 0) ? 'file_icon' : 'file_empty_icon';
return '<a href="#" class="File ' + iconClass + '"></a>';
}
},
{
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 60,
title: '2D',
field: 'CU02_CNT',
formatter: function(cell) {
var rowData = cell.getData();
var iconClass = (rowData.CU02_CNT && rowData.CU02_CNT > 0) ? 'file_icon' : 'file_empty_icon';
return '<a href="#" class="File ' + iconClass + '"></a>';
}
},
{
headerHozAlign: 'center',
hozAlign: 'center',
headerSort: false,
width: 60,
title: 'PDF',
field: 'CU03_CNT',
formatter: function(cell) {
var rowData = cell.getData();
var iconClass = (rowData.CU03_CNT && rowData.CU03_CNT > 0) ? 'file_icon' : 'file_empty_icon';
return '<a href="#" class="File ' + iconClass + '"></a>';
}
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 130,
title: '재료',
field: 'MATERIAL'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 120,
title: '열처리경도',
field: 'HEAT_TREATMENT_HARDNESS'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 130,
title: '열처리방법',
field: 'HEAT_TREATMENT_METHOD'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 130,
title: '표면처리',
field: 'SURFACE_TREATMENT'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 120,
title: '메이커',
field: 'MAKER'
},
{
headerHozAlign: 'center',
hozAlign: 'left',
headerSort: false,
width: 100,
title: '범주이름',
field: 'CATEGORY_NAME'
}
);
// 기존 그리드 제거
if(_tabulGrid) {
_tabulGrid.destroy();
}
// Tabulator 생성
_tabulGrid = new Tabulator("#structureGrid", {
data: data,
layout: "fitColumns",
height: "calc(100vh - 360px)",
columns: columns,
rowFormatter: function(row) {
var data = row.getData();
if(data.LEVEL) {
$(row.getElement()).addClass('level-' + data.LEVEL);
}
},
placeholder: "BOM 데이터를 조회하려면 E-BOM 또는 M-BOM 품번을 입력하고 선택 버튼을 클릭하세요."
});
}
// BOM 복사 저장 - PROJECT_MGMT에 할당 정보만 저장
function fn_saveBomCopy() {
var copyPartNo = $("#COPY_PART_NO").val().trim();
var copyPartName = $("#COPY_PART_NAME").val().trim();
var targetObjId = $("#TARGET_OBJID").val();
// 유효성 검사
if(!targetObjId) {
Swal.fire('프로젝트가 선택되지 않았습니다.');
return;
}
if(!copyPartNo || !copyPartName) {
Swal.fire('품번과 품명을 입력해주세요.');
return;
}
if(!selectedBomObjId) {
Swal.fire('복사할 BOM을 선택해주세요.');
return;
}
if(bomGridData.length === 0) {
Swal.fire('복사할 BOM 데이터가 없습니다.');
return;
}
// 확인 메시지
var confirmMessage = '선택한 ' + selectedBomType + '을(를) M-BOM 기준으로 할당하시겠습니까?\n' +
'실제 M-BOM 생성은 M-BOM 상세 팝업에서 저장 시 이루어집니다.';
Swal.fire({
title: 'BOM 할당',
text: confirmMessage,
icon: 'question',
showCancelButton: true,
confirmButtonText: '할당',
cancelButtonText: '취소'
}).then((result) => {
if(result.isConfirmed) {
// 할당 처리
Swal.fire({
title: '할당 중...',
text: 'BOM 할당 정보를 저장하고 있습니다.',
allowOutsideClick: false,
didOpen: () => {
Swal.showLoading();
}
});
$.ajax({
url: "/productionplanning/saveBomAssignment.do",
type: "POST",
data: JSON.stringify({
projectObjId: targetObjId,
sourceBomType: selectedBomType, // 'EBOM' or 'MBOM'
sourceBomObjId: selectedBomObjId
}),
contentType: "application/json",
dataType: "json",
success: function(response) {
Swal.close();
if(response && response.result === 'success') {
Swal.fire({
title: '할당 완료',
text: 'BOM 할당 정보가 저장되었습니다.\nM-BOM 셀을 클릭하여 실제 M-BOM을 생성하세요.',
icon: 'success'
}).then(() => {
// 부모 창(M-BOM 관리)의 검색 함수 호출하여 그리드 업데이트
if(window.opener && !window.opener.closed) {
if(typeof window.opener.fn_search === 'function') {
window.opener.fn_search();
}
}
window.close();
});
} else {
Swal.fire({
title: '할당 실패',
text: response.message || 'BOM 할당 중 오류가 발생했습니다.',
icon: 'error'
});
}
},
error: function(xhr, status, error) {
Swal.close();
console.error('Save error:', error);
Swal.fire({
title: '할당 실패',
text: '서버 오류가 발생했습니다: ' + error,
icon: 'error'
});
}
});
}
});
}
// 닫기
function fn_close() {
window.close();
}
// Excel 다운로드
function fn_excel() {
if(_tabulGrid) {
_tabulGrid.download("xlsx", "BOM_Copy.xlsx", {sheetName: "BOM"});
}
}
</script>
</head>
<body class="backcolor">
<form name="form1" id="form1" action="" method="post">
<!-- Hidden fields -->
<input type="hidden" id="TARGET_OBJID" name="TARGET_OBJID" value="${param.objId}">
<!-- 상단: 품번/품명 입력 및 BOM 선택 영역 -->
<div class="top-input-section">
<table class="pmsPopuptable" style="margin-bottom: 10px;">
<colgroup>
<col width="10%">
<col width="20%">
<col width="10%">
<col width="20%">
<col width="30%">
<col width="10%">
</colgroup>
<tr>
<td class="input_title"><label for="COPY_PART_NO">품번</label></td>
<td>
<input type="text" id="COPY_PART_NO" name="COPY_PART_NO" style="width: 100%;" readonly>
</td>
<td class="input_title"><label for="COPY_PART_NAME">품명</label></td>
<td>
<input type="text" id="COPY_PART_NAME" name="COPY_PART_NAME" style="width: 100%;" readonly>
</td>
<td></td>
<td style="text-align: center;">
<!-- <input type="button" value="담기" class="plm_btns" id="btnAddItem"> -->
<input type="button" class="plm_btns" value="닫기" onclick="window.close();" >
<input type="button" value="저장" class="plm_btns" id="btnSaveItem">
</td>
</tr>
</table>
<table class="pmsPopuptable">
<colgroup>
<col width="10%">
<col width="90%">
</colgroup>
<tr>
<td class="input_title"><label for="EBOM_SELECT">E-BOM 선택</label></td>
<td>
<select id="EBOM_SELECT" name="EBOM_SELECT" style="width: 100%;" class="select2">
<option value="">선택</option>
${code_map.ebom_list}
</select>
</td>
</tr>
<tr>
<td class="input_title"><label for="MBOM_SELECT">M-BOM 선택</label></td>
<td>
<select id="MBOM_SELECT" name="MBOM_SELECT" style="width: 100%;" class="select2">
<option value="">선택</option>
${code_map.mbom_list}
</select>
</td>
</tr>
</table>
</div>
<!-- 중간: BOM 미리보기 그리드 -->
<div id="structureTableWrap1">
<div id="structureName">
<span id="bomPartName" style="font-weight: bold; color: #333;"></span>
<input type="button" value="Excel Download" class="plm_btns structure_btn" id="btnExcel" style="float:right;">
<input type="button" value="도면 다중 업로드" class="plm_btns structure_btn" id="btnDrawingUpload" style="float:right; margin-right:5px;">
<input type="file" id="drawingFiles" multiple style="display:none;" accept=".stp,.step,.dwg,.dxf,.pdf">
</div>
<div id="structureGrid"></div>
</div>
</form>
</body>
</html>