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 / +10 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
    [% ELSIF (patron.account.outstanding_debits.total_outstanding > 0) %]
60
    <li>They have unpaid fines</li>
61
    [% ELSE %]
62
    <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
63
    [% END %]
64
    </ul>
56
[% ELSE %]
65
[% ELSE %]
57
    [% IF patron.holds.count %]
66
    [% IF patron.holds.count %]
58
        <p>Patron has holds. They will be cancelled if the discharge is generated.</p>
67
        <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 / +22 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
                        [% ELSIF has_issues %]
52
                            <li> You have checked out items. Please return them before reapplying.</li>
53
                        [% ELSE %]
54
                            <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
55
                        [% END %]
56
                        </ul>
48
                    [% ELSIF not messages %]
57
                    [% ELSIF not messages %]
49
                        <h2>What is a discharge?</h2>
58
                        <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>
59
                        <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>
60
                        <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 %]
61
                        [% 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>
62
                            <div class="alert alert-info">You cannot be discharged for following reasons:
63
                            <ul>
64
                                [% IF has_debt %]
65
                                    <li> You have unpaid fines. Please pay your fines before reapplying.</li>
66
                                [% ELSIF has_checkouts %]
67
                                    <li> You have checked out items. Please return them before reapplying.</li>
68
                                [% ELSE %]
69
                                    <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
70
                                [% END %]
71
                            </ul>
72
                            </div>
54
                        [% ELSE %]
73
                        [% ELSE %]
55
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
74
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
56
                                [% INCLUDE 'csrf-token.inc' %]
75
                                [% 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 (-4 / +10 lines)
Lines 44-52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ Link Here
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 / +22 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
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with fines and checkouts cannot be discharged' );
102
93
AddReturn( $barcode );
103
AddReturn( $barcode );
94
104
95
# Discharge possible without issue
105
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' );
106
107
108
$patron->account->pay(
109
    {
110
        amount => 0.1,
111
    }
112
);
113
114
# Discharge possible without issue or fine
115
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues or fines can be discharged' );
97
116
98
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
117
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
99
118
100
- 

Return to bug 14250