feat: enhance order sales inventory workflows
This commit is contained in:
@@ -21,33 +21,34 @@ class BagIssue 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->issueModel->where('bi2_lg_idx', $lgIdx);
|
||||
$startDate = $this->request->getGet('start_date');
|
||||
$endDate = $this->request->getGet('end_date');
|
||||
if ($startDate) $builder->where('bi2_issue_date >=', $startDate);
|
||||
if ($endDate) $builder->where('bi2_issue_date <=', $endDate);
|
||||
if ($startDate) {
|
||||
$builder->where('bi2_issue_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$builder->where('bi2_issue_date <=', $endDate);
|
||||
}
|
||||
|
||||
$list = $builder->orderBy('bi2_issue_date', 'DESC')->orderBy('bi2_idx', 'DESC')->paginate(20);
|
||||
$list = $builder->orderBy('bi2_issue_date', 'DESC')->orderBy('bi2_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->issueModel->pager;
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '무료용 불출 관리',
|
||||
'content' => view('admin/bag_issue/index', compact('list', 'startDate', 'endDate', 'pager')),
|
||||
]);
|
||||
return $this->renderWorkPage('무료용 불출 관리', 'admin/bag_issue/index', compact('list', 'startDate', 'endDate', 'pager'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
helper('admin');
|
||||
$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/bag_issue/create', compact('bagCodes')),
|
||||
]);
|
||||
return $this->renderWorkPage('무료용 불출 처리', 'admin/bag_issue/create', compact('bagCodes'));
|
||||
}
|
||||
|
||||
public function store()
|
||||
@@ -71,8 +72,8 @@ class BagIssue extends BaseController
|
||||
$bagCode = $this->request->getPost('bi2_bag_code');
|
||||
$qty = (int) $this->request->getPost('bi2_qty');
|
||||
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->where('cd_ck_idx', $kindO->ck_idx)->where('cd_code', $bagCode)->first() : null;
|
||||
$kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first();
|
||||
$detail = $kindO ? model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, (string) $bagCode, $lgIdx) : null;
|
||||
$bagName = $detail ? $detail->cd_name : '';
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -95,24 +96,22 @@ class BagIssue extends BaseController
|
||||
$this->issueModel->insert($issueData);
|
||||
$bi2Idx = (int) $this->issueModel->getInsertID();
|
||||
|
||||
// CT-05: 감사 로그
|
||||
helper('audit');
|
||||
audit_log('create', 'bag_issue', $bi2Idx, null, array_merge($issueData, ['bi2_idx' => $bi2Idx]));
|
||||
|
||||
// 재고 감산
|
||||
model(BagInventoryModel::class)->adjustQty($lgIdx, $bagCode, $bagName, -$qty);
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('success', '불출 처리되었습니다.');
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('success', '불출 처리되었습니다.');
|
||||
}
|
||||
|
||||
public function cancel(int $id)
|
||||
{
|
||||
helper('admin');
|
||||
$item = $this->issueModel->find($id);
|
||||
if (!$item || (int) $item->bi2_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('error', '불출 내역을 찾을 수 없습니다.');
|
||||
if (! $item || (int) $item->bi2_lg_idx !== admin_effective_lg_idx()) {
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('error', '불출 내역을 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
@@ -120,14 +119,12 @@ class BagIssue extends BaseController
|
||||
|
||||
$before = (array) $item;
|
||||
$this->issueModel->update($id, ['bi2_status' => 'cancelled']);
|
||||
// CT-05: 감사 로그
|
||||
helper('audit');
|
||||
audit_log('update', 'bag_issue', $id, $before, ['bi2_status' => 'cancelled']);
|
||||
// 재고 복원
|
||||
model(BagInventoryModel::class)->adjustQty((int) $item->bi2_lg_idx, $item->bi2_bag_code, $item->bi2_bag_name, (int) $item->bi2_qty);
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
return redirect()->to(site_url('admin/bag-issues'))->with('success', '불출이 취소되었습니다.');
|
||||
return redirect()->to(mgmt_url('bag-issues'))->with('success', '불출이 취소되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user