diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6f6538e..eb31589 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -28,6 +28,8 @@ $routes->get('bag/window', 'Bag::window'); $routes->get('bag/help', 'Bag::help'); // 사이트 메뉴 CRUD (사이트 레이아웃) +$routes->get('bag/inventory/adjust', 'Bag::inventoryAdjust'); +$routes->post('bag/inventory/adjust', 'Bag::inventoryAdjustStore'); $routes->get('bag/issue/create', 'Bag::issueCreate'); $routes->post('bag/issue/store', 'Bag::issueStore'); $routes->post('bag/issue/cancel/(:num)', 'Bag::issueCancel/$1'); diff --git a/app/Controllers/Bag.php b/app/Controllers/Bag.php index f6bee95..ab091b5 100644 --- a/app/Controllers/Bag.php +++ b/app/Controllers/Bag.php @@ -249,6 +249,55 @@ class Bag extends BaseController return $this->render('도움말', 'bag/help', []); } + // ────────────────────────────────────────────── + // 재고 조정 (실사) + // ────────────────────────────────────────────── + public function inventoryAdjust(): string + { + $lgIdx = $this->lgIdx(); + $inventory = $lgIdx ? model(BagInventoryModel::class)->where('bi_lg_idx', $lgIdx)->orderBy('bi_bag_code')->findAll() : []; + return $this->render('재고 조정', 'bag/inventory_adjust', compact('inventory')); + } + + public function inventoryAdjustStore() + { + helper('admin'); + $lgIdx = $this->lgIdx(); + if (! $lgIdx) { + return redirect()->to(site_url('bag/inventory'))->with('error', '지자체를 선택해 주세요.'); + } + + $rules = [ + 'bag_code' => 'required|max_length[50]', + 'adjust_type' => 'required|in_list[set,add,sub]', + 'qty' => 'required|is_natural', + ]; + if (! $this->validate($rules)) { + return redirect()->back()->withInput()->with('errors', $this->validator->getErrors()); + } + + $bagCode = $this->request->getPost('bag_code'); + $type = $this->request->getPost('adjust_type'); + $qty = (int) $this->request->getPost('qty'); + + $invModel = model(BagInventoryModel::class); + $existing = $invModel->where('bi_lg_idx', $lgIdx)->where('bi_bag_code', $bagCode)->first(); + + if ($type === 'set') { + if ($existing) { + $invModel->update($existing->bi_idx, ['bi_qty' => $qty, 'bi_updated_at' => date('Y-m-d H:i:s')]); + } + } elseif ($type === 'add') { + $bagName = $existing ? $existing->bi_bag_name : ''; + $invModel->adjustQty($lgIdx, $bagCode, $bagName, $qty); + } elseif ($type === 'sub') { + $bagName = $existing ? $existing->bi_bag_name : ''; + $invModel->adjustQty($lgIdx, $bagCode, $bagName, -$qty); + } + + return redirect()->to(site_url('bag/inventory'))->with('success', '재고가 조정되었습니다.'); + } + // ══════════════════════════════════════════════ // CRUD — 사이트 레이아웃으로 등록/처리 폼 제공 // ══════════════════════════════════════════════ diff --git a/app/Views/bag/flow.php b/app/Views/bag/flow.php index 265a898..9c24425 100644 --- a/app/Views/bag/flow.php +++ b/app/Views/bag/flow.php @@ -7,6 +7,11 @@ 초기화 +
+ 입고 처리 + 판매 등록 + 불출 처리 +
diff --git a/app/Views/bag/inventory.php b/app/Views/bag/inventory.php index a7bc3e3..ca3164f 100644 --- a/app/Views/bag/inventory.php +++ b/app/Views/bag/inventory.php @@ -1,20 +1,27 @@ -
- - - - - - $row): ?> - - - - - - - - - - - - -
번호봉투코드봉투명현재재고(낱장)최종갱신
bi_bag_code ?? '') ?>bi_bag_name ?? '') ?>bi_qty_sheet ?? 0)) ?>bi_updated_at ?? $row->updated_at ?? '') ?>
재고 데이터가 없습니다.
+
+
+ + 재고 조정 +
+ + + + + + + + $row): ?> + + + + + + + + + + + + +
번호봉투코드봉투명현재재고(낱장)최종갱신
bi_bag_code ?? '') ?>bi_bag_name ?? '') ?>bi_qty ?? 0)) ?>bi_updated_at ?? '') ?>
재고 데이터가 없습니다.
+
diff --git a/app/Views/bag/inventory_adjust.php b/app/Views/bag/inventory_adjust.php new file mode 100644 index 0000000..13622f6 --- /dev/null +++ b/app/Views/bag/inventory_adjust.php @@ -0,0 +1,43 @@ +
+
+

재고 수량 조정 (실사)

+
+ +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + 취소 +
+
+