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

(-)a/Koha/Patron/Discharge.pm (-14 / +28 lines)
Lines 39-51 sub can_be_discharged { 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 0 if $has_pending_checkouts;
43
    my $problems          = {};
44
44
45
    my $has_debt = ( $patron->account->outstanding_debits->total_outstanding > 0 );
45
    my $checkouts = $patron->checkouts->count;
46
    return 0 if $has_debt;
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
    }
47
56
48
    return 1;
57
    return ( $can_be_discharged, $problems );
49
}
58
}
50
59
51
sub is_discharged {
60
sub is_discharged {
Lines 53-62 sub is_discharged { Link Here
53
    return unless $params->{borrowernumber};
62
    return unless $params->{borrowernumber};
54
    my $borrowernumber = $params->{borrowernumber};
63
    my $borrowernumber = $params->{borrowernumber};
55
64
56
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
65
    my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred;
57
    my @validated = get_validated({borrowernumber => $borrowernumber});
66
    my @validated  = get_validated( { borrowernumber => $borrowernumber } );
58
67
59
    if ($restricted && @validated) {
68
    if ( $restricted && @validated ) {
60
        return 1;
69
        return 1;
61
    } else {
70
    } else {
62
        return 0;
71
        return 0;
Lines 67-85 sub request { Link Here
67
    my ($params) = @_;
76
    my ($params) = @_;
68
    my $borrowernumber = $params->{borrowernumber};
77
    my $borrowernumber = $params->{borrowernumber};
69
    return unless $borrowernumber;
78
    return unless $borrowernumber;
70
    return unless can_be_discharged({ borrowernumber => $borrowernumber });
79
    my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
80
    return unless $can;
71
81
72
    my $rs = Koha::Database->new->schema->resultset('Discharge');
82
    my $rs = Koha::Database->new->schema->resultset('Discharge');
73
    return $rs->create({
83
    return $rs->create(
74
        borrower => $borrowernumber,
84
        {
75
        needed   => dt_from_string,
85
            borrower => $borrowernumber,
76
    });
86
            needed   => dt_from_string,
87
        }
88
    );
77
}
89
}
78
90
79
sub discharge {
91
sub discharge {
80
    my ($params) = @_;
92
    my ($params) = @_;
81
    my $borrowernumber = $params->{borrowernumber};
93
    my $borrowernumber = $params->{borrowernumber};
82
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
94
95
    my ( $can ) = can_be_discharged({ borrowernumber => $borrowernumber });
96
    return unless $borrowernumber and $can;
83
97
84
    # Cancel reserves
98
    # Cancel reserves
85
    my $patron = Koha::Patrons->find( $borrowernumber );
99
    my $patron = Koha::Patrons->find( $borrowernumber );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-9 / +8 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Price %]
4
[% USE AuthorisedValues %]
5
[% USE AuthorisedValues %]
5
[% USE Branches %]
6
[% USE Branches %]
6
[% PROCESS 'i18n.inc' %]
7
[% PROCESS 'i18n.inc' %]
Lines 54-68 Link Here
54
[% UNLESS can_be_discharged %]
55
[% UNLESS can_be_discharged %]
55
    <p>Cannot edit discharge for following reasons: </p>
56
    <p>Cannot edit discharge for following reasons: </p>
56
    <ul>
57
    <ul>
57
    [% IF patron.checkouts.count %]
58
        [% IF discharge_problems.checkouts %]
58
    <li>They have checked out items</li>
59
            <li>They have [% discharge_problems.checkouts | html %] item(s) checked out</li>
59
    [% END %]
60
        [% END %]
60
    [% IF (patron.account.outstanding_debits.total_outstanding > 0) %]
61
61
    <li>They have unpaid fines</li>
62
        [% IF discharge_problems.debt %]
62
    [% END %]
63
            <li>They have unpaid fines totaling [% discharge_problems.debt | $Price %]</li>
63
    [% IF patron.checkouts.count == 0 and (patron.account.outstanding_debits.total_outstanding == 0) %]
64
        [% END %]
64
    <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
65
    [% END %]
66
    </ul>
65
    </ul>
67
[% ELSE %]
66
[% ELSE %]
68
    [% IF patron.holds.count %]
67
    [% IF patron.holds.count %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt (-7 / +12 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 63-76 Link Here
63
                        [% UNLESS can_be_discharged %]
64
                        [% UNLESS can_be_discharged %]
64
                            <div class="alert alert-info">You cannot be discharged for following reasons:
65
                            <div class="alert alert-info">You cannot be discharged for following reasons:
65
                            <ul>
66
                            <ul>
66
                                [% IF has_debt %]
67
                                [% IF discharge_problems.checkouts %]
67
                                    <li> You have unpaid fines. Please pay your fines before reapplying.</li>
68
                                    <li>
69
                                        You have [% discharge_problems.checkouts | html %] item(s) checked out.
70
                                        Please return them before reapplying.
71
                                    </li>
68
                                [% END %]
72
                                [% END %]
69
                                [% IF has_checkouts %]
73
70
                                    <li> You have checked out items. Please return them before reapplying.</li>
74
                                [% IF discharge_problems.debt %]
71
                                [% END %]
75
                                    <li>
72
                                [% IF !has_checkouts and !has_debt %]
76
                                        They have unpaid fines totaling [% discharge_problems.debt | $Price %].
73
                                    <li>   Patron cannot be discharged for an unknown reason, please contact a librarian for more information</li>
77
                                        Please pay your fines before reapplying.
78
                                    </li>
74
                                [% END %]
79
                                [% END %]
75
                            </ul>
80
                            </ul>
76
                            </div>
81
                            </div>
(-)a/members/discharge.pl (-9 / +4 lines)
Lines 61-76 my $logged_in_user = Koha::Patrons->find( $loggedinuser ); 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 ) = Koha::Patron::Discharge::can_be_discharged({
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
74
# Generating discharge if needed
68
# Generating discharge if needed
75
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
69
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
76
    my $is_discharged = Koha::Patron::Discharge::is_discharged({
70
    my $is_discharged = Koha::Patron::Discharge::is_discharged({
Lines 111-118 my @validated_discharges = Koha::Patron::Discharge::get_validated({ Link Here
111
});
105
});
112
106
113
$template->param(
107
$template->param(
114
    patron => $patron,
108
    patron               => $patron,
115
    can_be_discharged => $can_be_discharged,
109
    can_be_discharged    => $can_be_discharged,
110
    discharge_problems   => $discharge_problems,
116
    validated_discharges => \@validated_discharges,
111
    validated_discharges => \@validated_discharges,
117
);
112
);
118
113
(-)a/opac/opac-discharge.pl (-4 / +8 lines)
Lines 43-56 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, $discharge_problems ) =
47
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
47
my $patron                = Koha::Patrons->find($loggedinuser);
48
my $patron                = Koha::Patrons->find($loggedinuser);
48
my $has_pending_checkouts = $patron->checkouts->count;
49
my $has_pending_checkouts = $patron->checkouts->count;
49
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
50
my $has_debt              = ( $patron->account->outstanding_debits->total_outstanding > 0 );
50
51
51
$template->param( can_be_discharged => $can_be_discharged );
52
$template->param(
52
$template->param( has_checkouts     => $has_pending_checkouts );
53
    can_be_discharged   => $can_be_discharged,
53
$template->param( has_debt          => $has_debt );
54
    discharge_problems => $discharge_problems,
55
    has_checkouts       => $has_pending_checkouts,
56
    has_debt            => $has_debt,
57
);
54
58
55
my $pending = Koha::Patron::Discharge::count({
59
my $pending = Koha::Patron::Discharge::count({
56
    borrowernumber => $loggedinuser,
60
    borrowernumber => $loggedinuser,
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-6 / +19 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 25;
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 84-90 $builder->build_sample_item( Link Here
84
);
84
);
85
85
86
AddIssue( $patron, $barcode );
86
AddIssue( $patron, $barcode );
87
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with issues cannot be discharged' );
87
my ( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber });
88
is( $can, 0, 'A patron with issues cannot be discharged' );
89
is( $problems->{checkouts}, 1, "Patron has checkouts" );
90
is( $problems->{debt}, undef, "Patron has no debt" );
88
91
89
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
92
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
90
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
93
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
Lines 100-113 $patron->account->add_debit( Link Here
100
    }
103
    }
101
);
104
);
102
105
106
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber });
103
is(
107
is(
104
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
108
    $can, 0,
105
    'A patron with fines and checkouts cannot be discharged'
109
    'A patron with fines and checkouts cannot be discharged'
106
);
110
);
111
is( $problems->{checkouts}, 1, "Patron has checkouts" );
112
is( $problems->{debt}, 0.1, "Patron has debt" );
107
113
108
AddReturn( $barcode );
114
AddReturn( $barcode );
109
115
110
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with fines cannot be discharged' );
116
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber });
117
is(
118
    $can, 0,
119
    'A patron with fines cannot be discharged'
120
);
121
is( $problems->{checkouts}, undef, "Patron has checkouts" );
122
is( $problems->{debt}, 0.1, "Patron has debt" );
111
123
112
124
113
$patron->account->pay(
125
$patron->account->pay(
Lines 117-126 $patron->account->pay( Link Here
117
);
129
);
118
130
119
# Discharge possible without issue or fine
131
# Discharge possible without issue or fine
132
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber });
120
is(
133
is(
121
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
134
    $can, 1,
122
    'A patron without issues or fines can be discharged'
135
    'A patron without issues or fines can be discharged'
123
);
136
);
137
is( scalar keys %$problems, 0, "No dishcharge problems found" );
124
138
125
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
139
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
126
140
127
- 

Return to bug 14250