Bug 19837: Add error feedback for duplicated or unfound cardnumbers
authorNick Clemens <nick@bywatersolutions.com>
Wed, 3 Jan 2018 01:40:13 +0000 (01:40 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 18 Feb 2018 19:48:46 +0000 (16:48 -0300)
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 <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt
patron_lists/list.pl

index 9f2eba1..935a409 100644 (file)
         <div class="yui-b">
         <h1>[% list.name |html %]</h1>
 
+        [% IF ( not_found.size > 0 ) %]
+        <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
+        <table style="margin:auto;">
+            <thead>
+                <tr><th>Cardnumbers not found</th></tr>
+            </thead>
+            <tbody>
+            [% FOREACH nf IN not_found %]
+                <tr><td>[% nf |html %]</td></td>
+            [% END %]
+            </tbody>
+        </table>
+        [% END %]
+
+        [% IF ( existed.size > 0 ) %]
+        <div class="dialog alert"><p>Warning, the following cardnumbers were already in this list:</p></div>
+        <table style="margin:auto;">
+            <thead>
+                <tr><th>Cardnumbers already in list</th></tr>
+            </thead>
+            <tbody>
+            [% FOREACH ed IN existed %]
+                <tr><td>[% ed |html %]</td></td>
+            [% END %]
+            </tbody>
+        </table>
+        [% END %]
+
         <form action="list.pl" id="add_patrons" method="post" class="clearfix">
             <fieldset class="rows">
                 <legend>Add patrons</legend>
index 91e6370..71bfa38 100755 (executable)
@@ -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');