From ab50417926596ec3131bc03ea6d01ff6a28ecbf5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 3 Jan 2018 01:40:13 +0000 Subject: [PATCH] Bug 19837 - Add error feedback for duplicatred or unfound cardnumbers To test: 1 - Enter some patrons on a list 2 - 'Enter multiple cardnumbers' 3 - Make sure to add some that are already in list, some that don't exist, and some new patrons 4 - Verify results are as expected with warnings Signed-off-by: Owen Leonard --- .../prog/en/modules/patron_lists/list.tt | 28 ++++++++++++++++++++++ patron_lists/list.pl | 15 +++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt index d18bf6f..104335d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt @@ -31,6 +31,34 @@

[% list.name |html %]

+ [% IF ( not_found.size > 0 ) %] +

Warning, the following cardnumbers were not found:

+ + + + + + [% FOREACH nf IN not_found %] + + [% END %] + +
Cardnumbers not found
[% nf |html %]
+ [% END %] + + [% IF ( existed.size > 0 ) %] +

Warning, the following cardnumbers were already in this list:

+ + + + + + [% FOREACH ed IN existed %] + + [% END %] + +
Cardnumbers already in list
[% ed |html %]
+ [% END %] +
Add patrons diff --git a/patron_lists/list.pl b/patron_lists/list.pl index 91e6370..71bfa38 100755 --- a/patron_lists/list.pl +++ b/patron_lists/list.pl @@ -41,12 +41,25 @@ my ( $template, $logged_in_user, $cookie ) = get_template_and_user( my ($list) = GetPatronLists( { patron_list_id => scalar $cgi->param('patron_list_id') } ); +my @existing = $list->patron_list_patrons; + my $cardnumbers = $cgi->param('patrons_by_barcode'); my @patrons_by_barcode; if ( $cardnumbers ){ push my @patrons_by_barcode, uniq( split(/\s\n/, $cardnumbers) ); - AddPatronsToList( { list => $list, cardnumbers => \@patrons_by_barcode } ); + my @results = AddPatronsToList( { list => $list, cardnumbers => \@patrons_by_barcode } ); + my %found = map { $_->borrowernumber->cardnumber => 1 } @results; + my %exist = map { $_->borrowernumber->cardnumber => 1 } @existing; + my (@not_found, @existed); + foreach my $barcode ( @patrons_by_barcode ){ + push (@not_found, $barcode) unless defined $found{$barcode}; + push (@existed, $barcode) if defined $exist{$barcode}; + } + $template->param( + not_found => \@not_found, + existed => \@existed, + ); } my @patrons_to_add = $cgi->multi_param('patrons_to_add'); -- 2.1.4