최초 커밋
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"mysql:host=localhost;dbname=egbim;charset=utf8mb4",
|
||||
"egbim",
|
||||
"baron3840!!",
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(["status" => "fail", "message" => "DB 연결 실패"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $_POST['action'] ?? $_GET['action'] ?? "";
|
||||
|
||||
/* -----------------------------------------------------
|
||||
LIST
|
||||
----------------------------------------------------- */
|
||||
if ($action === "list") {
|
||||
$stmt = $pdo->query("
|
||||
SELECT *
|
||||
FROM sales_targets
|
||||
ORDER BY target_month DESC, emp_no ASC
|
||||
");
|
||||
|
||||
echo json_encode([
|
||||
"status" => "ok",
|
||||
"records" => $stmt->fetchAll()
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* DELETE는 즉시 처리 */
|
||||
if ($action === "delete") {
|
||||
$id = $_POST['id'] ?? 0;
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM sales_targets WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
echo json_encode(["status" => "ok"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------
|
||||
공통 입력값
|
||||
----------------------------------------------------- */
|
||||
$id = $_POST['id'] ?? 0;
|
||||
$target_month = $_POST['target_month'] ?? '';
|
||||
$emp_no = $_POST['emp_no'] ?? '';
|
||||
$target_qty = $_POST['target_qty'] ?? 0;
|
||||
$target_amount = $_POST['target_amount'] ?? 0;
|
||||
|
||||
if (!$target_month || !$emp_no) {
|
||||
echo json_encode(["status" => "error", "message" => "필수 값 누락"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------
|
||||
INSERT
|
||||
----------------------------------------------------- */
|
||||
if ($action === "insert") {
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO sales_targets
|
||||
(target_month, emp_no, target_qty, target_amount, created_at, created_id)
|
||||
VALUES
|
||||
(?, ?, ?, ?, NOW(), 'system')
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
$target_month,
|
||||
$emp_no,
|
||||
$target_qty,
|
||||
$target_amount
|
||||
]);
|
||||
|
||||
echo json_encode([
|
||||
"status" => "ok",
|
||||
"id" => $pdo->lastInsertId()
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------
|
||||
UPDATE
|
||||
----------------------------------------------------- */
|
||||
if ($action === "update") {
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE sales_targets
|
||||
SET
|
||||
target_month = ?,
|
||||
emp_no = ?,
|
||||
target_qty = ?,
|
||||
target_amount = ?,
|
||||
updated_at = NOW(),
|
||||
updated_id = 'system'
|
||||
WHERE id = ?
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
$target_month,
|
||||
$emp_no,
|
||||
$target_qty,
|
||||
$target_amount,
|
||||
$id
|
||||
]);
|
||||
|
||||
echo json_encode(["status" => "ok"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(["status" => "fail", "message" => "잘못된 요청"]);
|
||||
exit;
|
||||
Reference in New Issue
Block a user