Remove old Print button
This commit is contained in:
-108
@@ -226,7 +226,6 @@ function setupEventListeners() {
|
|||||||
const variantForm = document.getElementById('variantForm');
|
const variantForm = document.getElementById('variantForm');
|
||||||
const editVariantForm = document.getElementById('editVariantForm');
|
const editVariantForm = document.getElementById('editVariantForm');
|
||||||
const dispenseForm = document.getElementById('dispenseForm');
|
const dispenseForm = document.getElementById('dispenseForm');
|
||||||
const prescribeForm = document.getElementById('prescribeForm');
|
|
||||||
const editForm = document.getElementById('editForm');
|
const editForm = document.getElementById('editForm');
|
||||||
const printNotesForm = document.getElementById('printNotesForm');
|
const printNotesForm = document.getElementById('printNotesForm');
|
||||||
const disposeBatchForm = document.getElementById('disposeBatchForm');
|
const disposeBatchForm = document.getElementById('disposeBatchForm');
|
||||||
@@ -234,7 +233,6 @@ function setupEventListeners() {
|
|||||||
const addVariantModal = document.getElementById('addVariantModal');
|
const addVariantModal = document.getElementById('addVariantModal');
|
||||||
const editVariantModal = document.getElementById('editVariantModal');
|
const editVariantModal = document.getElementById('editVariantModal');
|
||||||
const dispenseModal = document.getElementById('dispenseModal');
|
const dispenseModal = document.getElementById('dispenseModal');
|
||||||
const prescribeModal = document.getElementById('prescribeModal');
|
|
||||||
const editModal = document.getElementById('editModal');
|
const editModal = document.getElementById('editModal');
|
||||||
const printNotesModal = document.getElementById('printNotesModal');
|
const printNotesModal = document.getElementById('printNotesModal');
|
||||||
const disposeBatchModal = document.getElementById('disposeBatchModal');
|
const disposeBatchModal = document.getElementById('disposeBatchModal');
|
||||||
@@ -247,7 +245,6 @@ function setupEventListeners() {
|
|||||||
const cancelVariantBtn = document.getElementById('cancelVariantBtn');
|
const cancelVariantBtn = document.getElementById('cancelVariantBtn');
|
||||||
const cancelEditVariantBtn = document.getElementById('cancelEditVariantBtn');
|
const cancelEditVariantBtn = document.getElementById('cancelEditVariantBtn');
|
||||||
const cancelDispenseBtn = document.getElementById('cancelDispenseBtn');
|
const cancelDispenseBtn = document.getElementById('cancelDispenseBtn');
|
||||||
const cancelPrescribeBtn = document.getElementById('cancelPrescribeBtn');
|
|
||||||
const cancelEditBtn = document.getElementById('cancelEditBtn');
|
const cancelEditBtn = document.getElementById('cancelEditBtn');
|
||||||
const cancelDisposeBatchBtn = document.getElementById('cancelDisposeBatchBtn');
|
const cancelDisposeBatchBtn = document.getElementById('cancelDisposeBatchBtn');
|
||||||
const cancelBatchReceiveBtn = document.getElementById('cancelBatchReceiveBtn');
|
const cancelBatchReceiveBtn = document.getElementById('cancelBatchReceiveBtn');
|
||||||
@@ -279,7 +276,6 @@ function setupEventListeners() {
|
|||||||
if (variantForm) variantForm.addEventListener('submit', handleAddVariant);
|
if (variantForm) variantForm.addEventListener('submit', handleAddVariant);
|
||||||
if (editVariantForm) editVariantForm.addEventListener('submit', handleEditVariant);
|
if (editVariantForm) editVariantForm.addEventListener('submit', handleEditVariant);
|
||||||
if (dispenseForm) dispenseForm.addEventListener('submit', handleDispenseDrug);
|
if (dispenseForm) dispenseForm.addEventListener('submit', handleDispenseDrug);
|
||||||
if (prescribeForm) prescribeForm.addEventListener('submit', handlePrescribeDrug);
|
|
||||||
if (editForm) editForm.addEventListener('submit', handleEditDrug);
|
if (editForm) editForm.addEventListener('submit', handleEditDrug);
|
||||||
if (printNotesForm) printNotesForm.addEventListener('submit', handlePrintNotes);
|
if (printNotesForm) printNotesForm.addEventListener('submit', handlePrintNotes);
|
||||||
if (disposeBatchForm) disposeBatchForm.addEventListener('submit', handleDisposeBatch);
|
if (disposeBatchForm) disposeBatchForm.addEventListener('submit', handleDisposeBatch);
|
||||||
@@ -333,7 +329,6 @@ function setupEventListeners() {
|
|||||||
if (cancelVariantBtn) cancelVariantBtn.addEventListener('click', () => closeModal(addVariantModal));
|
if (cancelVariantBtn) cancelVariantBtn.addEventListener('click', () => closeModal(addVariantModal));
|
||||||
if (cancelEditVariantBtn) cancelEditVariantBtn.addEventListener('click', () => closeModal(editVariantModal));
|
if (cancelEditVariantBtn) cancelEditVariantBtn.addEventListener('click', () => closeModal(editVariantModal));
|
||||||
if (cancelDispenseBtn) cancelDispenseBtn.addEventListener('click', () => closeModal(dispenseModal));
|
if (cancelDispenseBtn) cancelDispenseBtn.addEventListener('click', () => closeModal(dispenseModal));
|
||||||
if (cancelPrescribeBtn) cancelPrescribeBtn.addEventListener('click', () => closeModal(prescribeModal));
|
|
||||||
if (cancelEditBtn) cancelEditBtn.addEventListener('click', closeEditModal);
|
if (cancelEditBtn) cancelEditBtn.addEventListener('click', closeEditModal);
|
||||||
if (cancelDisposeBatchBtn) cancelDisposeBatchBtn.addEventListener('click', closeDisposeBatchModal);
|
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() {
|
function toggleDispensePrintFields() {
|
||||||
const printEnabled = document.getElementById('dispensePrintEnabled');
|
const printEnabled = document.getElementById('dispensePrintEnabled');
|
||||||
const printFields = document.getElementById('dispensePrintFields');
|
const printFields = document.getElementById('dispensePrintFields');
|
||||||
@@ -1567,7 +1556,6 @@ function renderDrugs() {
|
|||||||
</div>
|
</div>
|
||||||
<div class="variant-actions">
|
<div class="variant-actions">
|
||||||
${!isReadOnly ? `
|
${!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-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-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>
|
<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'));
|
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
|
// Handle print notes form submission
|
||||||
async function handlePrintNotes(e) {
|
async function handlePrintNotes(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -288,55 +288,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Prescribe Drug Modal -->
|
|
||||||
<div id="prescribeModal" class="modal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<span class="close">×</span>
|
|
||||||
<h2>Prescribe Drug & Print Label</h2>
|
|
||||||
<form id="prescribeForm" novalidate>
|
|
||||||
<input type="hidden" id="prescribeVariantId">
|
|
||||||
<input type="hidden" id="prescribeDrugName">
|
|
||||||
<input type="hidden" id="prescribeVariantStrength">
|
|
||||||
<input type="hidden" id="prescribeUnit">
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeQuantity">Quantity *</label>
|
|
||||||
<input type="number" id="prescribeQuantity" step="0.1" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeAnimal">Animal Name/ID *</label>
|
|
||||||
<input type="text" id="prescribeAnimal" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeDosage">Dosage Instructions *</label>
|
|
||||||
<input type="text" id="prescribeDosage" placeholder="e.g., 1 tablet twice daily with food" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeExpiry">Expiry Date *</label>
|
|
||||||
<input type="date" id="prescribeExpiry" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeUser">Prescribed by *</label>
|
|
||||||
<input type="text" id="prescribeUser" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="prescribeNotes">Notes</label>
|
|
||||||
<input type="text" id="prescribeNotes" placeholder="Optional">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="submit" class="btn btn-primary">Prescribe & Print Label</button>
|
|
||||||
<button type="button" class="btn btn-secondary" id="cancelPrescribeBtn">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Add Variant Modal -->
|
<!-- Add Variant Modal -->
|
||||||
<div id="addVariantModal" class="modal">
|
<div id="addVariantModal" class="modal">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
|||||||
Reference in New Issue
Block a user