diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2c63937..c9b6d90 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -93,6 +93,26 @@ $routes->group('', ['namespace' => 'App\Controllers\Article'], static function ( $routes->get('excel', 'Record::excel'); }); + /** + * 처리가능 수량관리 + */ + $routes->group('article/processible', static function ($routes) { + $routes->get('datecount', 'Processible::datecount'); + + // 일자별 처리가능 수량 + $routes->get('getList1', 'Processible::getList1'); + $routes->get('excel', 'Processible::excel'); + + // 지역별 수량 + $routes->get('getList2', 'Processible::getList2'); + $routes->post('saveArea', 'Processible::saveArea'); // 데이터 저장 + + // 기본 수량 + $routes->get('getList3', 'Processible::getList3'); + $routes->post('saveCount', 'Processible::saveCount'); // 데이터 저장 + + }); + }); diff --git a/app/Controllers/Article/Processible.php b/app/Controllers/Article/Processible.php new file mode 100644 index 0000000..d7bdcea --- /dev/null +++ b/app/Controllers/Article/Processible.php @@ -0,0 +1,184 @@ +model = new ProcessibleModel(); + } + + public function datecount(): string + { + + $sido = $this->model->getAreaList(); // 지역조회 + + $this->data['sido'] = $sido; + + return view("pages/article/processible/datecount", $this->data); + } + + public function getList1() + { + $start = (int) $this->request->getGet('start') ?: 0; + $end = (int) $this->request->getGet('length') ?: 10; + + $data = [ + 'sdate' => $this->request->getGet('sdate'), // 시작일 + 'edate' => $this->request->getGet('edate'), // 종료일 + ]; + + $totalCount = $this->model->getTotal1($data); + + $datas = $this->model->getList1($start, $end, $data); + + return $this->response->setJSON(body: [ + 'recordsTotal' => $totalCount, + 'recordsFiltered' => $totalCount, + 'data' => $datas, + ]); + } + + public function getList2() + { + // $start = (int) $this->request->getGet('start') ?: 0; + // $end = (int) $this->request->getGet('length') ?: 10; + + $data = [ + 'sdate' => $this->request->getGet('sdate'), // 시작일 + 'region' => $this->request->getGet('region'), // 종료일 + ]; + + $totalCount = $this->model->getTotal2($data); + + $datas = $this->model->getList2($data); + + return $this->response->setJSON(body: [ + 'recordsTotal' => $totalCount, + 'recordsFiltered' => $totalCount, + 'data' => $datas, + ]); + } + + public function getList3() + { + + $data = [ + 'region' => $this->request->getGet('region'), // 종료일 + ]; + + $totalCount = $this->model->getTotal3($data); + + $datas = $this->model->getList3($data); + + return $this->response->setJSON(body: [ + 'recordsTotal' => $totalCount, + 'recordsFiltered' => $totalCount, + 'data' => $datas, + ]); + } + + // 엑셀다운로드 + public function excel() + { + try { + + $data = [ + 'sdate' => $this->request->getGet('sdate'), + 'edate' => $this->request->getGet('edate'), + ]; + + $datas = $this->model->getExcelList($data); + + return $this->response->setJSON(body: [ + 'data' => $datas, + ]); + + } catch (\Exception $e) { + $e->getPrevious()->getTraceAsString(); + } + } + + + // 지역별 수량 저장 + public function saveArea() + { + try { + + $rows = $this->request->getPost('rows'); + $rows = json_decode($rows, true); + + // dd($rows); + // exit; + + if (count($rows) > 0) { + + foreach ($rows as $row): + $this->model->saveArea($row); + endforeach; + + return $this->response->setJSON([ + 'code' => '0', + 'msg' => 'success' + ]); + + } else { + return $this->response->setJSON([ + 'code' => '9', + 'msg' => '저장가능한 데이터가 없습니다.' + ]); + } + + + } catch (\Exception $e) { + return $this->response->setJSON([ + 'code' => '9', + 'msg' => $e->getMessage(), + ]); + } + } + + // 기본 수량 저장 + public function saveCount() + { + try { + + $rows = $this->request->getPost('rows'); + $rows = json_decode($rows, true); + + // dd($rows); + // exit; + + if (count($rows) > 0) { + + foreach ($rows as $row): + $this->model->saveCount($row); + endforeach; + + return $this->response->setJSON([ + 'code' => '0', + 'msg' => 'success' + ]); + + } else { + return $this->response->setJSON([ + 'code' => '9', + 'msg' => '저장가능한 데이터가 없습니다.' + ]); + } + + + } catch (\Exception $e) { + return $this->response->setJSON([ + 'code' => '9', + 'msg' => $e->getMessage(), + ]); + } + } +} \ No newline at end of file diff --git a/app/Models/article/ProcessibleModel.php b/app/Models/article/ProcessibleModel.php new file mode 100644 index 0000000..a77ddfd --- /dev/null +++ b/app/Models/article/ProcessibleModel.php @@ -0,0 +1,286 @@ +db->query($sql, [$gugun]); + + } else if (!empty($sido)) { + $chk_sido = substr($sido, '0', '2'); + + if ($chk_sido === '36') { + $sido = substr($sido, '0', '4'); + $sql = "SELECT a.region_cd, TRIM(REPLACE(a.region_nm, b.region_nm, '')) region_nm " . + "FROM region_codes a " . + "LEFT JOIN region_codes b ON b.region_cd = CONCAT(SUBSTR(a.region_cd,1,4),'000000') " . + "WHERE a.region_cd LIKE concat(?, '%') " . + "AND a.region_cd NOT LIKE '%000000' " . + "AND a.region_cd LIKE '%00' " . + "AND a.use_yn = 'Y' " . + "AND EXISTS (SELECT 'x' FROM region_codes c WHERE c.region_cd LIKE CONCAT(SUBSTR(a.region_cd,1,5),'%') AND c.region_cd > CONCAT(SUBSTR(a.region_cd,1,5),'00000')) " . + "ORDER BY a.region_nm ASC"; + } else { + $sido = substr($sido, '0', '2'); + $sql = "SELECT a.region_cd, TRIM(REPLACE(a.region_nm, b.region_nm, '')) region_nm" . + " FROM region_codes a" . + " LEFT JOIN region_codes b ON b.region_cd = CONCAT(SUBSTR(a.region_cd,1,2),'00000000')" . + " WHERE a.region_cd LIKE concat(?, '%')" . + " AND a.region_cd NOT LIKE '%00000000'" . + " AND a.region_cd LIKE '%00000'" . + " AND a.use_yn = 'Y'" . + " AND EXISTS (SELECT 'x' FROM region_codes c WHERE c.region_cd LIKE CONCAT(SUBSTR(a.region_cd,1,5),'%') AND c.region_cd > CONCAT(SUBSTR(a.region_cd,1,5),'00000'))" . + " ORDER BY a.region_nm ASC"; + } + + $query = $this->db->query($sql, [$sido]); + } else { + $sql = "SELECT a.region_cd, a.region_nm " . + "FROM region_codes a " . + "WHERE (a.region_cd LIKE '%00000000' " . + "AND a.use_yn = 'Y') " . + "OR region_cd = 3611000000;"; + + $query = $this->db->query($sql); + } + + + return $query->getResultArray(); + } + + + /** + * 일자별 처리가능 수량 + */ + public function getTotal1($data) + { + $sql = " + SELECT + COUNT(*) AS cnt + FROM + ( + SELECT + a.sol_date sc_date, DATE_FORMAT(a.sol_date, '%w') day_week + , sum(ifnull(c.am_cnt, b.am_cnt)) am_cnt + , sum(ifnull(c.pm_cnt,b.pm_cnt)) pm_cnt + , sum(ifnull(c.day_cnt, b.day_cnt)) day_cnt + , case count(b.region_cd) when count(c.region_cd) then 'Y' ELSE 'N' END svc_check + , sum(c.day_cnt) svc_count + FROM calendar a + LEFT JOIN service_count b on b.sc_date = '0000-00-00' + LEFT JOIN service_count c on c.sc_date = a.sol_date AND c.region_cd = b.region_cd + WHERE a.sol_date BETWEEN ? AND ? + GROUP BY a.sol_date ASC + ) AS a"; + + $query = $this->db->query($sql, [$data['sdate'], $data['edate']]); + + return $query->getRow()->cnt; + } + + public function getList1($start, $end, $data) + { + $sql = "SELECT + a.sol_date sc_date, DATE_FORMAT(a.sol_date, '%w') day_week + , sum(ifnull(c.am_cnt, b.am_cnt)) am_cnt + , sum(ifnull(c.pm_cnt,b.pm_cnt)) pm_cnt + , sum(ifnull(c.day_cnt, b.day_cnt)) day_cnt + , case count(b.region_cd) when count(c.region_cd) then 'Y' ELSE 'N' END svc_check + , sum(c.day_cnt) svc_count + FROM calendar a + LEFT JOIN service_count b on b.sc_date = '0000-00-00' + LEFT JOIN service_count c on c.sc_date = a.sol_date AND c.region_cd = b.region_cd + WHERE a.sol_date BETWEEN ? AND ? + GROUP BY a.sol_date ASC "; + + $sql .= "LIMIT {$start}, {$end}"; + + $query = $this->db->query($sql, [$data['sdate'], $data['edate']]); + + return $query->getResultArray(); + } + + /** + * 지역별 수량 + */ + public function getTotal2($data) + { + $sql = "SELECT + COUNT(*) AS cnt + FROM calendar a + LEFT JOIN service_count b on b.sc_date = '0000-00-00' and b.region_cd LIKE CONCAT(SUBSTR(?,1,2),'%') + LEFT JOIN service_count c on c.sc_date = a.sol_date and c.region_cd = b.region_cd + JOIN region_codes d on d.region_cd = b.region_cd and d.use_yn = 'Y' + WHERE a.sol_date = ? + ORDER BY d.region_nm"; + + $query = $this->db->query($sql, [$data['region'], $data['sdate']]); + + return $query->getRow()->cnt; + } + + public function getList2($data) + { + $sql = "SELECT + a.sol_date + , b.region_cd, d.region_nm + , c.am_cnt, b.am_cnt default_am_cnt + , c.pm_cnt, b.pm_cnt default_pm_cnt + , c.day_cnt, b.day_cnt default_day_cnt + FROM calendar a + LEFT JOIN service_count b on b.sc_date = '0000-00-00' and b.region_cd LIKE CONCAT(SUBSTR(?,1,2),'%') + LEFT JOIN service_count c on c.sc_date = a.sol_date and c.region_cd = b.region_cd + JOIN region_codes d on d.region_cd = b.region_cd and d.use_yn = 'Y' + WHERE a.sol_date = ? + ORDER BY d.region_nm"; + + $query = $this->db->query($sql, [$data['region'], $data['sdate']]); + + return $query->getResultArray(); + } + + /** + * 기본수량 + */ + public function getTotal3($data) + { + $sql = "SELECT + COUNT(*) AS cnt + FROM (SELECT DISTINCT CONCAT(SUBSTR(aa.region_cd, 1, 5), '00000') region_cd FROM region_codes aa WHERE aa.region_cd like CONCAT(SUBSTR(?,1,2),'%') AND aa.region_cd NOT LIKE '%00000000' AND aa.dept_sq != 0 AND aa.use_yn = 'Y') a + INNER JOIN region_codes b ON b.region_cd = a.region_cd + LEFT JOIN service_count c ON c.sc_date = '0000-00-00' AND c.region_cd = a.region_cd + ORDER BY b.region_nm"; + + $query = $this->db->query($sql, [$data['region']]); + + return $query->getRow()->cnt; + } + + public function getList3($data) + { + $sql = "SELECT + b.region_cd, b.region_nm, IFNULL(c.am_cnt,0)am_cnt, IFNULL(c.pm_cnt,0) pm_cnt + FROM (SELECT DISTINCT CONCAT(SUBSTR(aa.region_cd, 1, 5), '00000') region_cd FROM region_codes aa WHERE aa.region_cd like CONCAT(SUBSTR(?,1,2),'%') AND aa.region_cd NOT LIKE '%00000000' AND aa.dept_sq != 0 AND aa.use_yn = 'Y') a + INNER JOIN region_codes b ON b.region_cd = a.region_cd + LEFT JOIN service_count c ON c.sc_date = '0000-00-00' AND c.region_cd = a.region_cd + ORDER BY b.region_nm"; + + $query = $this->db->query($sql, [$data['region']]); + + return $query->getResultArray(); + } + + // 일자별 수량 엑셀 + public function getExcelList($data) + { + $sql = "SELECT + a.sol_date sc_date + , CASE WHEN DATE_FORMAT(a.sol_date, '%w') = 'N' THEN '기본지정' ELSE '별도지정' END AS sc_type + , sum(ifnull(c.am_cnt, b.am_cnt)) am_cnt + , sum(ifnull(c.pm_cnt,b.pm_cnt)) pm_cnt + , sum(ifnull(c.day_cnt, b.day_cnt)) day_cnt + , case count(b.region_cd) when count(c.region_cd) then 'Y' ELSE 'N' END svc_check + , sum(c.day_cnt) svc_count + FROM calendar a + LEFT JOIN service_count b on b.sc_date = '0000-00-00' + LEFT JOIN service_count c on c.sc_date = a.sol_date AND c.region_cd = b.region_cd + WHERE a.sol_date BETWEEN ? AND ? + GROUP BY a.sol_date ASC"; + + $query = $this->db->query($sql, [$data['sdate'], $data['edate']]); + + return $query->getResultArray(); + } + + // 지역별 수량 저장 + public function saveArea($data) + { + $this->db->transStart(); + + $usr_sq = session('usr_sq'); + + $sql = "INSERT INTO service_count + (sc_date, region_cd, am_cnt, pm_cnt, day_cnt, insert_usr, insert_tm, update_usr, update_tm) + VALUES + (?, ?, ?, ?, ?, ?, NOW(), ?, NOW()) + ON DUPLICATE KEY UPDATE am_cnt=values(am_cnt), pm_cnt=values(pm_cnt), day_cnt=values(day_cnt), update_usr=values(update_usr) + "; + + $datas = [ + $data['sc_date'], + $data['region_cd'], + $data['am_cnt'], + $data['pm_cnt'], + ((int) $data['am_cnt'] + (int) $data['pm_cnt']), + $usr_sq, + $usr_sq + ]; + + if ($this->db->query($sql, $datas) === false) { + return [ + 'success' => false, + 'msg' => '저장실패', + ]; + } + + $this->db->transComplete(); + + return [ + 'success' => true, + ]; + } + + public function saveCount($data) + { + $this->db->transStart(); + + $usr_sq = session('usr_sq'); + + $sql = "INSERT INTO service_count + (sc_date, region_cd, am_cnt, pm_cnt, day_cnt, insert_usr, insert_tm, update_usr, update_tm) + VALUES + (?, ?, ?, ?, ?, ?, NOW(), ?, NOW()) + ON DUPLICATE KEY UPDATE am_cnt=values(am_cnt), pm_cnt=values(pm_cnt), day_cnt=values(day_cnt), update_usr=values(update_usr) + "; + + $datas = [ + '0000-00-00', + $data['region_cd'], + $data['am_cnt'], + $data['pm_cnt'], + ((int) $data['am_cnt'] + (int) $data['pm_cnt']), + $usr_sq, + $usr_sq + ]; + + if ($this->db->query($sql, $datas) === false) { + return [ + 'success' => false, + 'msg' => '저장실패', + ]; + } + + $this->db->transComplete(); + + return [ + 'success' => true, + ]; + } +} \ No newline at end of file diff --git a/app/Views/pages/article/processible/datecount.php b/app/Views/pages/article/processible/datecount.php new file mode 100644 index 0000000..ead0f53 --- /dev/null +++ b/app/Views/pages/article/processible/datecount.php @@ -0,0 +1,809 @@ +extend('layouts/main') ?> +section('content') ?> + + + +

처리가능 수량관리

+ +
+
+ + + + +
+ + +
+
+ + + +
+
+ + ~ + +
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + + + + + + + + + + + + + +
날짜기본적용 여부처리가능건수시간대별
오전오후
+
+
+ + +
+
+ + + + + + + + + + + + + + +
지역건수개별초기화시간대별
오전오후
+
+
+ + +
+
+ + + + + + + + + + + + + +
지역건수시간대별
오전오후
+
+
+ +
+ +
+ + +
+
+ + + + + + + +endSection() ?> \ No newline at end of file