- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
1612 lines
64 KiB
PHP
1612 lines
64 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
|
|
if (!isset($_SESSION["level"]) || $_SESSION["level"] > 5) {
|
|
sleep(1);
|
|
header("Location:" . $WebSite . "login/login_form.php");
|
|
exit;
|
|
}
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';
|
|
$title_message = '절곡 BOM 생성/수정';
|
|
?>
|
|
<title> <?=$title_message?> </title>
|
|
<?php if($chkMobile==true) { ?>
|
|
<style>
|
|
@media (max-width: 1000px) {
|
|
body { font-size: 25px; }
|
|
.form-control, .fw-bold, .table td, .table th { font-size: 25px; }
|
|
button { font-size: 30px; }
|
|
.modal-body, .modal-title { font-size: 30px; }
|
|
}
|
|
</style>
|
|
<?php } ?>
|
|
</head>
|
|
<body>
|
|
<?php
|
|
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
|
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';
|
|
$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : '';
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
// 임시테이블
|
|
$tablename_tmp = 'price_bend';
|
|
|
|
try {
|
|
// 최신 데이터를 가져오기 위해 ORDER BY와 LIMIT을 추가
|
|
$sql = "SELECT * FROM {$DB}.$tablename_tmp where (is_deleted IS NULL or is_deleted = '0') ORDER BY num DESC LIMIT 1";
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC); // $row 배열로 DB 정보를 불러온다.
|
|
$itemList = isset($row['itemList']) ? $row['itemList'] : [];
|
|
$load_priceDate = $row['registedate'] ?? '';
|
|
|
|
// itemList 문자열일 때만 json_decode 실행
|
|
if (is_string($itemList)) {
|
|
$itemList = json_decode($itemList, true);
|
|
}
|
|
|
|
// itemList 유효한 배열이 아닐 경우 빈 배열로 초기화
|
|
if (!is_array($itemList)) {
|
|
$itemList = [];
|
|
}
|
|
|
|
} catch (PDOException $Exception) {
|
|
print "오류: ".$Exception->getMessage();
|
|
}
|
|
|
|
// 단가를 처리하는 과정에서
|
|
// echo '<pre>';
|
|
// print_r($itemList);
|
|
// echo '</pre>';
|
|
|
|
if($mode == 'copy')
|
|
{
|
|
try {
|
|
$sql = "SELECT * FROM {$DB}.{$tablename} WHERE num = ?";
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(1, $num, PDO::PARAM_INT);
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
include '_row.php';
|
|
|
|
} catch (PDOException $Exception) {
|
|
print "오류: ".$Exception->getMessage();
|
|
}
|
|
}
|
|
else {
|
|
if($num > 0) {
|
|
try {
|
|
$sql = "SELECT * FROM {$DB}.{$tablename} WHERE num = ?";
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(1, $num, PDO::PARAM_INT);
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
include '_row.php';
|
|
} catch (PDOException $Exception) {
|
|
print "오류: ".$Exception->getMessage();
|
|
}
|
|
$mode = 'modify';
|
|
} else {
|
|
include '_request.php';
|
|
$mode = 'insert';
|
|
$priceDate = $load_priceDate;
|
|
|
|
}
|
|
}
|
|
|
|
// print 'mode : '. $mode;
|
|
|
|
?>
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/common/modal.php'); ?>
|
|
|
|
<form id="board_form" name="board_form" method="post" enctype="multipart/form-data">
|
|
<input type="hidden" id="num" name="num" value="<?= isset($row['num']) ? $row['num'] : '' ?>">
|
|
<input type="hidden" id="num" name="num" value="<?= isset($row['num']) ? $row['num'] : '' ?>">
|
|
<input type="hidden" id="mode" name="mode" value="<?= isset($mode) ? $mode : '' ?>">
|
|
<input type="hidden" id="update_log" name="update_log" value="<?= isset($row['update_log']) ? $row['update_log'] : '' ?>">
|
|
<input type="hidden" id="tablename" name="tablename" value="<?= isset($tablename) ? $tablename : '' ?>">
|
|
<input type="hidden" id="savejson" name="savejson" value="">
|
|
|
|
<div class="container-fluid">
|
|
<!-- Modal -->
|
|
<div id="myModal" class="modal">
|
|
<div class="modal-content" style="width:1400px; height:830px;">
|
|
<div class="modal-header">
|
|
<span class="modal-title"><?=$title_message?></span>
|
|
<span class="close closeBtn">×</span>
|
|
</div>
|
|
<div class="modal-body d-flex justify-content-center">
|
|
<div class="modal_detail" style="width:1350px;">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container-fluid">
|
|
<div class="card justify-content-center mt-2 mb-5">
|
|
<div class="card-header text-center">
|
|
<div class="d-flex justify-content-center align-items-center ">
|
|
<span class="text-center fs-5 mx-5"><?=$title_message?></span>
|
|
<button type="button" class="btn btn-dark btn-sm mx-2" onclick='location.reload();' > <i class="bi bi-arrow-clockwise"></i> </button>
|
|
|
|
<button type="button" id="saveBtn" class="btn btn-dark btn-sm mx-1">
|
|
<i class="bi bi-floppy-fill"></i> 저장
|
|
</button>
|
|
<?php if($num > 0 && $mode !== 'copy' ){ ?>
|
|
<button type="button" id="deleteBtn" class="btn btn-danger btn-sm mx-1">
|
|
<i class="bi bi-trash"></i> 삭제
|
|
</button>
|
|
<!-- 수정모드이면 복사 버튼도 보임 -->
|
|
<?php if($mode === 'modify'): ?>
|
|
<button type="button" id="copyBtn" class="btn btn-primary btn-sm mx-1">
|
|
<i class="bi bi-copy"></i> 복사
|
|
</button>
|
|
<button type="button" class="btn btn-outline-dark btn-sm ms-5 me-5" id="showlogBtn"> H
|
|
<?php endif; ?>
|
|
<?php } ?>
|
|
<button type="button" id="closeBtn" class="btn btn-outline-dark btn-sm ms-5">
|
|
× 닫기
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-center">
|
|
<table class="table table-bordered">
|
|
<tbody>
|
|
<tr>
|
|
<td><label for="major_category">대분류</label></td>
|
|
<td>
|
|
<select id="major_category" name="major_category" class="form-select mx-1 d-block w-auto" style="font-size: 0.8rem; height: 32px;">
|
|
<option value="" >(대분류)</option>
|
|
<option value="스크린" <?= (isset($row['major_category']) && $row['major_category'] == '스크린') ? 'selected' : '' ?>>스크린</option>
|
|
<option value="철재" <?= (isset($row['major_category']) && $row['major_category'] == '철재') ? 'selected' : '' ?>>철재</option>
|
|
</select>
|
|
</td>
|
|
<td><label for="seconditem">중분류</label></td>
|
|
<td>
|
|
<!-- 중분류 -->
|
|
<?php
|
|
// 예: getCategoryByName($parentName) 함수가 존재하며,
|
|
// '절곡물'이라는 2단계 카테고리의 자식(3단계) 카테고리 이름 배열을 리턴한다.
|
|
$l3_list = getCategoryByName('스크린','절곡물');
|
|
?>
|
|
<select id="seconditem" name="seconditem" class="form-select mx-1 d-block w-auto" style="font-size: 0.8rem; height: 32px;">
|
|
<option value="">(중분류)</option>
|
|
<?php foreach($l3_list as $itemVal): ?>
|
|
<option
|
|
value="<?= htmlspecialchars($itemVal, ENT_QUOTES, 'UTF-8') ?>"
|
|
<?= ($seconditem === $itemVal) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($itemVal, ENT_QUOTES, 'UTF-8') ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</td>
|
|
<td><label for="model_name">모델명</label></td>
|
|
<td>
|
|
<!-- 제품모델(KSS01 등) 선택 -->
|
|
<?php selectModel('model_name', $model_name); ?>
|
|
</td>
|
|
<td><label for="spec">규격</label></td>
|
|
<td colspan="3">
|
|
<div class="d-flex justify-content-center align-items-center text-center">
|
|
<!-- check_type 컨테이너 (동적으로 숨김/보임 처리) -->
|
|
<div id="check_type_container">
|
|
<select id="check_type" name="check_type" class="form-select mx-1 d-block w-auto" style="font-size: 0.8rem; height: 32px;">
|
|
<?php if($seconditem == '가이드레일') { ?>
|
|
<option value="">형상 선택</option>
|
|
<option value="벽면형" <?= (isset($check_type) && $check_type == '벽면형') ? 'selected' : '' ?>>벽면형</option>
|
|
<option value="측면형" <?= (isset($check_type) && $check_type == '측면형') ? 'selected' : '' ?>>측면형</option>
|
|
<?php } elseif($seconditem == '케이스') { ?>
|
|
<option value="">점검구 형태</option>
|
|
<option value="양면 점검구" <?= (isset($check_type) && $check_type == '양면 점검구') ? 'selected' : '' ?>>양면 점검구</option>
|
|
<!-- <option value="밑면 점검구" <?= (isset($check_type) && $check_type == '밑면 점검구') ? 'selected' : '' ?>>밑면 점검구</option>
|
|
<option value="후면 점검구" <?= (isset($check_type) && $check_type == '후면 점검구') ? 'selected' : '' ?>>후면 점검구</option>
|
|
-->
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<input id="spec" name="spec" class="form-control text-start" autocomplete="off" value="<?= isset($row['spec']) ? $row['spec'] : '' ?>" >
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="caseDetailsRow" style="display:none;">
|
|
<td><label for="box_width">박스폭</label></td>
|
|
<td>
|
|
<input id="box_width" name="box_width" class="form-control text-end w60px" autocomplete="off" value="<?= isset($row['box_width']) ? $row['box_width'] : '' ?>">
|
|
</td>
|
|
<td><label for="box_height">박스높이</label></td>
|
|
<td>
|
|
<input id="box_height" name="box_height" class="form-control text-end w60px" autocomplete="off" value="<?= isset($row['box_height']) ? $row['box_height'] : '' ?>">
|
|
</td>
|
|
<td><label for="front_bottom_width">전면밑 치수</label></td>
|
|
<td>
|
|
<input id="front_bottom_width" name="front_bottom_width" class="form-control text-end w60px" autocomplete="off" value="<?= isset($row['front_bottom_width']) ? $row['front_bottom_width'] : '' ?>">
|
|
</td>
|
|
<td><label for="rail_width">레일폭</label></td>
|
|
<td>
|
|
<input id="rail_width" name="rail_width" class="form-control text-end w60px" autocomplete="off" value="<?= isset($row['rail_width']) ? $row['rail_width'] : '' ?>">
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><label for="finishing_type">마감</label></td>
|
|
<td>
|
|
<select id="finishing_type" name="finishing_type" class="form-select mx-1 w100px" style="font-size: 0.8rem; height: 32px;">
|
|
<option value="" > (마감) </option>
|
|
<option value="SUS마감" <?= (isset($row['finishing_type']) && $row['finishing_type'] == 'SUS마감') ? 'selected' : '' ?>>SUS마감</option>
|
|
<option value="EGI마감" <?= (isset($row['finishing_type']) && $row['finishing_type'] == 'EGI마감') ? 'selected' : '' ?>>EGI마감</option>
|
|
</select>
|
|
</td>
|
|
<td><label for="unitprice">단가</label></td>
|
|
<td colspan="1">
|
|
<input id="unitprice" name="unitprice" class="form-control text-end w100px" autocomplete="off" value="<?= isset($row['unitprice']) ? $row['unitprice'] : '' ?>" >
|
|
</td>
|
|
<td><label for="priceDate">단가 기준일</label></td>
|
|
<td colspan="1">
|
|
<input id="priceDate" name="priceDate" type="date" class="form-control w120px" autocomplete="off" value="<?= isset($priceDate) ? $priceDate: '' ?>" >
|
|
</td>
|
|
<td><label for="description">메모</label></td>
|
|
<td colspan="1">
|
|
<input id="description" name="description" type="text" class="form-control text-start" autocomplete="off" value="<?= isset($row['description']) ? $row['description'] : '' ?>" >
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- 모델 상세 폼 하단에 부품 관리 섹션 추가 -->
|
|
<div class="container-fluid mt-3">
|
|
<div class="d-flex justify-content-center align-items-center mb-2">
|
|
<h5> 부품 </h5>
|
|
<button type="button" class="btn btn-outline-primary btn-sm mx-3" style="padding:2;" onclick="openBendingSearchModal(this)"> <i class="bi bi-search"></i> 검색 </button>
|
|
</div>
|
|
<table class="table table-bordered" id="partsTable">
|
|
<thead class="table-secondary">
|
|
<tr>
|
|
<th class="text-center">부품명</th>
|
|
<th class="text-center">재질</th>
|
|
<th class="text-center">연신율 합</th>
|
|
<th class="text-center">전개도 합</th>
|
|
<th class="text-center">연신율 + 전개도</th>
|
|
<th class="text-center">면적당 단가</th>
|
|
<th class="text-center w110px">단가</th>
|
|
<th class="text-center w60px">수량</th>
|
|
<th class="text-center w110px">단가합계</th>
|
|
<th class="text-center" style="width:80px;">삭제</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="partsTableTbody">
|
|
</tbody>
|
|
</table>
|
|
<div class="d-flex align-items-center justify-content-center mb-5 mt-2 m-2">
|
|
<div class="image-container mb-5">
|
|
<!-- 초기 src는 빈값으로 두고, JavaScript로 업데이트 -->
|
|
<img id="imageBending" style="width:250px;height:250px;" src="../img/no_image.png" alt="Image">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- bending 아이템 검색 모달 -->
|
|
<div class="modal fade" id="bendingSearchModal" tabindex="-1" aria-labelledby="bendingSearchModalLabel">
|
|
<div class="modal-dialog modal-full modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="bendingSearchModalLabel">절곡품 아이템 찾기</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body" style="max-height: 400px; overflow-y: auto;">
|
|
<!-- 검색결과가 표시될 영역 -->
|
|
<div id="bendingSearchResults"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</form>
|
|
|
|
<!-- 가이드레일 모달창 가져오기 load 함수 -->
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . "/guiderail/load_modal_loadForm.php" ; ?>
|
|
|
|
<script>
|
|
$(document).ready(function(){
|
|
var loader = document.getElementById('loadingOverlay');
|
|
if(loader)
|
|
loader.style.display = 'none';
|
|
});
|
|
|
|
var ajaxRequest_write = null;
|
|
|
|
$("#closeBtn").on("click", function() {
|
|
self.close();
|
|
});
|
|
|
|
$("#saveBtn").on("click", function() {
|
|
let formData = [];
|
|
$('#partsTable tbody tr').each(function() {
|
|
let rowData = {};
|
|
$(this).find('td').each(function(index) {
|
|
let cellValue = '';
|
|
// 만약 input 또는 select 요소가 있으면 해당 요소의 value 사용, 아니면 td의 텍스트 사용
|
|
if ($(this).find('input, select').length > 0) {
|
|
cellValue = $(this).find('input, select').val();
|
|
} else {
|
|
cellValue = $(this).text().trim();
|
|
}
|
|
// 키를 "col1", "col2", ... 형식으로 설정
|
|
let key = 'col' + (index + 1);
|
|
rowData[key] = cellValue;
|
|
});
|
|
formData.push(rowData);
|
|
});
|
|
let jsonString = JSON.stringify(formData);
|
|
console.log(jsonString);
|
|
// hidden input에 JSON 문자열 세팅
|
|
$('#savejson').val(jsonString);
|
|
|
|
// 이후 기존의 폼 전송 코드 실행
|
|
let msg = '저장완료';
|
|
var form = $('#board_form')[0];
|
|
var data = new FormData(form);
|
|
|
|
if (ajaxRequest_write !== null) {
|
|
ajaxRequest_write.abort();
|
|
}
|
|
|
|
ajaxRequest_write = $.ajax({
|
|
url: "insert.php",
|
|
type: "post",
|
|
data: data,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: "json",
|
|
success: function(res) {
|
|
console.log(res);
|
|
|
|
// 서버 에러 여부 체크
|
|
if (!res.success) {
|
|
Toastify({
|
|
text: '저장에 실패했습니다: ' + (res.message || ''),
|
|
gravity: "top",
|
|
position: "center",
|
|
style: { background: "#d33" }
|
|
}).showToast();
|
|
return;
|
|
}
|
|
|
|
// 부모창의 테이블 업데이트
|
|
updateParentTable(res);
|
|
|
|
Toastify({
|
|
text: msg,
|
|
duration: 3000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
backgroundColor: "#4fbe87",
|
|
}).showToast();
|
|
|
|
// 창 닫기
|
|
setTimeout(function() {
|
|
self.close();
|
|
}, 1000);
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
console.log(jqxhr, status, error);
|
|
Toastify({
|
|
text: '저장 중 오류가 발생했습니다.',
|
|
gravity: "top",
|
|
position: "center",
|
|
style: { background: "#d33" }
|
|
}).showToast();
|
|
}
|
|
});
|
|
});
|
|
|
|
// 부모창 테이블 업데이트 함수
|
|
function updateParentTable(res) {
|
|
// 부모창이 /bendingfee/list.php 파일인지 확인
|
|
const isBendingfeeListPage = opener && opener.location &&
|
|
(opener.location.href.includes('/bendingfee/list.php') ||
|
|
opener.location.pathname.includes('/bendingfee/list.php'));
|
|
|
|
if (!isBendingfeeListPage) {
|
|
console.log('Parent page is not /bendingfee/list.php, skipping table update');
|
|
return;
|
|
}
|
|
|
|
// 부모창의 테이블 찾기
|
|
const parentTable = opener.$('#myTable');
|
|
if (!parentTable.length) {
|
|
console.warn('Parent table not found');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 새 행 생성
|
|
if (res.rowHtml && res.rowHtml.trim()) {
|
|
const newRow = $(res.rowHtml.trim());
|
|
if (newRow.length && newRow.is('tr')) {
|
|
const tbody = parentTable.find('tbody');
|
|
if (tbody.length) {
|
|
if (res.mode === 'modify') {
|
|
// 수정 모드: 기존 행을 찾아서 같은 위치에 교체
|
|
const selector = 'tr[data-num="' + res.num + '"]';
|
|
const $existingRow = opener.$(selector);
|
|
if ($existingRow.length) {
|
|
// 기존 행의 위치에 새 행 삽입
|
|
$existingRow.replaceWith(newRow);
|
|
} else {
|
|
// 기존 행을 찾을 수 없으면 맨 위에 추가
|
|
tbody.prepend(newRow);
|
|
}
|
|
} else if (res.mode === 'copy') {
|
|
// 복사 모드: 기존 행 제거 후 맨 위에 새 행 추가
|
|
const selector = 'tr[data-num="' + res.num + '"]';
|
|
const $existingRow = opener.$(selector);
|
|
if ($existingRow.length) {
|
|
$existingRow.remove();
|
|
}
|
|
tbody.prepend(newRow);
|
|
} else {
|
|
// 신규 추가 모드: 맨 위에 추가
|
|
tbody.prepend(newRow);
|
|
}
|
|
} else {
|
|
parentTable.append(newRow);
|
|
}
|
|
} else {
|
|
console.warn('Invalid row HTML structure:', res.rowHtml);
|
|
// 페이지 새로고침으로 대체
|
|
opener.location.reload();
|
|
}
|
|
} else {
|
|
console.warn('No rowHtml provided in response');
|
|
// 페이지 새로고침으로 대체
|
|
opener.location.reload();
|
|
}
|
|
} catch (error) {
|
|
console.error('Table update failed:', error);
|
|
// 오류 발생 시 페이지 새로고침으로 대체
|
|
opener.location.reload();
|
|
}
|
|
}
|
|
|
|
$("#deleteBtn").on("click", function() {
|
|
var delId = $("#num").val();
|
|
delFn(delId);
|
|
});
|
|
|
|
$("#copyBtn").on("click", function() {
|
|
// 복사 모드로 전환 (기존 mode 필드의 값을 "copy"로 변경)
|
|
$("#mode").val("copy");
|
|
|
|
// 복사 진행 전 사용자 확인 (Swal 이용)
|
|
Swal.fire({
|
|
title: '복사 확인',
|
|
text: "자료를 복사합니다. 계속하시겠습니까?",
|
|
icon: 'info',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: '복사',
|
|
cancelButtonText: '취소'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// 복사 모드로 저장 버튼 클릭과 동일한 처리
|
|
$("#saveBtn").click();
|
|
}
|
|
});
|
|
});
|
|
|
|
function delFn(delId) {
|
|
$("#mode").val("delete");
|
|
$("#num").val(delId);
|
|
|
|
Swal.fire({
|
|
title: '모델 삭제',
|
|
text: "모델 삭제는 신중하셔야 합니다. 정말 삭제 하시겠습니까?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: '삭제',
|
|
cancelButtonText: '취소'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
if (ajaxRequest_write !== null) {
|
|
ajaxRequest_write.abort();
|
|
}
|
|
ajaxRequest_write = $.ajax({
|
|
url: "insert.php",
|
|
type: "post",
|
|
data: $("#board_form").serialize(),
|
|
dataType: "json",
|
|
success: function(res) {
|
|
console.log(res);
|
|
|
|
// 서버 에러 여부 체크
|
|
if (!res.success) {
|
|
Toastify({
|
|
text: '삭제에 실패했습니다: ' + (res.message || ''),
|
|
gravity: "top",
|
|
position: "center",
|
|
style: { background: "#d33" }
|
|
}).showToast();
|
|
return;
|
|
}
|
|
|
|
// 부모창에서 해당 행 제거
|
|
removeRowFromParentTable(delId);
|
|
|
|
Toastify({
|
|
text: "모델 삭제 완료!",
|
|
duration: 3000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
backgroundColor: "#4fbe87"
|
|
}).showToast();
|
|
|
|
setTimeout(function() {
|
|
self.close();
|
|
}, 1000);
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
console.log(jqxhr, status, error);
|
|
Toastify({
|
|
text: '삭제 중 오류가 발생했습니다.',
|
|
gravity: "top",
|
|
position: "center",
|
|
style: { background: "#d33" }
|
|
}).showToast();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// 부모창에서 행 제거 함수
|
|
function removeRowFromParentTable(num) {
|
|
// 부모창이 /bendingfee/list.php 파일인지 확인
|
|
const isBendingfeeListPage = opener && opener.location &&
|
|
(opener.location.href.includes('/bendingfee/list.php') ||
|
|
opener.location.pathname.includes('/bendingfee/list.php'));
|
|
|
|
if (!isBendingfeeListPage) {
|
|
console.log('Parent page is not /bendingfee/list.php, skipping row removal');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 해당 번호의 행 찾아서 제거
|
|
const selector = 'tr[data-num="' + num + '"]';
|
|
const $existingRow = opener.$(selector);
|
|
if ($existingRow.length) {
|
|
$existingRow.remove();
|
|
} else {
|
|
console.warn('Row with num ' + num + ' not found in parent table');
|
|
}
|
|
} catch (error) {
|
|
console.error('Row removal failed:', error);
|
|
}
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
var title = '<?=$title_message;?>';
|
|
saveMenuLog(title);
|
|
});
|
|
|
|
// PHP의 모델 목록 데이터를 JavaScript 변수로 전달
|
|
var modelsList = <?= json_encode($modelsList) ?>;
|
|
// 기존 선택된 모델명 (있다면)
|
|
var selectedModel = $("#model_name").val();
|
|
|
|
$("#major_category").on("change", function() {
|
|
var selectedMajor = $(this).val();
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.empty();
|
|
$modelSelect.append('<option value="">모델 선택</option>');
|
|
|
|
$.each(modelsList, function(index, model) {
|
|
// 대분류가 빈 값이거나, 해당 모델의 slatitem이 선택된 대분류와 일치하면 옵션 추가
|
|
if (selectedMajor === "" || model.slatitem === selectedMajor) {
|
|
var option = $('<option></option>')
|
|
.attr('value', model.model_name)
|
|
.text(model.model_name);
|
|
// 이전에 선택된 모델이 있다면 재선택
|
|
if (model.model_name === selectedModel) {
|
|
option.prop('selected', true);
|
|
}
|
|
$modelSelect.append(option);
|
|
}
|
|
});
|
|
});
|
|
// 페이지 로드 시, 현재 대분류에 맞게 모델명 목록 업데이트
|
|
$("#major_category").trigger("change");
|
|
|
|
function openBendingSearchModal(btn) {
|
|
window.currentSearchButton = btn;
|
|
// 상단 검색폼의 대분류 값은 그대로 사용하고,
|
|
// 현재 subpart 행의 조상인 subparts-row에서 부모 부품의 선택값을 가져옵니다.
|
|
var major_category = $("#major_category").val();
|
|
var seconditem = $("#seconditem").val();
|
|
var model_name = $("#model_name").val();
|
|
var finishing_type = $("#finishing_type").val();
|
|
var spec = $("#spec").val();
|
|
var check_type = $("#check_type").val();
|
|
var subpartsRow = $(btn).closest('tr.subparts-row');
|
|
|
|
console.log('major_category:', major_category);
|
|
console.log('seconditem:', seconditem);
|
|
|
|
$.ajax({
|
|
url: "searchBending.php",
|
|
type: "GET",
|
|
data: {
|
|
major_category: major_category,
|
|
seconditem: seconditem,
|
|
model_name: model_name,
|
|
finishing_type: finishing_type,
|
|
check_type: check_type, // 가이드레일 측면형, 벽면형 구분
|
|
spec: spec
|
|
},
|
|
success: function(response) {
|
|
$("#bendingSearchResults").html(response);
|
|
var modal = new bootstrap.Modal(document.getElementById('bendingSearchModal'));
|
|
modal.show();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error("Error fetching bending items: " + error);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 각 행의 단가와 수량을 이용해 행별 단가합계를 계산하여 업데이트하는 함수
|
|
function updateRowLineTotal(row) {
|
|
var unitPriceStr = row.find('input.unit-price').val();
|
|
var quantityStr = row.find('input.quantity').val();
|
|
var unitPrice = parseFloat(unitPriceStr.replace(/,/g, '')) || 0;
|
|
var quantity = parseFloat(quantityStr) || 1;
|
|
var lineTotal = unitPrice * quantity;
|
|
row.find('input.line-total').val(lineTotal.toLocaleString());
|
|
}
|
|
|
|
// 전체 행의 단가합계(각 행의 line-total 값)를 합산하여 #unitprice 입력 필드에 업데이트하는 함수
|
|
function updateTotalUnitPrice() {
|
|
var total = 0;
|
|
$('#partsTable tbody tr').each(function() {
|
|
var lineTotalStr = $(this).find('input.line-total').val();
|
|
if (lineTotalStr) {
|
|
var num = parseFloat(lineTotalStr.replace(/,/g, '')) || 0;
|
|
total += num;
|
|
}
|
|
});
|
|
$('#unitprice').val(total.toLocaleString());
|
|
}
|
|
|
|
// 삭제 버튼 클릭 시 해당 행을 제거하고 총합계 업데이트
|
|
$(document).on('click', '.delete-row', function() {
|
|
$(this).closest('tr').remove();
|
|
updateTotalUnitPrice();
|
|
});
|
|
|
|
// unit-price 또는 수량 입력값이 변경될 경우 해당 행의 line-total 및 전체 합계 업데이트
|
|
$(document).on('change', 'input.unit-price, input.quantity', function() {
|
|
var $row = $(this).closest('tr');
|
|
updateRowLineTotal($row);
|
|
updateTotalUnitPrice();
|
|
});
|
|
|
|
// PHP에서 저장된 JSON 문자열을 그대로 자바스크립트 변수에 할당 (이미 저장된 값)
|
|
var savedData = <?php echo isset($savejson) ? $savejson : '[]'; ?>;
|
|
|
|
// 페이지 로드시 저장된 JSON 데이터를 테이블에 나타내는 함수
|
|
function initializePage() {
|
|
// savedData가 문자열이라면 파싱합니다.
|
|
if (typeof savedData === "string") {
|
|
try {
|
|
savedData = JSON.parse(savedData);
|
|
} catch (e) {
|
|
console.error("JSON 파싱 오류:", e);
|
|
savedData = [];
|
|
}
|
|
}
|
|
// 배열이 아니면 빈 배열로 초기화
|
|
if (!Array.isArray(savedData)) {
|
|
savedData = [];
|
|
}
|
|
|
|
|
|
console.log('initializePage savedData', savedData);
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
savedData.forEach(function(rowData) {
|
|
addRow(tableBody, rowData);
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
// 테이블에 한 행을 추가하는 함수 (저장할 때 사용한 키 순서대로: col1, col2, …)
|
|
function addRow(tableBody, rowData) {
|
|
|
|
console.log('rowData',rowData);
|
|
var newRow = $('<tr>');
|
|
|
|
// col1 ~ col6: 단순 텍스트로 표시
|
|
newRow.append('<td>' + (rowData.col1 || '') + '</td>');
|
|
newRow.append('<td>' + (rowData.col2 || '') + '</td>');
|
|
newRow.append('<td>' + (rowData.col3 || '') + '</td>');
|
|
newRow.append('<td>' + (rowData.col4 || '') + '</td>');
|
|
newRow.append('<td>' + (rowData.col5 || '') + '</td>');
|
|
newRow.append('<td>' + (rowData.col6 || '') + '</td>');
|
|
|
|
// col7: 단가 (입력 필드)
|
|
newRow.append('<td><input type="text" name="col7[]" class="form-control text-end unit-price" value="' + (rowData.col7 || '') + '" /></td>');
|
|
// col8: 수량 (입력 필드)
|
|
newRow.append('<td><input type="text" name="col8[]" class="form-control text-end quantity" value="' + (rowData.col8 || '') + '" /></td>');
|
|
// col9: 단가합계 (입력 필드)
|
|
newRow.append('<td><input type="text" name="col9[]" class="form-control text-end line-total" value="' + (rowData.col9 || '') + '" /></td>');
|
|
|
|
// col10: 삭제 버튼
|
|
newRow.append('<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>');
|
|
|
|
tableBody.append(newRow);
|
|
|
|
// 숫자 필드에 3자리 콤마 적용 등 필요한 이벤트 핸들러 등록
|
|
newRow.find('.unit-price, .quantity').on('change', function() {
|
|
updateRowLineTotal(newRow);
|
|
});
|
|
|
|
// 삭제 버튼 클릭 이벤트
|
|
newRow.find('.delete-row').on('click', function() {
|
|
newRow.remove();
|
|
updateTotalUnitPrice();
|
|
});
|
|
|
|
// 행 추가 시 해당 행의 단가합계를 계산
|
|
updateRowLineTotal(newRow);
|
|
}
|
|
|
|
// 문서 로딩 시 initializePage() 호출
|
|
$(document).ready(function(){
|
|
initializePage();
|
|
|
|
function toggleCheckType() {
|
|
var secondItemVal = $('#seconditem').val();
|
|
// 현재 check_type select의 값을 저장
|
|
var currentVal = $('#check_type').val();
|
|
if (secondItemVal === '가이드레일') {
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", false); // select 요소 활성화
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.prop("disabled", false); // select 요소 활성화
|
|
var $check_type = $("#check_type");
|
|
$check_type.prop("disabled", false); // select 요소를 활성화
|
|
var $finishing_type = $("#finishing_type");
|
|
$finishing_type.prop("disabled", false); // select 요소를 활성화
|
|
$('#check_type_container').show();
|
|
var defaultOptions = '<option value="">(형태)</option>' +
|
|
'<option value="벽면형">벽면형</option>' +
|
|
'<option value="측면형">측면형</option>';
|
|
$('#check_type').html(defaultOptions);
|
|
// 이전 선택값이 유효하면 복원
|
|
if (currentVal === '벽면형' || currentVal === '측면형') {
|
|
$('#check_type').val(currentVal);
|
|
}
|
|
$('#caseDetailsRow').hide();
|
|
}
|
|
else if(secondItemVal === '케이스'){
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.prop("disabled", true); // select 요소를 비활성화
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", true); // select 요소를 비활성화
|
|
$('#check_type_container').show();
|
|
// var caseOptions = '<option value="">(점검구 선택)</option>' +
|
|
// '<option value="양면 점검구">양면 점검구</option>' +
|
|
// '<option value="밑면 점검구">밑면 점검구</option>' +
|
|
// '<option value="후면 점검구">후면 점검구</option>';
|
|
var caseOptions = '<option value="양면 점검구">양면 점검구</option>' ;
|
|
$('#check_type').html(caseOptions);
|
|
var modelOptions = '<option value="">(선택안함) </option>' ;
|
|
$('#check_type').html(caseOptions);
|
|
// 이전 선택값이 유효하면 복원
|
|
if (currentVal === '양면 점검구' || currentVal === '밑면 점검구' || currentVal === '후면 점검구') {
|
|
$('#check_type').val(currentVal);
|
|
}
|
|
$('#caseDetailsRow').show();
|
|
}
|
|
else if(secondItemVal === '마구리'){
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.prop("disabled", true); // select 요소를 비활성화
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", true); // select 요소를 비활성화
|
|
var $check_type = $("#check_type");
|
|
$check_type.prop("disabled", true); // select 요소를 비활성화
|
|
var $finishing_type = $("#finishing_type");
|
|
$finishing_type.prop("disabled", true); // select 요소를 비활성화
|
|
$('#check_type_container').hide();
|
|
$('#caseDetailsRow').hide();
|
|
}
|
|
else if(secondItemVal === '하단마감재') {
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", true); // select 요소 비활성화
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.prop("disabled", false); // select 요소 활성화
|
|
var $check_type = $("#check_type");
|
|
$check_type.prop("disabled", true); // select 요소를 비활성화
|
|
var $finishing_type = $("#finishing_type");
|
|
$finishing_type.prop("disabled", false); // select 요소를 활성화
|
|
$('#check_type_container').hide();
|
|
$('#caseDetailsRow').hide();
|
|
}
|
|
else if(secondItemVal === 'L-BAR') {
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", false); // select 요소 활성화
|
|
$major_category.val("스크린");
|
|
var $modelSelect = $("#model_name"); // 모델선택가능하게..
|
|
$modelSelect.prop("disabled", false);
|
|
var $check_type = $("#check_type");
|
|
$check_type.prop("disabled", true);
|
|
var $finishing_type = $("#finishing_type");
|
|
$finishing_type.prop("disabled", true);
|
|
$('#check_type_container').hide();
|
|
$('#caseDetailsRow').hide();
|
|
}
|
|
else if(secondItemVal === '보강평철') {
|
|
var tableBody = $('#partsTable tbody');
|
|
tableBody.empty(); // 기존 내용 제거
|
|
var $major_category = $("#major_category");
|
|
$major_category.prop("disabled", false); // select 요소 활성화
|
|
$major_category.val("스크린");
|
|
var $modelSelect = $("#model_name");
|
|
$modelSelect.prop("disabled", true);
|
|
var $check_type = $("#check_type");
|
|
$check_type.prop("disabled", true);
|
|
var $finishing_type = $("#finishing_type");
|
|
$finishing_type.prop("disabled", true);
|
|
$('#check_type_container').hide();
|
|
$('#caseDetailsRow').hide();
|
|
}
|
|
else {
|
|
$('#caseDetailsRow').hide();
|
|
$('#check_type_container').hide();
|
|
}
|
|
}
|
|
|
|
// 5개의 select 요소에 대한 변경 이벤트 핸들러 등록
|
|
$('#seconditem, #check_type, #model_name, #major_category, #finishing_type').on('change', function(){
|
|
toggleCheckType();
|
|
changeImage();
|
|
});
|
|
|
|
// 페이지 로드 시에도 초기 상태 설정
|
|
changeImage();
|
|
});
|
|
|
|
function selectGuidrail(rowElement, num) {
|
|
|
|
// aria-hidden 오류를 방지하기 위해서.... 강제 포커스를 부여함
|
|
// $('#spec').focus();
|
|
|
|
var item_bend = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
|
|
|
if (typeof item_bend === 'string') {
|
|
try {
|
|
item_bend = JSON.parse(item_bend);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
item_bend = [];
|
|
}
|
|
}
|
|
if (!Array.isArray(item_bend)) {
|
|
item_bend = [];
|
|
}
|
|
|
|
var $row = $(rowElement);
|
|
var model_name = $row.data('model_name');
|
|
var rail_length = $row.data('rail_length');
|
|
var rail_width = $row.data('rail_width');
|
|
var finishing_type = $row.data('finishing_type');
|
|
var seconditem = $row.data('seconditem');
|
|
var check_type = $row.data('check_type');
|
|
|
|
$("#spec").val(rail_length + '*' + rail_width);
|
|
|
|
$.ajax({
|
|
url: 'ajax_getGuiderailData.php',
|
|
type: 'POST',
|
|
data: {
|
|
model_name: model_name,
|
|
seconditem: seconditem,
|
|
finishing_type: finishing_type,
|
|
rail_length: rail_length,
|
|
rail_width: rail_width,
|
|
check_type: check_type
|
|
},
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
var tableBody = '';
|
|
response.forEach(function(product, index) {
|
|
var bendSum = 0;
|
|
if (product.bendingRates && product.bendingRates.length > 0) {
|
|
product.bendingRates.forEach(function(rate) {
|
|
bendSum += Number(rate);
|
|
});
|
|
}
|
|
var plateSum = (product.sums && product.sums.length > 0) ? product.sums[product.sums.length - 1] : 0;
|
|
var finalSum = bendSum*-1 + plateSum;
|
|
|
|
var unitPrice = '';
|
|
var computedPrice = 0;
|
|
|
|
// 재질을 가져오고 공백 제거 후 대문자로 변환
|
|
var appliedMaterial = (product.material ? product.material.trim().toUpperCase() : "");
|
|
|
|
// 두께에서 숫자만 추출 (공백 및 'T' 제거)
|
|
var appliedThickness = (product.material ? product.material.replace(/[^0-9.]/g, '') : "");
|
|
|
|
// "EGI" 또는 "SUS"만 추출하여 RawMaterial 값 설정
|
|
var RawMaterial = appliedMaterial.includes("EGI") ? "EGI" :
|
|
appliedMaterial.includes("SUS") ? "SUS" : "";
|
|
|
|
// 'EGI'가 포함된 경우 매칭 로직 적용
|
|
if (appliedMaterial.includes("EGI")) {
|
|
if (appliedThickness === "1.15") {
|
|
appliedThickness = "1.2";
|
|
} else if (appliedThickness === "1.55") {
|
|
appliedThickness = "1.6";
|
|
}
|
|
}
|
|
|
|
var matchedItem = item_bend.find(function(item) {
|
|
return item.col1.toUpperCase() === RawMaterial && item.col5 === appliedThickness;
|
|
});
|
|
|
|
var appliedUnitPrice = matchedItem ? parseFloat(matchedItem.col17.toString().replace(/,/g, '')) : 0;
|
|
|
|
if (!isNaN(finalSum) && finalSum !== 0 && matchedItem) {
|
|
computedPrice = finalSum * appliedUnitPrice / 1000;
|
|
unitPrice = computedPrice.toLocaleString();
|
|
}
|
|
|
|
var quantity = product.surang ;
|
|
var lineTotal = (computedPrice > 0) ? computedPrice * quantity : 0;
|
|
|
|
tableBody += '<tr>';
|
|
tableBody += '<td>' + product.label + '</td>';
|
|
tableBody += '<td>' + appliedMaterial + '</td>';
|
|
tableBody += '<td>' + bendSum + '</td>';
|
|
tableBody += '<td>' + plateSum + '</td>';
|
|
tableBody += '<td>' + finalSum + '</td>';
|
|
tableBody += '<td>' + appliedUnitPrice.toLocaleString() + '</td>'; // 적용된 면적당 단가 표시
|
|
tableBody += '<td><input type="text" class="form-control text-end unit-price" value="' + unitPrice + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end quantity" value="' + quantity + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end line-total" value="' + lineTotal.toLocaleString() + '" /></td>';
|
|
tableBody += '<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>';
|
|
tableBody += '</tr>';
|
|
});
|
|
$('#partsTable tbody').html(tableBody);
|
|
updateTotalUnitPrice();
|
|
},
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
console.error("AJAX 호출 실패: " + textStatus, errorThrown);
|
|
}
|
|
});
|
|
|
|
|
|
var btn = window.currentSearchButton;
|
|
$('#bendingSearchModal').modal('hide');
|
|
}
|
|
|
|
function selectCase(rowElement, num) {
|
|
var item_bend = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
|
|
|
if (typeof item_bend === 'string') {
|
|
try {
|
|
item_bend = JSON.parse(item_bend);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
item_bend = [];
|
|
}
|
|
}
|
|
if (!Array.isArray(item_bend)) {
|
|
item_bend = [];
|
|
}
|
|
|
|
console.log('단가표 : ', item_bend);
|
|
|
|
var $row = $(rowElement);
|
|
var check_type = $row.data('check_type');
|
|
var box_width = $row.data('box_width');
|
|
var box_height = $row.data('box_height');
|
|
var front_bottom_width = $row.data('front_bottom_width');
|
|
var rail_width = $row.data('rail_width');
|
|
var seconditem = $row.data('seconditem');
|
|
var bending_components = $row.data('bending_components');
|
|
|
|
$("#check_type").val(check_type);
|
|
$("#box_width").val(box_width);
|
|
$("#box_height").val(box_height);
|
|
$("#front_bottom_width").val(front_bottom_width);
|
|
$("#rail_width").val(rail_width);
|
|
|
|
$("#spec").val(box_width + '*' + box_height);
|
|
|
|
// bending_components가 문자열인 경우 JSON으로 파싱
|
|
if (typeof bending_components === 'string') {
|
|
// 빈 문자열이나 null 체크
|
|
if (bending_components && bending_components.trim() !== '') {
|
|
try {
|
|
bending_components = JSON.parse(bending_components);
|
|
} catch (e) {
|
|
console.error('bending_components JSON 파싱 오류:', e);
|
|
console.log('파싱 시도한 값:', bending_components);
|
|
bending_components = [];
|
|
}
|
|
} else {
|
|
console.log('bending_components가 빈 문자열입니다.');
|
|
bending_components = [];
|
|
}
|
|
}
|
|
|
|
// bending_components가 배열이 아닌 경우 처리
|
|
if (!Array.isArray(bending_components)) {
|
|
console.warn('bending_components가 배열이 아닙니다:', bending_components);
|
|
bending_components = [];
|
|
}
|
|
|
|
console.log('bending_components:', bending_components);
|
|
|
|
var tableBody = '';
|
|
bending_components.forEach(function(component, index) {
|
|
// '마구리'라는 단어가 포함된 항목은 제외
|
|
if (component.itemName && component.itemName.includes('마구리')) {
|
|
return; // 현재 항목을 건너뜀
|
|
}
|
|
|
|
var bendSum = 0;
|
|
if (component.bendingrateList && component.bendingrateList.length > 0) {
|
|
component.bendingrateList.forEach(function(rate) {
|
|
bendSum += Number(rate) || 0;
|
|
});
|
|
}
|
|
var plateSum = (component.sumList && component.sumList.length > 0) ? Number(component.sumList[component.sumList.length - 1]) : 0;
|
|
var finalSum = bendSum * -1 + plateSum;
|
|
|
|
var unitPrice = '';
|
|
var computedPrice = 0;
|
|
var meterUnitPrice = 0;
|
|
|
|
// EGI 1.55T → EGI 1.6T 적용 1.55적용
|
|
var appliedMaterial = "EGI";
|
|
var appliedThickness = "1.55";
|
|
|
|
var matchedItem = item_bend.find(function(item) {
|
|
return item.col1.toUpperCase() === appliedMaterial && item.col5 === appliedThickness;
|
|
});
|
|
|
|
var appliedUnitPrice = matchedItem ? parseFloat(matchedItem.col17.toString().replace(/,/g, '')) : 0; // 가격추가
|
|
meterUnitPrice = matchedItem ? parseFloat(matchedItem.col18.toString().replace(/,/g, '')) : 0; // 미터당 단가 추가
|
|
|
|
if (!isNaN(finalSum) && finalSum !== 0 && matchedItem) {
|
|
computedPrice = finalSum * appliedUnitPrice / 1000;
|
|
unitPrice = computedPrice.toLocaleString();
|
|
}
|
|
|
|
var quantity = component.quantity || 1;
|
|
var lineTotal = (computedPrice > 0) ? computedPrice * quantity : 0;
|
|
|
|
tableBody += '<tr>';
|
|
tableBody += '<td>' + (component.itemName || '케이스부품') + '</td>';
|
|
tableBody += '<td> ' + appliedMaterial + ' ' + appliedThickness + 'T </td>';
|
|
tableBody += '<td>' + bendSum + '</td>';
|
|
tableBody += '<td>' + plateSum + '</td>';
|
|
tableBody += '<td>' + finalSum + '</td>';
|
|
tableBody += '<td>' + appliedUnitPrice.toLocaleString() + '</td>'; // 적용된 면적당 단가 표시
|
|
tableBody += '<td><input type="text" class="form-control text-end unit-price" value="' + unitPrice + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end quantity" value="' + quantity + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end line-total" value="' + lineTotal.toLocaleString() + '" /></td>';
|
|
tableBody += '<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>';
|
|
tableBody += '</tr>';
|
|
});
|
|
|
|
$('#partsTable tbody').html(tableBody);
|
|
updateTotalUnitPrice();
|
|
|
|
var btn = window.currentSearchButton;
|
|
var modalEl = document.getElementById('bendingSearchModal');
|
|
var modalInstance = bootstrap.Modal.getInstance(modalEl);
|
|
modalInstance.hide();
|
|
}
|
|
|
|
function selectMarguri(rowElement, num) {
|
|
var item_bend = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
|
|
|
if (typeof item_bend === 'string') {
|
|
try {
|
|
item_bend = JSON.parse(item_bend);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
item_bend = [];
|
|
}
|
|
}
|
|
if (!Array.isArray(item_bend)) {
|
|
item_bend = [];
|
|
}
|
|
|
|
console.log('단가표 : ', item_bend);
|
|
|
|
var $row = $(rowElement);
|
|
var item_name = $row.data('item_name');
|
|
var item_spec = $row.data('item_spec'); // '450*800' 형태
|
|
var material = 'EGI 1.6T'; // 마구리는 1.55T 대신 1.6T로 고정
|
|
|
|
$("#spec").val(item_spec);
|
|
|
|
var imgdata = $row.data('imgdata');
|
|
$("#imageBending").attr('src', imgdata ? imgdata : '../img/no_image.png');
|
|
|
|
var dimensions = item_spec.split('*').map(Number);
|
|
if (dimensions.length !== 2 || isNaN(dimensions[0]) || isNaN(dimensions[1])) {
|
|
console.error("item_spec 값 오류: ", item_spec);
|
|
return;
|
|
}
|
|
var width = dimensions[0] + 100;
|
|
var height = dimensions[1] + 100;
|
|
|
|
// 면적 계산 (mm^2 → m^2 변환: / 1,000,000)
|
|
var area = (width * height) / 1000000;
|
|
|
|
// 단가 계산
|
|
var unitPrice = 0;
|
|
var computedPrice = 0;
|
|
var meterUnitPrice = 0;
|
|
|
|
var appliedMaterial = "EGI";
|
|
var appliedThickness = "1.6";
|
|
|
|
var matchedItem = item_bend.find(function(item) {
|
|
return item.col1.toUpperCase() === appliedMaterial && item.col5 === appliedThickness;
|
|
});
|
|
|
|
var appliedUnitPrice = matchedItem ? parseFloat(matchedItem.col17.toString().replace(/,/g, '')) : 0;
|
|
meterUnitPrice = matchedItem ? parseFloat(matchedItem.col18.toString().replace(/,/g, '')) : 0; // 미터당 단가 추가
|
|
|
|
if (!isNaN(area) && area > 0 && matchedItem) {
|
|
computedPrice = Math.round(area * appliedUnitPrice);
|
|
unitPrice = computedPrice.toLocaleString(undefined, { maximumFractionDigits: 0 });
|
|
}
|
|
|
|
var quantity = 2 ; // 마구리는 기본2개 설정
|
|
var lineTotal = computedPrice * quantity;
|
|
|
|
var tableRow = '<tr>';
|
|
tableRow += '<td>' + item_name + '</td>';
|
|
tableRow += '<td>' + material + '</td>';
|
|
tableRow += '<td>가로폭(' + width + ')</td>';
|
|
tableRow += '<td>세로높이(' + height + ')</td>';
|
|
tableRow += '<td> 면적㎡(' + area.toFixed(2) + ')</td>'; // 면적 소수점 2자리 유지
|
|
tableRow += '<td>' + appliedUnitPrice.toLocaleString() + '</td>'; // 면적당 단가
|
|
tableRow += '<td><input type="text" class="form-control text-end unit-price" value="' + unitPrice + '" /></td>';
|
|
tableRow += '<td><input type="text" class="form-control text-end quantity" value="' + quantity + '" /></td>';
|
|
tableRow += '<td><input type="text" class="form-control text-end line-total" value="' + lineTotal.toLocaleString(undefined, { maximumFractionDigits: 0 }) + '" /></td>';
|
|
tableRow += '<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>';
|
|
tableRow += '</tr>';
|
|
|
|
$('#partsTable tbody').html(tableRow);
|
|
updateTotalUnitPrice();
|
|
|
|
var modalEl = document.getElementById('bendingSearchModal');
|
|
var modalInstance = bootstrap.Modal.getInstance(modalEl);
|
|
modalInstance.hide();
|
|
}
|
|
|
|
function selectBottombar(rowElement, num) {
|
|
var item_bend = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
|
|
|
if (typeof item_bend === 'string') {
|
|
try {
|
|
item_bend = JSON.parse(item_bend);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
item_bend = [];
|
|
}
|
|
}
|
|
if (!Array.isArray(item_bend)) {
|
|
item_bend = [];
|
|
}
|
|
|
|
console.log('단가표 : ', item_bend);
|
|
|
|
var $row = $(rowElement);
|
|
var model_name = $row.data('model_name');
|
|
var finishing_type = $row.data('finishing_type');
|
|
var bar_height = $row.data('bar_height');
|
|
var bar_width = $row.data('bar_width');
|
|
var bending_components = $row.data('bending_components');
|
|
|
|
$("#spec").val(bar_width + '*' + bar_height );
|
|
|
|
// bending_components가 문자열인 경우 JSON으로 파싱
|
|
if (typeof bending_components === 'string') {
|
|
// 빈 문자열이나 null 체크
|
|
if (bending_components && bending_components.trim() !== '') {
|
|
try {
|
|
bending_components = JSON.parse(bending_components);
|
|
} catch (e) {
|
|
console.error('bending_components JSON 파싱 오류:', e);
|
|
console.log('파싱 시도한 값:', bending_components);
|
|
bending_components = [];
|
|
}
|
|
} else {
|
|
console.log('bending_components가 빈 문자열입니다.');
|
|
bending_components = [];
|
|
}
|
|
}
|
|
|
|
// bending_components가 배열이 아닌 경우 처리
|
|
if (!Array.isArray(bending_components)) {
|
|
console.warn('bending_components가 배열이 아닙니다:', bending_components);
|
|
bending_components = [];
|
|
}
|
|
|
|
console.log('bending_components:', bending_components);
|
|
|
|
// $.ajax({
|
|
// url: 'ajax_getBottombarData.php',
|
|
// type: 'POST',
|
|
// data: {
|
|
// model_name: model_name,
|
|
// finishing_type: finishing_type,
|
|
// bar_height: bar_height,
|
|
// bar_width: bar_width
|
|
// },
|
|
// dataType: 'json',
|
|
// success: function(response) {
|
|
// console.log('get ajax_getBottombarData.php response : ', response);
|
|
// var tableBody = '';
|
|
var tableBody = '';
|
|
bending_components.forEach(function(component, index) {
|
|
|
|
// 'L'이 포함되거나 '평철'의 단어가 포함된 항목은 제외
|
|
if (component.itemName && (component.itemName.includes('L') || component.itemName.includes('평철'))) {
|
|
return; // 현재 항목을 건너뜀
|
|
}
|
|
|
|
var bendSum = 0;
|
|
if (component.bendingrateList && component.bendingrateList.length > 0) {
|
|
component.bendingrateList.forEach(function(rate) {
|
|
bendSum += Number(rate) || 0;
|
|
});
|
|
}
|
|
var plateSum = (component.sumList && component.sumList.length > 0) ? Number(component.sumList[component.sumList.length - 1]) : 0;
|
|
var finalSum = bendSum * -1 + plateSum ;
|
|
|
|
var unitPrice = '';
|
|
var computedPrice = 0;
|
|
// 재질을 가져오고 공백 제거 후 대문자로 변환
|
|
var appliedMaterial = (component.material ? component.material.trim().toUpperCase() : "");
|
|
|
|
// 두께에서 숫자만 추출 (공백 및 'T' 제거)
|
|
var appliedThickness = (component.material ? component.material.replace(/[^0-9.]/g, '') : "");
|
|
|
|
// "EGI" 또는 "SUS"만 추출하여 RawMaterial 값 설정
|
|
var RawMaterial = appliedMaterial.includes("EGI") ? "EGI" :
|
|
appliedMaterial.includes("SUS") ? "SUS" : "";
|
|
|
|
console.log("Material:", appliedMaterial, "순수자재 : ", RawMaterial, "Thickness:", appliedThickness);
|
|
|
|
// 'EGI'가 포함된 경우 매칭 로직 적용
|
|
if (appliedMaterial.includes("EGI")) {
|
|
if (appliedThickness === "1.15") {
|
|
appliedThickness = "1.2";
|
|
} else if (appliedThickness === "1.55") {
|
|
appliedThickness = "1.6";
|
|
}
|
|
}
|
|
|
|
var matchedItem = item_bend.find(function(item) {
|
|
return item.col1.toUpperCase() === RawMaterial && item.col5 === appliedThickness;
|
|
});
|
|
|
|
var appliedUnitPrice = matchedItem ? parseFloat(matchedItem.col17.toString().replace(/,/g, '')) : 0;
|
|
|
|
if (!isNaN(finalSum) && finalSum !== 0 && matchedItem) {
|
|
computedPrice = finalSum * appliedUnitPrice / 1000;
|
|
unitPrice = computedPrice.toLocaleString();
|
|
}
|
|
|
|
// 수량은 component.quantity 사용
|
|
var quantity = component.quantity || 1;
|
|
var lineTotal = (computedPrice > 0) ? computedPrice * quantity : 0;
|
|
|
|
tableBody += '<tr>';
|
|
tableBody += '<td>' + (component.itemName || '하장바') + '</td>';
|
|
tableBody += '<td>' + component.material + '</td>';
|
|
tableBody += '<td>' + bendSum + '</td>';
|
|
tableBody += '<td>' + plateSum + '</td>';
|
|
tableBody += '<td>' + finalSum + '</td>';
|
|
tableBody += '<td>' + appliedUnitPrice.toLocaleString() + '</td>'; // 적용된 면적당 단가 표시
|
|
tableBody += '<td><input type="text" class="form-control text-end unit-price" value="' + unitPrice + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end quantity" value="' + quantity + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end line-total" value="' + lineTotal.toLocaleString() + '" /></td>';
|
|
tableBody += '<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>';
|
|
tableBody += '</tr>';
|
|
});
|
|
$('#partsTable tbody').html(tableBody);
|
|
updateTotalUnitPrice();
|
|
|
|
// },
|
|
// error: function(jqXHR, textStatus, errorThrown) {
|
|
// console.error("AJAX 호출 실패: " + textStatus, errorThrown);
|
|
// }
|
|
// });
|
|
|
|
var btn = window.currentSearchButton;
|
|
var modalEl = document.getElementById('bendingSearchModal');
|
|
var modalInstance = bootstrap.Modal.getInstance(modalEl);
|
|
modalInstance.hide();
|
|
}
|
|
|
|
function selectLbar(rowElement, num) {
|
|
var item_bend = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
|
|
|
if (typeof item_bend === 'string') {
|
|
try {
|
|
item_bend = JSON.parse(item_bend);
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
item_bend = [];
|
|
}
|
|
}
|
|
if (!Array.isArray(item_bend)) {
|
|
item_bend = [];
|
|
}
|
|
|
|
console.log('단가표 : ', item_bend);
|
|
|
|
var $row = $(rowElement);
|
|
var itemName = $row.data('itemname');
|
|
var item_spec = $row.data('item_spec');
|
|
var appliedMaterial = $row.data('material'); // data-material에서 가져옴
|
|
|
|
// 재질 변환 및 공백 제거
|
|
appliedMaterial = appliedMaterial ? appliedMaterial.trim().toUpperCase() : "";
|
|
|
|
var response = $row.data('response');
|
|
|
|
console.log('response : ', response);
|
|
|
|
try {
|
|
if (typeof response === "string") {
|
|
response = JSON.parse(response);
|
|
}
|
|
} catch (e) {
|
|
console.error('JSON 파싱 오류:', e);
|
|
response = {};
|
|
}
|
|
|
|
console.log('파싱 후 response : ', response);
|
|
|
|
$("#spec").val(item_spec);
|
|
|
|
// response 내부의 배열을 개별 변수로 저장
|
|
var inputList = response.inputList || [];
|
|
var bendingrateList = response.bendingrateList || [];
|
|
var sumList = response.sumList || [];
|
|
|
|
// console.log('inputList:', inputList);
|
|
// console.log('bendingrateList:', bendingrateList);
|
|
// console.log('sumList:', sumList);
|
|
// console.log('itemName:', itemName);
|
|
|
|
var tableBody = '';
|
|
|
|
var bendSum = bendingrateList.reduce((acc, val) => acc + Number(val || 0), 0);
|
|
// var plateSum = sumList.reduce((acc, val) => acc + Number(val || 0), 0); // 전체를 더하는 공식
|
|
var plateSum = sumList.length > 0 ? Number(sumList.slice(-1)[0]) : 0; // 마지막 값만 가져오는 코드
|
|
|
|
var finalSum = bendSum + plateSum;
|
|
|
|
var unitPrice = '';
|
|
var computedPrice = 0;
|
|
|
|
// 두께에서 숫자만 추출 (공백 및 'T' 제거)
|
|
var appliedThickness = (appliedMaterial ? appliedMaterial.replace(/[^0-9.]/g, '') : "");
|
|
|
|
// "EGI" 또는 "SUS"만 추출하여 RawMaterial 값 설정
|
|
var RawMaterial = appliedMaterial.includes("EGI") ? "EGI" :
|
|
appliedMaterial.includes("SUS") ? "SUS" : "";
|
|
|
|
console.log("Material:", appliedMaterial, "순수자재 : ", RawMaterial, "Thickness:", appliedThickness);
|
|
|
|
// 'EGI'가 포함된 경우 매칭 로직 적용
|
|
if (appliedMaterial.includes("EGI")) {
|
|
if (appliedThickness === "1.15") {
|
|
appliedThickness = "1.2";
|
|
} else if (appliedThickness === "1.55") {
|
|
appliedThickness = "1.6";
|
|
}
|
|
}
|
|
|
|
// 면적당 단가 찾기
|
|
var matchedItem = item_bend.find(function(bendItem) {
|
|
return bendItem.col1.toUpperCase() === RawMaterial && bendItem.col5 === appliedThickness;
|
|
});
|
|
|
|
var appliedUnitPrice = matchedItem ? parseFloat(matchedItem.col17.toString().replace(/,/g, '')) : 0;
|
|
|
|
if (!isNaN(finalSum) && finalSum !== 0 && matchedItem) {
|
|
computedPrice = finalSum * appliedUnitPrice / 1000;
|
|
unitPrice = computedPrice.toLocaleString();
|
|
}
|
|
|
|
var quantity = itemName.includes('L') ? 2 : 1;
|
|
var lineTotal = (computedPrice > 0) ? computedPrice * quantity : 0;
|
|
|
|
// **1개의 행만 추가**
|
|
var tableBody = '<tr>';
|
|
tableBody += '<td>' + itemName + '</td>';
|
|
tableBody += '<td>' + appliedMaterial + '</td>';
|
|
tableBody += '<td>' + bendSum + '</td>';
|
|
tableBody += '<td>' + plateSum + '</td>';
|
|
tableBody += '<td>' + finalSum + '</td>';
|
|
tableBody += '<td>' + appliedUnitPrice.toLocaleString() + '</td>'; // 면적당 단가 표시
|
|
tableBody += '<td><input type="text" class="form-control text-end unit-price" value="' + unitPrice + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end quantity" value="' + quantity + '" /></td>';
|
|
tableBody += '<td><input type="text" class="form-control text-end line-total" value="' + lineTotal.toLocaleString() + '" /></td>';
|
|
tableBody += '<td><button type="button" class="btn btn-danger btn-sm delete-row">삭제</button></td>';
|
|
tableBody += '</tr>';
|
|
|
|
$('#partsTable tbody').html(tableBody);
|
|
updateTotalUnitPrice();
|
|
|
|
|
|
var btn = window.currentSearchButton;
|
|
var modalEl = document.getElementById('bendingSearchModal');
|
|
var modalInstance = bootstrap.Modal.getInstance(modalEl);
|
|
modalInstance.hide();
|
|
}
|
|
|
|
function changeImage() {
|
|
var $imageBending = $('#imageBending'); // 이미지 요소 참조
|
|
var secondItemVal = $('#seconditem').val();
|
|
// 기본적으로 이미지 초기화
|
|
$imageBending.attr('src', '../img/no_image.png');
|
|
|
|
if (secondItemVal === '가이드레일') {
|
|
// 가이드레일 스타일 유지
|
|
$imageBending.css({ "width": "250px", "height": "250px" });
|
|
// PHP에서 guiderail.json 파일의 내용을 JavaScript 변수에 로드
|
|
var guiderailImages = <?php
|
|
$jsonFile = $_SERVER['DOCUMENT_ROOT'].'/guiderail/guiderail.json';
|
|
if (file_exists($jsonFile)) {
|
|
echo file_get_contents($jsonFile);
|
|
} else {
|
|
echo '[]';
|
|
}
|
|
?>;
|
|
|
|
function updateImage(model, checkType, finishing_type) {
|
|
let imagePath = '';
|
|
|
|
if (Array.isArray(guiderailImages)) {
|
|
let found = guiderailImages.find(function(item) {
|
|
return item.model_name === model && item.check_type === checkType && item.finishing_type === finishing_type ;
|
|
});
|
|
if (found) {
|
|
imagePath = found.image;
|
|
}
|
|
}
|
|
|
|
$imageBending.attr('src', imagePath || '../img/no_image.png'); // 기본값 설정
|
|
}
|
|
|
|
var selectedProdModel = $("#model_name").val();
|
|
var selected_check_type = $("#check_type").val();
|
|
var finishing_type = $("#finishing_type").val();
|
|
|
|
console.log('selectedProdModel', selectedProdModel);
|
|
console.log('selected_check_type', selected_check_type);
|
|
console.log('finishing_type', finishing_type);
|
|
|
|
updateImage(selectedProdModel, selected_check_type, finishing_type);
|
|
}
|
|
else if (secondItemVal === '케이스') {
|
|
// 셔터박스 스타일 변경
|
|
$imageBending.css({ "width": "auto", "height": "auto" });
|
|
|
|
var selectedCheckType = $("#check_type").val();
|
|
var imagePath = '../img/box/box_both_sample.jpg'; // 기본 이미지
|
|
|
|
$imageBending.attr('src', imagePath);
|
|
}
|
|
else if (secondItemVal === '마구리') {
|
|
$imageBending.css({ "width": "auto", "height": "auto" });
|
|
|
|
var selectedCheckType = $("#check_type").val();
|
|
var imagePath = '../img/box/box_both_Maguri.jpg'; // 기본 이미지
|
|
|
|
$imageBending.attr('src', imagePath);
|
|
}
|
|
else if (secondItemVal === '하단마감재') {
|
|
$imageBending.css({ "width": "450px", "height": "250px" });
|
|
// PHP에서 bottombar.json 파일의 내용을 JavaScript 변수에 로드
|
|
var bottombarImages = <?php
|
|
$jsonFile = $_SERVER['DOCUMENT_ROOT'].'/bottombar/bottombar.json';
|
|
if (file_exists($jsonFile)) {
|
|
echo file_get_contents($jsonFile);
|
|
} else {
|
|
echo '[]';
|
|
}
|
|
?>;
|
|
|
|
function updateImage(model, finishing_type) {
|
|
let imagePath = '';
|
|
|
|
if (Array.isArray(bottombarImages)) {
|
|
let found = bottombarImages.find(function(item) {
|
|
return item.model_name === model && item.finishing_type === finishing_type ;
|
|
});
|
|
if (found) {
|
|
imagePath = found.image;
|
|
}
|
|
}
|
|
|
|
$imageBending.attr('src', imagePath || '../img/no_image.png'); // 기본값 설정
|
|
}
|
|
|
|
var selectedProdModel = $("#model_name").val();
|
|
var finishing_type = $("#finishing_type").val();
|
|
|
|
console.log('selectedProdModel', selectedProdModel);
|
|
console.log('finishing_type', finishing_type);
|
|
|
|
updateImage(selectedProdModel, finishing_type);
|
|
}
|
|
else if (secondItemVal === 'L-BAR') {
|
|
$imageBending.css({ "width": "auto", "height": "auto" });
|
|
var imagePath = '../img/Lbar/Lbar2.jpg'; // 기본 이미지
|
|
$imageBending.attr('src', imagePath);
|
|
}
|
|
else if (secondItemVal === '보강평철') {
|
|
$imageBending.css({ "width": "auto", "height": "auto" });
|
|
var imagePath = '../bending/img/2024_09_28_11_48_24_평철.jpg'; // 기본 이미지
|
|
$imageBending.attr('src', imagePath);
|
|
}
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
// Log 파일보기
|
|
$("#showlogBtn").click( function() {
|
|
var num = $('#num').val();
|
|
// table 이름을 넣어야 함
|
|
var workitem = $('#tablename').val();
|
|
// 버튼 비활성화
|
|
var btn = $(this);
|
|
popupCenter("../Showlog.php?num=" + num + "&workitem=" + workitem , '로그기록', 500, 500);
|
|
btn.prop('disabled', false);
|
|
});
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|