| Summary: | Add ability to search by Vendor ID | ||
|---|---|---|---|
| Product: | Koha | Reporter: | Angela Berrett <angela.berrett> |
| Component: | Acquisitions | Assignee: | Bugs List <koha-bugs> |
| Status: | NEW --- | QA Contact: | Testopia <testopia> |
| Severity: | enhancement | ||
| Priority: | P5 - low | CC: | angela.berrett |
| Version: | 24.11 | ||
| Hardware: | All | ||
| OS: | All | ||
| GIT URL: | Initiative type: | --- | |
| Sponsorship status: | --- | Comma delimited list of Sponsors: | |
| Crowdfunding goal: | 0 | Patch complexity: | --- |
| Documentation contact: | Documentation submission: | ||
| Text to go in the release notes: | Version(s) released in: | ||
| Circulation function: | |||
|
Description
Angela Berrett
2025-04-11 18:00:57 UTC
The update to 25.05 took care of not being able to find vendors with no names, but the vendor ID issue is still present: The item record only shows the Vendor ID, and currently does not link back to the vendor (I think that broke), so we need a way to search by that ID to find the name of the vendor. Is this a quick development? Also, the Vendor ID used to show next to the name in the Vendor profile page and now no longer does - so when opening the Vendor information you no longer see the vendor ID except in the URL. Is this a quick fix? jQuery to add a vendor ID search to the main Acquisitions page. In case anyone else would like this. Also adding to the jQuery wiki.
$(document).ready(function() {
// Only run on the acquisitions page with the vendor search form
if ($('#acqui_acqui_home_order').length || $('form[name="findsupplier"]').length) {
// Add Vendor ID search field and button - MAIN CONTENT version
var vendorIdSearchHTML = `
<li style="display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 5px 0;">
<label for="vendor_id_search" style="white-space: nowrap;">Vendor ID:</label>
<input type="text" id="vendor_id_search" name="vendor_id_search" size="25" style="flex: 1; min-width: 150px; max-width: 300px;" />
<button type="button" id="search_by_vendor_id" class="btn btn-primary" style="white-space: nowrap;">
Search by ID
</button>
</li>
`;
// Target the MAIN CONTENT form, not the header
// Explicitly exclude header forms
var $mainForm = $('#acqui_acqui_home_order form[name="findsupplier"]').not('#header_search form');
// If that doesn't work, try finding forms NOT in the header
if (!$mainForm.length) {
$mainForm = $('main form[name="findsupplier"], #main form[name="findsupplier"], .main form[name="findsupplier"]').not('#header_search form, header form');
}
// Last resort: find all findsupplier forms, exclude header, and use the last one
if (!$mainForm.length) {
var $allForms = $('form[name="findsupplier"]').not('#header_search form, header form, .navbar form');
$mainForm = $allForms.last();
}
// Add to MAIN CONTENT
if ($mainForm.length) {
// Find supplier input in THIS specific form
var $supplierInput = $mainForm.find('input[name="supplier"]');
console.log('Supplier input in main form found:', $supplierInput.length);
if ($supplierInput.length) {
var $supplierLi = $supplierInput.closest('li');
console.log('Supplier li found:', $supplierLi.length);
if ($supplierLi.length) {
$supplierLi.after(vendorIdSearchHTML);
console.log('Added after supplier li in main form');
} else {
// No li, add after parent or try wrapping in div
var $parent = $supplierInput.parent();
var divHTML = '<div style="margin: 10px 0;">' +
'<label for="vendor_id_search_main">Vendor ID:</label>' +
'<input type="text" id="vendor_id_search_main" name="vendor_id_search" size="25" />' +
'<button type="button" id="search_by_vendor_id" class="btn btn-primary" style="margin-left: 10px;">Search by ID</button>' +
'</div>';
$parent.after(divHTML);
console.log('Added after supplier parent in main form (no li)');
}
} else {
// Find any ul in this form and append
var $ul = $mainForm.find('ul').first();
console.log('UL in main form found:', $ul.length);
if ($ul.length) {
$ul.append(vendorIdSearchHTML);
console.log('Appended to ul in main form');
}
}
}
// Handle Search by ID button click (works for both main and header buttons)
$(document).on('click', '#search_by_vendor_id, .search_by_vendor_id', function() {
console.log('Search by ID clicked');
// Find the vendor ID input - it should be near the button
var $vendorIdInput = $(this).siblings('input[name="vendor_id_search"]');
// If not a sibling, try finding by ID (check both main and header)
if (!$vendorIdInput.length) {
$vendorIdInput = $('#vendor_id_search, #vendor_id_search_main, #vendor_id_search_header');
}
console.log('Found input fields:', $vendorIdInput.length);
var vendorId = $vendorIdInput.val();
console.log('Raw vendor ID value:', vendorId);
if (vendorId) {
vendorId = vendorId.trim();
}
if (!vendorId || vendorId === '') {
alert('Please enter a Vendor ID');
return;
}
console.log('Searching for vendor ID:', vendorId);
// Navigate to the vendor page by ID
window.location.href = '/cgi-bin/koha/acqui/supplier.pl?booksellerid=' + vendorId;
});
// Allow Enter key in the Vendor ID field to trigger search (both main and header)
$(document).on('keypress', '#vendor_id_search, #vendor_id_search_main, #vendor_id_search_header', function(e) {
if (e.which === 13) { // Enter key
e.preventDefault();
$('#search_by_vendor_id').click();
}
});
} else {
console.log('Not on acquisitions page');
}
});
I tried adding the search to the header as well but it was messy and didn't work.
|