fix: 판매 모달에서 마일리지 표시 오류 수정

- patient_id를 통한 직접 조회로 변경
- /api/patients/search 엔드포인트 추가
- 판매 버튼에 patient_id 데이터 속성 추가
- loadPatientMileage 함수 개선 (patient_id 기반 조회)

이제 박주호 회원의 50,000 마일리지가 판매 모달에서 정상 표시됨

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
시골약사 2026-02-18 06:32:31 +00:00
parent 3f96b286d3
commit 605db69daa
2 changed files with 37 additions and 9 deletions

20
app.py
View File

@ -110,6 +110,26 @@ def get_patient(patient_id):
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/api/patients/search', methods=['GET'])
def search_patients():
"""환자 검색 (이름으로)"""
try:
name = request.args.get('name', '')
with get_db() as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT patient_id, name, phone, gender, birth_date, notes,
mileage_balance, total_mileage_earned, total_mileage_used
FROM patients
WHERE name LIKE ? AND is_active = 1
ORDER BY name
""", (f'%{name}%',))
patients = [dict(row) for row in cursor.fetchall()]
return jsonify({'success': True, 'data': patients})
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/api/patients', methods=['POST'])
def create_patient():
"""새 환자 등록"""

View File

@ -1380,6 +1380,7 @@ $(document).ready(function() {
<button class="btn btn-sm btn-outline-success process-sale" data-id="${compound.compound_id}"
data-formula="${compound.formula_name || '직접조제'}"
data-patient="${compound.patient_name || '직접조제'}"
data-patient-id="${compound.patient_id || ''}"
data-cost="${compound.cost_total || 0}"
data-price="${compound.sell_price_total || 0}">
<i class="bi bi-cash-coin"></i>
@ -1411,10 +1412,11 @@ $(document).ready(function() {
const compoundId = $(this).data('id');
const formulaName = $(this).data('formula');
const patientName = $(this).data('patient');
const patientId = $(this).data('patient-id');
const costTotal = $(this).data('cost');
const priceTotal = $(this).data('price');
openSalesModal(compoundId, formulaName, patientName, costTotal, priceTotal);
openSalesModal(compoundId, formulaName, patientName, patientId, costTotal, priceTotal);
});
// 배송 처리 버튼 이벤트
@ -3553,14 +3555,14 @@ $(document).ready(function() {
// ==================== 판매 관리 기능 ====================
// 판매 모달 열기
function openSalesModal(compoundId, formulaName, patientName, costTotal, priceTotal) {
function openSalesModal(compoundId, formulaName, patientName, patientId, costTotal, priceTotal) {
$('#salesCompoundId').val(compoundId);
$('#salesFormulaName').val(formulaName);
$('#salesPatientName').val(patientName);
$('#salesCostTotal').val(costTotal);
// 환자 마일리지 조회
loadPatientMileage(patientName);
// 환자 마일리지 조회 (patient_id로 직접 조회)
loadPatientMileage(patientId);
// 기본 가격 계산 (원가 + 조제료)
const dispensingFee = parseFloat($('#salesDispensingFee').val()) || 20000;
@ -3598,11 +3600,12 @@ $(document).ready(function() {
}
// 환자 마일리지 조회
function loadPatientMileage(patientName) {
if (patientName && patientName !== '직접조제') {
$.get('/api/patients/search', { name: patientName }, function(response) {
if (response.success && response.data.length > 0) {
const patient = response.data[0];
function loadPatientMileage(patientId) {
if (patientId) {
// patient_id로 직접 조회
$.get(`/api/patients/${patientId}`, function(response) {
if (response.success && response.data) {
const patient = response.data;
const mileage = patient.mileage_balance || 0;
$('#patientMileageBalance').text(mileage.toLocaleString());
$('#salesMileageUse').attr('max', mileage);
@ -3610,8 +3613,13 @@ $(document).ready(function() {
$('#patientMileageBalance').text('0');
$('#salesMileageUse').attr('max', 0);
}
}).fail(function() {
console.error('Failed to load patient mileage');
$('#patientMileageBalance').text('0');
$('#salesMileageUse').attr('max', 0);
});
} else {
// 직접조제인 경우
$('#patientMileageBalance').text('0');
$('#salesMileageUse').attr('max', 0);
}