From b08535d381adeb19f4fa56170e12cda1aa2ebe6c Mon Sep 17 00:00:00 2001 From: Alexandre Noel Date: Fri, 21 Jun 2024 07:53:53 -0400 Subject: [PATCH] Bug 32742: Patron's lists option are not in alphabetical MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch add sorting feature to the patron card lists export option To test 1. Go to Tools > Patron lists 2. Create a new patron list 3. Add 10 patrons in a random order (not in alphabetical nor in cardnumber sequence) 4. Go back to Tools > Patron lists management page 5. Find your list, click on 'Action' and select 'Print patron cards' 6. Check the cards order in the pdf --> notice these cards aren't in alphabetical order. 7. Apply the patch 8. Repeat step 4, 5 9. Fill the «Order by» field and submit 10. Check the cards order in the pdf --> notice the cards are now ordered. It's also working for export in Patron card creator page. To test 1. Go to Tools > Patron card creator 2. Create a new patron card batch 3. Add some patrons 4. Test the "Order by" option for different export button 5. In an export form, Select the "Order by" field and submit 6. Check that it's ordered Export buttons : --> manage > card batches (or /cgi-bin/koha/patroncards/manage.pl?card_element=batch) > Export (from the table) > Select few batches > Export selected batches > Export from patron list --> Click "Edit" of your batch in the table > Export card batch > Export (from a row of the patrons table) note that this export doesn't need the order by option. > Select few patrons > Export selected card(s) --- .../prog/en/modules/patroncards/print.tt | 29 ++++++++--------- patroncards/create-pdf.pl | 32 +++++++++++++++---- patroncards/print.pl | 15 +++++---- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt index 545a05879b..7a6f2edf1f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt @@ -23,17 +23,17 @@ [% IF ( batche.label_ids ) %] [% batche.card_count | html %] Single patron cards

- label_single_[% batche.card_count | html %].pdf + label_single_[% batche.card_count | html %].pdf

[% ELSIF ( batche.borrower_numbers ) %] [% batche.card_count | html %] Single patron cards

- label_single_[% batche.card_count | html %].pdf + label_single_[% batche.card_count | html %].pdf

[% ELSE %] Card batch number [% batche.batch_id | html %]

- label_batch_[% batche.batch_id | html %].pdf + label_batch_[% batche.batch_id | html %].pdf

[% END %] [% END %] @@ -77,17 +77,6 @@ [% IF (patronlist_id) %] [% END %]
    - [% IF (patronlist_id) %] -
  1. - - -
  2. - [% END %]
  3. Used for duplex printers (needs a '1 up template')
  4. - + [% IF ( card_count != 1 ) %] +
  5. + + +
  6. + [% END %]
  7. diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl index fbe4708c58..e79b0d78ba 100755 --- a/patroncards/create-pdf.pl +++ b/patroncards/create-pdf.pl @@ -91,24 +91,44 @@ eval { my ( $llx, $lly ) = 0, 0; ( undef, undef, $llx, $lly ) = $pc_template->get_label_position($start_card); + # sort the borrower list by the order_by field + sub sort_borrowerlist { + my ( $list, $order_by ) = @_; # $list is a reference to an array of borrower numbers + my @borrower_list = @$list; + if ($order_by) { + @borrower_list = + map { $_->borrowernumber } + Koha::Patrons->search( { borrowernumber => { -in => \@borrower_list } }, { order_by => [$order_by] } ) + ->as_list; + } + return @borrower_list; + } + if (@label_ids) { my $batch_items = $batch->get_attr('items'); + my @selected_borrower; grep { my $label_id = $_; - push( @{$items}, grep { $_->{'label_id'} == $label_id; } @{$batch_items} ); + push( @selected_borrower, grep { $_->{'label_id'} == $label_id; } @{$batch_items} ); } @label_ids; + @selected_borrower = map { $_->{borrower_number} } @selected_borrower; + @selected_borrower = sort_borrowerlist( \@selected_borrower, $order_by ) if ($order_by); + grep { push( @{$items}, { borrower_number => $_ } ); } @selected_borrower; } elsif (@borrower_numbers) { + @borrower_numbers = sort_borrowerlist( \@borrower_numbers, $order_by ) if ($order_by); grep { push( @{$items}, { borrower_number => $_ } ); } @borrower_numbers; } elsif ($patronlist_id) { my ($list) = GetPatronLists( { patron_list_id => $patronlist_id } ); my @borrowerlist = $list->patron_list_patrons()->search_related('borrowernumber')->get_column('borrowernumber')->all(); - @borrowerlist = - map { $_->borrowernumber } - Koha::Patrons->search( { borrowernumber => { -in => \@borrowerlist } }, { order_by => [$order_by] } ) - ->as_list - if ($order_by); + @borrowerlist = sort_borrowerlist( \@borrowerlist, $order_by ) if ($order_by); grep { push( @{$items}, { borrower_number => $_ } ); } @borrowerlist; + } elsif ($batch_id) { + $items = $batch->get_attr('items'); + my @borrowerlist = map { $_->{'borrower_number'} } @{$items}; + @borrowerlist = sort_borrowerlist( \@borrowerlist, $order_by ) if ($order_by); + @{$items} = map { { borrower_number => $_ } } @borrowerlist; + } else { $items = $batch->get_attr('items'); } diff --git a/patroncards/print.pl b/patroncards/print.pl index b4745ffbff..803d4a7806 100755 --- a/patroncards/print.pl +++ b/patroncards/print.pl @@ -77,8 +77,9 @@ if ( $op eq 'cud-export' ) { #FIXME Seems like a GET operation? } ); $template->param( - batches => \@batches, - referer => $referer, + batches => \@batches, + referer => $referer, + order_by => $order_by, ); } elsif (@borrower_numbers) { my $borrower_number_param = '&borrower_number='; @@ -96,8 +97,9 @@ if ( $op eq 'cud-export' ) { #FIXME Seems like a GET operation? } ); $template->param( - batches => \@batches, - referer => $referer, + batches => \@batches, + referer => $referer, + order_by => $order_by, ); } elsif (@batch_ids) { foreach my $batch_id (@batch_ids) { @@ -114,8 +116,9 @@ if ( $op eq 'cud-export' ) { #FIXME Seems like a GET operation? ); } $template->param( - batches => \@batches, - referer => $referer, + batches => \@batches, + referer => $referer, + order_by => $order_by, ); } elsif ($patronlist_id) { $template->param( -- 2.34.1