Files
firstgarden-web-gnu/manager/bakery/bakery_stock.update.php

35 lines
1.4 KiB
PHP

<?php
include_once '_common.php';
if(!$_SESSION['user_id']) exit; // 로그인 되어있지 않으면 확인 불가
if ($_SERVER["REQUEST_METHOD"] == "POST") { // POST로 넘어온 값이 있다면
// 변수 선언
$product_name = trim($_POST["product_name"]);
$barcode = trim($_POST['barcode']);
$date = trim($_POST['searchDate']);
$id = trim($_POST['id']);
$value = trim($_POST['value']);
$edit_datetime = date('Y-m-d H:i:s', strtotime($date)); // 최종 수정 시간 업데이트
// 리스트에서 product name을 가지고 와야 함, 사전에 post로 전달받거나 품목 테이블에서 가져와야함
// 기존에 동일한 date, barcode를 가진 값이 있는 경우 insert가 아닌 update 로 처리해야 함
// update query
$query = "INSERT INTO {$fg['bakery_inventory_table']} (date, barcode, {$id}, edit_datetime) ";
$query .= "VALUES('{$date}', '{$barcode}', '{$value}', '{$edit_datetime}') ";
$query .= "ON DUPLICATE KEY UPDATE
{$id} = '{$value}',
edit_datetime = '{$edit_datetime}'
"; // 이미 값이 있는 경우 업데이트함
$result = sql_query($query);
if ($result) {
echo json_encode(array('status' => 'success'));
} else {
echo json_encode(array('status' => 'error', 'message' => 'Database error'));
}
} else {
echo json_encode(array('status' => 'error', 'message' => 'Invalid request method'));
}