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

(-)a/Koha/Patron/Discharge.pm (-4 / +58 lines)
Lines 56-76 sub can_be_discharged { Link Here
56
    return ( $can_be_discharged, $problems );
56
    return ( $can_be_discharged, $problems );
57
}
57
}
58
58
59
=pod
60
59
sub is_discharged {
61
sub is_discharged {
60
    my ($params) = @_;
62
    my ($params) = @_;
61
    return unless $params->{borrowernumber};
63
    return unless $params->{borrowernumber};
62
    my $borrowernumber = $params->{borrowernumber};
64
    my $borrowernumber = $params->{borrowernumber};
63
65
64
    my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred;
66
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
65
    my @validated  = get_validated( { borrowernumber => $borrowernumber } );
67
    my @validated = get_validated({borrowernumber => $borrowernumber});
66
68
67
    if ( $restricted && @validated ) {
69
    if ($restricted && @validated) {
68
        return 1;
70
        return 1;
69
    } else {
71
    } else {
70
        return 0;
72
        return 0;
71
    }
73
    }
72
}
74
}
73
75
76
=cut
77
78
sub is_discharged {
79
    my ($params) = @_;
80
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
81
        {
82
            borrower  => $params->{borrowernumber},
83
            validated => { "not" => undef },
84
            cancelled => undef,
85
        }
86
    );
87
    return $discharge->count > 0;
88
}
89
74
sub request {
90
sub request {
75
    my ($params) = @_;
91
    my ($params) = @_;
76
    my $borrowernumber = $params->{borrowernumber};
92
    my $borrowernumber = $params->{borrowernumber};
Lines 87-92 sub request { Link Here
87
    );
103
    );
88
}
104
}
89
105
106
sub is_cancelled {
107
    my ($params) = @_;
108
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
109
        {
110
            discharge_id => $params->{discharge_id},
111
            cancelled    => { "not" => undef },
112
        }
113
    );
114
    return $discharge->count > 0;
115
}
116
117
sub cancel {
118
    my ($params) = @_;
119
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
120
        {
121
            discharge_id => $params->{discharge_id},
122
        }
123
    );
124
    $discharge->update(
125
        {
126
            cancelled           => dt_from_string,
127
            cancellation_reason => 'BORROWER_MISTAKE'
128
        }
129
    );
130
    Koha::Patron::Debarments::DelUniqueDebarment(
131
        {
132
            borrowernumber => $params->{borrowernumber},
133
            type           => "DISCHARGE",
134
        }
135
    );
136
}
137
90
sub discharge {
138
sub discharge {
91
    my ($params) = @_;
139
    my ($params) = @_;
92
    my $borrowernumber = $params->{borrowernumber};
140
    my $borrowernumber = $params->{borrowernumber};
Lines 113-119 sub discharge { Link Here
113
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
161
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
114
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
162
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
115
    if ( $discharge->count > 0 ) {
163
    if ( $discharge->count > 0 ) {
116
        $discharge->update( { validated => dt_from_string } );
164
        $discharge->update(
165
            {
166
                validated           => dt_from_string,
167
                cancelled           => undef,
168
                cancellation_reason => undef
169
            }
170
        );
117
    } else {
171
    } else {
118
        $rs->create(
172
        $rs->create(
119
            {
173
            {
(-)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 cancellation_date 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','BORROWER_MISTAKE', 'Borrower asked a discharge by mistake'),
31
                    ('DISCHARGE_CANCELLATION','BORROWER_STILL_NEEDS_TO_BORROW','Administration required a discharge however the borrower still needs to borrow')
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 values";
40
            say $out "Added authorized values";
41
        }
42
    },
43
};
(-)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(32) DEFAULT NULL,
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/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 why a discharge can be cancelled</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 / +71 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 of cancellation</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="exampleModalLabel" 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="exampleModalLabel">Confirm deletion</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_dicharge_alert" class="alert alert-danger" style="display:none;"></div>
137
                    <fieldset class="action">
138
                        <p>Are you sure you want to cancel this discharge ? Borrower will again have right to check out books after this.</p>
139
                        [% SET discharge_cancellation = AuthorisedValues.GetAuthValueDropbox('DISCHARGE_CANCELLATION') %]
140
                        [% IF discharge_cancellation.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 %]
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
                    <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
156
        <button type="button" class="btn btn-primary">Save changes</button> -->
157
                </div>
158
            </form>
159
        </div>
160
    </div>
161
</div>
162
104
[% MACRO jsinclude BLOCK %]
163
[% MACRO jsinclude BLOCK %]
105
    [% INCLUDE 'str/members-menu.inc' %]
164
    [% INCLUDE 'str/members-menu.inc' %]
106
    [% Asset.js("js/members-menu.js") | $raw %]
165
    [% Asset.js("js/members-menu.js") | $raw %]
166
    <script>
167
        $(".cancel-discharge").on("click", function (e) {
168
            e.preventDefault;
169
            cancel_link = $(this);
170
            let discharge_id = cancel_link.data("discharge_id");
171
            let borrowernumber = cancel_link.data("borrowernumber");
172
            $("#cancel_modal_form").append('<input type="hidden" name="discharge_id" value="' + discharge_id + '">');
173
            $("#cancel_modal_form").append('<input type="hidden" name="borrowernumber" value="' + borrowernumber + '">');
174
            return false;
175
        });
176
    </script>
107
[% END %]
177
[% END %]
108
178
109
[% INCLUDE 'intranet-bottom.inc' %]
179
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/members/discharge.pl (+12 lines)
Lines 52-57 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( Link Here
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');
55
56
56
unless ( C4::Context->preference('useDischarge') ) {
57
unless ( C4::Context->preference('useDischarge') ) {
57
    print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&nopermission=1");
58
    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 ) =
69
my ( $can_be_discharged, $discharge_problems ) =
69
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
70
    Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
70
71
72
if ( $op eq "cud-cancel-discharge" ) {
73
    unless ( Koha::Patron::Discharge::is_cancelled( { discharge_id => $discharge_id } ) ) {
74
        Koha::Patron::Discharge::cancel(
75
            {
76
                discharge_id   => $discharge_id,
77
                borrowernumber => $borrowernumber,
78
            }
79
        );
80
    }
81
}
82
71
# Generating discharge if needed
83
# Generating discharge if needed
72
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
84
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
73
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
85
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
(-)a/opac/opac-reserve.pl (-1 / +6 lines)
Lines 157-162 if ( $patron->is_debarred ) { Link Here
157
    );
157
    );
158
}
158
}
159
159
160
if ( Koha::Patron::Dicharge::is_discharged( { borrowernumber => $patron->borrowernumber } ) ) {
161
    $template->param(
162
        is_discharged => 1,
163
    );
164
}
165
160
my $holds          = $patron->holds;
166
my $holds          = $patron->holds;
161
my $reserves_count = $holds->count;
167
my $reserves_count = $holds->count;
162
$template->param( RESERVES => $holds->unblessed );
168
$template->param( RESERVES => $holds->unblessed );
163
- 

Return to bug 37344