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

(-)a/Koha/Patron/Discharge.pm (-4 / +21 lines)
Lines 38-45 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 $has_pending_checkouts ? 0 : 1;
42
    my $problems          = {};
43
44
    my $checkouts = $patron->checkouts->count;
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
    }
55
56
    return ( $can_be_discharged, $problems );
43
}
57
}
44
58
45
sub is_discharged {
59
sub is_discharged {
Lines 61-67 sub request { Link Here
61
    my ($params) = @_;
75
    my ($params) = @_;
62
    my $borrowernumber = $params->{borrowernumber};
76
    my $borrowernumber = $params->{borrowernumber};
63
    return unless $borrowernumber;
77
    return unless $borrowernumber;
64
    return unless can_be_discharged( { borrowernumber => $borrowernumber } );
78
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
79
    return unless $can;
65
80
66
    my $rs = Koha::Database->new->schema->resultset('Discharge');
81
    my $rs = Koha::Database->new->schema->resultset('Discharge');
67
    return $rs->create(
82
    return $rs->create(
Lines 75-81 sub request { Link Here
75
sub discharge {
90
sub discharge {
76
    my ($params) = @_;
91
    my ($params) = @_;
77
    my $borrowernumber = $params->{borrowernumber};
92
    my $borrowernumber = $params->{borrowernumber};
78
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
93
94
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
95
    return unless $borrowernumber and $can;
79
96
80
    # Cancel reserves
97
    # Cancel reserves
81
    my $patron = Koha::Patrons->find($borrowernumber);
98
    my $patron = Koha::Patrons->find($borrowernumber);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-2 / +16 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 52-61 Link Here
52
        </div>
53
        </div>
53
    [% END %]
54
    [% END %]
54
    [% UNLESS can_be_discharged %]
55
    [% UNLESS can_be_discharged %]
55
        <p>Cannot edit discharge: the patron has checked out items.</p>
56
        <p>A discharge cannot be generated for this patron because:</p>
57
        <ul>
58
            [% IF discharge_problems.checkouts %]
59
                <li>The patron has [% discharge_problems.checkouts | html %] item(s) checked out</li>
60
            [% END %]
61
62
            [% IF discharge_problems.debt %]
63
                <li>The patron has unpaid charges of [% discharge_problems.debt | $Price %]</li>
64
            [% END %]
65
        </ul>
56
    [% ELSE %]
66
    [% ELSE %]
57
        [% IF patron.holds.count %]
67
        [% IF patron.holds.count %]
58
            <p>Patron has holds. They will be cancelled if the discharge is generated.</p>
68
            <p>The patron has holds. The holds will be cancelled if the discharge is generated.</p>
69
        [% END %]
70
71
        [% IF discharge_problems.debt %]
72
            <li>The patron has unpaid charges of [% discharge_problems.debt | $Price %]</li>
59
        [% END %]
73
        [% END %]
60
        <div class="btn-toolbar">
74
        <div class="btn-toolbar">
61
            <form method="post">
75
            <form method="post">
(-)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 41-48 Link Here
41
                        <p><a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></p>
42
                        <p><a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></p>
42
                    [% ELSIF pending %]
43
                    [% ELSIF pending %]
43
                        <p>Your discharge will be available on this page within a few days.</p>
44
                        <p>Your discharge will be available on this page within a few days.</p>
44
                    [% ELSIF has_issues %]
45
                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
46
                    [% ELSIF not messages %]
45
                    [% ELSIF not messages %]
47
                        <h2>What is a discharge?</h2>
46
                        <h2>What is a discharge?</h2>
48
                        <p
47
                        <p
Lines 50-63 Link Here
50
                            available on your reader account.</p
49
                            available on your reader account.</p
51
                        >
50
                        >
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>
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>
53
                        [% IF has_checkouts %]
52
                        [% IF 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>
55
                        [% ELSE %]
56
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
53
                            <form action="/cgi-bin/koha/opac-discharge.pl" method="post">
57
                                [% INCLUDE 'csrf-token.inc' %]
54
                                [% INCLUDE 'csrf-token.inc' %]
58
                                <input type="hidden" name="op" value="cud-request" />
55
                                <input type="hidden" name="op" value="cud-request" />
59
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
56
                                <button class="btn btn-primary" type="submit">Ask for a discharge</button>
60
                            </form>
57
                            </form>
58
                        [% ELSE %]
59
                            [% IF failure %]
60
                                <p> There was an error during the discharge process </p>
61
                            [% END %]
62
                            <div class="alert alert-info"
63
                                >You cannot be discharged because:
64
                                <ul>
65
                                    [% IF discharge_problems.checkouts %]
66
                                        <li> You have [% discharge_problems.checkouts | html %] item(s) checked out. Please return your checked out items before reapplying. </li>
67
                                    [% END %]
68
69
                                    [% IF discharge_problems.debt %]
70
                                        <li> You have unpaid charges of [% discharge_problems.debt | $Price %]. Please pay your charges before reapplying. </li>
71
                                    [% END %]
72
                                </ul>
73
                            </div>
61
                        [% END %]
74
                        [% END %]
62
                    [% END %]
75
                    [% END %]
63
                </div>
76
                </div>
(-)a/members/discharge.pl (-1 / +3 lines)
Lines 65-71 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
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
69
70
70
# Generating discharge if needed
71
# Generating discharge if needed
71
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 112-117 my @validated_discharges = Koha::Patron::Discharge::get_validated( Link Here
112
$template->param(
113
$template->param(
113
    patron               => $patron,
114
    patron               => $patron,
114
    can_be_discharged    => $can_be_discharged,
115
    can_be_discharged    => $can_be_discharged,
116
    discharge_problems   => $discharge_problems,
115
    validated_discharges => \@validated_discharges,
117
    validated_discharges => \@validated_discharges,
116
);
118
);
117
119
(-)a/opac/opac-discharge.pl (-5 / +10 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, $discharge_problems ) =
49
if ( $can_be_discharged == 0 ) {
49
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
50
    $template->param( has_checkouts => 1 );
50
my $patron                = Koha::Patrons->find($loggedinuser);
51
}
51
my $has_pending_checkouts = $patron->checkouts->count;
52
53
$template->param(
54
    can_be_discharged  => $can_be_discharged,
55
    discharge_problems => $discharge_problems,
56
);
52
57
53
my $pending = Koha::Patron::Discharge::count(
58
my $pending = Koha::Patron::Discharge::count(
54
    {
59
    {
Lines 73-79 if ( $op eq 'cud-request' ) { Link Here
73
    if ($success) {
78
    if ($success) {
74
        $template->param( success => 1 );
79
        $template->param( success => 1 );
75
    } else {
80
    } else {
76
        $template->param( has_issues => 1 );
81
        $template->param( failure => 1 );
77
    }
82
    }
78
} elsif ( $op eq 'get' ) {
83
} elsif ( $op eq 'get' ) {
79
    unless ($available) {
84
    unless ($available) {
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-9 / +41 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 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 105-117 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
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
118
is(
119
    $can, 0,
120
    'A patron with fines and checkouts cannot be discharged'
121
);
122
is( $problems->{checkouts}, 1,   "Patron has checkouts" );
123
is( $problems->{debt},      0.1, "Patron has debt" );
124
108
AddReturn($barcode);
125
AddReturn($barcode);
109
126
110
# Discharge possible without issue
127
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
128
is(
129
    $can, 0,
130
    'A patron with fines cannot be discharged'
131
);
132
is( $problems->{checkouts}, undef, "Patron has checkouts" );
133
is( $problems->{debt},      0.1,   "Patron has debt" );
134
135
$patron->account->pay(
136
    {
137
        amount => 0.1,
138
    }
139
);
140
141
# Discharge possible without issue or fine
142
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
111
is(
143
is(
112
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
144
    $can, 1,
113
    'A patron without issues can be discharged'
145
    'A patron without issues or fines can be discharged'
114
);
146
);
147
is( scalar keys %$problems, 0, "No dishcharge problems found" );
115
148
116
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" );
117
150
118
- 

Return to bug 14250