282 lines
13 KiB
PHP
282 lines
13 KiB
PHP
<?php
|
|
// 베이커리 재고관리
|
|
include_once "_common.php";
|
|
if (!isset($_SESSION['user_id'])) header( 'Location: FG_MANAGER_URL' ); // 로그인 되어있지 않으면 로그인 페이지로 보냄
|
|
|
|
include_once 'head.sub.php';
|
|
include_once FG_MANAGER_PATH."/head.php";
|
|
|
|
// 검색 변수 초기화
|
|
!isset($search) ?? "";
|
|
!isset($where) ?? "";
|
|
!isset($search_count) ?? "";
|
|
|
|
$is_debug = false; // 디버깅 시 true로 변경
|
|
|
|
// ord_by 로 넘어온 값이 있으면 반영
|
|
$ord_by = isset($_REQUEST["ord_by"]) ? $_REQUEST["ord_by"] : "product_name ASC";
|
|
|
|
// 날짜로 검색한 경우 해당 날짜를 사용하고, 아닌 경우 오늘 날짜를 사용함
|
|
$searchDate = isset($_REQUEST["searchDate"]) ? $_REQUEST["searchDate"] : date("Y-m-d"); // 검색일
|
|
$prevDate = date("Y-m-d", strtotime("-1 day", strtotime($searchDate))); // 검색 전일
|
|
$edit_datetime = date('Y-m-d H:i:s'); // 최종 수정 시간 업데이트
|
|
|
|
// 베이커리 계정인지 확인하고, 오늘 이후 날짜인 경우 생산-결제금액란을 공란으로 출력하기 위한 변수
|
|
$is_bakery = ( $_SESSION['user_id'] == "bakery" ) ? true : false;
|
|
$is_bakery_input = ( strtotime($searchDate) >= strtotime(date("Y-m-d")) ) ? true : false;
|
|
|
|
// 합계 변수 선언
|
|
$t_prev_stock = $t_production = $t_inhouse_use = $t_recycling = $t_disposal = $t_sales = $t_sales_amount = $t_menu_discount = $t_payment_amount = $t_current_stock = 0;
|
|
|
|
|
|
/*
|
|
$chkQuery = "SELECT * FROM {$fg['bakery_product_table']} WHERE used = 1 ";
|
|
|
|
$cheQueryResult = sql_query($chkQuery);
|
|
$a=1;
|
|
while ($row = sql_fetch_array($cheQueryResult)) {
|
|
echo $a;
|
|
print_r($row);
|
|
echo "<br>";
|
|
$a++;
|
|
}
|
|
|
|
echo "여기까지 테스트";
|
|
*/
|
|
|
|
|
|
bakeryPreUpdate($searchDate, $edit_datetime);
|
|
|
|
$authInfo = getAuthorInfo($searchDate);
|
|
if (!$authInfo) {
|
|
$authInfo = ['worker' => '', 'author' => ''];
|
|
}
|
|
?>
|
|
<style>
|
|
/* 베이커리용 CSS */
|
|
|
|
|
|
.bakery tfoot {
|
|
font-weight: 600;
|
|
}
|
|
.sort-icon {
|
|
margin-left: 5px;
|
|
font-size: 12px;
|
|
vertical-align: middle;
|
|
}
|
|
/* 틀 고정
|
|
.tableWrapper {
|
|
overflow: auto;
|
|
height: 700px;
|
|
width: 100%;
|
|
}
|
|
#bakeryTable th {
|
|
position: sticky;
|
|
top: 0px;
|
|
}
|
|
*/
|
|
</style>
|
|
|
|
<h2 class="mb-3">베이커리 일일현황</h2>
|
|
<div class="d-flex justify-content-between">
|
|
<div class="row align-items-start flex-nowrap">
|
|
<div class="col-auto input-group">
|
|
<span class="input-group-text">날짜선택</span>
|
|
<input type="date" class="form-control" id="searchDateInput" name="searchDate" max="9999-12-31" value="<?= $searchDate ?>">
|
|
</div>
|
|
<div class="col-auto">
|
|
<form>
|
|
<input type="hidden" id="hiddenSearchDate" name="searchDate" value="<?= date("Y-m-d") ?>">
|
|
<button type="submit" class="btn btn-primary mb-3">오늘</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<input type="file" id="inventoryFileInput" style="display:none;" accept=".xls,.xlsx" />
|
|
<div class="btn-group" role="group" aria-label="bakery-button">
|
|
<?php if(!bakeryChkDate($searchDate, $_SESSION['user_id'])) {?>
|
|
<button type="button" class="btn btn-primary" id="editButton" onclick="toggleEditMode()" >수정</button>
|
|
<button type="button" class="btn btn-primary d-none" id="confirmButton" onclick="confirmEditMode()">확인</button>
|
|
<?php } ?>
|
|
<button type="button" class="btn btn-secondary" id="uploadInventoryButton">파일첨부</button>
|
|
<button type="button" class="btn btn-success" id="exportExcelButton">엑셀변환</button>
|
|
<?php if ($is_bakery || $is_admin) { ?>
|
|
<button type="button" class="btn btn-success" id="print">양식출력</button>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3" style="max-width:600px;">
|
|
<form class="form-group" id="author" name="author" >
|
|
<input type="hidden" name="searchDate" id="searchDate" value="<?=$searchDate?>">
|
|
<div class="input-group">
|
|
<span class="input-group-text" id="worker">근무자</span>
|
|
<input style="width: 250px;" type="text" class="form-control" name="worker" id="worker" value="<?=$authInfo['worker']?>" required>
|
|
<span class="input-group-text" id="author">작성자</span>
|
|
<input style="width: 100px;" type="text" class="form-control" name="author" id="author" value="<?=$authInfo['author']?>" required>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="tableWrapper">
|
|
<table class="table table-striped align-middle table-hover bakery" id="bakeryTable">
|
|
<colgroup>
|
|
<col width="30px">
|
|
<col width="150px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
<col width="70px">
|
|
</colgroup>
|
|
<!-- 테이블 제목 -->
|
|
<thead class="table-light">
|
|
<tr class="align-middle">
|
|
<th class="text-center no-click">No.</th>
|
|
<th class="text-center" data-column="product_name" data-order="asc">품목 <span class="sort-icon fa fa-sort-up" data-column="product_name"></span></th>
|
|
<th class="text-center" data-column="barcode" data-order="asc">바코드 <span class="sort-icon" data-column="barcode"></span></th>
|
|
<th class="text-center" data-column="previous_stock" data-order="asc">전일재고 <span class="sort-icon" data-column="previous_stock"></span></th>
|
|
<th class="text-center" data-column="production" data-order="asc">생산 <span class="sort-icon" data-column="production"></span></th>
|
|
<th class="text-center" data-column="inhouse_use" data-order="asc">업장사용 <span class="sort-icon" data-column="inhouse_use"></span></th>
|
|
<th class="text-center" data-column="recycling" data-order="asc">재활용 <span class="sort-icon" data-column="recycling"></span></th>
|
|
<th class="text-center" data-column="disposal" data-order="asc">폐기 <span class="sort-icon" data-column="disposal"></span></th>
|
|
<th class="text-center" data-column="sales" data-order="asc">판매수량 <span class="sort-icon" data-column="sales"></span></th>
|
|
<th class="text-center" data-column="unit_price" data-order="asc">단가 <span class="sort-icon" data-column="unit_price"></span></th>
|
|
<th class="text-center" data-column="sales_amount" data-order="asc">판매금액 <span class="sort-icon" data-column="sales_amount"></span></th>
|
|
<th class="text-center" data-column="menu_discount" data-order="asc">메뉴별할인 <span class="sort-icon" data-column="menu_discount"></span></th>
|
|
<th class="text-center" data-column="payment_amount" data-order="asc">결제금액 <span class="sort-icon" data-column="payment_amount"></span></th>
|
|
<th class="text-center" data-column="current_stock" data-order="asc">현재고 <span class="sort-icon" data-column="current_stock"></span></th>
|
|
</tr>
|
|
</thead>
|
|
<!-- 테이블 데이터 -->
|
|
<tbody class="table-group-divider" id="bakeryTableBody">
|
|
<?php
|
|
// 데이터 가져와서 뿌리기
|
|
$i = 1; // number 표시를 위한 변수
|
|
foreach (getBakeryInvenData($searchDate, $ord_by) as $row) {
|
|
|
|
// 전일자 현재고 가져오기, 없으면 0을 반환함
|
|
$previous_stock = getPrevStock($searchDate, $row['barcode']) ;
|
|
// 현재고
|
|
$current_stock = $previous_stock + $row['production'] - $row['inhouse_use'] - $row['recycling'] - $row['disposal'] - $row['sales'];
|
|
|
|
// 계산된 값과 DB에 저장된 값이 일치하지 않으면 업데이트
|
|
if ( $row['current_stock'] != $current_stock ) bakeryCurrentStockUpdate($searchDate, $row['barcode'], $current_stock);
|
|
|
|
// 단가 만들기
|
|
$unit_price = 0;
|
|
if ( $row['sales_amount'] != 0 || $row['sales'] != 0 ) {
|
|
$unit_price = $row['sales_amount'] / $row['sales'];
|
|
}
|
|
|
|
|
|
// 합계값 만들기, 전일재고와 현재고는 DB의 값을 사용하지 않음
|
|
$t_prev_stock += $previous_stock;
|
|
$t_production += $row['production'];
|
|
$t_inhouse_use += $row['inhouse_use'];
|
|
$t_recycling += $row['recycling'];
|
|
$t_disposal += $row['disposal'];
|
|
$t_sales += $row['sales'];
|
|
$t_sales_amount += $row['sales_amount'];
|
|
$t_menu_discount += $row['menu_discount'];
|
|
$t_payment_amount += $row['payment_amount'];
|
|
$t_current_stock += $current_stock;
|
|
|
|
?>
|
|
<tr id="row-<?=$row['barcode']?>">
|
|
<td class="text-center"><?=$i?></td>
|
|
<td class="text-center">
|
|
<a data-bs-toggle="modal" data-bs-target="#modify_modal_<?=$row['idx']?>">
|
|
<?=htmlspecialchars($row['product_name'])?>
|
|
</a>
|
|
</td>
|
|
<td class="text-center"><?=$row['barcode']?></td>
|
|
<td class="text-end"><?=number_format($previous_stock)?></td>
|
|
<td class="text-end"><span class="value"><?=number_format($row['production'])?></span>
|
|
<input class="form-control text-end d-none" type="text" value="<?=$row['production']?>" id="production-<?=$row['barcode']?>" product_name="<?=$row['product_name']?>" aria-label="production" readonly>
|
|
</td>
|
|
<td class="text-end"><span class="value"><?=number_format($row['inhouse_use'])?></span>
|
|
<input class="form-control text-end d-none" type="text" value="<?=$row['inhouse_use']?>" id="inhouse_use-<?=$row['barcode']?>" product_name="<?=$row['product_name']?>" aria-label="inhouse_use" readonly>
|
|
</td>
|
|
<td class="text-end"><span class="value"><?=number_format($row['recycling'])?></span>
|
|
<input class="form-control text-end d-none" type="text" value="<?=$row['recycling']?>" id="recycling-<?=$row['barcode']?>" product_name="<?=$row['product_name']?>" aria-label="recycling" readonly>
|
|
</td>
|
|
<td class="text-end"><span class="value"><?=number_format($row['disposal'])?></span>
|
|
<input class="form-control text-end d-none" type="text" value="<?=$row['disposal']?>" id="disposal-<?=$row['barcode']?>" product_name="<?=$row['product_name']?>" aria-label="disposal" readonly>
|
|
</td>
|
|
<td class="text-end"><?=number_format($row['sales'])?></td>
|
|
<td class="text-end"><?=number_format($unit_price)?></td>
|
|
<td class="text-end"><?=number_format($row['sales_amount'])?></td>
|
|
<td class="text-end"><?=number_format($row['menu_discount'])?></td>
|
|
<td class="text-end"><?=number_format($row['payment_amount'])?></td>
|
|
<td class="text-end"><?=number_format($current_stock)?></td>
|
|
</tr>
|
|
|
|
<!-- 수정 모달 -->
|
|
<div id="modify_modal_<?=$row['idx']?>" class="modal fade" tabindex="-1" aria-labelledby="modify_modal_<?=$row['idx']?>" aria-hidden="true">
|
|
<div class="modal-dialog modal modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<form class="modify" id="modify_<?=$row['idx']?>" name="modify_<?=$row['idx']?>">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">정보 보기/수정</h5>
|
|
</div>
|
|
<div class="modal-body text-start">
|
|
<div class="input-group mb-1">
|
|
<span class="input-group-text col-md-2" id="product_name_<?=$row['idx']?>">품명</span>
|
|
<input type="text" class="form-control" id="product_name_<?=$row['idx']?>" name="product_name" value="<?=$row['product_name'] ?>">
|
|
<input type="radio" class="btn-check" name="used" id="used_<?=$row['idx']?>_1" value="1" <?=$row['used'] == "1" ? "checked": "" ?> required>
|
|
<label class="btn btn-outline-primary" for="used_<?=$row['idx']?>_1">사용</label>
|
|
<input type="radio" class="btn-check" name="used" id="used_<?=$row['idx']?>_0" value="0" <?=$row['used'] =="0" ? "checked" : "" ?> required>
|
|
<label class="btn btn-outline-primary" for="used_<?=$row['idx']?>_0">미사용</label>
|
|
</div>
|
|
<div class="input-group mb-1">
|
|
<span class="input-group-text col-md-2" id="barcode_<?=$row['idx']?>">바코드</span>
|
|
<input type="text" class="form-control" id="barcode_<?=$row['idx']?>" name="barcode" value="<?=$row['barcode']?>" required>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn btn-primary" >수정</button>
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="Close" data-bs-target="#modify_modal_<?=$row['idx']?>">닫기</button>
|
|
</div>
|
|
</form>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div>
|
|
<!-- 수정 모달 끝 -->
|
|
|
|
<?php $i++;
|
|
} // endforeach
|
|
?>
|
|
</tbody>
|
|
<!-- 합계 데이터 출력 -->
|
|
<tfoot>
|
|
<tr>
|
|
<td colspan="3" class="text-center">합계</th>
|
|
<td class="text-end" id="total_prev_stock"><?=number_format($t_prev_stock)?></th>
|
|
<td class="text-end" id="total_production"><?=number_format($t_production)?></th>
|
|
<td class="text-end" id="total_inhouse_use"><?=number_format($t_inhouse_use)?></th>
|
|
<td class="text-end" id="total_recycling"><?=number_format($t_recycling)?></th>
|
|
<td class="text-end" id="total_disposal"><?=number_format($t_disposal)?></th>
|
|
<td class="text-end" id="total_sales"><?=number_format($t_sales)?></th>
|
|
<td class="text-end" id="total_unit_price"></th>
|
|
<td class="text-end" id="total_sales_amount"><?=number_format($t_sales_amount)?></th>
|
|
<td class="text-end" id="total_menu_discount"><?=number_format($t_menu_discount)?></th>
|
|
<td class="text-end" id="total_payment_amount"><?=number_format($t_payment_amount)?></th>
|
|
<td class="text-end" id="total_current_stock"><?=number_format($t_current_stock)?></th>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
<?php
|
|
include_once "tail.sub.php";
|
|
include_once FG_MANAGER_PATH."/tail.php";
|