Bugzilla – Attachment 19766 Details for
Bug 10612
Add ability to delete patrons with batch patron deletion tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10612 - Add ability to delete patrons with batch patron modification tool
Bug-10612---Add-ability-to-delete-patrons-with-bat.patch (text/plain), 17.03 KB, created by
Kyle M Hall (khall)
on 2013-07-18 14:06:12 UTC
(
hide
)
Description:
Bug 10612 - Add ability to delete patrons with batch patron modification tool
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-07-18 14:06:12 UTC
Size:
17.03 KB
patch
obsolete
>From 6e646b37a650559b438983062e0b30ea8a615743 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 18 Jul 2013 10:00:41 -0400 >Subject: [PATCH] Bug 10612 - Add ability to delete patrons with batch patron modification tool > >The batch patron deletion/anonymization does not allow for batch >deletion of arbitrary lists of patrons. The batch patron modification >tool allows for modification of arbitrary lists of patrons, but not >deletion. If would be highly beneficial to add patron deletion to the >batch patron modification tool. > >Test Plan: >1) Apply all dependencies for this patch >2) Apply this patch >3) Create a list of patrons with the new Patron Lists feature > a) Include at least one patron owing fines > b) Include at least one patron with items currently checked out > c) Include at least one patron not falling into a) or b) >4) Browse to the batch patron modifications tool >5) Select your list from the pulldown, and submit >6) Check the "Delete patrons" checkbox, the click the submit button >7) You should a list of errors for the patrons with fines or issues > and a table of patrons that were deleted successfully. >8) Click the link for a deleted patron, you should get a "patron not > found" message. >--- > .../prog/en/modules/tools/modborrowers.tt | 57 +++++-- > tools/modborrowers.pl | 203 +++++++++++++------- > 2 files changed, 173 insertions(+), 87 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 b4b899c..db388fd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt >@@ -107,6 +107,9 @@ > $("#"+nodeid).val(""); > } > >+ function TogglePatronDelete() { >+ $("#modifications-form").find(":input").not(".prevent-disable").not(":hidden").attr("disabled", $("#delete-checkbox").is(":checked") ); >+ } > //]]> > </script> > </head> >@@ -191,22 +194,38 @@ > [% IF ( op == 'show_results' ) %] > [% IF ( errors ) %] > <div class="dialog alert"> >- <h4>Errors occured:</h4> >- <ul class="warnings"> >- [% FOREACH error IN errors %] >- [% IF ( error.error == 'can_not_update' ) %] >- <li>Can not update patron with borrowernumber [% error.borrowernumber %]</li> >- [% ELSE %] >- <li>[% error.error %]</li> >- [% END %] >- [% END %] >- </ul> >+ <h4>Errors occured:</h4> >+ <ul class="warnings"> >+ [% FOREACH error IN errors %] >+ [% IF ( error.error == 'can_not_update' ) %] >+ <li>Can not update patron with borrowernumber [% error.borrowernumber %]</li> >+ [% ELSIF error.error == 'current_issues' %] >+ <li> >+ Cannot delete patron >+ <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% error.borrower.borrowernumber %]"> >+ [% error.borrower.firstname %] [% error.borrower.surname %] >+ </a>. >+ This patron has items checked out. >+ </li> >+ [% ELSIF error.error == 'fees_owed' %] >+ <li> >+ Cannot delete patron >+ <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% error.borrower.borrowernumber %]"> >+ [% error.borrower.firstname %] [% error.borrower.surname %] >+ </a>. >+ This patron owes fees. >+ </li> >+ [% ELSE %] >+ <li>[% error.error %]</li> >+ [% END %] >+ [% END %] >+ </ul> > </div> > [% END %] > [% END %] > > [% IF ( op == 'show' ) %] >- <form name="f" action="modborrowers.pl" method="post"> >+ <form id="modifications-form" name="f" action="modborrowers.pl" method="post"> > <input type="hidden" name="op" value="do" /> > [% IF ( borrowers ) %] > <div id="toolbar"><a id="selectallbutton" href="#">Select All</a> | <a id="clearallbutton" href="#">Clear All</a></div> >@@ -215,6 +234,10 @@ > [% IF borrowers %] > <div id="cataloguing_additem_itemlist"> > <div style="overflow:auto"> >+ [% IF action == 'delete_patrons' %] >+ <h3>Patrons deleted</h3> >+ [% END %] >+ > <table id="borrowerst"> > <thead> > <tr> >@@ -238,7 +261,7 @@ > [% FOREACH borrower IN borrowers %] > <tr> > [% IF ( op == 'show' ) %] >- <td><input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td> >+ <td><input type="checkbox" class="prevent-disable" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td> > [% END %] > <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td> > <td>[% borrower.surname %]</td> >@@ -341,9 +364,17 @@ > </li> > [% END %] > </ol> >+ >+ <ol> >+ <li> >+ <label for="delete_patrons">Delete patrons:</label> >+ <input type="checkbox" class="prevent-disable" name="delete" id="delete-checkbox" value="1" title="check to delete the selected patrons" onclick="TogglePatronDelete()"/> >+ </li> >+ </ol> >+ > </fieldset> > <fieldset class="action"> >- <input type="submit" name="mainformsubmit" value="Save" /> >+ <input type="submit" class="prevent-disable" name="mainformsubmit" id="modications-form-submit" value="Save" /> > <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a> > </fieldset> > </div> >diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl >index 7009014..d505a97 100755 >--- a/tools/modborrowers.pl >+++ b/tools/modborrowers.pl >@@ -239,98 +239,153 @@ if ( $op eq 'show' ) { > > # Process modifications > if ( $op eq 'do' ) { >+ my @borrowernumbers = $input->param('borrowernumber'); >+ my @errors; > >- my @disabled = $input->param('disable_input'); >- my $infos; >- for my $field ( qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ ) { >- my $value = $input->param($field); >- $infos->{$field} = $value if $value; >- $infos->{$field} = "" if grep { /^$field$/ } @disabled; >- } >- >- my @attributes = $input->param('patron_attributes'); >- my @attr_values = $input->param('patron_attributes_value'); >+ if ( $input->param("delete") ) { >+ my @deleted_borrowers; > >- my @errors; >- my @borrowernumbers = $input->param('borrowernumber'); >- # For each borrower selected >- for my $borrowernumber ( @borrowernumbers ) { >- # If at least one field are filled, we want to modify the borrower >- if ( defined $infos ) { >- $infos->{borrowernumber} = $borrowernumber; >- my $success = ModMember(%$infos); >- push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber} } if not $success; >- } >+ for my $borrowernumber (@borrowernumbers) { >+ my $borrower = GetMember( borrowernumber => $borrowernumber ); >+ my ( $overdue_count, $issue_count, $total_fines ) = >+ GetMemberIssuesAndFines($borrowernumber); > >- # >- my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; >- my $i=0; >- for ( @attributes ) { >- my $attribute; >- $attribute->{code} = $_; >- $attribute->{attribute} = $attr_values[$i]; >- my $attr_type = C4::Members::AttributeTypes->fetch( $_ ); >- # If this borrower is not in the category of this attribute, we don't want to modify this attribute >- ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode; >- my $valuename = "attr" . $i . "_value"; >- if ( grep { /^$valuename$/ } @disabled ) { >- # The attribute is disabled, we remove it for this borrower ! >- eval { >- C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute ); >- }; >- push @errors, { error => $@ } if $@; >- } else { >- # Attribute's value is empty, we don't want to modify it >- ++$i and next if not $attribute->{attribute}; >- >- eval { >- C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute ); >- }; >- push @errors, { error => $@ } if $@; >+ if ($issue_count) { >+ push( @errors, >+ { error => "current_issues", borrower => $borrower } ); >+ } >+ elsif ($total_fines) { >+ push( @errors, >+ { error => "fees_owed", borrower => $borrower } ); >+ } >+ else { >+ MoveMemberToDeleted($borrowernumber); >+ DelMember($borrowernumber); >+ push( @deleted_borrowers, $borrower ); > } >- $i++; > } >+ >+ $template->param( >+ borrowers => \@deleted_borrowers, >+ action => 'delete_patrons', >+ ); > } >- $op = "show_results"; # We have process modifications, the user want to view its >+ else { >+ my @disabled = $input->param('disable_input'); >+ my $infos; > >- # Construct the results list >- my @borrowers; >- my $max_nb_attr = 0; >- for my $borrowernumber ( @borrowernumbers ) { >- my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber ); >- if ( $borrower ) { >- $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) >- if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr; >- push @borrowers, $borrower; >+ for my $field ( >+ qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ >+ ) >+ { >+ my $value = $input->param($field); >+ $infos->{$field} = $value if $value; >+ $infos->{$field} = "" if grep { /^$field$/ } @disabled; > } >- } >- my @patron_attributes_option; >- for my $borrower ( @borrowers ) { >- push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} }; >- my $length = scalar( @{ $borrower->{patron_attributes} } ); >- push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); >- } > >- my @attributes_header = (); >- for ( 1 .. scalar( $max_nb_attr ) ) { >- push @attributes_header, { attribute => "Attributes $_" }; >- } >+ my @attributes = $input->param('patron_attributes'); >+ my @attr_values = $input->param('patron_attributes_value'); >+ >+ # For each borrower selected >+ for my $borrowernumber (@borrowernumbers) { >+ >+ # If at least one field are filled, we want to modify the borrower >+ if ( defined $infos ) { >+ $infos->{borrowernumber} = $borrowernumber; >+ my $success = ModMember(%$infos); >+ push @errors, >+ { >+ error => "can_not_update", >+ borrowernumber => $infos->{borrowernumber} >+ } >+ if not $success; >+ } > >- $template->param( borrowers => \@borrowers ); >- $template->param( attributes_header => \@attributes_header ); >+ my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; >+ my $i = 0; >+ for (@attributes) { >+ my $attribute; >+ $attribute->{code} = $_; >+ $attribute->{attribute} = $attr_values[$i]; >+ my $attr_type = C4::Members::AttributeTypes->fetch($_); >+ >+ # If this borrower is not in the category of this attribute, we don't want to modify this attribute >+ ++$i and next >+ if $attr_type->{category_code} >+ and $attr_type->{category_code} ne $borrower_categorycode; >+ >+ my $valuename = "attr" . $i . "_value"; >+ if ( grep { /^$valuename$/ } @disabled ) { >+ >+ # The attribute is disabled, we remove it for this borrower ! >+ eval { >+ C4::Members::Attributes::DeleteBorrowerAttribute( >+ $borrowernumber, $attribute ); >+ }; >+ push @errors, { error => $@ } if $@; >+ } >+ else { >+ >+ # Attribute's value is empty, we don't want to modify it >+ ++$i and next if not $attribute->{attribute}; >+ >+ eval { >+ C4::Members::Attributes::UpdateBorrowerAttribute( >+ $borrowernumber, $attribute ); >+ }; >+ push @errors, { error => $@ } if $@; >+ } >+ $i++; >+ } >+ >+ # Construct the results list >+ my @borrowers; >+ my $max_nb_attr = 0; >+ for my $borrowernumber (@borrowernumbers) { >+ my $borrower = >+ GetBorrowerInfos( borrowernumber => $borrowernumber ); >+ if ($borrower) { >+ $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) >+ if scalar( @{ $borrower->{patron_attributes} } ) > >+ $max_nb_attr; >+ push @borrowers, $borrower; >+ } >+ } >+ my @patron_attributes_option; >+ for my $borrower (@borrowers) { >+ push @patron_attributes_option, >+ { value => "$_->{code}", lib => $_->{code} } >+ for @{ $borrower->{patron_attributes} }; >+ >+ my $length = scalar( @{ $borrower->{patron_attributes} } ); >+ >+ push @{ $borrower->{patron_attributes} }, {} >+ for ( $length .. $max_nb_attr - 1 ); >+ } >+ >+ my @attributes_header = (); >+ for ( 1 .. scalar($max_nb_attr) ) { >+ push @attributes_header, { attribute => "Attributes $_" }; >+ } >+ >+ $template->param( borrowers => \@borrowers ); >+ $template->param( attributes_header => \@attributes_header ); >+ } >+ >+ } > >- $template->param( borrowers => \@borrowers ); > $template->param( errors => \@errors ); >+ >+ $op = "show_results"; >+ > } else { > > $template->param( patron_lists => [ GetPatronLists() ] ); > } > >-$template->param( >- op => $op, >-); >+$template->param( op => $op ); >+ > output_html_with_http_headers $input, $cookie, $template->output; >-exit; > > sub GetBorrowerInfos { > my ( %info ) = @_; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10612
:
19766
|
19767
|
21081
|
21444
|
21445
|
21446
|
22837
|
22838
|
28779
|
28780
|
36311
|
36313
|
36314
|
36315
|
41289
|
41363
|
41364
|
41365
|
46239
|
46279
|
46280
|
46834
|
47153
|
47224
|
47225
|
47226
|
47255
|
47259
|
47393
|
47394
|
47395
|
47396
|
47478
|
48833
|
48881
|
48888
|
48890
|
48891
|
48892
|
49596
|
49597
|
49607
|
49694
|
49740
|
49741
|
49766
|
49767
|
49768
|
49769
|
49770