From 3b87ec988dd786ca1286a7baa9f14fabdcb1c6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Mon, 8 May 2017 16:18:41 +0200 Subject: [PATCH] Bug 18555: Create patron list from patron import Create a patron list from imported patrons to be used for printing patron cards and other patron list related actions. To test: - Apply patch - Go to Home > Tools > Import patrons - Select a file to import and check new checkbox 'Create patron list' - Import file - Verify that in import results you see the time stamped name of the patronlist containig the imported patrons (if any patrons were imported) - Go to Home > Tools > Patron lists - Verify that the list shows up and contains the imported patrons Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- .../prog/en/modules/tools/import_borrowers.tt | 9 +++++++++ tools/import_borrowers.pl | 23 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt index ea3a3c959b..7e8245d010 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -37,6 +37,9 @@
Import results :
  • [% imported %] imported records [% IF ( lastimported ) %](last was [% lastimported %])[% END %]
  • + [% IF imported and patronlistname %] +
  • Patronlist with imported patrons: [% patronlistname %]
  • + [% END %]
  • [% overwritten %] overwritten [% IF ( lastoverwritten ) %](last was [% lastoverwritten %])[% END %]
  • [% alreadyindb %] not imported because already in borrowers table and overwrite disabled [% IF ( lastalreadyindb ) %](last was [% lastalreadyindb %])[% END %]
  • [% invalid %] not imported because they are not in the expected format [% IF ( lastinvalid ) %](last was [% lastinvalid %])[% END %]
  • @@ -113,6 +116,12 @@ +
  • + + + List name will be file name with timestamp +
  • +
    Field to use for record matching diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 66190e2737..b693017c3f 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -52,6 +52,7 @@ use Koha::DateUtils; use Koha::Token; use Koha::Libraries; use Koha::Patron::Categories; +use Koha::List::Patron; use Text::CSV; # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: @@ -105,6 +106,12 @@ if ($matchpoint) { } my $overwrite_cardnumber = $input->param('overwrite_cardnumber'); +#create a patronlist +my $createpatronlist = $input->param('createpatronlist') || 0; +my $dt = dt_from_string(); +my $timestamp = $dt->ymd('-').' '.$dt->hms(':'); +my $patronlistname = $uploadborrowers . ' (' . $timestamp .')'; + $template->param( SCRIPT_NAME => '/cgi-bin/koha/tools/import_borrowers.pl' ); if ( $uploadborrowers && length($uploadborrowers) > 0 ) { @@ -114,13 +121,21 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { token => scalar $input->param('csrf_token'), }); + #create a patronlist + my $createpatronlist = $input->param('createpatronlist'); + my $dt = dt_from_string(); + my $timestamp = $dt->ymd('-').' '.$dt->hms(':'); + my $patronlistname = $uploadborrowers. ' (' . $timestamp .')'; + push @feedback, {feedback=>1, name=>'filename', value=>$uploadborrowers, filename=>$uploadborrowers}; my $handle = $input->upload('uploadborrowers'); my $uploadinfo = $input->uploadInfo($uploadborrowers); foreach (keys %$uploadinfo) { push @feedback, {feedback=>1, name=>$_, value=>$uploadinfo->{$_}, $_=>$uploadinfo->{$_}}; } + my $imported = 0; + my @imported_borrowers; my $alreadyindb = 0; my $overwritten = 0; my $invalid = 0; @@ -356,6 +371,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { $imported++; $template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber); + push @imported_borrowers, $borrowernumber; #for patronlist } else { $invalid++; push @errors, {unknown_error => 1}; @@ -363,6 +379,13 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { } } } + + if ( $imported && $createpatronlist ) { + my $patronlist = AddPatronList({ name => $patronlistname }); + AddPatronsToList({ list => $patronlist, borrowernumbers => \@imported_borrowers }); + $template->param('patronlistname' => $patronlistname); + } + (@errors ) and $template->param( ERRORS=>\@errors ); (@feedback) and $template->param(FEEDBACK=>\@feedback); $template->param( -- 2.11.0