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

(-)a/Koha/Patron/Discharge.pm (-1 / +6 lines)
Lines 40-46 sub can_be_discharged { Link Here
40
    return unless $patron;
40
    return unless $patron;
41
41
42
    my $has_pending_checkouts = $patron->checkouts->count;
42
    my $has_pending_checkouts = $patron->checkouts->count;
43
    return $has_pending_checkouts ? 0 : 1;
43
    return 0 if $has_pending_checkouts;
44
45
    my $has_debt = ( $patron->account->outstanding_debits->total_outstanding > 0 );
46
    return 0 if $has_debt;
47
48
    return 1;
44
}
49
}
45
50
46
sub is_discharged {
51
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 / +26 lines)
Lines 43-56 Link Here
43
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
43
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
44
                    [% ELSIF pending %]
44
                    [% ELSIF pending %]
45
                        <p>Your discharge will be available on this page within a few days.</p>
45
                        <p>Your discharge will be available on this page within a few days.</p>
46
                    [% ELSIF has_issues %]
46
                    [% ELSIF failure %]
47
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
47
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
48
                        <ul>
49
                        [% IF has_debt %]
50
                            <li> You have unpaid fines. Please pay your fines before reapplying.</li>
51
                        [% END %]
52
                        [% IF has_issues %]
53
                            <li> You have checked out items. Please return them before reapplying.</li>
54
                        [% END %]
55
                        [% IF !has_issue and !has_debt %]
56
                            <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
57
                        [% END %]
58
                        </ul>
48
                    [% ELSIF not messages %]
59
                    [% ELSIF not messages %]
49
                        <h2>What is a discharge?</h2>
60
                        <h2>What is a discharge?</h2>
50
                        <p>This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.</p>
61
                        <p>This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.</p>
51
                        <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>
62
                        <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>
52
                        [% IF has_checkouts %]
63
                        [% UNLESS can_be_discharged %]
53
                            <div class="alert alert-info">You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</div>
64
                            <div class="alert alert-info">You cannot be discharged for following reasons:
65
                            <ul>
66
                                [% IF has_debt %]
67
                                    <li> You have unpaid fines. Please pay your fines before reapplying.</li>
68
                                [% END %]
69
                                [% IF has_checkouts %]
70
                                    <li> You have checked out items. Please return them before reapplying.</li>
71
                                [% END %]
72
                                [% IF !has_checkouts and !has_debt %]
73
                                    <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
74
                                [% END %]
75
                            </ul>
76
                            </div>
54
                        [% ELSE %]
77
                        [% ELSE %]
55
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
78
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
56
                                [% INCLUDE 'csrf-token.inc' %]
79
                                [% INCLUDE 'csrf-token.inc' %]
(-)a/members/discharge.pl (+6 lines)
Lines 65-70 my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ Link Here
65
    borrowernumber => $borrowernumber
65
    borrowernumber => $borrowernumber
66
});
66
});
67
67
68
69
unless ($can_be_discharged) {
70
    my $has_checkout = $patron->checkouts->count;
71
    my $has_fine     = $patron->account->outstanding_debits->total_outstanding;
72
}
73
68
# Generating discharge if needed
74
# Generating discharge if needed
69
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
75
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
70
    my $is_discharged = Koha::Patron::Discharge::is_discharged({
76
    my $is_discharged = Koha::Patron::Discharge::is_discharged({
(-)a/opac/opac-discharge.pl (-5 / +11 lines)
Lines 43-52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ Link Here
43
    type          => "opac",
43
    type          => "opac",
44
});
44
});
45
45
46
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $loggedinuser });
46
my $can_be_discharged     = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
47
if ($can_be_discharged == 0) {
47
my $patron                = Koha::Patrons->find($loggedinuser);
48
    $template->param( has_checkouts => 1 );
48
my $has_pending_checkouts = $patron->checkouts->count;
49
}
49
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
50
51
$template->param( can_be_discharged => $can_be_discharged );
52
$template->param( has_checkouts     => $has_pending_checkouts );
53
$template->param( has_debt          => $has_debt );
50
54
51
my $pending = Koha::Patron::Discharge::count({
55
my $pending = Koha::Patron::Discharge::count({
52
    borrowernumber => $loggedinuser,
56
    borrowernumber => $loggedinuser,
Lines 67-73 if ( $op eq 'cud-request' ) { Link Here
67
        $template->param( success => 1 );
71
        $template->param( success => 1 );
68
    }
72
    }
69
    else {
73
    else {
70
        $template->param( has_issues => 1 );
74
        $template->param( failure => 1 );
75
        $template->param( has_issues => $has_pending_checkouts );
76
        $template->param( has_debt => $has_debt );
71
    }
77
    }
72
}
78
}
73
elsif ( $op eq 'get' ) {
79
elsif ( $op eq 'get' ) {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-4 / +29 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 90-99 is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumb Link Here
90
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
90
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
91
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
91
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
92
92
93
# Discharge not possible with issues and fines
94
$patron->account->add_debit(
95
    {
96
        amount    => 0.1,
97
        interface => C4::Context->interface,
98
        type      => 'OVERDUE'
99
    }
100
);
101
102
is(
103
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
104
    'A patron with fines and checkouts cannot be discharged'
105
);
106
93
AddReturn( $barcode );
107
AddReturn( $barcode );
94
108
95
# Discharge possible without issue
109
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with fines cannot be discharged' );
96
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' );
110
111
112
$patron->account->pay(
113
    {
114
        amount => 0.1,
115
    }
116
);
117
118
# Discharge possible without issue or fine
119
is(
120
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
121
    'A patron without issues or fines can be discharged'
122
);
97
123
98
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
124
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
99
125
100
- 

Return to bug 14250