diff --git a/app/Controllers/Admin/BagPrice.php b/app/Controllers/Admin/BagPrice.php index 38c1023..651df81 100644 --- a/app/Controllers/Admin/BagPrice.php +++ b/app/Controllers/Admin/BagPrice.php @@ -27,14 +27,143 @@ class BagPrice extends BaseController return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); } - $list = $this->priceModel->where('bp_lg_idx', $lgIdx) + $get = $this->request->getGet(); + $readSrc = static function (array $src, string $key): ?string { + if (! array_key_exists($key, $src)) { + return null; + } + $v = $src[$key]; + if ($v === null || is_array($v)) { + return null; + } + $s = trim((string) $v); + + return $s === '' ? null : $s; + }; + + $sy = $readSrc($get, 'start_y'); + $sm = $readSrc($get, 'start_m'); + $sd = $readSrc($get, 'start_d'); + $ey = $readSrc($get, 'end_y'); + $em = $readSrc($get, 'end_m'); + $ed = $readSrc($get, 'end_d'); + + $startDate = null; + if ($sy !== null && $sy !== '' && $sm !== null && $sm !== '' && $sd !== null && $sd !== '') { + $startDate = parse_ymd_from_triple($sy, $sm, $sd); + } + if ($startDate === null) { + $legacyStart = $readSrc($get, 'start_date'); + $startDate = ($legacyStart !== null && $legacyStart !== '') ? $legacyStart : null; + } + + $endDate = null; + if ($ey !== null && $ey !== '' && $em !== null && $em !== '' && $ed !== null && $ed !== '') { + $endDate = parse_ymd_from_triple($ey, $em, $ed); + } + if ($endDate === null) { + $legacyEnd = $readSrc($get, 'end_date'); + $endDate = ($legacyEnd !== null && $legacyEnd !== '') ? $legacyEnd : null; + } + + $startParts = ['y' => '', 'm' => '', 'd' => '']; + $endParts = ['y' => '', 'm' => '', 'd' => '']; + if ($startDate !== null && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $startDate, $m)) { + $startParts = ['y' => $m[1], 'm' => (int) $m[2], 'd' => (int) $m[3]]; + } + if ($endDate !== null && preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $endDate, $m)) { + $endParts = ['y' => $m[1], 'm' => (int) $m[2], 'd' => (int) $m[3]]; + } + + $bagKindE = $readSrc($get, 'bag_kind_e'); + $bagCode = $readSrc($get, 'bag_code'); + + $builder = $this->priceModel->where('bp_lg_idx', $lgIdx); + if (($startDate !== null && $startDate !== '') || ($endDate !== null && $endDate !== '')) { + $qStart = ($startDate !== null && $startDate !== '') ? $startDate : $endDate; + $qEnd = ($endDate !== null && $endDate !== '') ? $endDate : $startDate; + if (strcmp((string) $qStart, (string) $qEnd) > 0) { + [$qStart, $qEnd] = [$qEnd, $qStart]; + } + $builder->where('bp_start_date <=', $qEnd); + $builder->groupStart() + ->where('bp_end_date IS NULL') + ->orWhere('bp_end_date >=', $qStart) + ->groupEnd(); + } + + if ($bagKindE !== null && $bagKindE !== '') { + $kindE = model(CodeKindModel::class)->where('ck_code', 'E')->first(); + if ($kindE) { + $detailE = model(CodeDetailModel::class) + ->where('cd_ck_idx', (int) $kindE->ck_idx) + ->where('cd_code', $bagKindE) + ->where('cd_state', 1) + ->first(); + if ($detailE !== null) { + $builder->like('bp_bag_code', $bagKindE, 'after'); + } + } + } + + if ($bagCode !== null && $bagCode !== '') { + $kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first(); + if ($kindO) { + $detailO = model(CodeDetailModel::class)->findResolvedByKindAndCode((int) $kindO->ck_idx, $bagCode, $lgIdx); + if ($detailO !== null) { + $builder->where('bp_bag_code', $bagCode); + } + } + } + + $list = $builder ->orderBy('bp_bag_code', 'ASC') ->orderBy('bp_start_date', 'DESC') ->paginate(20); + $queryForPager = []; + if ($sy !== null && $sm !== null && $sd !== null && $sy !== '' && $sm !== '' && $sd !== '') { + $queryForPager['start_y'] = $sy; + $queryForPager['start_m'] = $sm; + $queryForPager['start_d'] = $sd; + } + if ($ey !== null && $em !== null && $ed !== null && $ey !== '' && $em !== '' && $ed !== '') { + $queryForPager['end_y'] = $ey; + $queryForPager['end_m'] = $em; + $queryForPager['end_d'] = $ed; + } + if ($bagKindE !== null && $bagKindE !== '') { + $queryForPager['bag_kind_e'] = $bagKindE; + } + if ($bagCode !== null && $bagCode !== '') { + $queryForPager['bag_code'] = $bagCode; + } + $pagerPath = mgmt_url('bag-prices'); + if ($queryForPager !== []) { + $pagerPath .= '?' . http_build_query($queryForPager); + } + $this->priceModel->pager->setPath($pagerPath); + + $kindO = model(CodeKindModel::class)->where('ck_code', 'O')->first(); + $bagCodes = $kindO + ? model(CodeDetailModel::class)->getByKind((int) $kindO->ck_idx, true, $lgIdx) + : []; + $kindE = model(CodeKindModel::class)->where('ck_code', 'E')->first(); + $bagKindOptions = $kindE + ? model(CodeDetailModel::class)->getByKind((int) $kindE->ck_idx, true, null) + : []; + return $this->renderWorkPage('봉투 단가 관리', 'admin/bag_price/index', [ - 'list' => $list, + 'list' => $list, 'pager' => $this->priceModel->pager, + 'startParts' => $startParts, + 'endParts' => $endParts, + 'dateYearMin' => (int) date('Y') - 12, + 'dateYearMax' => (int) date('Y') + 2, + 'bag_kind_e' => $bagKindE, + 'bag_code' => $bagCode, + 'bag_codes' => $bagCodes, + 'bag_kind_options' => $bagKindOptions, ]); } diff --git a/app/Controllers/Admin/Company.php b/app/Controllers/Admin/Company.php index 8492574..8548dac 100644 --- a/app/Controllers/Admin/Company.php +++ b/app/Controllers/Admin/Company.php @@ -9,6 +9,11 @@ class Company extends BaseController { private CompanyModel $model; + private function companyTypeOptions(): array + { + return ['협회', '제작업체', '회수업체']; + } + public function __construct() { $this->model = model(CompanyModel::class); @@ -22,10 +27,33 @@ class Company extends BaseController return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); } - $list = $this->model->where('cp_lg_idx', $lgIdx)->orderBy('cp_idx', 'DESC')->paginate(20); + $companyType = trim((string) ($this->request->getGet('cp_type') ?? '')); + $typeOptions = $this->companyTypeOptions(); + + $builder = $this->model->where('cp_lg_idx', $lgIdx); + if ($companyType !== '' && in_array($companyType, $typeOptions, true)) { + $builder->where('cp_type', $companyType); + } + + $list = $builder->orderBy('cp_idx', 'DESC')->paginate(20); $pager = $this->model->pager; - return $this->renderWorkPage('업체 관리', 'admin/company/index', ['list' => $list, 'pager' => $pager]); + $queryForPager = []; + if ($companyType !== '' && in_array($companyType, $typeOptions, true)) { + $queryForPager['cp_type'] = $companyType; + } + $pagerPath = mgmt_url('companies'); + if ($queryForPager !== []) { + $pagerPath .= '?' . http_build_query($queryForPager); + } + $pager->setPath($pagerPath); + + return $this->renderWorkPage('업체 관리', 'admin/company/index', [ + 'list' => $list, + 'pager' => $pager, + 'cpType' => $companyType, + 'typeOptions' => $typeOptions, + ]); } public function create() diff --git a/app/Controllers/Admin/DesignatedShop.php b/app/Controllers/Admin/DesignatedShop.php index ed11247..a635a44 100644 --- a/app/Controllers/Admin/DesignatedShop.php +++ b/app/Controllers/Admin/DesignatedShop.php @@ -227,6 +227,9 @@ class DesignatedShop extends BaseController */ private function buildDesignatedShopDetailPayload(array $list, array $lgMap): array { + helper('admin'); + $lgIdx = admin_effective_lg_idx() ?? 0; + $gugunMap = $lgIdx > 0 ? $this->gugunCodeNameMap($lgIdx) : []; $payload = []; foreach ($list as $row) { $sn = (string) ($row->ds_shop_no ?? ''); @@ -263,6 +266,7 @@ class DesignatedShop extends BaseController 'ds_rep_phone' => (string) ($row->ds_rep_phone ?? ''), 'ds_email' => (string) ($row->ds_email ?? ''), 'ds_gugun_code' => (string) ($row->ds_gugun_code ?? ''), + 'gugun_name' => $gugunMap[(string) ($row->ds_gugun_code ?? '')] ?? (string) ($row->ds_gugun_code ?? ''), 'ds_zone_code' => $this->designatedShopScalar($row, 'ds_zone_code'), 'ds_branch_no' => $this->designatedShopScalar($row, 'ds_branch_no'), 'ds_designated_at' => $daOut, @@ -306,6 +310,7 @@ class DesignatedShop extends BaseController } $stateCounts = $this->countDesignatedShopsByState($lgIdx, $dsName, $dsGugunCode, $dsState); + $gugunNameMap = $this->gugunCodeNameMap($lgIdx); $detailRows = $this->buildDesignatedShopDetailPayload($list, $lgMap); // 구군코드 목록 (검색 필터용) @@ -321,6 +326,7 @@ class DesignatedShop extends BaseController 'dsState' => $dsState ?? '', 'gugunCodes' => $gugunCodes, 'stateCounts' => $stateCounts, + 'gugunNameMap' => $gugunNameMap, 'detailRowsJson' => json_encode($detailRows, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE), 'kakaoJavascriptKey' => $this->kakaoJavascriptKey(), ]; @@ -336,6 +342,7 @@ class DesignatedShop extends BaseController return redirect()->to(work_area_home_url()) ->with('error', '작업할 지자체가 선택되지 않았습니다. 지자체를 선택해 주세요.'); } + $data['readOnly'] = false; return $this->renderWorkPage('지정판매소 관리', 'admin/designated_shop/index', $data); } @@ -352,7 +359,7 @@ class DesignatedShop extends BaseController } $data['readOnly'] = true; - return $this->renderWorkPage('지정판매소 조회', 'admin/designated_shop/index', $data); + return $this->renderWorkPage('지정판매소 조회', 'admin/designated_shop/manage', $data); } /** diff --git a/app/Controllers/Admin/Manager.php b/app/Controllers/Admin/Manager.php index 4e2b7ab..ff0d32e 100644 --- a/app/Controllers/Admin/Manager.php +++ b/app/Controllers/Admin/Manager.php @@ -25,6 +25,15 @@ class Manager extends BaseController return $kind ? model(CodeDetailModel::class)->getByKind((int) $kind->ck_idx, true, $lgIdx) : []; } + private function managerCategoryOptions(): array + { + return [ + 'company' => '제작업체', + 'district' => '구·군', + 'agency' => '대행소', + ]; + } + public function index() { helper('admin'); @@ -35,16 +44,29 @@ class Manager extends BaseController return redirect()->to(work_area_home_url())->with('error', '지자체를 선택해 주세요.'); } - $list = $this->model->where('mg_lg_idx', $lgIdx)->orderBy('mg_idx', 'DESC')->paginate(20); + $category = (string) ($this->request->getGet('category') ?? ''); + $categories = $this->managerCategoryOptions(); + + $builder = $this->model->where('mg_lg_idx', $lgIdx); + if ($category !== '' && isset($categories[$category])) { + $builder->where('mg_dept_code', $category); + } + + $list = $builder->orderBy('mg_idx', 'DESC')->paginate(20); $pager = $this->model->pager; - return $this->renderWorkPage('담당자 관리', 'admin/manager/index', ['list' => $list, 'pager' => $pager]); + return $this->renderWorkPage('담당자 관리', 'admin/manager/index', [ + 'list' => $list, + 'pager' => $pager, + 'categories' => $categories, + 'category' => $category, + ]); } public function create() { return $this->renderWorkPage('담당자 등록', 'admin/manager/create', [ - 'deptCodes' => $this->getCodeOptions('S'), + 'categories' => $this->managerCategoryOptions(), 'positionCodes' => $this->getCodeOptions('T'), ]); } @@ -54,6 +76,7 @@ class Manager extends BaseController helper(['admin', 'url']); $rules = [ 'mg_name' => 'required|max_length[50]', + 'mg_category' => 'required|in_list[company,district,agency]', 'mg_tel' => 'permit_empty|max_length[20]', 'mg_phone' => 'permit_empty|max_length[20]', 'mg_email' => 'permit_empty|valid_email|max_length[100]', @@ -65,7 +88,7 @@ class Manager extends BaseController $this->model->insert([ 'mg_lg_idx' => admin_effective_lg_idx(), 'mg_name' => $this->request->getPost('mg_name'), - 'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '', + 'mg_dept_code' => (string) ($this->request->getPost('mg_category') ?? ''), 'mg_position_code' => $this->request->getPost('mg_position_code') ?? '', 'mg_tel' => $this->request->getPost('mg_tel') ?? '', 'mg_phone' => $this->request->getPost('mg_phone') ?? '', @@ -87,7 +110,7 @@ class Manager extends BaseController return $this->renderWorkPage('담당자 수정', 'admin/manager/edit', [ 'item' => $item, - 'deptCodes' => $this->getCodeOptions('S'), + 'categories' => $this->managerCategoryOptions(), 'positionCodes' => $this->getCodeOptions('T'), ]); } @@ -102,6 +125,7 @@ class Manager extends BaseController $rules = [ 'mg_name' => 'required|max_length[50]', + 'mg_category' => 'required|in_list[company,district,agency]', 'mg_state' => 'required|in_list[0,1]', ]; if (! $this->validate($rules)) { @@ -110,7 +134,7 @@ class Manager extends BaseController $this->model->update($id, [ 'mg_name' => $this->request->getPost('mg_name'), - 'mg_dept_code' => $this->request->getPost('mg_dept_code') ?? '', + 'mg_dept_code' => (string) ($this->request->getPost('mg_category') ?? ''), 'mg_position_code' => $this->request->getPost('mg_position_code') ?? '', 'mg_tel' => $this->request->getPost('mg_tel') ?? '', 'mg_phone' => $this->request->getPost('mg_phone') ?? '', diff --git a/app/Controllers/Admin/PackagingUnit.php b/app/Controllers/Admin/PackagingUnit.php index ae7314f..f38dca6 100644 --- a/app/Controllers/Admin/PackagingUnit.php +++ b/app/Controllers/Admin/PackagingUnit.php @@ -143,14 +143,31 @@ class PackagingUnit extends BaseController $db = \Config\Database::connect(); $db->transStart(); - $trackFields = ['pu_box_per_pack', 'pu_pack_per_sheet']; + $trackFields = ['pu_box_per_pack', 'pu_pack_per_sheet', 'pu_start_date', 'pu_end_date', 'pu_state']; + $fieldLabels = [ + 'pu_box_per_pack' => '박스당 팩 수', + 'pu_pack_per_sheet' => '팩당 낱장 수', + 'pu_start_date' => '적용시작일', + 'pu_end_date' => '적용종료일', + 'pu_state' => '상태', + ]; foreach ($trackFields as $field) { - $oldVal = (string) $item->$field; - $newVal = (string) $this->request->getPost($field); + $oldRaw = $item->$field; + $newRaw = $this->request->getPost($field); + if ($field === 'pu_end_date') { + $oldRaw = $oldRaw ?: ''; + $newRaw = $newRaw ?: ''; + } + if ($field === 'pu_state') { + $oldRaw = (int) $oldRaw === 1 ? '사용' : '미사용'; + $newRaw = (int) $newRaw === 1 ? '사용' : '미사용'; + } + $oldVal = (string) $oldRaw; + $newVal = (string) $newRaw; if ($oldVal !== $newVal) { $this->historyModel->insert([ 'puh_pu_idx' => $id, - 'puh_field' => $field, + 'puh_field' => $fieldLabels[$field] ?? $field, 'puh_old_value' => $oldVal, 'puh_new_value' => $newVal, 'puh_changed_at' => date('Y-m-d H:i:s'), diff --git a/app/Views/admin/bag_price/index.php b/app/Views/admin/bag_price/index.php index 86468cb..e88c86a 100644 --- a/app/Views/admin/bag_price/index.php +++ b/app/Views/admin/bag_price/index.php @@ -1,4 +1,4 @@ - '봉투 단가 관리']) ?> + '봉투 단가 관리', 'printShowApproval' => false]) ?>