Bug 39616 - Add ability to search by Vendor ID
Summary: Add ability to search by Vendor ID
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: 24.11
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-11 18:00 UTC by Angela Berrett
Modified: 2025-12-18 20:20 UTC (History)
1 user (show)

See Also:
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:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angela Berrett 2025-04-11 18:00:57 UTC
The Acquisitions module only allows a search of Vendors by Name, not ID number. 

We have 224 vendors with no names, but we can't search for them as there are too many in our system and it times out on a blank search. We can get the ID via a report, but we don't have a way to access the vendor account page to modify or delete it with only the ID number.  

Also, the vendor ID is populated in the item record. If you find that ID, then you would be able to search by it on items that does not have acquisition details linked to the item in the Holdings table.
Comment 1 Angela Berrett 2025-12-02 21:29:30 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?
Comment 2 Angela Berrett 2025-12-18 20:20:01 UTC
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.