|
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 %] |