feat: improve bag price and packaging unit management
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ class PackagingUnit extends BaseController
|
||||
{
|
||||
helper('admin');
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
if (!$lgIdx) {
|
||||
return redirect()->to(site_url('admin'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! $lgIdx) {
|
||||
return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$builder = $this->unitModel->where('pu_lg_idx', $lgIdx);
|
||||
@@ -38,31 +38,26 @@ class PackagingUnit extends BaseController
|
||||
$builder->groupStart()->where('pu_end_date IS NULL')->orWhere('pu_end_date <=', $endDate)->groupEnd();
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('pu_bag_code', 'ASC')->orderBy('pu_start_date', 'DESC')->paginate(20);
|
||||
$list = $builder->orderBy('pu_bag_code', 'ASC')->orderBy('pu_start_date', 'DESC')->paginate(20);
|
||||
$pager = $this->unitModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '포장 단위 관리',
|
||||
'content' => view('admin/packaging_unit/index', [
|
||||
'list' => $list, 'startDate' => $startDate, 'endDate' => $endDate, 'pager' => $pager,
|
||||
]),
|
||||
return $this->renderWorkPage('포장 단위 관리', 'admin/packaging_unit/index', [
|
||||
'list' => $list, 'startDate' => $startDate, 'endDate' => $endDate, 'pager' => $pager,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
helper('admin');
|
||||
if (!admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('error', '지자체를 선택해 주세요.');
|
||||
if (! admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('error', '지자체를 선택해 주세요.');
|
||||
}
|
||||
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '포장 단위 등록',
|
||||
'content' => view('admin/packaging_unit/create', ['bagCodes' => $bagCodes]),
|
||||
]);
|
||||
return $this->renderWorkPage('포장 단위 등록', 'admin/packaging_unit/create', ['bagCodes' => $bagCodes]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -83,10 +78,10 @@ class PackagingUnit extends BaseController
|
||||
}
|
||||
|
||||
$bagCode = $this->request->getPost('pu_bag_code');
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$kind = model(CodeKindModel::class)->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 : '';
|
||||
}
|
||||
|
||||
@@ -107,32 +102,30 @@ class PackagingUnit extends BaseController
|
||||
'pu_reg_mb_idx' => session()->get('mb_idx'),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('success', '포장 단위가 등록되었습니다.');
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('success', '포장 단위가 등록되었습니다.');
|
||||
}
|
||||
|
||||
public function edit(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->unitModel->find($id);
|
||||
if (!$item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true) : [];
|
||||
$lgIdx = admin_effective_lg_idx();
|
||||
$kind = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$bagCodes = $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : [];
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '포장 단위 수정',
|
||||
'content' => view('admin/packaging_unit/edit', ['item' => $item, 'bagCodes' => $bagCodes]),
|
||||
]);
|
||||
return $this->renderWorkPage('포장 단위 수정', 'admin/packaging_unit/edit', ['item' => $item, 'bagCodes' => $bagCodes]);
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->unitModel->find($id);
|
||||
if (!$item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
@@ -156,12 +149,12 @@ class PackagingUnit extends BaseController
|
||||
$newVal = (string) $this->request->getPost($field);
|
||||
if ($oldVal !== $newVal) {
|
||||
$this->historyModel->insert([
|
||||
'puh_pu_idx' => $id,
|
||||
'puh_field' => $field,
|
||||
'puh_old_value' => $oldVal,
|
||||
'puh_new_value' => $newVal,
|
||||
'puh_changed_at'=> date('Y-m-d H:i:s'),
|
||||
'puh_changed_by'=> session()->get('mb_idx'),
|
||||
'puh_pu_idx' => $id,
|
||||
'puh_field' => $field,
|
||||
'puh_old_value' => $oldVal,
|
||||
'puh_new_value' => $newVal,
|
||||
'puh_changed_at' => date('Y-m-d H:i:s'),
|
||||
'puh_changed_by' => session()->get('mb_idx'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -180,34 +173,33 @@ class PackagingUnit extends BaseController
|
||||
]);
|
||||
|
||||
$db->transComplete();
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('success', '포장 단위가 수정되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('success', '포장 단위가 수정되었습니다.');
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->unitModel->find($id);
|
||||
if (!$item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->unitModel->delete($id);
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('success', '포장 단위가 삭제되었습니다.');
|
||||
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('success', '포장 단위가 삭제되었습니다.');
|
||||
}
|
||||
|
||||
public function history(int $puIdx)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->unitModel->find($puIdx);
|
||||
if (!$item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->pu_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('packaging-units'))->with('error', '포장 단위를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$list = $this->historyModel->where('puh_pu_idx', $puIdx)->orderBy('puh_changed_at', 'DESC')->findAll();
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '포장 단위 변경 이력 — ' . $item->pu_bag_name,
|
||||
'content' => view('admin/packaging_unit/history', ['item' => $item, 'list' => $list]),
|
||||
]);
|
||||
return $this->renderWorkPage('포장 단위 변경 이력 — ' . $item->pu_bag_name, 'admin/packaging_unit/history', ['item' => $item, 'list' => $list]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ class PasswordChange extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('admin/layout', [
|
||||
'title' => '비밀번호 변경',
|
||||
'content' => view('admin/password_change/index'),
|
||||
]);
|
||||
helper('admin');
|
||||
|
||||
return $this->renderWorkPage('비밀번호 변경', 'admin/password_change/index');
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
helper('admin');
|
||||
$rules = [
|
||||
'current_password' => 'required',
|
||||
'new_password' => 'required|min_length[4]|max_length[255]',
|
||||
@@ -50,6 +50,6 @@ class PasswordChange extends BaseController
|
||||
'mb_passwd' => password_hash($this->request->getPost('new_password'), PASSWORD_DEFAULT),
|
||||
]);
|
||||
|
||||
return redirect()->to(site_url('admin/password-change'))->with('success', '비밀번호가 변경되었습니다.');
|
||||
return redirect()->to(mgmt_url('password-change'))->with('success', '비밀번호가 변경되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user