@@ -, +, @@ - Has a guarantee - Is the system-defined anonymous patron - Has outstanding debits - Has items checked out to delete the patron: - Has outstanding credit - Has holds placed - Has pending suggestions --- .../prog/en/modules/members/deletemem.tt | 20 ++++----- members/deletemem.pl | 41 ++++++++++--------- 2 files changed, 30 insertions(+), 31 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt @@ -33,17 +33,15 @@
[% INCLUDE 'members-toolbar.inc' %] - [% IF ItemsOnIssues || debits || is_guarantor %] + [% IF safe_to_delete != 'ok' %]

Cannot delete patron

@@ -51,10 +49,10 @@ [% ELSIF op == 'delete_confirm' and patron %] [%# TODO add "patron does not exist" unless patron %]
- [% IF ItemsOnHold or credits or pending_suggestions > 0 %] + [% IF holds_count or credits or pending_suggestions > 0 %]
    - [% IF ItemsOnHold %] -
  • Patron has [% ItemsOnHold | html %] hold(s). Deleting patron cancels all their holds.
  • + [% IF holds_count %] +
  • Patron has [% holds_count | html %] hold(s). Deleting patron cancels all their holds.
  • [% END %] [% IF credits %]
  • Patron has a [% credits | $Price %] credit.
  • --- a/members/deletemem.pl +++ a/members/deletemem.pl @@ -45,8 +45,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -#print $input->header; -my $member = $input->param('member'); +my $member = $input->param('member'); #Do not delete yourself... if ( $loggedinuser == $member ) { @@ -58,9 +57,6 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser ); my $patron = Koha::Patrons->find( $member ); output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); -my $debits = $patron->account->outstanding_debits->total_outstanding; -my $credits = abs $patron->account->outstanding_credits->total_outstanding; -my $countissues = $patron->checkouts->count; my $userenv = C4::Context->userenv; if ($patron->category->category_type eq "S") { @@ -85,17 +81,14 @@ if (C4::Context->preference("IndependentBranches")) { } } -if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) { - if ( $patron->id eq $anonymous_patron ) { - print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_ANONYMOUS_PATRON"); - exit 0; # Exit without error - } +my $safe_to_delete = $patron->safe_to_delete; + +if ( $safe_to_delete eq 'is_anonymous_patron' ) { + print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_ANONYMOUS_PATRON"); + exit 0; # Exit without error } my $op = $input->param('op') || 'delete_confirm'; -my $dbh = C4::Context->dbh; -my $is_guarantor = $patron->guarantee_relationships->count; -my $countholds = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE borrowernumber=?", undef, $member); # Add warning if patron has pending suggestions $template->param( @@ -106,16 +99,24 @@ $template->param( } ); +my $account = $patron->account; +my $credits = abs $account->outstanding_credits->total_outstanding; + $template->param( - patron => $patron, - ItemsOnIssues => $countissues, - debits => $debits, - credits => $credits, - is_guarantor => $is_guarantor, - ItemsOnHold => $countholds, + credits => $credits, + holds_count => $patron->holds->count, + patron => $patron, + safe_to_delete => $safe_to_delete, ); -if ( $op eq 'delete_confirm' or $countissues > 0 or $debits or $is_guarantor ) { +if ( $safe_to_delete eq 'has_checkouts' ) { + $template->param( checkouts_count => $patron->checkouts->count, ); +} +elsif ( $safe_to_delete eq 'has_debt' ) { + $template->param( charges => $account->outstanding_debits->total_outstanding, ); +} + +if ( $op eq 'delete_confirm' or $safe_to_delete ne 'ok' ) { $template->param( op => 'delete_confirm', csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }), --