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

46 lines
3.1 KiB
PHP

<?php
include_once "_common.php";
if(!$_SESSION['user_id']) exit; // 로그인 되어있지 않으면 확인 불가
// POST 데이터 받아오기
$searchDate = isset($_POST['searchDate']) ? $_POST['searchDate'] : '';
$ord_by = isset($_POST['ord_by']) ? $_POST['ord_by'] : 'product_name ASC';
// getBakeryInvenData 함수 호출
$results = getBakeryInvenData($searchDate, $ord_by);
// 데이터 출력
$output = '';
$i = 1;
foreach ($results as $row) {
// 재고 점검 후 일치하지 않으면 업데이트
// 전날 재고
$previous_stock = intval(getPrevStock($searchDate, $row['barcode']));
// 현재고
$current_stock = $previous_stock + $row['production'] - $row['inhouse_use'] - $row['recycling'] - $row['disposal'] - $row['sales'];
$output .= '<tr>';
$output .= '<td class="text-center">' . htmlspecialchars($i) . '</td>';
$output .= '<td class="text-center">' . htmlspecialchars($row['product_name']) . '</td>';
$output .= '<td class="text-center">' . htmlspecialchars($row['barcode']) . '</td>';
$output .= '<td class="text-end">' . number_format($previous_stock) . '</td>';
$output .= '<td class="text-end"><span class="value">' . htmlspecialchars($row['production']) . '</span>';
$output .= '<input class="form-control text-end d-none" type="text" value="' . htmlspecialchars($row['production']) . '" id="production-' . htmlspecialchars($row['barcode']) . '" product_name="' . htmlspecialchars($row['product_name']) . '" aria-label="production" readonly></td>';
$output .= '<td class="text-end"><span class="value">' . htmlspecialchars($row['inhouse_use']) . '</span>';
$output .= '<input class="form-control text-end d-none" type="text" value="' . htmlspecialchars($row['inhouse_use']) . '" id="inhouse_use-' . htmlspecialchars($row['barcode']) . '" product_name="' . htmlspecialchars($row['product_name']) . '" aria-label="inhouse_use" readonly></td>';
$output .= '<td class="text-end"><span class="value">' . htmlspecialchars($row['recycling']) . '</span>';
$output .= '<input class="form-control text-end d-none" type="text" value="' . htmlspecialchars($row['recycling']) . '" id="recycling-' . htmlspecialchars($row['barcode']) . '" product_name="' . htmlspecialchars($row['product_name']) . '" aria-label="recycling" readonly></td>';
$output .= '<td class="text-end"><span class="value">' . htmlspecialchars($row['disposal']) . '</span>';
$output .= '<input class="form-control text-end d-none" type="text" value="' . htmlspecialchars($row['disposal']) . '" id="disposal-' . htmlspecialchars($row['barcode']) . '" product_name="' . htmlspecialchars($row['product_name']) . '" aria-label="disposal" readonly></td>';
$output .= '<td class="text-end">' . number_format($row['sales']) . '</td>';
$output .= '<td class="text-end">' . number_format($row['sales_amount']) . '</td>';
$output .= '<td class="text-end">' . number_format($row['menu_discount']) . '</td>';
$output .= '<td class="text-end">' . number_format($row['payment_amount']) . '</td>';
$output .= '<td class="text-end">' . number_format($current_stock) . '</td>';
$output .= '</tr>';
$i++;
}
echo $output;