누계 데이터 출력 추가.
This commit is contained in:
@ -384,7 +384,53 @@ function get_total_count($db_name) {
|
||||
return sql_fetch($query); // 결과 없으면 false 반환
|
||||
}
|
||||
|
||||
// 누계 구하기
|
||||
function getBakeryInvenSummaryData($date, $ord_by = "b.product_name ASC") {
|
||||
global $fg;
|
||||
|
||||
// 해당 월의 시작일과 종료일 계산
|
||||
$month_start = date('Y-m-01', strtotime($date));
|
||||
$month_end = $date;
|
||||
|
||||
// 전월 마지막 날짜 계산
|
||||
$prev_month_last_day = date('Y-m-t', strtotime($month_start . ' -1 month'));
|
||||
|
||||
// 전월 current_stock 조회
|
||||
$prev_query = "
|
||||
SELECT SUM(current_stock) AS total_previous_stock
|
||||
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 = '{$prev_month_last_day}'
|
||||
";
|
||||
$prev_result = sql_fetch($prev_query);
|
||||
$total_previous_stock = $prev_result['total_previous_stock'] ?? '';
|
||||
|
||||
// 현재 월 누적 합산 조회
|
||||
$query = "
|
||||
SELECT
|
||||
SUM(a.production) AS total_production,
|
||||
SUM(a.inhouse_use) AS total_inhouse_use,
|
||||
SUM(a.recycling) AS total_recycling,
|
||||
SUM(a.disposal) AS total_disposal,
|
||||
SUM(a.sales) AS total_sales,
|
||||
SUM(a.sales_amount) AS total_sales_amount,
|
||||
SUM(a.menu_discount) AS total_menu_discount,
|
||||
SUM(a.payment_amount) AS total_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 '{$month_start}' AND '{$month_end}'
|
||||
";
|
||||
$result = sql_fetch($query);
|
||||
|
||||
// previous_stock 추가
|
||||
$result['total_previous_stock'] = $total_previous_stock;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 전체 품명 불러오기
|
||||
function getBakeryProductList($ord_by = "ASC") {
|
||||
|
||||
Reference in New Issue
Block a user