View | Details | Raw Unified | Return to bug 14250
Collapse All | Expand All

(-)a/Koha/Patron/Discharge.pm (-7 / +19 lines)
Lines 38-50 sub can_be_discharged { Link Here
38
    my $patron = Koha::Patrons->find( $params->{borrowernumber} );
38
    my $patron = Koha::Patrons->find( $params->{borrowernumber} );
39
    return unless $patron;
39
    return unless $patron;
40
40
41
    my $has_pending_checkouts = $patron->checkouts->count;
41
    my $can_be_discharged = 1;
42
    return 0 if $has_pending_checkouts;
42
    my $problems          = {};
43
43
44
    my $has_debt = ( $patron->account->outstanding_debits->total_outstanding > 0 );
44
    my $checkouts = $patron->checkouts->count;
45
    return 0 if $has_debt;
45
    if ($checkouts) {
46
        $can_be_discharged = 0;
47
        $problems->{checkouts} = $checkouts;
48
    }
49
50
    my $debt = $patron->account->outstanding_debits->total_outstanding;
51
    if ( $debt > 0 ) {
52
        $can_be_discharged = 0;
53
        $problems->{debt} = $debt;
54
    }
46
55
47
    return 1;
56
    return ( $can_be_discharged, $problems );
48
}
57
}
49
58
50
sub is_discharged {
59
sub is_discharged {
Lines 66-72 sub request { Link Here
66
    my ($params) = @_;
75
    my ($params) = @_;
67
    my $borrowernumber = $params->{borrowernumber};
76
    my $borrowernumber = $params->{borrowernumber};
68
    return unless $borrowernumber;
77
    return unless $borrowernumber;
69
    return unless can_be_discharged( { borrowernumber => $borrowernumber } );
78
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
79
    return unless $can;
70
80
71
    my $rs = Koha::Database->new->schema->resultset('Discharge');
81
    my $rs = Koha::Database->new->schema->resultset('Discharge');
72
    return $rs->create(
82
    return $rs->create(
Lines 80-86 sub request { Link Here
80
sub discharge {
90
sub discharge {
81
    my ($params) = @_;
91
    my ($params) = @_;
82
    my $borrowernumber = $params->{borrowernumber};
92
    my $borrowernumber = $params->{borrowernumber};
83
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
93
94
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
95
    return unless $borrowernumber and $can;
84
96
85
    # Cancel reserves
97
    # Cancel reserves
86
    my $patron = Koha::Patrons->find($borrowernumber);
98
    my $patron = Koha::Patrons->find($borrowernumber);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-7 / +6 lines)
Lines 2-7 Link Here
2
[% USE Koha %]
2
[% USE Koha %]
3
[% USE Asset %]
3
[% USE Asset %]
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% USE Price %]
5
[% USE AuthorisedValues %]
6
[% USE AuthorisedValues %]
6
[% USE Branches %]
7
[% USE Branches %]
7
[% PROCESS 'i18n.inc' %]
8
[% PROCESS 'i18n.inc' %]
Lines 54-67 Link Here
54
    [% UNLESS can_be_discharged %]
55
    [% UNLESS can_be_discharged %]
55
        <p>Cannot edit discharge for following reasons: </p>
56
        <p>Cannot edit discharge for following reasons: </p>
56
        <ul>
57
        <ul>
57
            [% IF patron.checkouts.count %]
58
            [% IF discharge_problems.checkouts %]
58
                <li>They have checked out items</li>
59
                <li>They have [% discharge_problems.checkouts | html %] item(s) checked out</li>
59
            [% END %]
60
            [% END %]
60
            [% IF (patron.account.outstanding_debits.total_outstanding > 0) %]
61
61
                <li>They have unpaid fines</li>
62
            [% IF discharge_problems.debt %]
62
            [% END %]
63
                <li>They have unpaid fines totaling [% discharge_problems.debt | $Price %]</li>
63
            [% IF patron.checkouts.count == 0 and (patron.account.outstanding_debits.total_outstanding == 0) %]
64
                <li> Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
65
            [% END %]
64
            [% END %]
66
        </ul>
65
        </ul>
67
    [% ELSE %]
66
    [% ELSE %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt (-7 / +6 lines)
Lines 1-5 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Koha %]
2
[% USE Koha %]
3
[% USE Price %]
3
[% USE AdditionalContents %]
4
[% USE AdditionalContents %]
4
[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
5
[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
5
[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
6
[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
Lines 65-78 Link Here
65
                            <div class="alert alert-info"
66
                            <div class="alert alert-info"
66
                                >You cannot be discharged for following reasons:
67
                                >You cannot be discharged for following reasons:
67
                                <ul>
68
                                <ul>
68
                                    [% IF has_debt %]
69
                                    [% IF discharge_problems.checkouts %]
69
                                        <li> You have unpaid fines. Please pay your fines before reapplying.</li>
70
                                        <li> You have [% discharge_problems.checkouts | html %] item(s) checked out. Please return them before reapplying. </li>
70
                                    [% END %]
71
                                    [% END %]
71
                                    [% IF has_checkouts %]
72
72
                                        <li> You have checked out items. Please return them before reapplying.</li>
73
                                    [% IF discharge_problems.debt %]
73
                                    [% END %]
74
                                        <li> They have unpaid fines totaling [% discharge_problems.debt | $Price %]. Please pay your fines before reapplying. </li>
74
                                    [% IF !has_checkouts and !has_debt %]
75
                                        <li> Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
76
                                    [% END %]
75
                                    [% END %]
77
                                </ul>
76
                                </ul>
78
                            </div>
77
                            </div>
(-)a/members/discharge.pl (-6 / +3 lines)
Lines 65-76 output_and_exit_if_error( Link Here
65
    { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
65
    { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
66
);
66
);
67
67
68
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
68
my ( $can_be_discharged, $discharge_problems ) =
69
69
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
70
unless ($can_be_discharged) {
71
    my $has_checkout = $patron->checkouts->count;
72
    my $has_fine     = $patron->account->outstanding_debits->total_outstanding;
73
}
74
70
75
# Generating discharge if needed
71
# Generating discharge if needed
76
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
72
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
Lines 117-122 my @validated_discharges = Koha::Patron::Discharge::get_validated( Link Here
117
$template->param(
113
$template->param(
118
    patron               => $patron,
114
    patron               => $patron,
119
    can_be_discharged    => $can_be_discharged,
115
    can_be_discharged    => $can_be_discharged,
116
    discharge_problems   => $discharge_problems,
120
    validated_discharges => \@validated_discharges,
117
    validated_discharges => \@validated_discharges,
121
);
118
);
122
119
(-)a/opac/opac-discharge.pl (-4 / +8 lines)
Lines 45-58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
45
    }
45
    }
46
);
46
);
47
47
48
my $can_be_discharged     = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
48
my ( $can_be_discharged, $discharge_problems ) =
49
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
49
my $patron                = Koha::Patrons->find($loggedinuser);
50
my $patron                = Koha::Patrons->find($loggedinuser);
50
my $has_pending_checkouts = $patron->checkouts->count;
51
my $has_pending_checkouts = $patron->checkouts->count;
51
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
52
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
52
53
53
$template->param( can_be_discharged => $can_be_discharged );
54
$template->param(
54
$template->param( has_checkouts     => $has_pending_checkouts );
55
    can_be_discharged  => $can_be_discharged,
55
$template->param( has_debt          => $has_debt );
56
    discharge_problems => $discharge_problems,
57
    has_checkouts      => $has_pending_checkouts,
58
    has_debt           => $has_debt,
59
);
56
60
57
my $pending = Koha::Patron::Discharge::count(
61
my $pending = Koha::Patron::Discharge::count(
58
    {
62
    {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-9 / +16 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 25;
19
use Test::More tests => 32;
20
20
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
Lines 89-98 $builder->build_sample_item( Link Here
89
);
89
);
90
90
91
AddIssue( $patron, $barcode );
91
AddIssue( $patron, $barcode );
92
is(
92
my ( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
93
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
93
is( $can,                   0,     'A patron with issues cannot be discharged' );
94
    'A patron with issues cannot be discharged'
94
is( $problems->{checkouts}, 1,     "Patron has checkouts" );
95
);
95
is( $problems->{debt},      undef, "Patron has no debt" );
96
96
97
is(
97
is(
98
    Koha::Patron::Discharge::request( { borrowernumber => $patron->borrowernumber } ), undef,
98
    Koha::Patron::Discharge::request( { borrowernumber => $patron->borrowernumber } ), undef,
Lines 114-130 $patron->account->add_debit( Link Here
114
    }
114
    }
115
);
115
);
116
116
117
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
117
is(
118
is(
118
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
119
    $can, 0,
119
    'A patron with fines and checkouts cannot be discharged'
120
    'A patron with fines and checkouts cannot be discharged'
120
);
121
);
122
is( $problems->{checkouts}, 1,   "Patron has checkouts" );
123
is( $problems->{debt},      0.1, "Patron has debt" );
121
124
122
AddReturn($barcode);
125
AddReturn($barcode);
123
126
127
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
124
is(
128
is(
125
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
129
    $can, 0,
126
    'A patron with fines cannot be discharged'
130
    'A patron with fines cannot be discharged'
127
);
131
);
132
is( $problems->{checkouts}, undef, "Patron has checkouts" );
133
is( $problems->{debt},      0.1,   "Patron has debt" );
128
134
129
$patron->account->pay(
135
$patron->account->pay(
130
    {
136
    {
Lines 133-142 $patron->account->pay( Link Here
133
);
139
);
134
140
135
# Discharge possible without issue or fine
141
# Discharge possible without issue or fine
142
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
136
is(
143
is(
137
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
144
    $can, 1,
138
    'A patron without issues or fines can be discharged'
145
    'A patron without issues or fines can be discharged'
139
);
146
);
147
is( scalar keys %$problems, 0, "No dishcharge problems found" );
140
148
141
is( Koha::Patron::Discharge::generate_as_pdf, undef, "Confirm failure when lacking borrower number" );
149
is( Koha::Patron::Discharge::generate_as_pdf, undef, "Confirm failure when lacking borrower number" );
142
150
143
- 

Return to bug 14250