초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
26
price_shaft/_request.php
Normal file
26
price_shaft/_request.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// 기본 키(num) 호출
|
||||
$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : '';
|
||||
|
||||
// 등록일자(registedate) 호출
|
||||
$registedate = isset($_REQUEST['registedate']) ? $_REQUEST['registedate'] : date('Y-m-d') ;
|
||||
|
||||
// itemList JSON 데이터를 호출 후 파싱
|
||||
$itemList = isset($_REQUEST['itemList']) ? json_decode($_REQUEST['itemList'], true) : [];
|
||||
|
||||
// 삭제 여부(is_deleted) 호출
|
||||
$is_deleted = isset($_REQUEST['is_deleted']) ? $_REQUEST['is_deleted'] : 0;
|
||||
|
||||
// 업데이트 로그(update_log) 호출
|
||||
$update_log = isset($_REQUEST['update_log']) ? $_REQUEST['update_log'] : '';
|
||||
|
||||
// 검색 태그(searchtag) 호출
|
||||
$searchtag = isset($_REQUEST['searchtag']) ? $_REQUEST['searchtag'] : '';
|
||||
|
||||
// 생성일시(created_at) 호출
|
||||
$created_at = isset($_REQUEST['created_at']) ? $_REQUEST['created_at'] : '';
|
||||
|
||||
$memo = isset($_REQUEST['memo']) ? $_REQUEST['memo'] : '';
|
||||
|
||||
?>
|
||||
25
price_shaft/_row.php
Normal file
25
price_shaft/_row.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// 기본 키(num) 처리
|
||||
$num = isset($row["num"]) ? $row["num"] : '';
|
||||
|
||||
// 등록일자(registedate) 처리
|
||||
$registedate = isset($row['registedate']) ? $row['registedate'] : '';
|
||||
|
||||
// itemList JSON 데이터를 처리
|
||||
$itemList = isset($row['itemList']) ? json_decode($row['itemList'], true) : [];
|
||||
|
||||
// 삭제 여부(is_deleted) 처리
|
||||
$is_deleted = isset($row['is_deleted']) ? $row['is_deleted'] : 0;
|
||||
|
||||
// 업데이트 로그(update_log) 처리
|
||||
$update_log = isset($row['update_log']) ? $row['update_log'] : '';
|
||||
|
||||
// 검색 태그(searchtag) 처리
|
||||
$searchtag = isset($row['searchtag']) ? $row['searchtag'] : '';
|
||||
|
||||
// 생성일시(created_at) 처리
|
||||
$created_at = isset($row['created_at']) ? $row['created_at'] : '';
|
||||
$memo = isset($row['memo']) ? $row['memo'] : '';
|
||||
|
||||
?>
|
||||
93
price_shaft/insert.php
Normal file
93
price_shaft/insert.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
||||
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
|
||||
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';
|
||||
|
||||
include '_request.php';
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
try {
|
||||
if ($mode == "modify") {
|
||||
$itemList = isset($_REQUEST['itemList']) ? $_REQUEST['itemList'] : ''; // 이미 JSON 형태로 받음
|
||||
$update_log = isset($_REQUEST['update_log']) ? $_REQUEST['update_log'] : '';
|
||||
$searchtag = isset($_REQUEST['searchtag']) ? $_REQUEST['searchtag'] : '';
|
||||
$is_deleted = isset($_REQUEST['is_deleted']) ? $_REQUEST['is_deleted'] : null;
|
||||
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
||||
|
||||
$pdo->beginTransaction();
|
||||
$sql = "UPDATE $DB.$tablename SET itemList=?, is_deleted=?, update_log=?, searchtag=?, memo=?, registedate=? WHERE num=? LIMIT 1";
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(1, $itemList, PDO::PARAM_STR); // 이미 JSON 인코딩된 데이터
|
||||
$stmh->bindValue(2, $is_deleted, PDO::PARAM_BOOL);
|
||||
$stmh->bindValue(3, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $searchtag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $memo, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $registedate, PDO::PARAM_STR);
|
||||
$stmh->bindValue(7, $num, PDO::PARAM_INT);
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
}
|
||||
|
||||
if ($mode == "insert") {
|
||||
$itemList = isset($_REQUEST['itemList']) ? $_REQUEST['itemList'] : ''; // 이미 JSON 형태로 받음
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"];
|
||||
$searchtag = isset($_REQUEST['searchtag']) ? $_REQUEST['searchtag'] : '';
|
||||
|
||||
$pdo->beginTransaction();
|
||||
$sql = "INSERT INTO $DB.$tablename (itemList, is_deleted, update_log, searchtag, memo, registedate) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(1, $itemList, PDO::PARAM_STR); // 이미 JSON 인코딩된 데이터
|
||||
$stmh->bindValue(2, $is_deleted, PDO::PARAM_BOOL);
|
||||
$stmh->bindValue(3, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $searchtag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $memo, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $registedate, PDO::PARAM_STR);
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
|
||||
// 가장 최근에 삽입된 레코드를 가져오기 위해 num 값을 조회
|
||||
$sql = "SELECT num FROM $DB.$tablename ORDER BY num DESC LIMIT 1";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->execute();
|
||||
$num = $stmh->fetchColumn(); // num 값 가져오기
|
||||
}
|
||||
|
||||
|
||||
if ($mode == "delete") {
|
||||
$pdo->beginTransaction();
|
||||
$sql = "UPDATE $DB.$tablename SET is_deleted='1' WHERE num=? LIMIT 1";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(1, $num, PDO::PARAM_INT);
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'num' => $num,
|
||||
'mode' => $mode,
|
||||
'is_deleted' => $is_deleted
|
||||
];
|
||||
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
} catch (PDOException $Exception) {
|
||||
error_log("오류: " . $Exception->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $Exception->getMessage()]);
|
||||
} catch (Exception $e) {
|
||||
error_log("오류: " . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
144
price_shaft/list.php
Normal file
144
price_shaft/list.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?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;
|
||||
}
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';
|
||||
$title_message = '부자재(샤프트) 단가 List';
|
||||
?>
|
||||
<title> <?=$title_message?> </title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/myheader.php'); ?>
|
||||
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/mymodal.php'); ?>
|
||||
<?php
|
||||
$tablename = 'price_shaft';
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
// 검색 조건 설정
|
||||
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
|
||||
$fromdate = isset($_REQUEST['fromdate']) ? $_REQUEST['fromdate'] : '';
|
||||
$todate = isset($_REQUEST['todate']) ? $_REQUEST['todate'] : '';
|
||||
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
||||
$SettingDate = isset($_REQUEST['SettingDate']) ? $_REQUEST['SettingDate'] : "registedate"; // 기본 날짜 설정: registedate
|
||||
|
||||
$separate_date = isset($_REQUEST["separate_date"]) ? $_REQUEST["separate_date"] : "";
|
||||
$existing_status = isset($_REQUEST["status_option"]) ? $_REQUEST["status_option"] : '전체';
|
||||
|
||||
$currentDate = date("Y-m-d");
|
||||
|
||||
if ($fromdate === "" || $fromdate === null || $todate === "" || $todate === null) {
|
||||
$fromdate = date("Y-m-d", strtotime("-5 years", strtotime($currentDate)));
|
||||
$todate = date("Y-m-d", strtotime("+3 months", strtotime($currentDate)));
|
||||
$Transtodate = $todate;
|
||||
} else {
|
||||
$Transtodate = $todate;
|
||||
}
|
||||
|
||||
$SettingDate = "registedate";
|
||||
|
||||
$orderby = " order by " . $SettingDate . " desc, num desc";
|
||||
|
||||
if ($existing_status == '전체') {
|
||||
$where = " where " . $SettingDate . " between date('$fromdate') and date('$Transtodate') and is_deleted = '0' " . $orderby;
|
||||
$searchwhere = " where is_deleted = '0' and searchtag like '%$search%'" . $orderby;
|
||||
} else {
|
||||
$where = " where " . $SettingDate . " between date('$fromdate') and date('$Transtodate') and is_deleted = '0' and regist_state = '$existing_status'" . $orderby;
|
||||
$searchwhere = " where is_deleted = '0' and regist_state = '$existing_status' and searchtag like '%$search%'" . $orderby;
|
||||
}
|
||||
|
||||
$sql = ($search == "") ?
|
||||
"select * from $DB.$tablename " . $where :
|
||||
"select * from $DB.$tablename " . $searchwhere;
|
||||
|
||||
$today = date("Y-m-d");
|
||||
|
||||
// print $sql;
|
||||
|
||||
try {
|
||||
$stmh = $pdo->query($sql);
|
||||
$total_row = $stmh->rowCount();
|
||||
} catch (PDOException $Exception) {
|
||||
print "오류: " . $Exception->getMessage();
|
||||
}
|
||||
?>
|
||||
<form id="board_form" name="board_form" method="post" action="list.php?mode=search">
|
||||
<input type="hidden" id="mode" name="mode" value="<?=$mode?>">
|
||||
<input type="hidden" id="num" name="num">
|
||||
<input type="hidden" id="tablename" name="tablename" value="<?=$tablename?>">
|
||||
<input type="hidden" id="header" name="header" value="<?=$header?>">
|
||||
<div class="container">
|
||||
<?php include $_SERVER['DOCUMENT_ROOT'] . "/common/listTopCard.php"; // list.php 파일의 검색날짜(기간) 검색버튼 신규버튼 모음 ?>
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<table class="table table-hover" id="myTable">
|
||||
<thead class="table-primary">
|
||||
<tr>
|
||||
<th class="text-center" style="width:5%;"> 번호 </th>
|
||||
<th class="text-center" style="width:10%;"> 등록일자 </th>
|
||||
<th class="text-center" style="width:65%;"> 업데이트 로그 </th>
|
||||
<th class="text-center" style="width:20%;"> 비고 </th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$start_num = $total_row;
|
||||
|
||||
while($row = $stmh->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
include '_row.php';
|
||||
|
||||
?>
|
||||
<tr onclick="redirectToView('<?= $num ?>', '<?= $tablename ?>')">
|
||||
<td class="text-center"><?= $start_num ?></td>
|
||||
<td class="text-center"><?= $registedate ?></td>
|
||||
<td class="text-start"><?= $update_log ?></td>
|
||||
<td class="text-start"><?= $memo ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$start_num--;
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div> <!--container-->
|
||||
</form>
|
||||
|
||||
<script>
|
||||
// 페이지 로딩
|
||||
$(document).ready(function(){
|
||||
var loader = document.getElementById('loadingOverlay');
|
||||
loader.style.display = 'none';
|
||||
});
|
||||
|
||||
function redirectToView(num, tablename) {
|
||||
var url = "write_form.php?mode=view&num=" + num + "&tablename=" + tablename;
|
||||
customPopup(url, '부자재(샤프트) 단가', 1900, 900);
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#writeBtn").click(function(){
|
||||
var tablename = '<?php echo $tablename; ?>';
|
||||
var url = "write_form.php?tablename=" + tablename;
|
||||
customPopup(url, '부자재(샤프트) 단가', 1900, 900);
|
||||
});
|
||||
});
|
||||
|
||||
function submitForm(status) {
|
||||
$('input[name=status_option]').val(status);
|
||||
document.getElementById('board_form').submit();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
589
price_shaft/write_form.php
Normal file
589
price_shaft/write_form.php
Normal file
@@ -0,0 +1,589 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
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';
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
$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='d-flex 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>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-12 col-sm-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title text-center">부자재(샤프트) 단가표</h5>
|
||||
<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">1다발(개)</th>
|
||||
<th class="align-middle">단위</th>
|
||||
<th class="align-middle">지름(mm)</th>
|
||||
<th class="align-middle">원 면적</th>
|
||||
<th class="align-middle">2</th>
|
||||
<th class="align-middle">파이</th>
|
||||
<th class="align-middle">R(반지름)</th>
|
||||
<th class="align-middle">길이(M)</th>
|
||||
<th class="align-middle">도장/㎡</th>
|
||||
<th class="align-middle">도장</th>
|
||||
<th class="align-middle">차1대/도장</th>
|
||||
<th class="align-middle">용차</th>
|
||||
<th class="align-middle">도장+용차</th>
|
||||
<th class="align-middle">가공비</th>
|
||||
<th class="align-middle">입고가<br>(6M)</th>
|
||||
<th class="align-middle">원가합계</th>
|
||||
<th class="align-middle bg-danger text-white">판매가 20% UP</th>
|
||||
<th class="align-middle">m / 단가</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부터 col20까지 채우기
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
let colValue = rowData['col' + i] || ''; // 값이 없으면 빈 문자열 사용
|
||||
|
||||
// 특정 열만 readonly 속성 부여
|
||||
if ([ 6, 9, 12, 13, 15, 18, 19, 20].includes(i)) {
|
||||
newRow.append('<td><input type="text" name="col' + i + '[]" value="' + colValue + '" class="text-center number-format col' + i + '" autocomplete="off" readonly></td>');
|
||||
} else if ([1].includes(i)) {
|
||||
newRow.append('<td><input type="text" name="col' + i + '[]" value="' + colValue + '" class=" number-format text-center col' + i + '" style="width:120px;" autocomplete="off"></td>');
|
||||
} else {
|
||||
newRow.append('<td><input type="text" name="col' + i + '[]" value="' + colValue + '" class=" number-format text-center 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, ',');
|
||||
|
||||
// 소수점 이하가 존재하는 경우, 정수 부분과 결합하여 반환
|
||||
if (decimalPart) {
|
||||
return `${integerPart}.${decimalPart}`;
|
||||
} else {
|
||||
return integerPart;
|
||||
}
|
||||
}
|
||||
|
||||
// col2부터 col20까지의 값을 가져오기
|
||||
const col2 = parseFloat(row.find('.col2').val().replace(/,/g, '')) || 0;
|
||||
const col3 = parseFloat(row.find('.col3').val().replace(/,/g, '')) || 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;
|
||||
const col9 = parseFloat(row.find('.col9').val().replace(/,/g, '')) || 0;
|
||||
const col10 = parseFloat(row.find('.col10').val().replace(/,/g, '')) || 0;
|
||||
const col11 = parseFloat(row.find('.col11').val().replace(/,/g, '')) || 0;
|
||||
const col12 = parseFloat(row.find('.col12').val().replace(/,/g, '')) || 0;
|
||||
const col17 = parseFloat(row.find('.col17').val().replace(/,/g, '')) || 0;
|
||||
|
||||
const col13 = col2 * col3 * col12; // col13는 col2 * col3 * col12
|
||||
if (!isNaN(col13)) {
|
||||
row.find('.col13').val(formatNumber(col13, 0));
|
||||
}
|
||||
|
||||
const col14 = parseFloat(row.find('.col14').val().replace(/,/g, '')) || 0;
|
||||
const col15 = col13 + col14; // col15는 col13 * col14
|
||||
if (!isNaN(col15)) {
|
||||
row.find('.col15').val(formatNumber(col15, 0));
|
||||
}
|
||||
const col16 = parseFloat(row.find('.col16').val().replace(/,/g, '')) || 0;
|
||||
|
||||
// 스크린, 철제 등은 계산방법이 다르다.
|
||||
let col18;
|
||||
|
||||
col18 = (col15/col2/col3)+col17
|
||||
if (!isNaN(col18)) {
|
||||
row.find('.col18').val(formatNumber(col18, 0));
|
||||
}
|
||||
|
||||
const col19 = Math.round(col18 * 1.2 / 1000) * 1000;
|
||||
if (!isNaN(col19)) {
|
||||
row.find('.col19').val(formatNumber(col19, 0));
|
||||
}
|
||||
const col20 = Math.round(col18 / 3 / 1000) * 1000;
|
||||
if (!isNaN(col20)) {
|
||||
row.find('.col20').val(formatNumber(col20, 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>
|
||||
Reference in New Issue
Block a user