From c02a1ea2a0b389bc6ce45784ec34ec09ccb23c55 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Thu, 20 Oct 2022 16:10:25 +0200 Subject: [PATCH] Bug 31115: Add additional field filtering for invoice search This patch adds support for filtering invoice searches on additional fields. To test: 1. Generate additional fields for invoices 2. Have invoices with additional fields 3. Use invoice searching and play with filtering by additional fields. => SUCCESS: It works! 4. Sign off :-D Sponsored-by: The Research University in the Helmholtz Association (KIT) Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- acqui/invoices.pl | 49 ++++++++++++++----- .../prog/en/modules/acqui/invoices.tt | 20 ++++++++ 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 0f6f666550..5cf2e338aa 100755 --- a/acqui/invoices.pl +++ b/acqui/invoices.pl @@ -36,6 +36,7 @@ use C4::Acquisition qw( GetInvoices GetInvoice ); use C4::Budgets qw( GetBudget GetBudgets CanUserUseBudget ); use Koha::DateUtils qw( dt_from_string ); use Koha::Acquisition::Booksellers; +use Koha::AdditionalFields; my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -62,25 +63,47 @@ my $branch = $input->param('branch'); my $message_id = $input->param('message_id'); my $op = $input->param('op'); +my @additional_fields = Koha::AdditionalFields->search( + { tablename => 'aqinvoices', + searchable => 1 + } +)->as_list; +my @additional_field_filters; +for my $field (@additional_fields) { + my $value = $input->param( 'additional_field_' . $field->id ); + if ( defined $value and $value ne '' ) { + push @additional_field_filters, + { id => $field->id, + value => $value, + }; + } +} + my $invoices = []; if ( $op and $op eq 'do_search' ) { @{$invoices} = GetInvoices( - invoicenumber => $invoicenumber, - supplierid => $supplierid, - shipmentdatefrom => $shipmentdatefrom, - shipmentdateto => $shipmentdateto, - billingdatefrom => $billingdatefrom, - billingdateto => $billingdateto, - isbneanissn => $isbneanissn, - title => $title, - author => $author, - publisher => $publisher, - publicationyear => $publicationyear, - branchcode => $branch, - message_id => $message_id, + invoicenumber => $invoicenumber, + supplierid => $supplierid, + shipmentdatefrom => $shipmentdatefrom, + shipmentdateto => $shipmentdateto, + billingdatefrom => $billingdatefrom, + billingdateto => $billingdateto, + isbneanissn => $isbneanissn, + title => $title, + author => $author, + publisher => $publisher, + publicationyear => $publicationyear, + branchcode => $branch, + message_id => $message_id, + additional_fields => \@additional_field_filters, ); } +$template->param( + additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters }, + additional_fields_for_invoice => \@additional_fields, +); + # Build suppliers list my @suppliers = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } )->as_list; my $suppliers_loop = []; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt index 04e595e2ce..126a7d4c01 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE AuthorisedValues %] [% USE KohaDates %] [% USE Branches %] [% SET footerjs = 1 %] @@ -385,6 +386,25 @@ [% PROCESS options_for_libraries libraries => Branches.all( selected => branch, unfiltered => 1 ) %] + [% FOR field IN additional_fields_for_invoice %] +
  • + + [% IF field.authorised_value_category %] + + [% ELSE %] + + [% END %] +
  • + [% END %]
    -- 2.39.5