- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
352 lines
13 KiB
PHP
352 lines
13 KiB
PHP
<script>
|
|
// 수주내역의 후반부 자바스크립트
|
|
$(document).ready(function() {
|
|
// 서버에서 전달된 estimateList 데이터
|
|
var mode = '<?php echo $mode; ?>' ;
|
|
let estimateList = <?php echo json_encode($estimateList ?? []); ?>;
|
|
let estimateList_auto = <?php echo json_encode($estimateList_auto ?? []); ?>;
|
|
let estimateSlatList = <?php echo json_encode($estimateSlatList ?? []); ?>;
|
|
let estimateSlatList_auto = <?php echo json_encode($estimateSlatList_auto ?? []); ?>;
|
|
var etcList = <?php echo json_encode($etcList ?? []); ?>;
|
|
let screen_unapprovedList = <?php echo json_encode($screen_unapprovedList ?? []); ?>;
|
|
let slat_unapprovedList = <?php echo json_encode($slat_unapprovedList ?? []); ?>;
|
|
let motorList = <?php echo json_encode($motorList ?? []); ?>;
|
|
let bendList = <?php echo json_encode($bendList ?? []); ?>;
|
|
|
|
/**
|
|
* 입력값(raw)을 안전하게 배열로 변환합니다.
|
|
* - raw가 문자열이면 JSON.parse
|
|
* - raw가 객체/배열이면 JSON.stringify → JSON.parse
|
|
* - 파싱 실패하거나 최종 결과가 배열이 아니면 빈 배열 반환
|
|
*/
|
|
function parseJsonList(raw) {
|
|
let str;
|
|
|
|
// 1) raw를 JSON 문자열로 확보
|
|
if (typeof raw === 'string') {
|
|
str = raw;
|
|
} else {
|
|
try {
|
|
str = JSON.stringify(raw);
|
|
} catch (e) {
|
|
console.error('parseJsonList: 데이터를 문자열로 변환 실패', e);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// 2) 문자열을 JSON으로 파싱
|
|
try {
|
|
const parsed = JSON.parse(str);
|
|
if (!Array.isArray(parsed)) {
|
|
console.warn('parseJsonList: 파싱 결과가 배열이 아님, 빈 배열로 초기화');
|
|
return [];
|
|
}
|
|
return parsed;
|
|
} catch (e) {
|
|
console.error('parseJsonList: JSON 파싱 오류', e);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
|
|
// 각각 리스트 파싱
|
|
screen_unapprovedList = parseJsonList(screen_unapprovedList);
|
|
slat_unapprovedList = parseJsonList(slat_unapprovedList);
|
|
motorList = parseJsonList(motorList);
|
|
bendList = parseJsonList(bendList);
|
|
|
|
// 화면 로딩 시 데이터가 있을 경우 해당 테이블에 행을 추가
|
|
screen_unapprovedList.forEach(rowData => {
|
|
addRowUA_screen($('#screen_unapprovedListBody'), rowData);
|
|
});
|
|
|
|
slat_unapprovedList.forEach(rowData => {
|
|
addRowUA_slat($('#slat_unapprovedListBody'), rowData);
|
|
});
|
|
|
|
motorList.forEach(rowData => {
|
|
addRowUA_motor($('#motor_listBody'), rowData);
|
|
});
|
|
|
|
bendList.forEach(rowData => {
|
|
addRowUA_bend($('#bend_listBody'), rowData);
|
|
});
|
|
|
|
|
|
// 장비리스트에 대한 JSON이 배열인지 아닌지 여부를 확인하는 방법
|
|
if (typeof etcList === 'string') {
|
|
try {
|
|
etcList = JSON.parse(etcList);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
etcList = [];
|
|
}
|
|
}
|
|
|
|
if (Array.isArray(etcList)) {
|
|
console.log('etcList is an array:', etcList);
|
|
} else {
|
|
console.log('etcList is not an array, resetting to empty array');
|
|
etcList = [];
|
|
}
|
|
|
|
etcList.forEach(function(rowData, index) {
|
|
$.ajax({
|
|
url: 'fetch_etc.php', // PHP 파일 경로 수정 필요
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
itemData = response;
|
|
|
|
addRow_etc($('#etcListBody'), rowData);
|
|
},
|
|
error: function() {
|
|
alert('데이터를 불러오는데 실패했습니다.');
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
// estimateList이 객체나 배열 형태라면 바로 사용
|
|
if (typeof estimateList === 'object' && estimateList !== null) {
|
|
console.log('estimateList 객체로 전달됨');
|
|
} else if (typeof estimateList === 'string') {
|
|
// 문자열로 전달된 경우만 JSON.parse로 파싱
|
|
try {
|
|
estimateList = JSON.parse(estimateList);
|
|
document.getElementById('estimateList').value = JSON.stringify(estimateList);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
estimateList = [];
|
|
}
|
|
}
|
|
|
|
// estimateList이 객체나 배열 형태라면 바로 사용
|
|
if (typeof estimateList_auto === 'object' && estimateList_auto !== null) {
|
|
console.log('estimateList_auto 객체로 전달됨');
|
|
} else if (typeof estimateList_auto === 'string') {
|
|
// 문자열로 전달된 경우만 JSON.parse로 파싱
|
|
try {
|
|
estimateList_auto = JSON.parse(estimateList_auto);
|
|
document.getElementById('estimateList_auto').value = JSON.stringify(estimateList_auto);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
estimateList_auto = [];
|
|
}
|
|
}
|
|
|
|
// 데이터가 배열이 아니거나 비어있을 경우를 처리
|
|
if (!Array.isArray(estimateList) || estimateList.length === 0) {
|
|
console.log('estimateList 유효한 데이터가 없습니다.');
|
|
if (mode === 'view')
|
|
$("#screenWindow").hide(); // 스크린 견적서 불러오기 등 작업일지 등등 감추기
|
|
} else {
|
|
// 데이터가 있을 경우 테이블을 생성하여 표시
|
|
renderEstimateData({ estimateList: JSON.stringify(estimateList) });
|
|
}
|
|
|
|
// estimateSlatList이 객체나 배열 형태라면 바로 사용
|
|
if (typeof estimateSlatList === 'object' && estimateSlatList !== null) {
|
|
console.log('estimateSlatList 객체로 전달됨');
|
|
} else if (typeof estimateSlatList === 'string') {
|
|
// 문자열로 전달된 경우만 JSON.parse로 파싱
|
|
try {
|
|
estimateSlatList = JSON.parse(estimateSlatList);
|
|
document.getElementById('estimateSlatList').value = JSON.stringify(estimateSlatList);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
estimateSlatList = [];
|
|
}
|
|
}
|
|
|
|
// estimateSlatList이 객체나 배열 형태라면 바로 사용
|
|
if (typeof estimateSlatList_auto === 'object' && estimateSlatList_auto !== null) {
|
|
console.log('estimateSlatList_auto 객체로 전달됨');
|
|
} else if (typeof estimateSlatList_auto === 'string') {
|
|
// 문자열로 전달된 경우만 JSON.parse로 파싱
|
|
try {
|
|
estimateSlatList_auto = JSON.parse(estimateSlatList_auto);
|
|
document.getElementById('estimateSlatList_auto').value = JSON.stringify(estimateSlatList_auto);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
estimateSlatList_auto = [];
|
|
}
|
|
}
|
|
|
|
// 데이터가 배열이 아니거나 비어있을 경우를 처리
|
|
if (!Array.isArray(estimateSlatList) || estimateSlatList.length === 0) {
|
|
console.log('estimateSlatList 유효한 데이터가 없습니다.');
|
|
if (mode === 'view')
|
|
$("#slatWindow").hide(); // 스라트 견적서 불러오기 등 작업일지 등등 감추기
|
|
} else {
|
|
// 데이터가 있을 경우 테이블을 생성하여 표시
|
|
renderEstimateData_slat({ estimateSlatList: JSON.stringify(estimateSlatList) });
|
|
}
|
|
});
|
|
|
|
// 쿠키 값 가져오는 함수
|
|
function getCookie(name) {
|
|
var cookies = document.cookie.split(';');
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
var cookie = cookies[i].trim();
|
|
if (cookie.startsWith(name + '=')) {
|
|
return cookie.substring(name.length + 1);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 쿠키 저장 함수
|
|
function setCookie(name, value, days) {
|
|
var date = new Date();
|
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
var expires = "expires=" + date.toUTCString();
|
|
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
|
}
|
|
|
|
function toggleView(viewId, cookieName, iconId = null) {
|
|
const view = getCookie(cookieName);
|
|
const listContainer = $("#" + viewId);
|
|
const icon = iconId ? $(iconId) : null;
|
|
|
|
if (view === "show") {
|
|
listContainer.hide();
|
|
setCookie(cookieName, "hide", 10);
|
|
if (icon) icon.removeClass("bi-chevron-down").addClass("bi-chevron-right");
|
|
} else {
|
|
listContainer.show();
|
|
setCookie(cookieName, "show", 10);
|
|
if (icon) icon.removeClass("bi-chevron-right").addClass("bi-chevron-down");
|
|
}
|
|
}
|
|
|
|
|
|
function initializeView(viewId, cookieName, iconId = null) {
|
|
const view = getCookie(cookieName);
|
|
const listContainer = $("#" + viewId);
|
|
const icon = iconId ? $(iconId) : null;
|
|
|
|
if (view === "show") {
|
|
listContainer.show();
|
|
if (icon) icon.removeClass("bi-chevron-right").addClass("bi-chevron-down");
|
|
} else {
|
|
listContainer.hide();
|
|
if (icon) icon.removeClass("bi-chevron-down").addClass("bi-chevron-right");
|
|
}
|
|
}
|
|
|
|
|
|
// searchWarrantyNumber 함수 정의
|
|
function searchWarrantyNumber(searchCode) {
|
|
// 제품명과 인정번호 데이터를 객체로 정의합니다.
|
|
const productData = {
|
|
"KD-SL60": "NVS22-0902-1",
|
|
"KTE01": "FDS-NVS23-0117-1",
|
|
"KSS01": "FDS-OTS23-0117-2",
|
|
"KSS02": "FDS-OTS25-0318-2",
|
|
"KSE01": "FDS-OTS23-0117-3",
|
|
"KWE01": "FDS-OTS23-0117-4",
|
|
"KQTS01": "FDS-NVS23-1226-3",
|
|
"KDSS01": "FDS-OTS25-0318-1"
|
|
};
|
|
|
|
// 입력된 제품명에 해당하는 인정번호를 반환
|
|
return productData[searchCode] || "해당 제품명이 없습니다.";
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
// 뷰 ID와 쿠키 이름 매핑 (output-list 제거)
|
|
var views = [
|
|
{ id: "estimate_screenDiv", cookie: "showEsimateView", button: "#estimate_view" , iconId: "#estimate_viewIcon" },
|
|
{ id: "estimate_slatDiv", cookie: "showEsimateView_slat", button: "#estimate_slat_view" , iconId: "#estimate_slat_viewIcon" },
|
|
{ id: "showGroupViewDiv", cookie: "showGroupView", button: "#showGroupViewBtn" , iconId: "#showGroupViewIcon" }
|
|
];
|
|
|
|
views.forEach(function (view) {
|
|
$(view.button).on("click", function () {
|
|
toggleView(view.id, view.cookie, view.iconId);
|
|
});
|
|
|
|
initializeView(view.id, view.cookie, view.iconId);
|
|
});
|
|
|
|
// output-list는 항상 보이게 설정
|
|
$("#output-list").css("display", "block");
|
|
});
|
|
|
|
$(document).ready(function(){
|
|
$('#prodCode').on('change', function() {
|
|
var prodCode = $(this).val(); // 선택된 제품코드
|
|
var pairCode = $(this).find(':selected').data('pair'); // 대응하는 인정제품 코드
|
|
|
|
if (prodCode && pairCode) {
|
|
// 로트번호 자동생성 체크박스가 체크되어 있는지 확인
|
|
var lotNum = 'KD-' + pairCode ;
|
|
$('#lotNum').val(lotNum); // lotNum 필드 업데이트
|
|
} else {
|
|
$('#lotNum').val(''); // 제품코드가 선택되지 않은 경우 필드 초기화
|
|
}
|
|
|
|
// console.log('호출 prodCode' + $("#prodCode").val());
|
|
});
|
|
});
|
|
|
|
|
|
$(document).ready(function() {
|
|
// 견적선택에서 전체 선택 또는 해제 동작 구현
|
|
$('#selectAllEstimates').on('change', function() {
|
|
var isChecked = $(this).is(':checked');
|
|
// 전체 체크박스 선택 또는 해제
|
|
$('.estimate-checkbox').prop('checked', isChecked);
|
|
});
|
|
|
|
// 모달창이 열릴 때 이미 선택된 상태 유지
|
|
$('#selectEstimateModal').on('show.bs.modal', function() {
|
|
$('#selectAllEstimates').prop('checked', false); // 모달이 열릴 때 전체 선택을 초기화
|
|
});
|
|
|
|
// 다른 필요한 초기화 코드
|
|
});
|
|
|
|
<!-- mode == 'view' 조회 화면일때 사용금지 시키는 구문 -->
|
|
$(document).ready(function() {
|
|
var mode = '<?php echo $mode; ?>' ;
|
|
|
|
// 마지막에 넣어줘야 전체를 적용할 수 있다.
|
|
if (mode === 'view')
|
|
disableView();
|
|
|
|
});
|
|
|
|
function disableView() {
|
|
$('input, textarea ').prop('readonly', true); // Disable all input, textarea, and select elements
|
|
$('input[type=hidden]').prop('readonly', false);
|
|
|
|
// checkbox와 radio는 클릭 불가능하게 하고 시각적 강조
|
|
$('input[type="checkbox"], input[type="radio"]').each(function() {
|
|
$(this).addClass('readonly-checkbox readonly-radio');
|
|
});
|
|
|
|
// 파일 입력 비활성화
|
|
$('input[type=file]').prop('disabled', true);
|
|
$('.fetch_receiverBtn').prop('disabled', true); // 수신자 버튼 비활성화
|
|
$('.viewNoBtn').prop('disabled', true); //버튼 비활성화
|
|
$('.searchplace').prop('disabled', true); // 수신자 버튼 비활성화
|
|
$('.searchsecondord').prop('disabled', true); // 수신자 버튼 비활성화
|
|
$('.fetch_loadgroupBtn').prop('disabled', true); // 품질인증 그룹명 버튼 비활성화
|
|
|
|
// 레이블 텍스트 크게 설정
|
|
$('label').css('font-size', '1.5em');
|
|
|
|
// select 속성 readonly 효과 내기
|
|
$('select[data-readonly="true"]').on('mousedown', function(event) {
|
|
event.preventDefault();
|
|
});
|
|
|
|
// checkbox 속성 readonly 효과 내기
|
|
$('input[type="checkbox"][data-readonly="true"]').on('click', function(event) {
|
|
event.preventDefault();
|
|
});
|
|
|
|
}
|
|
</script>
|