- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
199 lines
9.9 KiB
PHP
199 lines
9.9 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
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';
|
|
|
|
// json 형태는 저장할때 주의해야 한다.
|
|
if (isset($_POST['estimateList'])) {
|
|
$estimateList_jsondata = json_decode($_POST['estimateList'], true);
|
|
} else {
|
|
// Error handling or fallback
|
|
$estimateList_jsondata = null;
|
|
}
|
|
|
|
if (isset($_POST['estimateList_auto'])) {
|
|
$estimateList_auto_jsondata = json_decode($_POST['estimateList_auto'], true);
|
|
} else {
|
|
// Error handling or fallback
|
|
$estimateList_auto_jsondata = null;
|
|
}
|
|
// json 형태는 저장할때 주의해야 한다.
|
|
if (isset($_POST['estimateSlatList'])) {
|
|
$estimateSlatList_jsondata = json_decode($_POST['estimateSlatList'], true);
|
|
} else {
|
|
// Error handling or fallback
|
|
$estimateSlatList_jsondata = null;
|
|
}
|
|
|
|
if (isset($_POST['estimateSlatList_auto'])) {
|
|
$estimateSlatList_auto_jsondata = json_decode($_POST['estimateSlatList_auto'], true);
|
|
} else {
|
|
// Error handling or fallback
|
|
$estimateSlatList_auto_jsondata = null;
|
|
}
|
|
|
|
// 견적번호 자동생성
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/estimate/generate_serial_pjnum.php");
|
|
$pjnum = $_POST['pjnum'] ?? '';
|
|
|
|
// 정규식으로 -숫자형태가 아닌 경우만 generatePjnum() 실행
|
|
if (!preg_match('/^KD-PR-\d{6}-\d{2}$/', $pjnum)) {
|
|
$pjnum = generatePjnum();
|
|
}
|
|
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
try {
|
|
if ($mode == "modify") {
|
|
// 기존 데이터 조회
|
|
$sql = "SELECT * FROM $DB.$tablename WHERE num=?";
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(1, $num, PDO::PARAM_STR);
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// 자료수정 로그
|
|
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "\n";
|
|
|
|
// 트랜잭션 시작
|
|
$pdo->beginTransaction();
|
|
$sql = "UPDATE $DB.$tablename SET indate=?, orderman=?, outworkplace=?, comment=?, con_num=?, ";
|
|
$sql .= "model_name=?, update_log=?, secondord=?, secondordman=?, secondordmantel=?, estimateList=?, estimateList_auto=?, estimateSlatList=?, estimateSlatList_auto=?, pjnum=?, major_category=?, position=?, makeWidth=?, makeHeight=?, secondordnum=?, ";
|
|
$sql .= "estimateTotal=?, EstimateFirstSum=?, EstimateUpdatetSum=?, EstimateDiffer=?, EstimateDiscountRate=?, EstimateDiscount=?, EstimateFinalSum=?, maguriWing=?, inspectionFee=?, estimateSurang=?, ";
|
|
$sql .= "steel=?, motor=?, warranty=?, slatcheck=?, partscheck=? WHERE num=? LIMIT 1";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(1, $indate, PDO::PARAM_STR);
|
|
$stmh->bindValue(2, $orderman, PDO::PARAM_STR);
|
|
$stmh->bindValue(3, $outworkplace, PDO::PARAM_STR);
|
|
$stmh->bindValue(4, $comment, PDO::PARAM_STR);
|
|
$stmh->bindValue(5, $con_num, PDO::PARAM_STR);
|
|
$stmh->bindValue(6, $model_name, PDO::PARAM_STR);
|
|
$stmh->bindValue(7, $update_log, PDO::PARAM_STR);
|
|
$stmh->bindValue(8, $secondord, PDO::PARAM_STR);
|
|
$stmh->bindValue(9, $secondordman, PDO::PARAM_STR);
|
|
$stmh->bindValue(10, $secondordmantel, PDO::PARAM_STR);
|
|
$stmh->bindValue(11, json_encode($estimateList_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(12, json_encode($estimateList_auto_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(13, json_encode($estimateSlatList_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(14, json_encode($estimateSlatList_auto_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(15, $pjnum, PDO::PARAM_STR);
|
|
$stmh->bindValue(16, $major_category, PDO::PARAM_STR);
|
|
$stmh->bindValue(17, $position, PDO::PARAM_STR);
|
|
$stmh->bindValue(18, $makeWidth, PDO::PARAM_STR);
|
|
$stmh->bindValue(19, $makeHeight, PDO::PARAM_STR);
|
|
$stmh->bindValue(20, $secondordnum, PDO::PARAM_STR);
|
|
$stmh->bindValue(21, intval(str_replace(',', '', $estimateTotal)), PDO::PARAM_INT);
|
|
$stmh->bindValue(22, intval(str_replace(',', '', $EstimateFirstSum)), PDO::PARAM_INT);
|
|
$stmh->bindValue(23, intval(str_replace(',', '', $EstimateUpdatetSum)), PDO::PARAM_INT);
|
|
$stmh->bindValue(24, intval(str_replace(',', '', $EstimateDiffer)), PDO::PARAM_INT);
|
|
$stmh->bindValue(25, intval(str_replace(',', '', $EstimateDiscountRate)), PDO::PARAM_INT);
|
|
$stmh->bindValue(26, intval(str_replace(',', '', $EstimateDiscount)), PDO::PARAM_INT);
|
|
$stmh->bindValue(27, intval(str_replace(',', '', $EstimateFinalSum)), PDO::PARAM_INT);
|
|
$stmh->bindValue(28, $maguriWing, PDO::PARAM_STR);
|
|
$stmh->bindValue(29, intval(str_replace(',', '', $inspectionFee)), PDO::PARAM_INT);
|
|
$stmh->bindValue(30, intval(str_replace(',', '', $estimateSurang)), PDO::PARAM_INT);
|
|
$stmh->bindValue(31, $steel, PDO::PARAM_STR);
|
|
$stmh->bindValue(32, $motor, PDO::PARAM_STR);
|
|
$stmh->bindValue(33, $warranty, PDO::PARAM_STR);
|
|
$stmh->bindValue(34, $slatcheck, PDO::PARAM_STR);
|
|
$stmh->bindValue(35, $partscheck, PDO::PARAM_STR);
|
|
$stmh->bindValue(36, $num, PDO::PARAM_STR);
|
|
|
|
$stmh->execute();
|
|
$pdo->commit();
|
|
}
|
|
if ($mode == "insert") {
|
|
// 데이터 신규 등록하는 구간
|
|
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " ";
|
|
$pdo->beginTransaction();
|
|
$sql = "INSERT INTO $DB.$tablename (indate, orderman, outworkplace, comment, con_num, model_name, update_log, secondord, secondordman, secondordmantel, estimateList, estimateList_auto, estimateSlatList, estimateSlatList_auto, pjnum, major_category, position, makeWidth, makeHeight, secondordnum, ";
|
|
$sql .= " estimateTotal, EstimateFirstSum, EstimateUpdatetSum, EstimateDiffer, EstimateDiscountRate, EstimateDiscount, EstimateFinalSum, maguriWing, inspectionFee, estimateSurang, steel, motor, warranty, slatcheck, partscheck) ";
|
|
$sql .= "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->bindValue(1, $indate, PDO::PARAM_STR);
|
|
$stmh->bindValue(2, $orderman, PDO::PARAM_STR);
|
|
$stmh->bindValue(3, $outworkplace, PDO::PARAM_STR);
|
|
$stmh->bindValue(4, $comment, PDO::PARAM_STR);
|
|
$stmh->bindValue(5, $con_num, PDO::PARAM_STR);
|
|
$stmh->bindValue(6, $model_name, PDO::PARAM_STR);
|
|
$stmh->bindValue(7, $update_log, PDO::PARAM_STR);
|
|
$stmh->bindValue(8, $secondord, PDO::PARAM_STR);
|
|
$stmh->bindValue(9, $secondordman, PDO::PARAM_STR);
|
|
$stmh->bindValue(10, $secondordmantel, PDO::PARAM_STR);
|
|
$stmh->bindValue(11, json_encode($estimateList_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(12, json_encode($estimateList_auto_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(13, json_encode($estimateSlatList_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(14, json_encode($estimateSlatList_auto_jsondata), PDO::PARAM_STR);
|
|
$stmh->bindValue(15, $pjnum, PDO::PARAM_STR);
|
|
$stmh->bindValue(16, $major_category, PDO::PARAM_STR);
|
|
$stmh->bindValue(17, $position, PDO::PARAM_STR);
|
|
$stmh->bindValue(18, $makeWidth, PDO::PARAM_STR);
|
|
$stmh->bindValue(19, $makeHeight, PDO::PARAM_STR);
|
|
$stmh->bindValue(20, $secondordnum, PDO::PARAM_STR);
|
|
$stmh->bindValue(21, intval(str_replace(',', '', $estimateTotal)), PDO::PARAM_INT); // int 형태로 저장
|
|
$stmh->bindValue(22, intval(str_replace(',', '', $EstimateFirstSum)), PDO::PARAM_INT); // 추가된 필드
|
|
$stmh->bindValue(23, intval(str_replace(',', '', $EstimateUpdatetSum)), PDO::PARAM_INT); // 추가된 필드
|
|
$stmh->bindValue(24, intval(str_replace(',', '', $EstimateDiffer)), PDO::PARAM_INT); // 추가된 필드
|
|
$stmh->bindValue(25, intval(str_replace(',', '', $EstimateDiscountRate)), PDO::PARAM_INT);
|
|
$stmh->bindValue(26, intval(str_replace(',', '', $EstimateDiscount)), PDO::PARAM_INT);
|
|
$stmh->bindValue(27, intval(str_replace(',', '', $EstimateFinalSum)), PDO::PARAM_INT);
|
|
$stmh->bindValue(28, $maguriWing, PDO::PARAM_STR);
|
|
$stmh->bindValue(29, intval(str_replace(',', '', $inspectionFee)), PDO::PARAM_INT); // int 형태로 저장
|
|
$stmh->bindValue(30, intval(str_replace(',', '', $estimateSurang)), PDO::PARAM_INT); // int 형태로 저장
|
|
$stmh->bindValue(31, $steel, PDO::PARAM_STR);
|
|
$stmh->bindValue(32, $motor, PDO::PARAM_STR);
|
|
$stmh->bindValue(33, $warranty, PDO::PARAM_STR);
|
|
$stmh->bindValue(34, $slatcheck, PDO::PARAM_STR);
|
|
$stmh->bindValue(35, $partscheck, PDO::PARAM_STR);
|
|
$stmh->execute();
|
|
$pdo->commit();
|
|
}
|
|
|
|
if ($mode == "delete") {
|
|
$pdo->beginTransaction();
|
|
$query = "UPDATE $DB.$tablename SET is_deleted='1' WHERE num=? LIMIT 1";
|
|
$stmh = $pdo->prepare($query);
|
|
$params = [$num];
|
|
$stmh->execute($params);
|
|
$pdo->commit();
|
|
}
|
|
|
|
if ($mode == "insert" || $mode == "copy") {
|
|
$sql = "SELECT * FROM $DB.$tablename ORDER BY num DESC LIMIT 1";
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->execute();
|
|
$row = $stmh->fetch(PDO::FETCH_ASSOC);
|
|
$num = $row["num"];
|
|
}
|
|
|
|
$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()]);
|
|
}
|
|
?>
|