diff --git a/backend/app.py b/backend/app.py index ea066c6..7e86186 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1550,9 +1550,9 @@ def admin_user_detail(user_id): base_session = db_manager.get_session('PM_BASE') pres_session = db_manager.get_session('PM_PRES') - # 전화번호로 CUSCODE 조회 + # 전화번호로 CUSCODE 조회 (특이사항 CUSETC 포함) cuscode_query = text(""" - SELECT TOP 1 CUSCODE, PANAME + SELECT TOP 1 CUSCODE, PANAME, CUSETC FROM CD_PERSON WHERE REPLACE(REPLACE(PHONE, '-', ''), ' ', '') = :phone OR REPLACE(REPLACE(TEL_NO, '-', ''), ' ', '') = :phone @@ -1562,7 +1562,11 @@ def admin_user_detail(user_id): if cus_row: cuscode = cus_row.CUSCODE - pos_customer = {'cuscode': cuscode, 'name': cus_row.PANAME} + pos_customer = { + 'cuscode': cuscode, + 'name': cus_row.PANAME, + 'cusetc': cus_row.CUSETC or '' # 특이(참고)사항 + } # 조제 이력 조회 rx_query = text(""" @@ -3889,6 +3893,42 @@ def api_member_detail(cuscode): return jsonify({'success': False, 'error': str(e)}), 500 +@app.route('/api/members//cusetc', methods=['PUT']) +def api_update_cusetc(cuscode): + """특이(참고)사항 수정 API""" + try: + data = request.get_json() or {} + new_cusetc = data.get('cusetc', '').strip() + + # 길이 제한 (2000자) + if len(new_cusetc) > 2000: + return jsonify({'success': False, 'error': '특이사항은 2000자를 초과할 수 없습니다.'}), 400 + + base_session = db_manager.get_session('PM_BASE') + + # CUSETC 업데이트 + update_query = text(""" + UPDATE CD_PERSON + SET CUSETC = :cusetc + WHERE CUSCODE = :cuscode + """) + result = base_session.execute(update_query, {'cusetc': new_cusetc, 'cuscode': cuscode}) + base_session.commit() + + if result.rowcount == 0: + return jsonify({'success': False, 'error': '해당 고객을 찾을 수 없습니다.'}), 404 + + return jsonify({ + 'success': True, + 'message': '특이사항이 저장되었습니다.', + 'cusetc': new_cusetc + }) + + except Exception as e: + logging.error(f"특이사항 수정 오류: {e}") + return jsonify({'success': False, 'error': str(e)}), 500 + + @app.route('/api/members/history/') def api_member_history(phone): """ diff --git a/backend/templates/admin.html b/backend/templates/admin.html index 5ef63b8..b43e6fe 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -886,6 +886,63 @@ function closeUserModal() { document.getElementById('userDetailModal').style.display = 'none'; } + + // 특이사항 펼치기/접기 (클릭 시) + function toggleCusetc(el) { + if (el.style.maxHeight === 'none' || el.style.maxHeight === '') { + el.style.maxHeight = '40px'; + el.style.overflow = 'hidden'; + } else { + el.style.maxHeight = 'none'; + el.style.overflow = 'visible'; + } + } + + // 특이사항 수정 모드 + function editCusetc(cuscode, btn) { + document.getElementById('cusetc-view').style.display = 'none'; + document.getElementById('cusetc-edit').style.display = 'block'; + document.getElementById('cusetc-textarea').focus(); + btn.style.display = 'none'; + } + + // 특이사항 저장 + async function saveCusetc(cuscode) { + const textarea = document.getElementById('cusetc-textarea'); + const newValue = textarea.value.trim(); + + try { + const res = await fetch(`/api/members/${cuscode}/cusetc`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ cusetc: newValue }) + }); + const data = await res.json(); + + if (data.success) { + // 뷰 업데이트 + const viewEl = document.getElementById('cusetc-view'); + viewEl.innerHTML = newValue || '없음'; + viewEl.style.maxHeight = newValue.length > 30 ? '40px' : 'none'; + + cancelCusetc(); + alert('✅ 저장되었습니다.'); + } else { + alert('❌ ' + (data.error || '저장 실패')); + } + } catch (err) { + alert('❌ 오류: ' + err.message); + } + } + + // 특이사항 수정 취소 + function cancelCusetc() { + document.getElementById('cusetc-view').style.display = 'block'; + document.getElementById('cusetc-edit').style.display = 'none'; + // 수정 버튼 다시 표시 + const editBtn = document.querySelector('#cusetc-view').parentElement.querySelector('button'); + if (editBtn) editBtn.style.display = 'inline-block'; + } function renderUserDetail(data) { // 전역 변수에 데이터 저장 @@ -924,6 +981,25 @@
${user.birthday.includes('-') ? user.birthday.split('-')[0] + '월 ' + user.birthday.split('-')[1] + '일' : user.birthday.slice(0,2) + '월 ' + user.birthday.slice(2,4) + '일'}
` : ''} + + ${data.pos_customer ? ` +
+
+ ⚠️ 특이사항 + +
+
+ ${data.pos_customer.cusetc || '없음'} +
+ +
+ ` : ''}