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

(-)a/Koha/Patron/Discharge.pm (-10 / +40 lines)
Lines 39-46 Link Here
39
    my $patron = Koha::Patrons->find( $params->{borrowernumber} );
39
    my $patron = Koha::Patrons->find( $params->{borrowernumber} );
40
    return unless $patron;
40
    return unless $patron;
41
41
42
    my $has_pending_checkouts = $patron->checkouts->count;
42
    my $can_be_discharged = 1;
43
    return $has_pending_checkouts ? 0 : 1;
43
    my $problems          = {};
44
45
    my $checkouts = $patron->checkouts->count;
46
    if ($checkouts) {
47
        $can_be_discharged = 0;
48
        $problems->{checkouts} = $checkouts;
49
    }
50
51
    my $debt = $patron->account->outstanding_debits->total_outstanding;
52
    if ( $debt > 0 ) {
53
        $can_be_discharged = 0;
54
        $problems->{debt} = $debt;
55
    }
56
57
    return ( $can_be_discharged, $problems );
44
}
58
}
45
59
46
sub is_discharged {
60
sub is_discharged {
Lines 62-68 Link Here
62
    my ($params) = @_;
76
    my ($params) = @_;
63
    my $borrowernumber = $params->{borrowernumber};
77
    my $borrowernumber = $params->{borrowernumber};
64
    return unless $borrowernumber;
78
    return unless $borrowernumber;
65
    return unless can_be_discharged({ borrowernumber => $borrowernumber });
79
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
80
    return unless $can;
66
81
67
    my $rs = Koha::Database->new->schema->resultset('Discharge');
82
    my $rs = Koha::Database->new->schema->resultset('Discharge');
68
    return $rs->create({
83
    return $rs->create({
Lines 74-80 Link Here
74
sub discharge {
89
sub discharge {
75
    my ($params) = @_;
90
    my ($params) = @_;
76
    my $borrowernumber = $params->{borrowernumber};
91
    my $borrowernumber = $params->{borrowernumber};
77
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
92
93
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
94
    return unless $borrowernumber and $can;
78
95
79
    # Cancel reserves
96
    # Cancel reserves
80
    my $patron = Koha::Patrons->find( $borrowernumber );
97
    my $patron = Koha::Patrons->find( $borrowernumber );
81
-- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt  2025-05-20 17:40:38.293395967 +0300
98
++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt  2025-12-10 14:46:03.093599152 +0200
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 43-62 Link Here
43
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
44
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
44
                    [% ELSIF pending %]
45
                    [% ELSIF pending %]
45
                        <p>Your discharge will be available on this page within a few days.</p>
46
                        <p>Your discharge will be available on this page within a few days.</p>
46
                    [% ELSIF has_issues %]
47
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
48
                    [% ELSIF not messages %]
47
                    [% ELSIF not messages %]
49
                        <h2>What is a discharge?</h2>
48
                        <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>
49
                        <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>
50
                        <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 %]
51
                        [% IF 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>
54
                        [% ELSE %]
55
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
52
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
56
                                [% INCLUDE 'csrf-token.inc' %]
53
                                [% INCLUDE 'csrf-token.inc' %]
57
                                <input type="hidden" name="op" value="cud-request" />
54
                                <input type="hidden" name="op" value="cud-request" />
58
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
55
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
59
                            </form>
56
                            </form>
57
                        [% ELSE %]
58
                            [% IF failure %]
59
                                <p> There was an error during the discharge process </p>
60
                            [% END %]
61
                            <div class="alert alert-info"
62
                                >You cannot be discharged because:
63
                                <ul>
64
                                    [% IF discharge_problems.checkouts %]
65
                                        <li> You have [% discharge_problems.checkouts | html %] item(s) checked out. Please return your checked out items before reapplying. </li>
66
                                    [% END %]
67
68
                                    [% IF discharge_problems.debt %]
69
                                        <li> You have unpaid charges of [% discharge_problems.debt | $Price %]. Please pay your charges before reapplying. </li>
70
                                    [% END %]
71
                                </ul>
72
                            </div>
60
                        [% END %]
73
                        [% END %]
61
                    [% END %]
74
                    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt (-5 / +18 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 43-62 Link Here
43
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
44
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
44
                    [% ELSIF pending %]
45
                    [% ELSIF pending %]
45
                        <p>Your discharge will be available on this page within a few days.</p>
46
                        <p>Your discharge will be available on this page within a few days.</p>
46
                    [% ELSIF has_issues %]
47
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
48
                    [% ELSIF not messages %]
47
                    [% ELSIF not messages %]
49
                        <h2>What is a discharge?</h2>
48
                        <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>
49
                        <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>
50
                        <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 %]
51
                        [% IF 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>
54
                        [% ELSE %]
55
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
52
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
56
                                [% INCLUDE 'csrf-token.inc' %]
53
                                [% INCLUDE 'csrf-token.inc' %]
57
                                <input type="hidden" name="op" value="cud-request" />
54
                                <input type="hidden" name="op" value="cud-request" />
58
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
55
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
59
                            </form>
56
                            </form>
57
                        [% ELSE %]
58
                            [% IF failure %]
59
                                <p> There was an error during the discharge process </p>
60
                            [% END %]
61
                            <div class="alert alert-info"
62
                                >You cannot be discharged because:
63
                                <ul>
64
                                    [% IF discharge_problems.checkouts %]
65
                                        <li> You have [% discharge_problems.checkouts | html %] item(s) checked out. Please return your checked out items before reapplying. </li>
66
                                    [% END %]
67
68
                                    [% IF discharge_problems.debt %]
69
                                        <li> You have unpaid charges of [% discharge_problems.debt | $Price %]. Please pay your charges before reapplying. </li>
70
                                    [% END %]
71
                                </ul>
72
                            </div>
60
                        [% END %]
73
                        [% END %]
61
74
62
                    [% END %]
75
                    [% END %]
(-)a/members/discharge.pl (-9 / +13 lines)
Lines 61-69 Link Here
61
my $patron = Koha::Patrons->find( $borrowernumber );
61
my $patron = Koha::Patrons->find( $borrowernumber );
62
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
62
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
63
63
64
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({
64
my ( $can_be_discharged, $discharge_problems ) =
65
    borrowernumber => $borrowernumber
65
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
66
});
67
66
68
# Generating discharge if needed
67
# Generating discharge if needed
69
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
68
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
Lines 107-112 Link Here
107
$template->param(
106
$template->param(
108
    patron => $patron,
107
    patron => $patron,
109
    can_be_discharged => $can_be_discharged,
108
    can_be_discharged => $can_be_discharged,
109
    discharge_problems   => $discharge_problems,
110
    validated_discharges => \@validated_discharges,
110
    validated_discharges => \@validated_discharges,
111
);
111
);
112
112
113
-- a/opac/opac-discharge.pl      2025-05-20 17:40:45.151306301 +0300
113
++ b//opac/opac-discharge.pl     2025-12-10 14:59:49.806228119 +0200
Lines 43-52 Link Here
43
    type          => "opac",
43
    type          => "opac",
44
});
44
});
45
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $loggedinuser });
45
my ( $can_be_discharged, $discharge_problems ) =
46
if ($can_be_discharged == 0) {
46
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
47
    $template->param( has_checkouts => 1 );
47
my $patron = Koha::Patrons->find($loggedinuser);
48
}
48
49
$template->param(
50
    can_be_discharged  => $can_be_discharged,
51
    discharge_problems => $discharge_problems,
52
);
49
my $pending = Koha::Patron::Discharge::count({
53
my $pending = Koha::Patron::Discharge::count({
50
    borrowernumber => $loggedinuser,
54
    borrowernumber => $loggedinuser,
Lines 67-73 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 );
71
    }
75
    }
72
}
76
}
73
elsif ( $op eq 'get' ) {
77
elsif ( $op eq 'get' ) {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-4 / +43 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 => 32;
20
20
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
Lines 83-99 Link Here
83
);
83
);
84
84
85
AddIssue( $patron, $barcode );
85
AddIssue( $patron, $barcode );
86
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with issues cannot be discharged' );
86
my ( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
87
is( $can,                   0,     'A patron with issues cannot be discharged' );
88
is( $problems->{checkouts}, 1,     "Patron has checkouts" );
89
is( $problems->{debt},      undef, "Patron has no debt" );
87
90
88
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
91
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
89
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
92
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
90
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
93
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' );
94
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
92
95
96
# Discharge not possible with issues and fines
97
$patron->account->add_debit(
98
    {
99
        amount    => 0.1,
100
        interface => C4::Context->interface,
101
        type      => 'OVERDUE'
102
    }
103
);
104
105
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
106
is(
107
    $can, 0,
108
    'A patron with fines and checkouts cannot be discharged'
109
);
110
is( $problems->{checkouts}, 1,   "Patron has checkouts" );
111
is( $problems->{debt},      0.1, "Patron has debt" );
112
93
AddReturn( $barcode );
113
AddReturn( $barcode );
94
114
95
# Discharge possible without issue
115
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
96
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' );
116
is(
117
    $can, 0,
118
    'A patron with fines cannot be discharged'
119
);
120
is( $problems->{checkouts}, undef, "Patron has checkouts" );
121
is( $problems->{debt},      0.1,   "Patron has debt" );
122
123
$patron->account->pay(
124
    {
125
        amount => 0.1,
126
    }
127
);
128
129
# Discharge possible without issue or fine
130
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
131
 is(
132
    $can, 1,
133
    'A patron without issues or fines can be discharged'
134
 );
135
is( scalar keys %$problems, 0, "No dishcharge problems found" );
97
136
98
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
137
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
99
138

Return to bug 14250