재고 조정(실사) 기능 추가 + 수불 관리 바로가기 버튼

- /bag/inventory/adjust: 재고 수량 조정 (실사 설정/증가/감소)
- 재고 관리 페이지에 "재고 조정" 버튼 추가
- 봉투 수불 관리에 입고/판매/불출 바로가기 버튼 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
javamon1174
2026-03-26 16:20:35 +09:00
parent 39ee71cc80
commit 35561b414b
5 changed files with 126 additions and 20 deletions

View File

@@ -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 — 사이트 레이아웃으로 등록/처리 폼 제공
// ══════════════════════════════════════════════