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:
parent
3f96b286d3
commit
605db69daa
20
app.py
20
app.py
@ -110,6 +110,26 @@ def get_patient(patient_id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
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'])
|
@app.route('/api/patients', methods=['POST'])
|
||||||
def create_patient():
|
def create_patient():
|
||||||
"""새 환자 등록"""
|
"""새 환자 등록"""
|
||||||
|
|||||||
@ -1380,6 +1380,7 @@ $(document).ready(function() {
|
|||||||
<button class="btn btn-sm btn-outline-success process-sale" data-id="${compound.compound_id}"
|
<button class="btn btn-sm btn-outline-success process-sale" data-id="${compound.compound_id}"
|
||||||
data-formula="${compound.formula_name || '직접조제'}"
|
data-formula="${compound.formula_name || '직접조제'}"
|
||||||
data-patient="${compound.patient_name || '직접조제'}"
|
data-patient="${compound.patient_name || '직접조제'}"
|
||||||
|
data-patient-id="${compound.patient_id || ''}"
|
||||||
data-cost="${compound.cost_total || 0}"
|
data-cost="${compound.cost_total || 0}"
|
||||||
data-price="${compound.sell_price_total || 0}">
|
data-price="${compound.sell_price_total || 0}">
|
||||||
<i class="bi bi-cash-coin"></i> 판매
|
<i class="bi bi-cash-coin"></i> 판매
|
||||||
@ -1411,10 +1412,11 @@ $(document).ready(function() {
|
|||||||
const compoundId = $(this).data('id');
|
const compoundId = $(this).data('id');
|
||||||
const formulaName = $(this).data('formula');
|
const formulaName = $(this).data('formula');
|
||||||
const patientName = $(this).data('patient');
|
const patientName = $(this).data('patient');
|
||||||
|
const patientId = $(this).data('patient-id');
|
||||||
const costTotal = $(this).data('cost');
|
const costTotal = $(this).data('cost');
|
||||||
const priceTotal = $(this).data('price');
|
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);
|
$('#salesCompoundId').val(compoundId);
|
||||||
$('#salesFormulaName').val(formulaName);
|
$('#salesFormulaName').val(formulaName);
|
||||||
$('#salesPatientName').val(patientName);
|
$('#salesPatientName').val(patientName);
|
||||||
$('#salesCostTotal').val(costTotal);
|
$('#salesCostTotal').val(costTotal);
|
||||||
|
|
||||||
// 환자 마일리지 조회
|
// 환자 마일리지 조회 (patient_id로 직접 조회)
|
||||||
loadPatientMileage(patientName);
|
loadPatientMileage(patientId);
|
||||||
|
|
||||||
// 기본 가격 계산 (원가 + 조제료)
|
// 기본 가격 계산 (원가 + 조제료)
|
||||||
const dispensingFee = parseFloat($('#salesDispensingFee').val()) || 20000;
|
const dispensingFee = parseFloat($('#salesDispensingFee').val()) || 20000;
|
||||||
@ -3598,11 +3600,12 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 환자 마일리지 조회
|
// 환자 마일리지 조회
|
||||||
function loadPatientMileage(patientName) {
|
function loadPatientMileage(patientId) {
|
||||||
if (patientName && patientName !== '직접조제') {
|
if (patientId) {
|
||||||
$.get('/api/patients/search', { name: patientName }, function(response) {
|
// patient_id로 직접 조회
|
||||||
if (response.success && response.data.length > 0) {
|
$.get(`/api/patients/${patientId}`, function(response) {
|
||||||
const patient = response.data[0];
|
if (response.success && response.data) {
|
||||||
|
const patient = response.data;
|
||||||
const mileage = patient.mileage_balance || 0;
|
const mileage = patient.mileage_balance || 0;
|
||||||
$('#patientMileageBalance').text(mileage.toLocaleString());
|
$('#patientMileageBalance').text(mileage.toLocaleString());
|
||||||
$('#salesMileageUse').attr('max', mileage);
|
$('#salesMileageUse').attr('max', mileage);
|
||||||
@ -3610,8 +3613,13 @@ $(document).ready(function() {
|
|||||||
$('#patientMileageBalance').text('0');
|
$('#patientMileageBalance').text('0');
|
||||||
$('#salesMileageUse').attr('max', 0);
|
$('#salesMileageUse').attr('max', 0);
|
||||||
}
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
console.error('Failed to load patient mileage');
|
||||||
|
$('#patientMileageBalance').text('0');
|
||||||
|
$('#salesMileageUse').attr('max', 0);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// 직접조제인 경우
|
||||||
$('#patientMileageBalance').text('0');
|
$('#patientMileageBalance').text('0');
|
||||||
$('#salesMileageUse').attr('max', 0);
|
$('#salesMileageUse').attr('max', 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user