Bug 27629

Summary: Filter invoices by library in invoices.pl
Product: Koha Reporter: Daphne Hoolahan <dch>
Component: AcquisitionsAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P4 CC: clodagh.kerin, jonathan.druart, katrin.fischer
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:

Description Daphne Hoolahan 2021-02-04 17:35:17 UTC
Filter invoices by library doesn't work in invoices.pl
Some invoices will be listed but not all the applicable invoices.  
An easy way to reproduce this problem is to list all the invoices within a date range, make a note of the invoices for one particular library, now filter your list by that library and you will notice that all the invoices you expect are listed.
Comment 1 Jonathan Druart 2021-02-05 14:12:56 UTC
Can you confirm the invoices that are missing are linked with a basket that has the authorisedby column not NULL?
Comment 2 Daphne Hoolahan 2021-02-06 09:39:34 UTC
The missing invoices are all linked to a basket.  Baskets have authorisedby column = 0.  What is the significance of authorisedby for this filter?
Comment 3 Jonathan Druart 2021-02-08 10:12:18 UTC
When the "library" filter on the invoice page is set, a JOIN is done on the borrowers table using the branchcode of this patron.

And aqbasket.authorisedby is the borrowernumber of the librarian who created the basket.

BUT if the patron is removed, the column will be set to NULL, and the JOIN will not return the invoices created by this (now deleted) patron.

There is a "Managing library" (aqbasket.branch) at basket level, maybe we should use it instead of borrowers.branchcode.
Comment 4 Katrin Fischer 2021-02-08 10:16:59 UTC
Hm, the managing library was introduced later - which could explain why it was not used in the first place. In my experience libraries often forget to set it, but it would be more reliable in this case. 

Daphne, would it work for your data?

The meaning of authorised_by in several places has led us to migrate with a migration acq user for a valid borrowernumber, which helps, but is not a real good solution.
Comment 5 Daphne Hoolahan 2021-02-08 16:49:28 UTC
Managing Library might be more straightforward but my problem is arising on baskets created from EDI Quotes or the GOBI API so either way we are going to be dependent on data supplied by the vendor or an update when the basket is created.
Comment 6 Katrin Fischer 2023-01-23 22:59:38 UTC
Could we maybe do both, a search option for managing library or a fallback on managing library for the search option?