feat: 위치 편집 기능 추가

API:
- GET /api/locations - 모든 위치 목록 (461개)
- PUT /api/drugs/<code>/location - 위치 업데이트/삭제

UI:
- 위치 있음: 노란색 뱃지 (클릭 가능)
- 위치 없음: '미지정' 회색 점선 뱃지
- 클릭 시 위치 설정 모달 열림
- 드롭다운 선택 또는 직접 입력
- person-lookup-web-local 참고하여 구현
This commit is contained in:
thug0bin
2026-03-04 14:42:47 +09:00
parent 96a3df8470
commit 27bb0b7b86
2 changed files with 336 additions and 1 deletions

View File

@@ -3542,6 +3542,79 @@ def api_products():
return jsonify({'success': False, 'error': str(e)}), 500
# ==================== 위치 정보 API ====================
@app.route('/api/locations')
def api_get_all_locations():
"""모든 위치명 목록 조회"""
try:
drug_session = db_manager.get_session('PM_DRUG')
result = drug_session.execute(text("""
SELECT DISTINCT CD_NM_sale
FROM CD_item_position
WHERE CD_NM_sale IS NOT NULL AND CD_NM_sale != ''
ORDER BY CD_NM_sale
"""))
locations = [row[0] for row in result.fetchall()]
return jsonify({
'success': True,
'locations': locations,
'total': len(locations)
})
except Exception as e:
logging.error(f"위치 목록 조회 오류: {e}")
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/api/drugs/<drug_code>/location', methods=['PUT'])
def api_update_drug_location(drug_code):
"""약품 위치 업데이트"""
try:
data = request.get_json()
location_name = data.get('location_name', '').strip() if data else ''
# 위치명 길이 검증 (최대 20자)
if location_name and len(location_name) > 20:
return jsonify({'success': False, 'error': '위치명은 20자를 초과할 수 없습니다'}), 400
drug_session = db_manager.get_session('PM_DRUG')
# 기존 레코드 확인
existing = drug_session.execute(text("""
SELECT DrugCode FROM CD_item_position WHERE DrugCode = :drug_code
"""), {'drug_code': drug_code}).fetchone()
if existing:
# UPDATE
if location_name:
drug_session.execute(text("""
UPDATE CD_item_position SET CD_NM_sale = :location WHERE DrugCode = :drug_code
"""), {'location': location_name, 'drug_code': drug_code})
else:
# 빈 값이면 삭제
drug_session.execute(text("""
DELETE FROM CD_item_position WHERE DrugCode = :drug_code
"""), {'drug_code': drug_code})
else:
# INSERT (위치가 있을 때만)
if location_name:
drug_session.execute(text("""
INSERT INTO CD_item_position (DrugCode, CD_NM_sale) VALUES (:drug_code, :location)
"""), {'drug_code': drug_code, 'location': location_name})
drug_session.commit()
return jsonify({
'success': True,
'message': '위치 정보가 업데이트되었습니다',
'location': location_name
})
except Exception as e:
logging.error(f"위치 업데이트 오류: {e}")
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/admin/sales')
def admin_sales_pos():
"""판매 내역 페이지 (POS 스타일, 거래별 그룹핑)"""