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

(-)a/Koha/Patron/Discharge.pm (-1 / +6 lines)
Lines 39-45 sub can_be_discharged { Link Here
39
    return unless $patron;
39
    return unless $patron;
40
40
41
    my $has_pending_checkouts = $patron->checkouts->count;
41
    my $has_pending_checkouts = $patron->checkouts->count;
42
    return $has_pending_checkouts ? 0 : 1;
42
    return 0 if $has_pending_checkouts;
43
44
    my $has_debt = ( $patron->account->outstanding_debits->total_outstanding > 0 );
45
    return 0 if $has_debt;
46
47
    return 1;
43
}
48
}
44
49
45
sub is_discharged {
50
sub is_discharged {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-1 / +12 lines)
Lines 52-58 Link Here
52
        </div>
52
        </div>
53
    [% END %]
53
    [% END %]
54
    [% UNLESS can_be_discharged %]
54
    [% UNLESS can_be_discharged %]
55
        <p>Cannot edit discharge: the patron has checked out items.</p>
55
        <p>Cannot edit discharge for following reasons: </p>
56
        <ul>
57
            [% IF patron.checkouts.count %]
58
                <li>They have checked out items</li>
59
            [% END %]
60
            [% IF (patron.account.outstanding_debits.total_outstanding > 0) %]
61
                <li>They have unpaid fines</li>
62
            [% END %]
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 %]
66
        </ul>
56
    [% ELSE %]
67
    [% ELSE %]
57
        [% IF patron.holds.count %]
68
        [% IF patron.holds.count %]
58
            <p>Patron has holds. They will be cancelled if the discharge is generated.</p>
69
            <p>Patron has holds. They will be cancelled if the discharge is generated.</p>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt (-3 / +27 lines)
Lines 41-48 Link Here
41
                        <p><a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></p>
41
                        <p><a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></p>
42
                    [% ELSIF pending %]
42
                    [% ELSIF pending %]
43
                        <p>Your discharge will be available on this page within a few days.</p>
43
                        <p>Your discharge will be available on this page within a few days.</p>
44
                    [% ELSIF has_issues %]
44
                    [% ELSIF failure %]
45
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
45
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
46
                        <ul>
47
                            [% IF has_debt %]
48
                                <li> You have unpaid fines. Please pay your fines before reapplying.</li>
49
                            [% END %]
50
                            [% IF has_issues %]
51
                                <li> You have checked out items. Please return them before reapplying.</li>
52
                            [% END %]
53
                            [% IF !has_issue and !has_debt %]
54
                                <li> Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
55
                            [% END %]
56
                        </ul>
46
                    [% ELSIF not messages %]
57
                    [% ELSIF not messages %]
47
                        <h2>What is a discharge?</h2>
58
                        <h2>What is a discharge?</h2>
48
                        <p
59
                        <p
Lines 50-57 Link Here
50
                            available on your reader account.</p
61
                            available on your reader account.</p
51
                        >
62
                        >
52
                        <p><strong>Warning</strong>: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.</p>
63
                        <p><strong>Warning</strong>: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.</p>
53
                        [% IF has_checkouts %]
64
                        [% UNLESS can_be_discharged %]
54
                            <div class="alert alert-info">You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</div>
65
                            <div class="alert alert-info"
66
                                >You cannot be discharged for following reasons:
67
                                <ul>
68
                                    [% IF has_debt %]
69
                                        <li> You have unpaid fines. Please pay your fines before reapplying.</li>
70
                                    [% END %]
71
                                    [% IF has_checkouts %]
72
                                        <li> You have checked out items. Please return them before reapplying.</li>
73
                                    [% END %]
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 %]
77
                                </ul>
78
                            </div>
55
                        [% ELSE %]
79
                        [% ELSE %]
56
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
80
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
57
                                [% INCLUDE 'csrf-token.inc' %]
81
                                [% INCLUDE 'csrf-token.inc' %]
(-)a/members/discharge.pl (+5 lines)
Lines 67-72 output_and_exit_if_error( Link Here
67
67
68
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
68
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
69
69
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
# Generating discharge if needed
75
# Generating discharge if needed
71
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
76
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
72
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
77
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
(-)a/opac/opac-discharge.pl (-5 / +11 lines)
Lines 45-54 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     = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
49
if ( $can_be_discharged == 0 ) {
49
my $patron                = Koha::Patrons->find($loggedinuser);
50
    $template->param( has_checkouts => 1 );
50
my $has_pending_checkouts = $patron->checkouts->count;
51
}
51
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
52
53
$template->param( can_be_discharged => $can_be_discharged );
54
$template->param( has_checkouts     => $has_pending_checkouts );
55
$template->param( has_debt          => $has_debt );
52
56
53
my $pending = Koha::Patron::Discharge::count(
57
my $pending = Koha::Patron::Discharge::count(
54
    {
58
    {
Lines 73-79 if ( $op eq 'cud-request' ) { Link Here
73
    if ($success) {
77
    if ($success) {
74
        $template->param( success => 1 );
78
        $template->param( success => 1 );
75
    } else {
79
    } else {
76
        $template->param( has_issues => 1 );
80
        $template->param( failure    => 1 );
81
        $template->param( has_issues => $has_pending_checkouts );
82
        $template->param( has_debt   => $has_debt );
77
    }
83
    }
78
} elsif ( $op eq 'get' ) {
84
} elsif ( $op eq 'get' ) {
79
    unless ($available) {
85
    unless ($available) {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-4 / +28 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 23;
19
use Test::More tests => 25;
20
20
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
Lines 105-116 is( Link Here
105
is_deeply( [Koha::Patron::Discharge::get_pendings],  [], 'There is no pending discharge request' );
105
is_deeply( [Koha::Patron::Discharge::get_pendings],  [], 'There is no pending discharge request' );
106
is_deeply( [Koha::Patron::Discharge::get_validated], [], 'There is no validated discharge' );
106
is_deeply( [Koha::Patron::Discharge::get_validated], [], 'There is no validated discharge' );
107
107
108
# Discharge not possible with issues and fines
109
$patron->account->add_debit(
110
    {
111
        amount    => 0.1,
112
        interface => C4::Context->interface,
113
        type      => 'OVERDUE'
114
    }
115
);
116
117
is(
118
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
119
    'A patron with fines and checkouts cannot be discharged'
120
);
121
108
AddReturn($barcode);
122
AddReturn($barcode);
109
123
110
# Discharge possible without issue
124
is(
125
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
126
    'A patron with fines cannot be discharged'
127
);
128
129
$patron->account->pay(
130
    {
131
        amount => 0.1,
132
    }
133
);
134
135
# Discharge possible without issue or fine
111
is(
136
is(
112
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
137
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
113
    'A patron without issues can be discharged'
138
    'A patron without issues or fines can be discharged'
114
);
139
);
115
140
116
is( Koha::Patron::Discharge::generate_as_pdf, undef, "Confirm failure when lacking borrower number" );
141
is( Koha::Patron::Discharge::generate_as_pdf, undef, "Confirm failure when lacking borrower number" );
117
- 

Return to bug 14250