기간별 수량 조회 페이지 신설

This commit is contained in:
2025-07-23 16:55:58 +09:00
parent 95fbca87ab
commit fcc95c6c0a
2 changed files with 355 additions and 1 deletions

View File

@ -315,7 +315,77 @@ function get_total_count($db_name) {
return $R;
}
function getBakeryInvenDataPeriod($start_date, $end_date, $searchWord = "", $ord_by = "a.date ASC, b.product_name ASC") {
global $fg;
// 검색 조건
$search_sql = "";
if ($searchWord !== "") {
$searchWord = sql_real_escape_string($searchWord);
$search_sql = "AND b.product_name LIKE '%{$searchWord}%'";
}
$query = "SELECT
b.product_name,
SUM(a.production) AS production,
SUM(a.inhouse_use) AS inhouse_use,
SUM(a.recycling) AS recycling,
SUM(a.disposal) AS disposal,
SUM(a.sales) AS sales,
SUM(a.payment_amount) AS payment_amount
FROM {$fg['bakery_inventory_table']} AS a
LEFT JOIN {$fg['bakery_product_table']} AS b
ON a.barcode = b.barcode
WHERE b.used = 1
AND a.date BETWEEN '{$start_date}' AND '{$end_date}'
{$search_sql}
GROUP BY a.barcode
ORDER BY {$ord_by}";
error_log($query);
$result = sql_query($query);
$R = array();
while ($row = sql_fetch_array($result)) {
$R[] = $row;
}
return $R;
}
// 기간별 합계 수량 구하기
function getBakeryInvenSumPeriod($start_date, $end_date, $searchWord = "") {
global $fg;
$search_sql = "";
if ($searchWord !== "") {
$searchWord = sql_real_escape_string($searchWord);
$search_sql = "AND b.product_name LIKE '%{$searchWord}%'";
}
$query = "SELECT
SUM(a.production) AS t_production,
SUM(a.inhouse_use) AS t_inhouse_use,
SUM(a.recycling) AS t_recycling,
SUM(a.disposal) AS t_disposal,
SUM(a.sales) AS t_sales,
SUM(a.payment_amount) AS t_payment_amount
FROM {$fg['bakery_inventory_table']} AS a
LEFT JOIN {$fg['bakery_product_table']} AS b
ON a.barcode = b.barcode
WHERE b.used = 1
AND a.date BETWEEN '{$start_date}' AND '{$end_date}'
{$search_sql}";
error_log($query);
return sql_fetch($query); // 결과 없으면 false 반환
}
// 전체 품명 불러오기
function getBakeryProductList($ord_by = "ASC") {
global $fg;
@ -329,6 +399,21 @@ function get_total_count($db_name) {
return $R;
}
// 사용 중인(used=1) 품목 수 구하기
function cntUsedBakeryItems() {
global $fg;
$query = "SELECT COUNT(*) AS cnt FROM {$fg['bakery_product_table']} WHERE used = 1";
error_log($query);
$result = sql_fetch($query);
$result = $result['cnt'];
return $result;
}
// 어제자 최종재고 불러오기
function getPrevStock($date, $barcode) {
global $fg;