feat: improve bag price and packaging unit management

This commit is contained in:
taekyoungc
2026-04-08 00:21:53 +09:00
parent c2dc2fd38a
commit b5eed31b94
16 changed files with 362 additions and 160 deletions

View File

@@ -3,10 +3,10 @@
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\BagPriceModel;
use App\Models\BagPriceHistoryModel;
use App\Models\CodeKindModel;
use App\Models\BagPriceModel;
use App\Models\CodeDetailModel;
use App\Models\CodeKindModel;
class BagPrice extends BaseController
{
@@ -23,36 +23,18 @@ class BagPrice extends BaseController
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) {
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
if ($lgIdx === null) {
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
}
$builder = $this->priceModel->where('bp_lg_idx', $lgIdx);
$list = $this->priceModel->where('bp_lg_idx', $lgIdx)
->orderBy('bp_bag_code', 'ASC')
->orderBy('bp_start_date', 'DESC')
->paginate(20);
// 기간 필터 (P2-04)
$startDate = $this->request->getGet('start_date');
$endDate = $this->request->getGet('end_date');
if ($startDate) {
$builder->where('bp_start_date >=', $startDate);
}
if ($endDate) {
$builder->groupStart()
->where('bp_end_date IS NULL')
->orWhere('bp_end_date <=', $endDate)
->groupEnd();
}
$list = $builder->orderBy('bp_bag_code', 'ASC')->orderBy('bp_start_date', 'DESC')->paginate(20);
$pager = $this->priceModel->pager;
return view('admin/layout', [
'title' => '봉투 단가 관리',
'content' => view('admin/bag_price/index', [
'list' => $list,
'startDate' => $startDate,
'endDate' => $endDate,
'pager' => $pager,
]),
return $this->renderWorkPage('봉투 단가 관리', 'admin/bag_price/index', [
'list' => $list,
'pager' => $this->priceModel->pager,
]);
}
@@ -60,22 +42,18 @@ class BagPrice extends BaseController
{
helper('admin');
$lgIdx = admin_effective_lg_idx();
if (!$lgIdx) {
return redirect()->to(site_url('admin/bag-prices'))->with('error', '지자체를 선택해 주세요.');
if (! $lgIdx) {
return redirect()->to(mgmt_url('bag-prices'))->with('error', '지자체를 선택해 주세요.');
}
// 봉투명 코드(O) 목록
$kindModel = model(CodeKindModel::class);
$kind = $kindModel->where('ck_code', 'O')->first();
$bagCodes = [];
$kind = $kindModel->where('ck_code', 'O')->first();
$bagCodes = [];
if ($kind) {
$bagCodes = model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true);
$bagCodes = model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx);
}
return view('admin/layout', [
'title' => '봉투 단가 등록',
'content' => view('admin/bag_price/create', ['bagCodes' => $bagCodes]),
]);
return $this->renderWorkPage('봉투 단가 등록', 'admin/bag_price/create', ['bagCodes' => $bagCodes]);
}
public function store()
@@ -96,13 +74,12 @@ class BagPrice extends BaseController
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
// 봉투명 스냅샷
$bagCode = $this->request->getPost('bp_bag_code');
$bagCode = $this->request->getPost('bp_bag_code');
$kindModel = model(CodeKindModel::class);
$kind = $kindModel->where('ck_code', 'O')->first();
$bagName = '';
$kind = $kindModel->where('ck_code', 'O')->first();
$bagName = '';
if ($kind) {
$detail = model(CodeDetailModel::class)->where('cd_ck_idx', $kind->ck_idx)->where('cd_code', $bagCode)->first();
$detail = model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kind->ck_idx, (string) $bagCode, $lgIdx);
$bagName = $detail ? $detail->cd_name : '';
}
@@ -120,36 +97,34 @@ class BagPrice extends BaseController
'bp_reg_mb_idx' => session()->get('mb_idx'),
]);
return redirect()->to(site_url('admin/bag-prices'))->with('success', '봉투 단가가 등록되었습니다.');
return redirect()->to(mgmt_url('bag-prices'))->with('success', '봉투 단가가 등록되었습니다.');
}
public function edit(int $id)
{
helper('admin');
$item = $this->priceModel->find($id);
if (!$item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
$lgIdx = admin_effective_lg_idx();
$item = $this->priceModel->find($id);
if (! $item || (int) $item->bp_lg_idx !== $lgIdx) {
return redirect()->to(mgmt_url('bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
}
$kindModel = model(CodeKindModel::class);
$kind = $kindModel->where('ck_code', 'O')->first();
$bagCodes = [];
$kind = $kindModel->where('ck_code', 'O')->first();
$bagCodes = [];
if ($kind) {
$bagCodes = model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true);
$bagCodes = model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx);
}
return view('admin/layout', [
'title' => '봉투 단가 수정',
'content' => view('admin/bag_price/edit', ['item' => $item, 'bagCodes' => $bagCodes]),
]);
return $this->renderWorkPage('봉투 단가 수정', 'admin/bag_price/edit', ['item' => $item, 'bagCodes' => $bagCodes]);
}
public function update(int $id)
{
helper('admin');
$item = $this->priceModel->find($id);
if (!$item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
if (! $item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(mgmt_url('bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
}
$rules = [
@@ -165,7 +140,6 @@ class BagPrice extends BaseController
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
// 이력 기록
$db = \Config\Database::connect();
$db->transStart();
@@ -175,12 +149,12 @@ class BagPrice extends BaseController
$newVal = (string) $this->request->getPost($field);
if ($oldVal !== $newVal) {
$this->historyModel->insert([
'bph_bp_idx' => $id,
'bph_field' => $field,
'bph_old_value' => $oldVal,
'bph_new_value' => $newVal,
'bph_changed_at'=> date('Y-m-d H:i:s'),
'bph_changed_by'=> session()->get('mb_idx'),
'bph_bp_idx' => $id,
'bph_field' => $field,
'bph_old_value' => $oldVal,
'bph_new_value' => $newVal,
'bph_changed_at' => date('Y-m-d H:i:s'),
'bph_changed_by' => session()->get('mb_idx'),
]);
}
}
@@ -197,34 +171,32 @@ class BagPrice extends BaseController
$db->transComplete();
return redirect()->to(site_url('admin/bag-prices'))->with('success', '봉투 단가가 수정되었습니다.');
return redirect()->to(mgmt_url('bag-prices'))->with('success', '봉투 단가가 수정되었습니다.');
}
public function delete(int $id)
{
helper('admin');
$item = $this->priceModel->find($id);
if (!$item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
if (! $item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(mgmt_url('bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
}
$this->priceModel->delete($id);
return redirect()->to(site_url('admin/bag-prices'))->with('success', '봉투 단가가 삭제되었습니다.');
return redirect()->to(mgmt_url('bag-prices'))->with('success', '봉투 단가가 삭제되었습니다.');
}
public function history(int $bpIdx)
{
helper('admin');
$item = $this->priceModel->find($bpIdx);
if (!$item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(site_url('admin/bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
if (! $item || (int) $item->bp_lg_idx !== admin_effective_lg_idx()) {
return redirect()->to(mgmt_url('bag-prices'))->with('error', '단가 정보를 찾을 수 없습니다.');
}
$list = $this->historyModel->where('bph_bp_idx', $bpIdx)->orderBy('bph_changed_at', 'DESC')->findAll();
return view('admin/layout', [
'title' => '단가 변경 이력 — ' . $item->bp_bag_name,
'content' => view('admin/bag_price/history', ['item' => $item, 'list' => $list]),
]);
return $this->renderWorkPage('단가 변경 이력 — ' . $item->bp_bag_name, 'admin/bag_price/history', ['item' => $item, 'list' => $list]);
}
}