From 840fcd75d1df252644cff179ed203b02a04e079d Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 10 Jul 2019 03:05:18 +0000 Subject: [PATCH] Bug 23291: Find patrons by smsalertnumber in the batch patron modification Add ability to paste in sms numbers (one per line) or upload a file of sms numbers and find patrons with matching smsalertnumber values. If an sms number is not found then this is displayed in a yellow box to the librarian i.e. the batch patron modification tool will behave as it does currently when a cardnumber is not found. Test plan: 1. Go to Tools > Batch patron modification 2. Notice there is a file upload (for cardnumbers) and a text input area (for cardnumbers) 3. Apply patch and restart memached and plack 4. Refresh the page and notice a file upload (for sms numbers) and file text input area (for sms numbers) have been added 5. Create a file with valid sms numbers matching smsalertnumber values of patrons (one per line) 6. Select/upload the file into the sms number file upload and submit the form 7. Notice the patrons are found and you can batch modify them. Select a date in the 'Restriction expiration' datepicker and submit and notice this is added to the selected borrowers in the borrowers.debarred, borrowers.debarredcomment fields and borrower_debarment table. 8. Create a file with some valid and some invalid sms numbers (i.e. some smsnumbers belonging to patrons in their smsalertnumber field and some not matching) 9. Upload your file from 8 in the SMS number file upload and notice that error handling means the invalid/non-matching sms numbers are shown below the yellow box at the top of the page whilst matching sms numbers have returned patrons which you can edit 10. Confirm card number file upload still works by making a file of valid cardnumbers and uploading it in the Batch patron modification tool and noticing the patrons are successfully returned 11. In the batch patron modification tool paste valid sms numbers into the sms number text area input (0ne per line) and submit the batch patron modification. Notice that the patrons are successfully returned and displayed. 12. Repeat step 11 but this time paste in valid and invalid sms numbers and notice error handling means sms numbers which did not match borrowers, smsalertnumber are shown under the yellow box at the top of the page and patrons who matched sms numbers are shown below in the table 13. Repeat step 11 this time input only invalid sms numbers and submit. Notice that a page showing the yellow notice box and a list of all smsnumbers which could not be found are returned. 14. Repeat step 11 submitting valid smsnumbers in the cardnumber text area field and you will notice that a page showing the yellow notice box and a list of all non matching cardnumbers. 15. In your Koha home directory run: sudo koha-shell Then run: prove xt 16. Confirm all test pass 17. Sign off Sponsored-By: Brimbank Library, Australia --- .../prog/en/modules/tools/modborrowers.tt | 42 +++++++++++-- tools/modborrowers.pl | 68 ++++++++++++++++------ 2 files changed, 88 insertions(+), 22 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt index 9e491f1..446392b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -29,9 +29,16 @@

Batch patron modification

- Use a file + Use a file of cardnumbers
    -
  1. +
  2. +
+
+ +
+ Use a file of SMS numbers +
    +
@@ -61,6 +68,17 @@ + +
+ Or list SMS numbers one by one +
    +
  1. + + +
  2. +
+
+
@@ -69,11 +87,11 @@ [% END %] - [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) # Alert if no patrons given%] + [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) && (!notfoundsmsnumbers) # Alert if no patrons given%] [% op = 'noshow' # Change op to prevent display in code below %]

Batch patrons modification

-

No patron card numbers given.

+

No patron card numbers/SMS numbers given.

@@ -100,6 +118,21 @@ [% END %] + [% IF ( notfoundsmsnumbers ) %] +

Warning, the following sms numbers were not found:

+ + + + + + [% FOREACH notfoundsmsnumber IN notfoundsmsnumbers %] + + [% END %] + +
SMS numbers not found
[% notfoundsmsnumber.smsalertnumber | html %]
+ [% END %] + + [% IF ( op == 'show_results' ) %] [% IF ( errors ) %]
@@ -109,6 +142,7 @@ [% IF ( error.error == 'can_not_update' ) %]
  • Can not update patron. [% IF ( error.cardnumber ) %] Cardnumber: [% error.cardnumber | html %] [% END %] + [% IF ( error.smsnumber ) %] SMS number: [% error.smsnumber | html %] [% END %] (Borrowernumber: [% error.borrowernumber | html %])
  • [% ELSE %] diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index d693bb4..ccbd3e7 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -60,48 +60,77 @@ my $dbh = C4::Context->dbh; # Show borrower informations if ( $op eq 'show' ) { - my $filefh = $input->upload('uploadfile'); + my $cardnumberfilefh = $input->upload('uploadcardnumberfile'); + my $smsnumberfilefh = $input->upload('uploadsmsnumberfile'); my $filecontent = $input->param('filecontent'); my $patron_list_id = $input->param('patron_list_id'); my @borrowers; my @cardnumbers; - my ( @notfoundcardnumbers, @from_another_group_of_libraries ); + my @smsnumbers; + my ( @notfoundcardnumbers, @notfoundsmsnumbers, @from_another_group_of_libraries ); # Get cardnumbers from a file or the input area my @contentlist; - if ($filefh) { - while ( my $content = <$filefh> ) { + if ($cardnumberfilefh) { + while ( my $content = <$cardnumberfilefh> ) { $content =~ s/[\r\n]*$//g; push @cardnumbers, $content if $content; } + } elsif ( $smsnumberfilefh ) { + while ( my $content = <$smsnumberfilefh> ) { + $content =~ s/[\r\n]*$//g; + push @smsnumbers, $content if $content; + } } elsif ( $patron_list_id ) { my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); @cardnumbers = $list->patron_list_patrons()->search_related('borrowernumber') ->get_column('cardnumber')->all(); - + @smsnumbers = + $list->patron_list_patrons()->search_related('borrowernumber') + ->get_column('smsalertnumber')->all(); } else { - if ( my $list = $input->param('cardnumberlist') ) { - push @cardnumbers, split( /\s\n/, $list ); + if ( my $cardnumberlist = $input->param('cardnumberlist') ) { + push @cardnumbers, split( /\s\n/, $cardnumberlist ); + } elsif ( my $smsnumberlist = $input->param('smsnumberlist') ) { + push @smsnumbers, split( /\s\n/, $smsnumberlist ); } } my $max_nb_attr = 0; - for my $cardnumber ( @cardnumbers ) { - my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); - if ( $patron ) { - if ( $logged_in_user->can_see_patron_infos( $patron ) ) { - $patron = $patron->unblessed; - $patron->{patron_attributes} = C4::Members::Attributes::GetBorrowerAttributes( $patron->{borrowernumber} ); - $max_nb_attr = scalar( @{ $patron->{patron_attributes} } ) - if scalar( @{ $patron->{patron_attributes} } ) > $max_nb_attr; - push @borrowers, $patron; + + if ( @cardnumbers ) { + for my $cardnumber ( @cardnumbers ) { + my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); + if ( $patron ) { + if ( $logged_in_user->can_see_patron_infos( $patron ) ) { + $patron = $patron->unblessed; + $patron->{patron_attributes} = C4::Members::Attributes::GetBorrowerAttributes( $patron->{borrowernumber} ); + $max_nb_attr = scalar( @{ $patron->{patron_attributes} } ) if scalar( @{ $patron->{patron_attributes} } ) > $max_nb_attr; + push @borrowers, $patron; + } else { + push @notfoundcardnumbers, $cardnumber; + } } else { push @notfoundcardnumbers, $cardnumber; } - } else { - push @notfoundcardnumbers, $cardnumber; + } + } else { + for my $smsnumber (@smsnumbers ) { + my $patron = Koha::Patrons->find( { smsalertnumber => $smsnumber } ); + if ( $patron ) { + if ( $logged_in_user->can_see_patron_infos( $patron ) ) { + $patron = $patron->unblessed; + $patron->{patron_attributes} = C4::Members::Attributes::GetBorrowerAttributes( $patron->{borrowernumber} ); + $max_nb_attr = scalar( @{ $patron->{patron_attributes} } ) if scalar( @{ $patron->{patron_attributes} } ) > $max_nb_attr; + push @borrowers, $patron; + } else { + push @notfoundsmsnumbers, $smsnumber; + } + } else { + push @notfoundsmsnumbers, $smsnumber; + } } } @@ -151,6 +180,9 @@ if ( $op eq 'show' ) { $template->param( borrowers => \@borrowers ); $template->param( attributes_header => \@attributes_header ); @notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers; + @notfoundsmsnumbers = map { { smsalertnumber => $_ } } @notfoundsmsnumbers; + $template->param( notfoundsmsnumbers => \@notfoundsmsnumbers ) if @notfoundsmsnumbers; + $template->param( notfoundcardnumbers => \@notfoundcardnumbers ) if @notfoundcardnumbers; -- 2.1.4