Remove old Print button
This commit is contained in:
-108
@@ -226,7 +226,6 @@ function setupEventListeners() {
|
||||
const variantForm = document.getElementById('variantForm');
|
||||
const editVariantForm = document.getElementById('editVariantForm');
|
||||
const dispenseForm = document.getElementById('dispenseForm');
|
||||
const prescribeForm = document.getElementById('prescribeForm');
|
||||
const editForm = document.getElementById('editForm');
|
||||
const printNotesForm = document.getElementById('printNotesForm');
|
||||
const disposeBatchForm = document.getElementById('disposeBatchForm');
|
||||
@@ -234,7 +233,6 @@ function setupEventListeners() {
|
||||
const addVariantModal = document.getElementById('addVariantModal');
|
||||
const editVariantModal = document.getElementById('editVariantModal');
|
||||
const dispenseModal = document.getElementById('dispenseModal');
|
||||
const prescribeModal = document.getElementById('prescribeModal');
|
||||
const editModal = document.getElementById('editModal');
|
||||
const printNotesModal = document.getElementById('printNotesModal');
|
||||
const disposeBatchModal = document.getElementById('disposeBatchModal');
|
||||
@@ -247,7 +245,6 @@ function setupEventListeners() {
|
||||
const cancelVariantBtn = document.getElementById('cancelVariantBtn');
|
||||
const cancelEditVariantBtn = document.getElementById('cancelEditVariantBtn');
|
||||
const cancelDispenseBtn = document.getElementById('cancelDispenseBtn');
|
||||
const cancelPrescribeBtn = document.getElementById('cancelPrescribeBtn');
|
||||
const cancelEditBtn = document.getElementById('cancelEditBtn');
|
||||
const cancelDisposeBatchBtn = document.getElementById('cancelDisposeBatchBtn');
|
||||
const cancelBatchReceiveBtn = document.getElementById('cancelBatchReceiveBtn');
|
||||
@@ -279,7 +276,6 @@ function setupEventListeners() {
|
||||
if (variantForm) variantForm.addEventListener('submit', handleAddVariant);
|
||||
if (editVariantForm) editVariantForm.addEventListener('submit', handleEditVariant);
|
||||
if (dispenseForm) dispenseForm.addEventListener('submit', handleDispenseDrug);
|
||||
if (prescribeForm) prescribeForm.addEventListener('submit', handlePrescribeDrug);
|
||||
if (editForm) editForm.addEventListener('submit', handleEditDrug);
|
||||
if (printNotesForm) printNotesForm.addEventListener('submit', handlePrintNotes);
|
||||
if (disposeBatchForm) disposeBatchForm.addEventListener('submit', handleDisposeBatch);
|
||||
@@ -333,7 +329,6 @@ function setupEventListeners() {
|
||||
if (cancelVariantBtn) cancelVariantBtn.addEventListener('click', () => closeModal(addVariantModal));
|
||||
if (cancelEditVariantBtn) cancelEditVariantBtn.addEventListener('click', () => closeModal(editVariantModal));
|
||||
if (cancelDispenseBtn) cancelDispenseBtn.addEventListener('click', () => closeModal(dispenseModal));
|
||||
if (cancelPrescribeBtn) cancelPrescribeBtn.addEventListener('click', () => closeModal(prescribeModal));
|
||||
if (cancelEditBtn) cancelEditBtn.addEventListener('click', closeEditModal);
|
||||
if (cancelDisposeBatchBtn) cancelDisposeBatchBtn.addEventListener('click', closeDisposeBatchModal);
|
||||
|
||||
@@ -616,12 +611,6 @@ function updateDispenseSourceUi() {
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaultLabelExpiryDate() {
|
||||
const defaultExpiry = new Date();
|
||||
defaultExpiry.setMonth(defaultExpiry.getMonth() + 1);
|
||||
return defaultExpiry.toISOString().split('T')[0];
|
||||
}
|
||||
|
||||
function toggleDispensePrintFields() {
|
||||
const printEnabled = document.getElementById('dispensePrintEnabled');
|
||||
const printFields = document.getElementById('dispensePrintFields');
|
||||
@@ -1567,7 +1556,6 @@ function renderDrugs() {
|
||||
</div>
|
||||
<div class="variant-actions">
|
||||
${!isReadOnly ? `
|
||||
<button class="btn btn-primary btn-small" onclick="event.stopPropagation(); prescribeVariant(${variant.id}, '${drug.name.replace(/'/g, "\\'")}', '${variant.strength.replace(/'/g, "\\'")}', '${variant.unit.replace(/'/g, "\\'")}')">🏷️ Prescribe & Print</button>
|
||||
<button class="btn btn-success btn-small" onclick="event.stopPropagation(); dispenseVariant(${variant.id})">💊 Dispense</button>
|
||||
<button class="btn btn-warning btn-small" onclick="event.stopPropagation(); openEditVariantModal(${variant.id})">Edit</button>
|
||||
<button class="btn btn-danger btn-small" onclick="event.stopPropagation(); deleteVariant(${variant.id})" title="${variant.has_inventory_history ? 'Variant has history and cannot be deleted' : ''}">Delete</button>
|
||||
@@ -2306,102 +2294,6 @@ function dispenseVariant(variantId) {
|
||||
openModal(document.getElementById('dispenseModal'));
|
||||
}
|
||||
|
||||
// Prescribe variant and print label
|
||||
function prescribeVariant(variantId, drugName, variantStrength, unit) {
|
||||
// Set hidden fields
|
||||
document.getElementById('prescribeVariantId').value = variantId;
|
||||
document.getElementById('prescribeDrugName').value = drugName;
|
||||
document.getElementById('prescribeVariantStrength').value = variantStrength;
|
||||
document.getElementById('prescribeUnit').value = unit || 'units';
|
||||
|
||||
// Pre-fill user name if available
|
||||
if (currentUser) {
|
||||
document.getElementById('prescribeUser').value = currentUser.username;
|
||||
}
|
||||
|
||||
// Set default expiry date to 1 month from now
|
||||
document.getElementById('prescribeExpiry').value = getDefaultLabelExpiryDate();
|
||||
|
||||
// Open prescribe modal
|
||||
openModal(document.getElementById('prescribeModal'));
|
||||
}
|
||||
|
||||
// Handle prescribe drug form submission
|
||||
async function handlePrescribeDrug(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const variantId = parseInt(document.getElementById('prescribeVariantId').value);
|
||||
const drugName = document.getElementById('prescribeDrugName').value;
|
||||
const variantStrength = document.getElementById('prescribeVariantStrength').value;
|
||||
const unit = document.getElementById('prescribeUnit').value;
|
||||
const quantity = parseFloat(document.getElementById('prescribeQuantity').value);
|
||||
const animalName = document.getElementById('prescribeAnimal').value;
|
||||
const dosage = document.getElementById('prescribeDosage').value;
|
||||
const expiryDate = document.getElementById('prescribeExpiry').value;
|
||||
const userName = document.getElementById('prescribeUser').value;
|
||||
const notes = document.getElementById('prescribeNotes').value;
|
||||
|
||||
if (!variantId || isNaN(quantity) || quantity <= 0 || !animalName || !dosage || !expiryDate || !userName) {
|
||||
showToast('Please fill in all required fields', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// First, print the label
|
||||
const labelResult = await requestLabelPrint({
|
||||
animalName,
|
||||
drugName,
|
||||
variantStrength,
|
||||
quantity,
|
||||
unit,
|
||||
dosage,
|
||||
expiryDate
|
||||
});
|
||||
console.log('Label print result:', labelResult);
|
||||
|
||||
if (!labelResult.success) {
|
||||
// Label printing failed - don't dispense the drug
|
||||
const isError = labelResult.message && (
|
||||
labelResult.message.includes('not found') ||
|
||||
labelResult.message.includes('error') ||
|
||||
labelResult.message.includes('failed')
|
||||
);
|
||||
const toastType = isError ? 'error' : 'warning';
|
||||
showToast('Cannot dispense: ' + labelResult.message, toastType, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// Label printed successfully, now dispense the drug
|
||||
const dispensingData = {
|
||||
drug_variant_id: variantId,
|
||||
quantity: quantity,
|
||||
animal_name: animalName,
|
||||
user_name: userName,
|
||||
notes: notes || null
|
||||
};
|
||||
|
||||
const dispenseResponse = await apiCall('/dispense', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(dispensingData)
|
||||
});
|
||||
|
||||
if (!dispenseResponse.ok) {
|
||||
const error = await dispenseResponse.json();
|
||||
throw new Error(error.detail || 'Failed to dispense drug');
|
||||
}
|
||||
|
||||
// Both operations succeeded
|
||||
showToast('Drug prescribed and label printed successfully!', 'success');
|
||||
|
||||
document.getElementById('prescribeForm').reset();
|
||||
closeModal(document.getElementById('prescribeModal'));
|
||||
await loadDrugs();
|
||||
} catch (error) {
|
||||
console.error('Error prescribing drug:', error);
|
||||
showToast('Failed to prescribe drug: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle print notes form submission
|
||||
async function handlePrintNotes(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user