Phase 3 발주/입고/재고 관리 구현

- DB: bag_order, bag_order_item, bag_receiving, bag_inventory 테이블
- 발주: UUID v4, SHA-256 해시, LOT번호 자동생성, 봉투별 품목 관리
  - 포장단위 연동 (박스→낱장 자동 환산), 단가 연동 (금액 자동 계산)
  - 발주 현황 (기간/상태 필터), 상세 조회, 취소/삭제 (상태 변경)
- 입고: 발주건 기반 입고 처리, 박스→낱장 환산, 재고 자동 가산
- 재고: 지자체별 봉투 종류별 현재 재고 조회
- E2E 테스트 7개 전체 통과

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
javamon1174
2026-03-25 18:13:01 +09:00
parent c2840a9e34
commit d9d3ef46c1
17 changed files with 1002 additions and 12 deletions

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\BagReceivingModel;
use App\Models\BagOrderModel;
use App\Models\BagOrderItemModel;
use App\Models\BagInventoryModel;
use App\Models\CompanyModel;
class BagReceiving extends BaseController
{
private BagReceivingModel $recvModel;
public function __construct()
{
$this->recvModel = model(BagReceivingModel::class);
}
public function index()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
$builder = $this->recvModel->where('br_lg_idx', $lgIdx);
$startDate = $this->request->getGet('start_date');
$endDate = $this->request->getGet('end_date');
if ($startDate) $builder->where('br_receive_date >=', $startDate);
if ($endDate) $builder->where('br_receive_date <=', $endDate);
$list = $builder->orderBy('br_receive_date', 'DESC')->orderBy('br_idx', 'DESC')->findAll();
return view('admin/layout', [
'title' => '입고 현황',
'content' => view('admin/bag_receiving/index', compact('list', 'startDate', 'endDate')),
]);
}
public function create()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) return redirect()->to(site_url('admin/bag-receivings'))->with('error', '지자체를 선택해 주세요.');
// 미입고 발주 목록
$orders = model(BagOrderModel::class)->where('bo_lg_idx', $lgIdx)->where('bo_status', 'normal')->orderBy('bo_order_date', 'DESC')->findAll();
return view('admin/layout', [
'title' => '입고 처리',
'content' => view('admin/bag_receiving/create', compact('orders')),
]);
}
public function store()
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
$rules = [
'br_bo_idx' => 'required|is_natural_no_zero',
'br_bag_code' => 'required|max_length[50]',
'br_qty_box' => 'required|is_natural_no_zero',
'br_receive_date' => 'required|valid_date[Y-m-d]',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$boIdx = (int) $this->request->getPost('br_bo_idx');
$bagCode = $this->request->getPost('br_bag_code');
$qtyBox = (int) $this->request->getPost('br_qty_box');
// 포장단위로 낱장 환산
$unit = model(\App\Models\PackagingUnitModel::class)->where('pu_lg_idx', $lgIdx)->where('pu_bag_code', $bagCode)->where('pu_state', 1)->first();
$totalPerBox = $unit ? (int) $unit->pu_total_per_box : 1;
$qtySheet = $qtyBox * $totalPerBox;
// 봉투명
$kindO = model(\App\Models\CodeKindModel::class)->where('ck_code', 'O')->first();
$detail = $kindO ? model(\App\Models\CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $bagCode)->first() : null;
$bagName = $detail ? $detail->cd_name : '';
$db = \Config\Database::connect();
$db->transStart();
$this->recvModel->insert([
'br_bo_idx' => $boIdx,
'br_lg_idx' => $lgIdx,
'br_bag_code' => $bagCode,
'br_bag_name' => $bagName,
'br_qty_box' => $qtyBox,
'br_qty_sheet' => $qtySheet,
'br_receive_date' => $this->request->getPost('br_receive_date'),
'br_receiver_idx' => session()->get('mb_idx'),
'br_sender_name' => $this->request->getPost('br_sender_name') ?? '',
'br_type' => $this->request->getPost('br_type') ?? 'batch',
'br_regdate' => date('Y-m-d H:i:s'),
]);
// 재고 가산
model(BagInventoryModel::class)->adjustQty($lgIdx, $bagCode, $bagName, $qtySheet);
$db->transComplete();
return redirect()->to(site_url('admin/bag-receivings'))->with('success', '입고 처리되었습니다. (' . $bagName . ' ' . $qtyBox . '박스)');
}
}