diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 8a7749c..dff46da 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -86,6 +86,7 @@ $routes->group('', ['namespace' => 'App\Controllers\Article'], static function ( $routes->get('getResultList', 'Dept::getResultList'); $routes->get('excel', 'Dept::excel'); + $routes->get('excel2', 'Dept::excel2'); $routes->get('print', 'Dept::print'); // 관할포인트 $routes->get('updateAssign', 'Dept::updateAssign'); // 배정변경 diff --git a/app/Controllers/Article/Dept.php b/app/Controllers/Article/Dept.php index b23bde2..74f56d7 100644 --- a/app/Controllers/Article/Dept.php +++ b/app/Controllers/Article/Dept.php @@ -158,6 +158,51 @@ class Dept extends BaseController } } + public function excel2() + { + try { + + $data = [ + 'rcpt_atclno' => $this->request->getGet('rcpt_atclno'), // 매물ID + + 'sdate' => $this->request->getGet('sdate'), // 시작일 + 'edate' => $this->request->getGet('edate'), // 종료일 + + 'rsrv_tm_ap' => $this->request->getGet('rsrv_tm_ap'), // 유형 + 'rsrv_sdate' => $this->request->getGet('rsrv_sdate'), // 시작일 + 'rsrv_edate' => $this->request->getGet('rsrv_edate'), // 종료일 + + 'bonbu' => $this->request->getGet('bonbu'), // 본부 + 'team' => $this->request->getGet('team'), // 팀 + 'user' => $this->request->getGet('user'), // 담당자 + + 'sido' => $this->request->getGet('sido'), // 시도 + 'gugun' => $this->request->getGet('gugun'), // 시군구 + 'dong' => $this->request->getGet('dong'), // 읍면동 + + 'ground_plan_yn' => $this->request->getGet('ground_plan_yn'), // 평면도유무 + 'ground_plan' => $this->request->getGet('ground_plan'), // 평면도요청 + 'direct_trad_yn' => $this->request->getGet('direct_trad_yn'), // 직거래 + + 'stat' => $this->request->getGet('stat'), + + 'srchType' => $this->request->getGet('srchType'), // 검색유형 + 'srchTxt' => $this->request->getGet('srchTxt'), // 검색어 + + 'type' => 'excel', + ]; + + $datas = $this->model->getResultList(null, null, $data); + + return $this->response->setJSON(body: [ + 'data' => $datas, + ]); + + } catch (\Exception $e) { + $e->getPrevious()->getTraceAsString(); + } + } + // 배정변경 public function updateAssign() diff --git a/app/Models/article/DeptModel.php b/app/Models/article/DeptModel.php index cb9bede..8c82f82 100644 --- a/app/Models/article/DeptModel.php +++ b/app/Models/article/DeptModel.php @@ -776,8 +776,9 @@ class DeptModel extends Model $builder->orderBy('a.rcpt_atclno', 'DESC'); - $builder->limit($end, $start); - + if (empty($data['type'])) { + $builder->limit($end, $start); + } // echo $builder->getCompiledSelect(false); $rows = $builder->get()->getResultArray(); diff --git a/app/Views/pages/article/dept/lists.php b/app/Views/pages/article/dept/lists.php index 5498a1e..317c5e5 100644 --- a/app/Views/pages/article/dept/lists.php +++ b/app/Views/pages/article/dept/lists.php @@ -781,7 +781,7 @@ $usr_nm = session('usr_nm'); // 배정내역 excel $("#excel-download2").on("click", function () { $.ajax({ - url: "/article/dept/excel", + url: "/article/dept/excel2", method: "GET", dataType: "json", data: $("#frm_srch_info").serialize(), @@ -794,7 +794,9 @@ $usr_nm = session('usr_nm'); blockUI.unblockPage() }, success: function (result) { - downloadExcel(result.data); + // console.log(result) + exportExcel(result.data); + // downloadExcel(result.data); } }); }); @@ -953,6 +955,93 @@ $usr_nm = session('usr_nm'); URL.revokeObjectURL(link.href); } + // 배정내역 엑셀 양식 + function exportExcel(dataList) { + // 1. 워크북/시트 생성 + const wb = XLSX.utils.book_new(); + const ws = XLSX.utils.aoa_to_sheet([]); + + // (선택) 컬럼 너비 + ws['!cols'] = [ + { wch: 14 }, { wch: 30 }, { wch: 18 }, + { wch: 12 }, { wch: 18 }, { wch: 12 } + ]; + + let row = 0; + + // 2. 데이터 반복 + dataList.forEach(item => { + const blockHeight = addFormBlock(ws, row, item); + + // 🔹 데이터마다 여백 (1~2row) + const gap = item.gapRows ?? 2; + row += blockHeight + gap; + }); + + // 3. 시트 추가 + XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); + + // 4. 다운로드 (기존 코드 유지) + const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' }); + const blob = new Blob([wbout], { type: 'application/octet-stream' }); + + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + link.download = "배정내역_" + getDateTimeString() + ".xlsx"; + link.click(); + URL.revokeObjectURL(link.href); + } + + function addFormBlock(ws, r0, d) { + var contact = '대표 : ' + d.agent_head_tel + '\n'; + contact += '담당자 : ' + d.agent_contact_tel + '\n'; + contact += '연락가능 : ' + d.agent_tel; + + var addr = d.addr; + if (d.rcpt_ho != null) { } else { + addr = addr + ' ' + d.rcpt_dtl_addr + ' ' + d.rcpt_ho; + } else { + addr = addr + ' ' + d.rcpt_dtl_addr; + } + + const aoa = [ + [d.dept_nm, d.usr_nm ?? "", "", "사진여부: " + d.exp_photo_yn + ", 동영상여부: " + d.exp_movie_yn + ", 평면도요청: " + d.ground_plan, "", ""], + ["매물번호", "주소", "중개업소명", "거주여부", "예약일시", ""], + [d.rcpt_atclno ?? "", addr ?? "", d.agent_nm ?? "", d.rcpt_living_yn ?? "", d.rsrv_date ?? "", ""], + ["거래종류", "기사 요청서", "연락처", "접수일자", "진확인동의", ""], + [d.rcpt_product_info1 ?? "", d.request_msg ?? "", contact ?? "", d.rcpt_tm ?? "", "________", ""], + ["본인은 거주하고 있는 공간을 촬영하고 네이버 부동산에 노출하는 것에 동의합니다.", "", "", "", "", ""], + ["거주자명:", "________", "서명:", "________", "", ""] + ]; + + XLSX.utils.sheet_add_aoa(ws, aoa, { origin: { r: r0, c: 0 } }); + + // 병합 + ws['!merges'] = (ws['!merges'] || []).concat([ + { s: { r: r0 + 0, c: 2 }, e: { r: r0 + 0, c: 5 } }, + { s: { r: r0 + 5, c: 0 }, e: { r: r0 + 5, c: 5 } }, + ]); + + // 행 높이(선택) + ws['!rows'] = ws['!rows'] || []; + ws['!rows'][r0 + 5] = { hpt: 28 }; + + // 이 양식 블록 높이 = 7행 + return 7; + } + + // 날짜 문자열 + function getDateTimeString() { + const d = new Date(); + return ( + d.getFullYear() + + String(d.getMonth() + 1).padStart(2, '0') + + String(d.getDate()).padStart(2, '0') + '_' + + String(d.getHours()).padStart(2, '0') + + String(d.getMinutes()).padStart(2, '0') + ); + } + // 배정변경 function updateAssign() { var arr = new Array();