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

(-)a/Koha/Patron/Discharge.pm (-4 / +54 lines)
Lines 95-104 sub is_discharged { Link Here
95
    return unless $params->{borrowernumber};
95
    return unless $params->{borrowernumber};
96
    my $borrowernumber = $params->{borrowernumber};
96
    my $borrowernumber = $params->{borrowernumber};
97
97
98
    my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred;
98
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
99
    my @validated  = get_validated( { borrowernumber => $borrowernumber } );
99
    my @validated = get_validated({borrowernumber => $borrowernumber});
100
100
101
    if ( $restricted && @validated ) {
101
    if ($restricted && @validated) {
102
        return 1;
102
        return 1;
103
    } else {
103
    } else {
104
        return 0;
104
        return 0;
Lines 113-118 Place a discharge request on a given borrower after checking the borrower has th Link Here
113
113
114
=cut
114
=cut
115
115
116
sub is_discharged {
117
    my ($params) = @_;
118
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
119
        {
120
            borrower  => $params->{borrowernumber},
121
            validated => { "not" => undef },
122
            cancelled => undef,
123
        }
124
    );
125
    return $discharge->count > 0;
126
}
127
116
sub request {
128
sub request {
117
    my ($params) = @_;
129
    my ($params) = @_;
118
    my $borrowernumber = $params->{borrowernumber};
130
    my $borrowernumber = $params->{borrowernumber};
Lines 137-142 Place a discharge request on a given borrower, if a discharge was requested, upd Link Here
137
149
138
=cut
150
=cut
139
151
152
sub is_cancelled {
153
    my ($params) = @_;
154
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
155
        {
156
            discharge_id => $params->{discharge_id},
157
            cancelled    => { "not" => undef },
158
        }
159
    );
160
    return $discharge->count > 0;
161
}
162
163
sub cancel {
164
    my ($params) = @_;
165
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
166
        {
167
            discharge_id => $params->{discharge_id},
168
        }
169
    );
170
    $discharge->update(
171
        {
172
            cancelled           => dt_from_string,
173
            cancellation_reason => $params->{cancellation_reason}
174
        }
175
    );
176
    Koha::Patron::Debarments::DelUniqueDebarment(
177
        {
178
            borrowernumber => $params->{borrowernumber},
179
            type           => "DISCHARGE",
180
        }
181
    );
182
}
183
140
sub discharge {
184
sub discharge {
141
    my ($params) = @_;
185
    my ($params) = @_;
142
    my $borrowernumber = $params->{borrowernumber};
186
    my $borrowernumber = $params->{borrowernumber};
Lines 163-169 sub discharge { Link Here
163
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
207
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
164
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
208
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
165
    if ( $discharge->count > 0 ) {
209
    if ( $discharge->count > 0 ) {
166
        $discharge->update( { validated => dt_from_string } );
210
        $discharge->update(
211
            {
212
                validated           => dt_from_string,
213
                cancelled           => undef,
214
                cancellation_reason => undef
215
            }
216
        );
167
    } else {
217
    } else {
168
        $rs->create(
218
        $rs->create(
169
            {
219
            {
(-)a/installer/data/mysql/atomicupdate/bug_37344.pl (+43 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "37344",
6
    description => "Add columns cancellation_reason and cancelled to discharge",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        unless ( column_exists( 'discharges', 'cancellation_reason' ) ) {
13
            $dbh->do(
14
                q{
15
                ALTER TABLE discharges
16
                ADD COLUMN cancelled timestamp NULL default NULL,
17
                ADD COLUMN cancellation_reason VARCHAR(80) NULL default NULL ;
18
            }
19
            );
20
21
            $dbh->do(
22
                q{
23
                    INSERT IGNORE INTO authorised_value_categories (category_name) VALUES
24
                    ('DISCHARGE_CANCELLATION')
25
                }
26
            );
27
            $dbh->do(
28
                q{
29
                    INSERT IGNORE INTO authorised_values (category, authorised_value, lib) VALUES
30
                    ('DISCHARGE_CANCELLATION','PATRON_MISTAKE', 'The patron asked for a discharge by mistake.'),
31
                    ('DISCHARGE_CANCELLATION','PATRON_STILL_NEEDS_ACCOUNT','A discharge was required, however the patron still needs to use their account.')
32
                }
33
            );
34
35
            # Print useful stuff here
36
            # tables
37
            say $out "Added column 'discharges.cancelled'";
38
            say $out "Added column 'discharges.cancellation_reason'";
39
            say $out "Added authorized value category DISCHARGE_CANCELLATION";
40
            say $out "Added authorized values PATRON_MISTAKE and PATRON_STILL_NEEDS_ACCOUNT";
41
        }
42
    },
43
};
(-)a/installer/data/mysql/en/optional/auth_val.yml (+10 lines)
Lines 333-335 tables: Link Here
333
        - category: "AR_CANCELLATION"
333
        - category: "AR_CANCELLATION"
334
          authorised_value: "OPAC"
334
          authorised_value: "OPAC"
335
          lib: "Cancelled from the OPAC user page"
335
          lib: "Cancelled from the OPAC user page"
336
337
338
        # Disharge cancellations
339
        - category: "DISCHARGE_CANCELLATION"
340
          authorised_value: "PATRON_MISTAKE"
341
          lib: "Patron asked a discharge by mistake"
342
343
        - category: "DISCHARGE_CANCELLATION"
344
          authorised_value: "PATRON_STILL_NEEDS_ACCOUNT"
345
          lib: "Administration required a discharge however the borrower still needs to use their account"
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 2873-2878 CREATE TABLE `discharges` ( Link Here
2873
  `borrower` int(11) DEFAULT NULL,
2873
  `borrower` int(11) DEFAULT NULL,
2874
  `needed` timestamp NULL DEFAULT NULL,
2874
  `needed` timestamp NULL DEFAULT NULL,
2875
  `validated` timestamp NULL DEFAULT NULL,
2875
  `validated` timestamp NULL DEFAULT NULL,
2876
  `cancelled` timestamp DEFAULT NULL,
2877
  `cancellation_reason`varchar(80) DEFAULT NULL COMMENT 'authorised value CANCELLATION_REASON',
2876
  PRIMARY KEY (`discharge_id`),
2878
  PRIMARY KEY (`discharge_id`),
2877
  KEY `borrower_discharges_ibfk1` (`borrower`),
2879
  KEY `borrower_discharges_ibfk1` (`borrower`),
2878
  CONSTRAINT `borrower_discharges_ibfk1` FOREIGN KEY (`borrower`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2880
  CONSTRAINT `borrower_discharges_ibfk1` FOREIGN KEY (`borrower`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
(-)a/installer/data/mysql/mandatory/auth_val_cat.sql (+6 lines)
Lines 106-108 VALUES Link Here
106
INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
106
INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
107
VALUES
107
VALUES
108
    ('BOOKING_CANCELLATION', 1);
108
    ('BOOKING_CANCELLATION', 1);
109
110
111
-- For discharges
112
INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
113
VALUES
114
    ('DISCHARGE_CANCELLATION', 1);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (+2 lines)
Lines 516-521 Link Here
516
        <p>ILL request status aliases used by the interlibrary loans module</p>
516
        <p>ILL request status aliases used by the interlibrary loans module</p>
517
    [% CASE 'AR_CANCELLATION' %]
517
    [% CASE 'AR_CANCELLATION' %]
518
        <p>Reasons why an article request might have been cancelled</p>
518
        <p>Reasons why an article request might have been cancelled</p>
519
    [% CASE 'DISCHARGE_CANCELLATION' %]
520
        <p>Reasons for cancelling a discharge</p>
519
    [% CASE 'HSBND_FREQ' %]
521
    [% CASE 'HSBND_FREQ' %]
520
        <p>Frequencies used by the housebound module. They are displayed on the housebound tab in the patron account in staff.</p>
522
        <p>Frequencies used by the housebound module. They are displayed on the housebound tab in the patron account in staff.</p>
521
    [% CASE 'ITEMTYPECAT' %]
523
    [% CASE 'ITEMTYPECAT' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-1 / +69 lines)
Lines 86-91 Link Here
86
                    <tr>
86
                    <tr>
87
                        <th>Requested</th>
87
                        <th>Requested</th>
88
                        <th>Validated</th>
88
                        <th>Validated</th>
89
                        <th>Cancelled</th>
90
                        <th>Reason cancelled</th>
91
                        <th>Cancel</th>
89
                    </tr>
92
                    </tr>
90
                </thead>
93
                </thead>
91
                <tbody>
94
                <tbody>
Lines 93-99 Link Here
93
                        <tr>
96
                        <tr>
94
                            <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
97
                            <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
95
                            <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
98
                            <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
96
                        </tr>
99
                            <td>[% d.cancelled | $KohaDates with_hours = 1 %]</td>
100
                            <td>[% d.cancellation_reason | html %]</td>
101
                            <td>
102
                                [% IF d.cancelled %]
103
                                    <i> Cancelled </i>
104
                                [% ELSE %]
105
                                    <a
106
                                        class="cancel-discharge delete btn btn-default btn-xs"
107
                                        data-borrowernumber="[% patron.borrowernumber | html %]"
108
                                        data-bs-target="#cancelDischargeModal"
109
                                        data-bs-toggle="modal"
110
                                        data-discharge_id="[% d.discharge_id | html %]"
111
                                    >
112
                                        <i class="fa fa-trash-can"></i>
113
                                        Cancel
114
                                    </a>
115
                                [% END %]
116
                            </td></tr
117
                        >
97
                    [% END %]
118
                    [% END %]
98
                </tbody>
119
                </tbody>
99
            </table>
120
            </table>
Lines 101-109 Link Here
101
    [% END %]
122
    [% END %]
102
[% END %]
123
[% END %]
103
124
125
<div class="modal fade" id="cancelDischargeModal" tabindex="-1" aria-labelledby="cancelDischargeModal" aria-hidden="true">
126
    <div class="modal-dialog modal-lg">
127
        <div class="modal-content">
128
            <div class="modal-header">
129
                <h1 class="modal-title" id="cancelModalLabel">Confirm cancellation</h1>
130
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
131
            </div>
132
            <form id="cancel_modal_form" method="post" action="discharge.pl">
133
                <div class="modal-body">
134
                    [% INCLUDE 'csrf-token.inc' %]
135
                    <input name="op" type="hidden" value="cud-cancel-discharge" />
136
                    <div id="cancel_discharge_alert" class="alert alert-danger" style="display:none;"></div>
137
                    <fieldset class="action">
138
                        <p>Are you sure you want to cancel this discharge? The patron will be able to check out items again.</p>
139
                        [% SET discharge_cancellation_reasons = AuthorisedValues.GetAuthValueDropbox('DISCHARGE_CANCELLATION') %]
140
                        [% IF discharge_cancellation_reasons.count %]
141
                            <label for="cancellation-reason">Cancellation reason: </label>
142
                            <select class="cancellation-reason" name="cancellation-reason" id="modal-cancellation-reason">
143
                                [% FOREACH reason IN discharge_cancellation_reasons %]
144
                                    <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
145
                                [% END %]
146
                            </select>
147
                        [% ELSE %]
148
                            <div class="alert alert-warning audio-alert-warning"> You must define at least one authorized value for the category DISCHARGE_CANCELLATION </div>
149
                        [% END %]
150
                    </fieldset>
151
                </div>
152
                <div class="modal-footer">
153
                    <input id="cancelModalConfirmBtn" type="submit" class="btn btn-danger" value="Confirm cancellation" />
154
                    <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
155
                </div>
156
            </form>
157
        </div>
158
    </div>
159
</div>
160
104
[% MACRO jsinclude BLOCK %]
161
[% MACRO jsinclude BLOCK %]
105
    [% INCLUDE 'str/members-menu.inc' %]
162
    [% INCLUDE 'str/members-menu.inc' %]
106
    [% Asset.js("js/members-menu.js") | $raw %]
163
    [% Asset.js("js/members-menu.js") | $raw %]
164
    <script>
165
        $(".cancel-discharge").on("click", function (e) {
166
            e.preventDefault;
167
            cancel_link = $(this);
168
            let discharge_id = cancel_link.data("discharge_id");
169
            let borrowernumber = cancel_link.data("borrowernumber");
170
            $("#cancel_modal_form").append('<input type="hidden" name="discharge_id" value="' + discharge_id + '">');
171
            $("#cancel_modal_form").append('<input type="hidden" name="borrowernumber" value="' + borrowernumber + '">');
172
            return false;
173
        });
174
    </script>
107
[% END %]
175
[% END %]
108
176
109
[% INCLUDE 'intranet-bottom.inc' %]
177
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/members/discharge.pl (-2 / +16 lines)
Lines 50-57 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( Link Here
50
    }
50
    }
51
);
51
);
52
52
53
my $op             = $input->param('op') // q{};
53
my $op                  = $input->param('op') // q{};
54
my $borrowernumber = $input->param('borrowernumber');
54
my $borrowernumber      = $input->param('borrowernumber');
55
my $discharge_id        = $input->param('discharge_id');
56
my $cancellation_reason = $input->param('cancellation-reason');
55
57
56
unless ( C4::Context->preference('useDischarge') ) {
58
unless ( C4::Context->preference('useDischarge') ) {
57
    print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&nopermission=1");
59
    print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&nopermission=1");
Lines 68-73 output_and_exit_if_error( Link Here
68
my ( $can_be_discharged, $discharge_problems ) =
70
my ( $can_be_discharged, $discharge_problems ) =
69
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
71
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
70
72
73
if ( $op eq "cud-cancel-discharge" ) {
74
    unless ( Koha::Patron::Discharge::is_cancelled( { discharge_id => $discharge_id } ) ) {
75
        Koha::Patron::Discharge::cancel(
76
            {
77
                discharge_id        => $discharge_id,
78
                borrowernumber      => $borrowernumber,
79
                cancellation_reason => $cancellation_reason,
80
            }
81
        );
82
    }
83
}
84
71
# Generating discharge if needed
85
# Generating discharge if needed
72
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
86
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
73
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
87
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
(-)a/opac/opac-reserve.pl (-1 / +5 lines)
Lines 118-123 my $can_place_holds = $patron->can_place_holds( { no_short_circuit => 1 } ); Link Here
118
118
119
if ( !$can_place_holds ) {
119
if ( !$can_place_holds ) {
120
120
121
    if ( Koha::Patron::Dicharge::is_discharged( { borrowernumber => $patron->borrowernumber } ) ) {
122
        $template->param(
123
            is_discharged => 1,
124
        );
125
    }
121
    $template->param( message => 1 );
126
    $template->param( message => 1 );
122
127
123
    my $messages = $can_place_holds->messages();
128
    my $messages = $can_place_holds->messages();
124
- 

Return to bug 37344