퍼스트가든에서 사용하는 사용자 함수 및 관련파일 추가
This commit is contained in:
34
manager/bakery/bakery_stock.update.php
Normal file
34
manager/bakery/bakery_stock.update.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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'));
|
||||
}
|
||||
Reference in New Issue
Block a user