Files
wace_plm/WebContent/WEB-INF/view/productionplanning/prodResultFormPopup.jsp
2025-12-23 10:45:22 +09:00

415 lines
12 KiB
Plaintext

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.pms.common.utils.*"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*" %>
<%@include file= "/init_new.jsp" %>
<c:set var="now" value="<%=new java.util.Date()%>" />
<c:set var="today"><fmt:formatDate value="${now}" pattern="yyyy-MM-dd" /></c:set>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=Constants.SYSTEM_NAME%></title>
<style>
.input_title {border-left:1px solid #ccc; background-color:#f5f5f5; font-weight:bold;}
.required-mark { color: red; font-weight: bold; margin-left: 2px; }
.readonly-field { background-color: #eee !important; }
/* 공통 버튼 숨기기 */
.resetBtn, .excelBtn { display: none !important; }
body { min-height: auto !important; }
/* 정보 테이블 스타일 */
.info-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 10px;
}
.info-table th {
background-color: #f5f5f5;
border: 1px solid #ddd;
padding: 8px 15px;
text-align: center;
font-weight: bold;
width: 12%;
}
.info-table td {
border: 1px solid #ddd;
padding: 8px 15px;
text-align: left;
width: 21%;
}
.info-value {
font-weight: bold;
color: #333;
}
/* 실적등록 테이블 스타일 */
.result-table {
width: 100%;
border-collapse: collapse;
margin-top: 5px;
}
.result-table th {
background-color: #f5f5f5;
border: 1px solid #ccc;
padding: 8px;
text-align: center;
font-weight: bold;
}
.result-table td {
border: 1px solid #ccc;
padding: 5px;
text-align: center;
}
.result-table input[type="text"],
.result-table input[type="number"] {
width: 100%;
padding: 5px;
border: 1px solid #ddd;
box-sizing: border-box;
text-align: center;
}
.result-table input[type="number"] {
text-align: right;
}
.result-table .total-row {
background-color: #f8f9fa;
font-weight: bold;
}
.result-table .total-row td {
padding: 10px 5px;
}
.result-table .total-label {
background-color: #e9ecef;
font-weight: bold;
}
.result-table .total-value {
color: #0066cc;
font-weight: bold;
}
.result-table .delete-btn {
background-color: #dc3545;
color: white;
border: none;
padding: 3px 8px;
cursor: pointer;
border-radius: 3px;
font-size: 12px;
}
.result-table .delete-btn:hover {
background-color: #c82333;
}
</style>
</head>
<script type="text/javascript">
var _projectObjid = "${param.projectObjid}";
var _rowIndex = 0;
$(function(){
fnc_datepick();
// 프로젝트 정보 로드
if(_projectObjid) {
fn_loadProjectInfo();
}
// 실적 목록 조회
fn_search();
// 행추가 버튼
$("#btnAddRow").click(function(){
fn_addRow();
});
// 저장 버튼
$("#btnSave").click(function(){
fn_save();
});
});
// 날짜 선택기 초기화
function fnc_datepick(){
$(document).on('focus', '.date-input', function(){
$(this).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
});
}
// 프로젝트 정보 로드
function fn_loadProjectInfo() {
$.ajax({
url: "/productionplanning/getProdPlanProjectInfo.do",
type: "POST",
data: { "projectObjid": _projectObjid },
dataType: "json",
async: false,
success: function(data){
console.log("프로젝트 정보 응답:", data);
if(data && data.result == "success" && data.info){
var info = data.info;
console.log("info 데이터:", info);
// 대소문자 모두 체크
var partNo = info.part_no || info.PART_NO || '-';
var partName = info.part_name || info.PART_NAME || '-';
var orderQty = info.order_qty || info.ORDER_QTY || 0;
var extraProdQty = info.extra_prod_qty || info.EXTRA_PROD_QTY || 0;
$("#PART_NO").text(partNo);
$("#PART_NAME").text(partName);
$("#ORDER_QTY").text(fnc_formatNumber(orderQty));
$("#EXTRA_PROD_QTY").text(fnc_formatNumber(extraProdQty));
// 총생산수량 = 수주수량 + 추가생산수량
var orderQtyNum = parseInt(orderQty) || 0;
var extraProdQtyNum = parseInt(extraProdQty) || 0;
$("#TOTAL_PROD_QTY").text(fnc_formatNumber(orderQtyNum + extraProdQtyNum));
}
},
error: function(jqxhr, status, error){
console.error("프로젝트 정보 조회 실패:", error);
}
});
}
// 숫자 포맷팅
function fnc_formatNumber(num) {
if(num == null || num == '') return '0';
return parseInt(num).toLocaleString();
}
// 실적 목록 조회
function fn_search() {
var params = {
projectObjid: _projectObjid
};
$.ajax({
url: "/productionplanning/getProdResultListByDate.do",
type: "POST",
data: params,
dataType: "json",
success: function(data){
console.log("실적 데이터 응답:", data);
if(data && data.list && data.list.length > 0) {
// 기존 데이터 로드
for(var i = 0; i < data.list.length; i++) {
var row = data.list[i];
// 대소문자 모두 체크
var resultDate = row.result_date || row.RESULT_DATE || '';
var assemblyQty = row.assembly_qty || row.ASSEMBLY_QTY || 0;
var inspectionQty = row.inspection_qty || row.INSPECTION_QTY || 0;
var shipWaitQty = row.ship_wait_qty || row.SHIP_WAIT_QTY || 0;
fn_addRow(resultDate, assemblyQty, inspectionQty, shipWaitQty);
}
} else {
// 데이터 없으면 빈 행 하나 추가
fn_addRow();
}
fn_updateTotals();
},
error: function(jqxhr, status, error){
console.error("실적 조회 실패:", error);
fn_addRow();
}
});
}
// 행 추가
function fn_addRow(resultDate, assemblyQty, inspectionQty, shipWaitQty) {
_rowIndex++;
var today = '${today}';
var html = '<tr id="row_' + _rowIndex + '" data-row-index="' + _rowIndex + '">';
html += '<td><input type="text" class="date-input" name="RESULT_DATE_' + _rowIndex + '" value="' + (resultDate || today) + '" placeholder="YYYY-MM-DD"></td>';
html += '<td><input type="number" class="qty-input assembly-qty" name="ASSEMBLY_QTY_' + _rowIndex + '" value="' + (assemblyQty || 0) + '" min="0" onchange="fn_updateTotals()"></td>';
html += '<td><input type="number" class="qty-input inspection-qty" name="INSPECTION_QTY_' + _rowIndex + '" value="' + (inspectionQty || 0) + '" min="0" onchange="fn_updateTotals()"></td>';
html += '<td><input type="number" class="qty-input ship-wait-qty" name="SHIP_WAIT_QTY_' + _rowIndex + '" value="' + (shipWaitQty || 0) + '" min="0" onchange="fn_updateTotals()"></td>';
html += '<td><button type="button" class="delete-btn" onclick="fn_deleteRow(' + _rowIndex + ')">삭제</button></td>';
html += '</tr>';
$("#resultTableBody").append(html);
fn_updateTotals();
}
// 행 삭제
function fn_deleteRow(rowIndex) {
$("#row_" + rowIndex).remove();
fn_updateTotals();
}
// 총수량 업데이트
function fn_updateTotals() {
var totalAssembly = 0;
var totalInspection = 0;
var totalShipWait = 0;
$(".assembly-qty").each(function() {
totalAssembly += parseInt($(this).val()) || 0;
});
$(".inspection-qty").each(function() {
totalInspection += parseInt($(this).val()) || 0;
});
$(".ship-wait-qty").each(function() {
totalShipWait += parseInt($(this).val()) || 0;
});
$("#TOTAL_ASSEMBLY").text(totalAssembly.toLocaleString());
$("#TOTAL_INSPECTION").text(totalInspection.toLocaleString());
$("#TOTAL_SHIP_WAIT").text(totalShipWait.toLocaleString());
}
// 저장
function fn_save() {
var resultList = [];
$("#resultTableBody tr").each(function() {
var rowIndex = $(this).data('row-index');
var resultDate = $("input[name='RESULT_DATE_" + rowIndex + "']").val();
var assemblyQty = parseInt($("input[name='ASSEMBLY_QTY_" + rowIndex + "']").val()) || 0;
var inspectionQty = parseInt($("input[name='INSPECTION_QTY_" + rowIndex + "']").val()) || 0;
var shipWaitQty = parseInt($("input[name='SHIP_WAIT_QTY_" + rowIndex + "']").val()) || 0;
if(resultDate) {
resultList.push({
RESULT_DATE: resultDate,
ASSEMBLY_QTY: assemblyQty,
INSPECTION_QTY: inspectionQty,
SHIP_WAIT_QTY: shipWaitQty
});
}
});
if(resultList.length === 0) {
Swal.fire('저장할 데이터가 없습니다.');
return;
}
// 유효성 검사
for(var i = 0; i < resultList.length; i++) {
var row = resultList[i];
if(!row.RESULT_DATE) {
Swal.fire('날짜를 입력해주세요. (행 ' + (i+1) + ')');
return;
}
}
if(!confirm('저장하시겠습니까?')) return;
$.ajax({
url: "/productionplanning/saveProdResultByDate.do",
type: "POST",
contentType: "application/json",
data: JSON.stringify({
projectObjid: _projectObjid,
resultList: resultList
}),
dataType: "json",
success: function(data){
if(data.result == "success") {
alert(data.msg || "저장되었습니다.");
if(opener && opener.fn_search) {
opener.fn_search();
}
window.close(); // 저장 성공 시 자동 닫기
} else {
Swal.fire(data.msg || "저장에 실패했습니다.");
}
},
error: function(jqxhr, status, error){
Swal.fire("저장 중 오류가 발생했습니다.");
console.error(error);
}
});
}
// 팝업 닫힐 때 부모 새로고침
window.addEventListener('unload', function() {
if(window.opener && window.opener.fn_search) {
window.opener.fn_search();
}
});
</script>
<body style="overflow-x: hidden;">
<form name="form1" id="form1" method="post">
<input type="hidden" name="PROJECT_OBJID" id="PROJECT_OBJID" value="${param.projectObjid}">
<section>
<div class="plm_menu_name" style="display:flex;">
<h2 style="width:100%;height:50px;text-align:center;margin-top:10px;">
<span style="font-size:20px;">생산실적 등록</span>
</h2>
</div>
<!-- 프로젝트 정보 표시 -->
<div style="padding:10px 10px 0 10px;">
<table class="info-table">
<colgroup>
<col width="15%" />
<col width="35%" />
<col width="15%" />
<col width="35%" />
</colgroup>
<tr>
<th>품번 <span style="color:red;">*</span></th>
<td><span id="PART_NO" class="info-value">-</span></td>
<th>품명 <span style="color:red;">*</span></th>
<td><span id="PART_NAME" class="info-value">-</span></td>
</tr>
<tr>
<th>수주수량 <span style="color:red;">*</span></th>
<td><span id="ORDER_QTY" class="info-value">0</span></td>
<th>추가생산수량 <span style="color:red;">*</span></th>
<td><span id="EXTRA_PROD_QTY" class="info-value">0</span></td>
</tr>
<tr>
<th>총생산수량 <span style="color:red;">*</span></th>
<td colspan="3"><span id="TOTAL_PROD_QTY" class="info-value" style="color:#0066cc;">0</span></td>
</tr>
</table>
</div>
<div class="plm_menu_name_gdnsi" style="display:flex; justify-content:space-between; align-items:center; padding:0 10px; margin:10px 0;">
<h2 style="margin:0;"><span>실적등록</span></h2>
<div class="btnArea" style="margin:0;">
<input type="button" value="행추가" class="plm_btns" id="btnAddRow">
<input type="button" value="저장" class="plm_btns" id="btnSave">
<input type="button" value="닫기" class="plm_btns" onclick="window.close();">
</div>
</div>
<!-- 실적등록 테이블 -->
<div style="padding: 0 10px 10px 10px;">
<table class="result-table">
<thead>
<tr>
<th style="width:150px;">날짜</th>
<th style="width:120px;">완조립</th>
<th style="width:120px;">검사</th>
<th style="width:120px;">출하대기</th>
<th style="width:60px;">삭제</th>
</tr>
</thead>
<tbody id="resultTableBody">
<!-- 동적으로 행 추가 -->
</tbody>
<tfoot>
<tr class="total-row">
<td class="total-label">총수량</td>
<td class="total-value"><span id="TOTAL_ASSEMBLY">0</span></td>
<td class="total-value"><span id="TOTAL_INSPECTION">0</span></td>
<td class="total-value"><span id="TOTAL_SHIP_WAIT">0</span></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</section>
</form>
</body>
</html>