초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
133
instock/insert.php
Normal file
133
instock/insert.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||||
|
||||
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';
|
||||
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
||||
|
||||
header("Content-Type: application/json"); // JSON 콘텐츠 유형 설정
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
include "_request.php";
|
||||
|
||||
// searchtag 생성
|
||||
$searchtag = $lot_no . ' ' .
|
||||
$inspection_date . ' ' .
|
||||
$supplier . ' ' .
|
||||
$item_name . ' ' .
|
||||
$specification . ' ' .
|
||||
$unit . ' ' .
|
||||
$received_qty . ' ' .
|
||||
$material_no . ' ' .
|
||||
$manufacturer . ' ' .
|
||||
$purchase_price_excl_vat . ' ' .
|
||||
$weight_kg . ' ' .
|
||||
$lotDone . ' ' .
|
||||
$prodcode . ' ' .
|
||||
$remarks;
|
||||
|
||||
if($lotDone == '')
|
||||
$lotDone = NULL;
|
||||
|
||||
if ($mode == "update") {
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
// SQL 쿼리 생성 (업데이트)
|
||||
$sql = "UPDATE " . $DB . "." . $tablename . " SET ";
|
||||
$sql .= "lot_no = ?, inspection_date = ?, supplier = ?, item_name = ?, specification = ?, unit = ?, received_qty = ?, material_no = ?, manufacturer = ?, remarks = ?, purchase_price_excl_vat = ?, weight_kg = ?, searchtag = ?, update_log = ?, lotDone = ?, prodcode = ? ";
|
||||
$sql .= "WHERE num = ? LIMIT 1"; // num이 일치하는 하나의 레코드만 업데이트
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
|
||||
// 변수 바인딩
|
||||
$stmh->bindValue(1, $lot_no, PDO::PARAM_STR);
|
||||
$stmh->bindValue(2, $inspection_date, PDO::PARAM_STR);
|
||||
$stmh->bindValue(3, $supplier, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $item_name, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $specification, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $unit, PDO::PARAM_STR);
|
||||
$stmh->bindValue(7, str_replace(',', '', $received_qty), PDO::PARAM_STR);
|
||||
$stmh->bindValue(8, $material_no, PDO::PARAM_STR);
|
||||
$stmh->bindValue(9, $manufacturer, PDO::PARAM_STR);
|
||||
$stmh->bindValue(10, $remarks, PDO::PARAM_STR);
|
||||
$stmh->bindValue(11, str_replace(',', '', $purchase_price_excl_vat), PDO::PARAM_STR);
|
||||
$stmh->bindValue(12, str_replace(',', '', $weight_kg), PDO::PARAM_STR);
|
||||
$stmh->bindValue(13, $searchtag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(14, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(15, $lotDone, PDO::PARAM_STR);
|
||||
$stmh->bindValue(16, $prodcode, PDO::PARAM_STR);
|
||||
$stmh->bindValue(17, $num, PDO::PARAM_INT);
|
||||
|
||||
// 실행
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $Exception) {
|
||||
$pdo->rollBack();
|
||||
print "오류: " . $Exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == "insert" || $mode == "copy" || $mode == '' || $mode == null) { // 복사할때 추가
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
||||
// 데이터 삽입
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// SQL 쿼리 생성 (삽입)
|
||||
$sql = "INSERT INTO " . $DB . "." . $tablename . " (";
|
||||
$sql .= "lot_no, inspection_date, supplier, item_name, specification, unit, received_qty, material_no, manufacturer, remarks, purchase_price_excl_vat, weight_kg, searchtag, update_log, lotDone, prodcode ";
|
||||
$sql .= ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
|
||||
// 변수 바인딩
|
||||
$stmh->bindValue(1, $lot_no, PDO::PARAM_STR);
|
||||
$stmh->bindValue(2, $inspection_date, PDO::PARAM_STR);
|
||||
$stmh->bindValue(3, $supplier, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $item_name, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $specification, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $unit, PDO::PARAM_STR);
|
||||
$stmh->bindValue(7, str_replace(',', '', $received_qty), PDO::PARAM_STR);
|
||||
$stmh->bindValue(8, $material_no, PDO::PARAM_STR);
|
||||
$stmh->bindValue(9, $manufacturer, PDO::PARAM_STR);
|
||||
$stmh->bindValue(10, $remarks, PDO::PARAM_STR);
|
||||
$stmh->bindValue(11, str_replace(',', '', $purchase_price_excl_vat), PDO::PARAM_STR);
|
||||
$stmh->bindValue(12, str_replace(',', '', $weight_kg), PDO::PARAM_STR);
|
||||
$stmh->bindValue(13, $searchtag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(14, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(15, $lotDone, PDO::PARAM_STR);
|
||||
$stmh->bindValue(16, $prodcode, PDO::PARAM_STR);
|
||||
|
||||
// 실행
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $Exception) {
|
||||
$pdo->rollBack();
|
||||
print "오류: " . $Exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == "delete") { // 데이터 삭제
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
$sql = "UPDATE " . $DB . "." . $tablename . " SET is_deleted=1 WHERE num = ?";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(1, $num, PDO::PARAM_INT);
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $ex) {
|
||||
$pdo->rollBack();
|
||||
print "오류: ".$ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'num' => $num,
|
||||
'mode' => $mode
|
||||
];
|
||||
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user