565 lines
19 KiB
PHP
565 lines
19 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';
|
||
|
|
|
||
|
|
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
||
|
|
$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : "";
|
||
|
|
$tablename = isset($_REQUEST["tablename"]) ? $_REQUEST["tablename"] : "";
|
||
|
|
|
||
|
|
if ($mode === 'copy') {
|
||
|
|
$title_message = "(데이터복사) 부자재(연기차단재) 단가";
|
||
|
|
} else {
|
||
|
|
$title_message = "부자재(연기차단재) 단가";
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|
||
|
|
<title> <?=$title_message?> </title>
|
||
|
|
|
||
|
|
<style>
|
||
|
|
/* 테이블의 기본 레이아웃 설정 */
|
||
|
|
table {
|
||
|
|
width: 100%; /* 테이블을 부모 컨테이너의 너비에 맞춤 */
|
||
|
|
table-layout: auto; /* 테이블 레이아웃을 자동으로 설정 (열의 내용에 따라 크기 조정) */
|
||
|
|
border-collapse: collapse; /* 테두리를 합쳐서 중복 제거 */
|
||
|
|
}
|
||
|
|
|
||
|
|
/* td 요소의 기본 스타일 설정 */
|
||
|
|
td {
|
||
|
|
padding: 5px; /* 테이블 셀의 패딩 설정 */
|
||
|
|
vertical-align: middle; /* 텍스트를 가운데 정렬 */
|
||
|
|
}
|
||
|
|
|
||
|
|
/* input 요소가 td 요소에 꽉 차도록 설정 */
|
||
|
|
td input[type="text"], td input[type="number"] {
|
||
|
|
width: 100%; /* input 요소가 td 요소의 너비를 채우도록 설정 */
|
||
|
|
box-sizing: border-box; /* 패딩과 테두리를 포함한 전체 너비를 계산 */
|
||
|
|
padding: 2px; /* input 요소의 내부 여백 */
|
||
|
|
border: 1px solid #ccc; /* 테두리 설정 */
|
||
|
|
border-radius: 4px; /* 둥근 모서리 설정 */
|
||
|
|
font-size: 12px; /* 글꼴 크기 설정 */
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
|
||
|
|
</head>
|
||
|
|
|
||
|
|
<?php
|
||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/mymodal.php';
|
||
|
|
|
||
|
|
$today = date("Y-m-d"); // 현재일자 변수지정
|
||
|
|
$registedate = date("Y-m-d"); // 현재일자 변수지정
|
||
|
|
|
||
|
|
include '_request.php';
|
||
|
|
|
||
|
|
if ($mode == "modify" || !empty($num)) {
|
||
|
|
try {
|
||
|
|
$sql = "select * from $DB.$tablename where num = ?";
|
||
|
|
$stmh = $pdo->prepare($sql);
|
||
|
|
|
||
|
|
$stmh->bindValue(1, $num, PDO::PARAM_STR);
|
||
|
|
$stmh->execute();
|
||
|
|
$count = $stmh->rowCount();
|
||
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC); // $row 배열로 DB 정보를 불러온다.
|
||
|
|
if ($count < 1) {
|
||
|
|
print "검색결과가 없습니다.<br>";
|
||
|
|
} else {
|
||
|
|
include '_row.php';
|
||
|
|
}
|
||
|
|
} catch (PDOException $Exception) {
|
||
|
|
print "오류: ".$Exception->getMessage();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($mode == "copy" || $mode == 'split') {
|
||
|
|
try {
|
||
|
|
$sql = "select * from " . $DB . ".{$tablename} where num = ? ";
|
||
|
|
$stmh = $pdo->prepare($sql);
|
||
|
|
$stmh->bindValue(1, $num, PDO::PARAM_STR);
|
||
|
|
$stmh->execute();
|
||
|
|
$count = $stmh->rowCount();
|
||
|
|
if($count<1){
|
||
|
|
print "검색결과가 없습니다.<br>";
|
||
|
|
} else {
|
||
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
||
|
|
}
|
||
|
|
include '_row.php';
|
||
|
|
} catch (PDOException $Exception) {
|
||
|
|
print "오류: ".$Exception->getMessage();
|
||
|
|
}
|
||
|
|
// 자료번호 초기화
|
||
|
|
$num = 0;
|
||
|
|
$registedate=date("Y-m-d");
|
||
|
|
$mode = 'insert';
|
||
|
|
}
|
||
|
|
|
||
|
|
if(empty($mode))
|
||
|
|
$mode='insert';
|
||
|
|
|
||
|
|
?>
|
||
|
|
|
||
|
|
<form id="board_form" name="board_form" method="post" enctype="multipart/form-data">
|
||
|
|
|
||
|
|
<input type="hidden" id="mode" name="mode" value="<?= isset($mode) ? $mode : '' ?>">
|
||
|
|
<input type="hidden" id="num" name="num" value="<?= isset($num) ? $num : '' ?>">
|
||
|
|
<input type="hidden" id="level" name="level" value="<?= isset($level) ? $level : '' ?>">
|
||
|
|
<input type="hidden" id="user_name" name="user_name" value="<?= isset($user_name) ? $user_name : '' ?>">
|
||
|
|
<input type="hidden" id="update_log" name="update_log" value="<?= isset($update_log) ? $update_log : NULL ?>">
|
||
|
|
<input type="hidden" id="tablename" name="tablename" value="<?= isset($tablename) ? $tablename : '' ?>">
|
||
|
|
<input type="hidden" id="is_deleted" name="is_deleted" value="<?= isset($is_deleted) ? $is_deleted : '0' ?>">
|
||
|
|
<input type="hidden" id="itemList" name="itemList">
|
||
|
|
|
||
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . "/common/write_formTopCard.php"; // 저장, 수정, 닫기 등 card 모음 ?>
|
||
|
|
|
||
|
|
<div class="container-fluid mt-4">
|
||
|
|
<div class="row ">
|
||
|
|
<div class="col-lg-2 col-sm-2">
|
||
|
|
</div>
|
||
|
|
<div class="col-lg-8 col-sm-8">
|
||
|
|
<div class=" d-flex justify-content-center align-items-center">
|
||
|
|
<table class="table table-bordered">
|
||
|
|
<tbody>
|
||
|
|
<tr>
|
||
|
|
<td class="text-center" style="width:10%;"> 등록일 </td>
|
||
|
|
<td class="text-center" style="width:10%;" >
|
||
|
|
<input type="date" id="registedate" name="registedate" class="form-control"value="<?= isset($registedate) ? $registedate : '' ?>">
|
||
|
|
</td>
|
||
|
|
<td class="text-center" style="width:10%;" > 메모 </td>
|
||
|
|
<td >
|
||
|
|
<textarea id="memo" name="memo" class="form-control" rows="4"><?=$memo?></textarea>
|
||
|
|
</td>
|
||
|
|
</tr>
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-lg-2 col-sm-2">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="d-flex justify-content-center">
|
||
|
|
<div class="card">
|
||
|
|
<div class="card-body">
|
||
|
|
<h5 class="card-title text-center">부자재(연기차단재) 단가표</h5>
|
||
|
|
<div class='d-flex justify-content-start mt-2 mb-2 m-1'>
|
||
|
|
<span class='badge bg-dark fs-6 me-3'>품목(item)</span>
|
||
|
|
<button type='button' class='btn btn-primary btn-sm viewNoBtn add-row' data-table='myTable' style='margin-right: 5px;'>+</button>
|
||
|
|
<!-- <button type='button' class='btn btn-danger btn-sm viewNoBtn remove-row' data-table='myTable' style='margin-right: 5px;'>-</button> -->
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<table id="myTable" class="table table-bordered table-hover">
|
||
|
|
<thead class="table-primary text-center">
|
||
|
|
<tr>
|
||
|
|
<th class="align-middle">+ - Copy</th>
|
||
|
|
<th class="align-middle">품목</th>
|
||
|
|
<th class="align-middle">용도</th>
|
||
|
|
<th class="align-middle">단위(롤)</th>
|
||
|
|
<th class="align-middle">길이(mm)</th>
|
||
|
|
<th class="align-middle">폭(mm)</th>
|
||
|
|
<th class="align-middle">용차</th>
|
||
|
|
<th class="align-middle">가공비</th>
|
||
|
|
<th class="align-middle">입고가</th>
|
||
|
|
<th class="align-middle">원가합계</th>
|
||
|
|
<th class="align-middle bg-danger text-white">판매가 15%</th>
|
||
|
|
<th class="align-middle">1롤/50M</th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
|
||
|
|
<tbody>
|
||
|
|
<!-- Additional Rows Go Here -->
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
// 페이지 로딩
|
||
|
|
$(document).ready(function(){
|
||
|
|
var loader = document.getElementById('loadingOverlay');
|
||
|
|
loader.style.display = 'none';
|
||
|
|
});
|
||
|
|
|
||
|
|
var ajaxRequest = null;
|
||
|
|
var ajaxRequest_write = null;
|
||
|
|
|
||
|
|
$(document).ready(function() {
|
||
|
|
initializePage();
|
||
|
|
|
||
|
|
$("#saveBtn").click(function() {
|
||
|
|
saveData();
|
||
|
|
});
|
||
|
|
|
||
|
|
$("#deleteBtn").click(function() {
|
||
|
|
deleteData();
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
function initializePage() {
|
||
|
|
// PHP에서 넘어온 JSON 데이터를 JavaScript 객체로 변환
|
||
|
|
var itemList = <?php echo isset($itemList) ? json_encode($itemList) : '[]'; ?>;
|
||
|
|
|
||
|
|
// itemList가 올바른 배열인지 확인
|
||
|
|
if (!Array.isArray(itemList)) {
|
||
|
|
itemList = [];
|
||
|
|
}
|
||
|
|
|
||
|
|
var tableBody = $('#myTable tbody'); // 테이블의 tbody 선택
|
||
|
|
|
||
|
|
// JSON 데이터를 순회하며 각 행을 추가하고, 값을 채워 넣음
|
||
|
|
itemList.forEach(function(rowData) {
|
||
|
|
addRow(tableBody, rowData);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function saveData() {
|
||
|
|
|
||
|
|
const formData = [];
|
||
|
|
$('#myTable tbody tr').each(function() {
|
||
|
|
let rowData = {};
|
||
|
|
$(this).find('input, select').each(function() {
|
||
|
|
let name = $(this).attr('name').replace('[]', '');
|
||
|
|
let value = $(this).val();
|
||
|
|
rowData[name] = value;
|
||
|
|
});
|
||
|
|
formData.push(rowData);
|
||
|
|
});
|
||
|
|
|
||
|
|
// JSON으로 인코딩된 데이터를 서버로 전송
|
||
|
|
$('#itemList').val(JSON.stringify(formData));
|
||
|
|
|
||
|
|
const form = $('#board_form')[0];
|
||
|
|
const datasource = new FormData(form);
|
||
|
|
|
||
|
|
if (ajaxRequest_write !== null) {
|
||
|
|
ajaxRequest_write.abort();
|
||
|
|
}
|
||
|
|
|
||
|
|
ajaxRequest_write = $.ajax({
|
||
|
|
enctype: 'multipart/form-data',
|
||
|
|
processData: false,
|
||
|
|
contentType: false,
|
||
|
|
cache: false,
|
||
|
|
timeout: 600000,
|
||
|
|
url: "insert.php",
|
||
|
|
type: "post",
|
||
|
|
data: datasource,
|
||
|
|
dataType: "json",
|
||
|
|
success: function(data) {
|
||
|
|
console.log(data);
|
||
|
|
|
||
|
|
setTimeout(function() {
|
||
|
|
Toastify({
|
||
|
|
text: "저장완료",
|
||
|
|
duration: 3000,
|
||
|
|
close:true,
|
||
|
|
gravity:"top",
|
||
|
|
position: "center",
|
||
|
|
style: {
|
||
|
|
background: "linear-gradient(to right, #00b09b, #96c93d)"
|
||
|
|
},
|
||
|
|
}).showToast();
|
||
|
|
|
||
|
|
}, 1000);
|
||
|
|
|
||
|
|
setTimeout(function() {
|
||
|
|
if (window.opener && !window.opener.closed) {
|
||
|
|
if (typeof window.opener.restorePageNumber === 'function') {
|
||
|
|
window.opener.restorePageNumber(); // 함수가 있으면 실행
|
||
|
|
}
|
||
|
|
}
|
||
|
|
setTimeout(function() {
|
||
|
|
if (data && data.num)
|
||
|
|
// 저장된 데이터 번호를 사용하여 새로운 페이지로 이동
|
||
|
|
window.location.href = 'write_form.php?mode=view&tablename=' + $('#tablename').val() + '&num=' + data.num;
|
||
|
|
}, 1000);
|
||
|
|
|
||
|
|
}, 1500);
|
||
|
|
|
||
|
|
hideOverlay();
|
||
|
|
|
||
|
|
},
|
||
|
|
error: function(jqxhr, status, error) {
|
||
|
|
console.log(jqxhr, status, error);
|
||
|
|
alert("An error occurred: " + error); // Display error message
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function deleteData() {
|
||
|
|
var level = '<?php echo $level; ?>';
|
||
|
|
|
||
|
|
if (level !== '1') {
|
||
|
|
Swal.fire({
|
||
|
|
title: '삭제불가',
|
||
|
|
text: "작성자와 관리자만 삭제가능합니다.",
|
||
|
|
icon: 'error',
|
||
|
|
confirmButtonText: '확인'
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
Swal.fire({
|
||
|
|
title: '자료 삭제',
|
||
|
|
text: "삭제는 신중! 정말 삭제하시겠습니까?",
|
||
|
|
icon: 'warning',
|
||
|
|
showCancelButton: true,
|
||
|
|
confirmButtonColor: '#3085d6',
|
||
|
|
cancelButtonColor: '#d33',
|
||
|
|
confirmButtonText: '삭제',
|
||
|
|
cancelButtonText: '취소'
|
||
|
|
}).then((result) => {
|
||
|
|
if (result.isConfirmed) {
|
||
|
|
$("#mode").val('delete');
|
||
|
|
var form = $('#board_form')[0];
|
||
|
|
var formData = new FormData(form);
|
||
|
|
|
||
|
|
formData.set('mode', $("#mode").val());
|
||
|
|
formData.set('num', $("#num").val());
|
||
|
|
|
||
|
|
if (ajaxRequest_write !== null) {
|
||
|
|
ajaxRequest_write.abort();
|
||
|
|
}
|
||
|
|
|
||
|
|
ajaxRequest_write = $.ajax({
|
||
|
|
enctype: 'multipart/form-data',
|
||
|
|
processData: false,
|
||
|
|
contentType: false,
|
||
|
|
cache: false,
|
||
|
|
timeout: 1000000,
|
||
|
|
url: "insert.php",
|
||
|
|
type: "post",
|
||
|
|
data: formData,
|
||
|
|
dataType: "json",
|
||
|
|
success: function(data) {
|
||
|
|
Toastify({
|
||
|
|
text: "파일 삭제완료 ",
|
||
|
|
duration: 2000,
|
||
|
|
close: true,
|
||
|
|
gravity: "top",
|
||
|
|
position: "center",
|
||
|
|
style: {
|
||
|
|
background: "linear-gradient(to right, #00b09b, #96c93d)"
|
||
|
|
},
|
||
|
|
}).showToast();
|
||
|
|
|
||
|
|
setTimeout(function() {
|
||
|
|
if (window.opener && !window.opener.closed) {
|
||
|
|
window.opener.location.reload(); // 부모창 리로드
|
||
|
|
}
|
||
|
|
|
||
|
|
setTimeout(function() {
|
||
|
|
self.close(); // 현재 창 닫기
|
||
|
|
}, 1000);
|
||
|
|
|
||
|
|
}, 1500);
|
||
|
|
|
||
|
|
|
||
|
|
hideOverlay();
|
||
|
|
},
|
||
|
|
error: function(jqxhr, status, error) {
|
||
|
|
console.log(jqxhr, status, error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function addRow(tableBody, rowData) {
|
||
|
|
var newRow = $('<tr>');
|
||
|
|
|
||
|
|
// + / - 버튼 추가
|
||
|
|
newRow.append('<td class="text-center" style="width:80px;">' +
|
||
|
|
'<div class="d-flex justify-content-center mt-1">' +
|
||
|
|
'<button type="button" class="btn btn-primary btn-sm viewNoBtn add-row me-1" data-table="' + tableBody.closest('table').attr('id') + '">+</button>' +
|
||
|
|
'<button type="button" class="btn btn-danger btn-sm viewNoBtn remove-row ms-2 me-2">-</button>' +
|
||
|
|
'<button type="button" class="btn btn-success btn-sm viewNoBtn copy-row"><i class="bi bi-copy"></i></button>' +
|
||
|
|
'</div></td>');
|
||
|
|
|
||
|
|
// col1부터 col11까지 채우기
|
||
|
|
for (let i = 1; i <= 11; i++) {
|
||
|
|
let colValue = rowData['col' + i] || ''; // 값이 없으면 빈 문자열 사용
|
||
|
|
|
||
|
|
// 특정 열에 계산식 적용 (col9, col10, col11)
|
||
|
|
if ([9, 10, 11].includes(i)) {
|
||
|
|
newRow.append('<td><input type="text" name="col' + i + '[]" value="' + colValue + '" class="form-control text-center number-format col' + i + '" autocomplete="off" readonly></td>');
|
||
|
|
} else {
|
||
|
|
newRow.append('<td><input type="text" name="col' + i + '[]" value="' + colValue + '" class="form-control text-center number-format col' + i + '" autocomplete="off"></td>');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 새 행을 테이블에 추가
|
||
|
|
tableBody.append(newRow);
|
||
|
|
|
||
|
|
// 숫자 필드에 3자리마다 콤마 추가 (소수점 입력 가능)
|
||
|
|
newRow.find('.number-format').on('input change', function() {
|
||
|
|
let value = $(this).val().replace(/,/g, ''); // 기존의 콤마를 제거
|
||
|
|
|
||
|
|
// 소수점 포함 숫자 검사
|
||
|
|
if (!isNaN(value) && value !== '') {
|
||
|
|
// 정수와 소수 부분 분리
|
||
|
|
let parts = value.split('.');
|
||
|
|
parts[0] = Number(parts[0]).toLocaleString('en'); // 3자리마다 콤마 추가
|
||
|
|
|
||
|
|
// 소수점이 있는 경우
|
||
|
|
let formattedValue = parts.join('.');
|
||
|
|
|
||
|
|
$(this).val(formattedValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 행 계산 함수 호출
|
||
|
|
calculateRow(newRow);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 처음 로드될 때도 자동 계산 적용
|
||
|
|
calculateRow(newRow);
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateRow(row) {
|
||
|
|
// 소수점 자릿수와 콤마를 포함한 숫자 형식 변환 함수
|
||
|
|
function formatNumber(value, decimalPlaces) {
|
||
|
|
// value를 소수점 자릿수에 맞게 고정
|
||
|
|
let fixedValue = parseFloat(value).toFixed(decimalPlaces);
|
||
|
|
|
||
|
|
// 정수 부분과 소수 부분으로 분리
|
||
|
|
let [integerPart, decimalPart] = fixedValue.split('.');
|
||
|
|
|
||
|
|
// 정수 부분에만 콤마 추가
|
||
|
|
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||
|
|
|
||
|
|
// 소수점 이하가 존재하고 0보다 큰 경우, 정수 부분과 결합하여 반환
|
||
|
|
if (decimalPart && parseInt(decimalPart) > 0) {
|
||
|
|
return `${integerPart}.${decimalPart}`;
|
||
|
|
} else {
|
||
|
|
return integerPart; // 소수점 이하가 없거나 0인 경우 정수만 반환
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const col5 = parseFloat(row.find('.col5').val().replace(/,/g, '')) || 0;
|
||
|
|
const col6 = parseFloat(row.find('.col6').val().replace(/,/g, '')) || 0;
|
||
|
|
const col7 = parseFloat(row.find('.col7').val().replace(/,/g, '')) || 0;
|
||
|
|
const col8 = parseFloat(row.find('.col8').val().replace(/,/g, '')) || 0;
|
||
|
|
|
||
|
|
// col9 계산: col9 = col6 / (10 * 50) + col7 + col8
|
||
|
|
const col9 = (col6 / (10 * 50)) + col7 + col8;
|
||
|
|
if (!isNaN(col9)) {
|
||
|
|
row.find('.col9').val(formatNumber(col9, 2));
|
||
|
|
}
|
||
|
|
|
||
|
|
// col10 계산: col10 = ROUND(col9 * 1.15, -3)
|
||
|
|
const col10 = Math.round(col9 * 1.15 / 1000) * 1000;
|
||
|
|
if (!isNaN(col10)) {
|
||
|
|
row.find('.col10').val(formatNumber(col10, 0));
|
||
|
|
}
|
||
|
|
|
||
|
|
// col11 계산: col11 = ROUND((col10 * 50) / (1200 / col5 ), -4)
|
||
|
|
const col11 = Math.round((col10 * 50) / (1200 / col5 ) / 10000) * 10000;
|
||
|
|
if (!isNaN(col11)) {
|
||
|
|
row.find('.col11').val(formatNumber(col11, 0));
|
||
|
|
}
|
||
|
|
|
||
|
|
// 콤마 및 소수점 표시 설정
|
||
|
|
if (!isNaN(col6)) {
|
||
|
|
row.find('.col6').val(formatNumber(col6, 2));
|
||
|
|
}
|
||
|
|
if (!isNaN(col7)) {
|
||
|
|
row.find('.col7').val(formatNumber(col7, 2));
|
||
|
|
}
|
||
|
|
if (!isNaN(col8)) {
|
||
|
|
row.find('.col8').val(formatNumber(col8, 0));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$(document).ready(function() {
|
||
|
|
var mode = '<?php echo $mode; ?>';
|
||
|
|
|
||
|
|
|
||
|
|
$("#copyBtn").click(function(){
|
||
|
|
|
||
|
|
location.href = 'write_form.php?mode=copy&num=' + $("#num").val() + "&tablename=" + $("#tablename").val() ;
|
||
|
|
|
||
|
|
}); // end of function
|
||
|
|
|
||
|
|
// view 모드일 때, 버튼 및 입력 요소 비활성화
|
||
|
|
if (mode === 'view') {
|
||
|
|
$('input, textarea').prop('readonly', true); // Disable all input, textarea, and select elements
|
||
|
|
$('input[type=hidden]').prop('readonly', false);
|
||
|
|
$('button.add-row, button.remove-row, button.copy-row').prop('disabled', true); // 버튼 비활성화
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// 행 삭제
|
||
|
|
$(document).on('click', '.remove-row', function() {
|
||
|
|
if (mode !== 'view') {
|
||
|
|
$(this).closest('tr').remove();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// 행 추가
|
||
|
|
$(document).on('click', '.add-row', function() {
|
||
|
|
if (mode !== 'view') {
|
||
|
|
var tableId = $(this).data('table');
|
||
|
|
var tableBody = $('#' + tableId).find('tbody');
|
||
|
|
addRow(tableBody, {}, tableId);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// 행 복사
|
||
|
|
$(document).on('click', '.copy-row', function() {
|
||
|
|
if (mode !== 'view') {
|
||
|
|
var currentRow = $(this).closest('tr');
|
||
|
|
var clonedRow = currentRow.clone(true); // true로 이벤트와 데이터를 복사
|
||
|
|
|
||
|
|
clonedRow.find('input').each(function(index) {
|
||
|
|
var currentInput = currentRow.find('input').eq(index);
|
||
|
|
|
||
|
|
// 값 복사
|
||
|
|
$(this).val(currentInput.val());
|
||
|
|
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
// 현재 행 바로 아래에 추가
|
||
|
|
currentRow.after(clonedRow);
|
||
|
|
|
||
|
|
// 숫자 필드에 3자리마다 콤마 추가 (소수점 입력 가능)
|
||
|
|
clonedRow.find('.number-format').on('input change', function() {
|
||
|
|
let value = $(this).val().replace(/,/g, ''); // 기존의 콤마를 제거
|
||
|
|
|
||
|
|
// 소수점 포함 숫자 검사
|
||
|
|
if (!isNaN(value) && value !== '') {
|
||
|
|
// 정수와 소수 부분 분리
|
||
|
|
let parts = value.split('.');
|
||
|
|
parts[0] = Number(parts[0]).toLocaleString('en'); // 3자리마다 콤마 추가
|
||
|
|
|
||
|
|
// 소수점이 있는 경우
|
||
|
|
let formattedValue = parts.join('.');
|
||
|
|
|
||
|
|
$(this).val(formattedValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 행 계산 함수 호출
|
||
|
|
calculateRow(clonedRow);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
</script>
|
||
|
|
|
||
|
|
|
||
|
|
</body>
|
||
|
|
</html>
|