From 0282c98acf754b8cbae17164edd111d4adfb8037 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 8 Dec 2021 04:30:13 +0000 Subject: [PATCH] Bug 23291: Patron batch modification based on SMS number This patch is based on the patchset on bug 24019. It enabled librarians to list SMS numbers (one per line) or upload a file of SMS numbers, just like they can currently do with borrowernumbers or card numbers. Test plan: 1. Apply patch 2. Restart services 3. Create a patron list in: Tools > Patrons lists 4. Navigate to Tools > Batch patron modification 5. Observe there are 4 tabs: 'By card number', 'By SMS number', 'By borrowernumber', 'By patron list' 6. Test each option for batch patron modifications: - By cardnumber file - By cardnumber list - By SMS number file - By SMS number list - By borrowernumber file - By borrowernumber list - By patron list 7. In all of the above cases the correct patrons should be retrieved by Koha, and modified. 8. Test uploading a SMS number shared by multiple patrons and confirm all patrons with that SMS number are returned 9. Confirm the 'order of operations' for card numbers, SMS numbers and borrowernumbers is followed: - If a file is uploaded AND a list of number submitted then the list of numbers will be used 10. Confirm batches are only submitted from the active tab - If you upload a file OR input a list SMS numbers, and then switch to a different tab and input a list of borrowernumbers then the SMS numbers originally inputted should be ignored. Sponsored-By: Brimbank Library, Australia --- .../prog/en/modules/tools/modborrowers.tt | 41 ++++++++++++++++++-- tools/modborrowers.pl | 45 +++++++++++++++------- 2 files changed, 69 insertions(+), 17 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 f60a917a9b..db84178dde 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -44,6 +44,9 @@ By card number
  • + By SMS number +
  • +
  • By borrowernumber
  • [% IF patron_lists %] @@ -76,6 +79,30 @@ Cancel +
    +
    + Use a file of SMS numbers +
      +
    1. + +
      File must contain one SMS number per line.
      +
    2. +
    +
    +
    + List SMS numbers one by one +
      +
    1. + + +
    2. +
    +
    +
    + + Cancel +
    +
    Use a file of borrowernumbers @@ -130,7 +157,7 @@ [% op = 'noshow' # Change op to prevent display in code below %]

    Batch patrons modification

    -

    No patron card numbers or borrowernumbers given.

    +

    No patron card numbers, SMS numbers or borrowernumbers given.

    @@ -146,6 +173,8 @@ [% IF ( notfoundcardnumbers ) %] [% IF ( useborrowernumbers ) -%]

    Warning, the following borrowernumbers were not found:

    + [% ELSIF ( usesmsnumbers ) -%] +

    Warning, the following SMS numbers were not found:

    [% ELSE -%]

    Warning, the following card numbers were not found:

    [% END %] @@ -154,6 +183,8 @@ [% IF ( useborrowernumbers ) -%] Borrowernumbers not found + [% ELSIF ( usesmsnumbers ) -%] + SMS numbers not found [% ELSE -%] Card numbers not found [% END %] @@ -481,11 +512,13 @@ /* Reset form fields on inactive tabs */ var tab = $(this).find('.ui-tabs-active:first a').attr('href'); if ( tab == '#usecardnumber' ) { - $("#borrowernumberuploadfile, #patron_list_id, #borrowernumberlist").val(""); + $("#borrowernumberuploadfile, #smsnumberuploadfile, #patron_list_id, #borrowernumberlist, #smsnumberlist").val(""); + } else if ( tab == '#usesmsnumber' ) { + $("#borrowernumberuploadfile, #cardnumberuploadfile, #patron_list_id, #borrowernumberlist, #cardnumberlist").val(""); } else if ( tab == '#useborrowernumber' ) { - $("#cardnumberuploadfile, #cardnumberlist, #patron_list_id").val(""); + $("#cardnumberuploadfile, #smsnumberuploadfile, #cardnumberlist, #patron_list_id, #smsnumberlist").val(""); } else { // uselist - $("#borrowernumberuploadfile, #cardnumberuploadfile, #borrowernumberlist, #cardnumberlist").val(""); + $("#borrowernumberuploadfile, #cardnumberuploadfile, #smsnumberuploadfile, #borrowernumberlist, #cardnumberlist, #smsnumberlist").val(""); } }); }); diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 4ff7dfe6db..d882297b48 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -60,6 +60,7 @@ if ( $op eq 'show' ) { my @patronidnumbers; my @notfoundcardnumbers; my $useborrowernumbers = 0; + my $usesmsnumbers = 0; # Get cardnumbers from a file or the input area if( my $cardnumberlist = $input->param('cardnumberlist') ){ @@ -73,6 +74,19 @@ if ( $op eq 'show' ) { $content =~ s/[\r\n]*$//; push @patronidnumbers, $content if $content; } + } elsif ( my $smsnumberlist = $input->param('smsnumberlist') ){ + # User submitted a list of SMS numbers + $usesmsnumbers = 1; + push @patronidnumbers, split( /\s\n/, $smsnumberlist ); + } elsif ( my $smsnumberuploadfile = $input->param('smsnumberuploadfile') ){ + # User uploaded a file of SMS numbers + $usesmsnumbers = 1; + binmode $smsnumberuploadfile, ':encoding(UTF-8)'; + while ( my $content = <$smsnumberuploadfile> ) { + next unless $content; + $content =~ s/[\r\n]*$//; + push @patronidnumbers, $content if $content; + } } elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ){ # User submitted a list of borrowernumbers $useborrowernumbers = 1; @@ -97,22 +111,26 @@ if ( $op eq 'show' ) { my $max_nb_attr = 0; for my $patronidnumber ( @patronidnumbers ) { - my $patron; + my $patrons; if( $useborrowernumbers == 1 ){ - $patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } ); + $patrons = Koha::Patrons->search( { borrowernumber => $patronidnumber } ); + } elsif ( $usesmsnumbers == 1 ){ + $patrons = Koha::Patrons->search( { smsalertnumber => $patronidnumber } ); } else { - $patron = Koha::Patrons->find( { cardnumber => $patronidnumber } ); + $patrons = Koha::Patrons->search( { cardnumber => $patronidnumber } ); } - if ( $patron ) { - if ( $logged_in_user->can_see_patron_infos( $patron ) ) { - my $borrower = $patron->unblessed; - my $attributes = $patron->extended_attributes; - $borrower->{patron_attributes} = $attributes->as_list; - $borrower->{patron_attributes_count} = $attributes->count; - $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; - push @borrowers, $borrower; - } else { - push @notfoundcardnumbers, $patronidnumber; + if ( $patrons->count > 0 ) { + while ( my $patron = $patrons->next ) { + if ( $logged_in_user->can_see_patron_infos( $patron ) ) { + my $borrower = $patron->unblessed; + my $attributes = $patron->extended_attributes; + $borrower->{patron_attributes} = $attributes->as_list; + $borrower->{patron_attributes_count} = $attributes->count; + $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; + push @borrowers, $borrower; + } else { + push @notfoundcardnumbers, $patronidnumber; + } } } else { push @notfoundcardnumbers, $patronidnumber; @@ -168,6 +186,7 @@ if ( $op eq 'show' ) { $template->param( notfoundcardnumbers => \@notfoundcardnumbers ) if @notfoundcardnumbers; $template->param( useborrowernumbers => $useborrowernumbers ); + $template->param( usesmsnumbers => $usesmsnumbers ); # Construct drop-down list values my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; -- 2.11.0