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

(-)a/Koha/Patron/Discharge.pm (-4 / +58 lines)
Lines 42-62 sub can_be_discharged { Link Here
42
    return $has_pending_checkouts ? 0 : 1;
42
    return $has_pending_checkouts ? 0 : 1;
43
}
43
}
44
44
45
=pod
46
45
sub is_discharged {
47
sub is_discharged {
46
    my ($params) = @_;
48
    my ($params) = @_;
47
    return unless $params->{borrowernumber};
49
    return unless $params->{borrowernumber};
48
    my $borrowernumber = $params->{borrowernumber};
50
    my $borrowernumber = $params->{borrowernumber};
49
51
50
    my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred;
52
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
51
    my @validated  = get_validated( { borrowernumber => $borrowernumber } );
53
    my @validated = get_validated({borrowernumber => $borrowernumber});
52
54
53
    if ( $restricted && @validated ) {
55
    if ($restricted && @validated) {
54
        return 1;
56
        return 1;
55
    } else {
57
    } else {
56
        return 0;
58
        return 0;
57
    }
59
    }
58
}
60
}
59
61
62
=cut
63
64
sub is_discharged {
65
    my ($params) = @_;
66
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
67
        {
68
            borrower  => $params->{borrowernumber},
69
            validated => { "not" => undef },
70
            cancelled => undef,
71
        }
72
    );
73
    return $discharge->count > 0;
74
}
75
60
sub request {
76
sub request {
61
    my ($params) = @_;
77
    my ($params) = @_;
62
    my $borrowernumber = $params->{borrowernumber};
78
    my $borrowernumber = $params->{borrowernumber};
Lines 72-77 sub request { Link Here
72
    );
88
    );
73
}
89
}
74
90
91
sub is_cancelled {
92
    my ($params) = @_;
93
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
94
        {
95
            discharge_id => $params->{discharge_id},
96
            cancelled    => { "not" => undef },
97
        }
98
    );
99
    return $discharge->count > 0;
100
}
101
102
sub cancel {
103
    my ($params) = @_;
104
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
105
        {
106
            discharge_id => $params->{discharge_id},
107
        }
108
    );
109
    $discharge->update(
110
        {
111
            cancelled           => dt_from_string,
112
            cancellation_reason => 'BORROWER_MISTAKE'
113
        }
114
    );
115
    Koha::Patron::Debarments::DelUniqueDebarment(
116
        {
117
            borrowernumber => $params->{borrowernumber},
118
            type           => "DISCHARGE",
119
        }
120
    );
121
}
122
75
sub discharge {
123
sub discharge {
76
    my ($params) = @_;
124
    my ($params) = @_;
77
    my $borrowernumber = $params->{borrowernumber};
125
    my $borrowernumber = $params->{borrowernumber};
Lines 96-102 sub discharge { Link Here
96
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
144
    my $rs        = Koha::Database->new->schema->resultset('Discharge');
97
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
145
    my $discharge = $rs->search( { borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 } );
98
    if ( $discharge->count > 0 ) {
146
    if ( $discharge->count > 0 ) {
99
        $discharge->update( { validated => dt_from_string } );
147
        $discharge->update(
148
            {
149
                validated           => dt_from_string,
150
                cancelled           => undef,
151
                cancellation_reason => undef
152
            }
153
        );
100
    } else {
154
    } else {
101
        $rs->create(
155
        $rs->create(
102
            {
156
            {
(-)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 (-1 / +3 lines)
Lines 2872-2877 CREATE TABLE `discharges` ( Link Here
2872
  `borrower` int(11) DEFAULT NULL,
2872
  `borrower` int(11) DEFAULT NULL,
2873
  `needed` timestamp NULL DEFAULT NULL,
2873
  `needed` timestamp NULL DEFAULT NULL,
2874
  `validated` timestamp NULL DEFAULT NULL,
2874
  `validated` timestamp NULL DEFAULT NULL,
2875
  `cancelled` timestamp DEFAULT NULL,
2876
  `cancellation_reason`varchar(32) DEFAULT NULL,
2875
  PRIMARY KEY (`discharge_id`),
2877
  PRIMARY KEY (`discharge_id`),
2876
  KEY `borrower_discharges_ibfk1` (`borrower`),
2878
  KEY `borrower_discharges_ibfk1` (`borrower`),
2877
  CONSTRAINT `borrower_discharges_ibfk1` FOREIGN KEY (`borrower`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2879
  CONSTRAINT `borrower_discharges_ibfk1` FOREIGN KEY (`borrower`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
Lines 6796-6799 CREATE TABLE `zebraqueue` ( Link Here
6796
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
6798
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
6797
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
6799
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
6798
6800
6799
-- Dump completed on 2024-11-25 12:13:27
6801
-- Dump completed on 2024-11-25 12:13:27
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (+2 lines)
Lines 511-516 Link Here
511
        <p>ILL request status aliases used by the interlibrary loans module</p>
511
        <p>ILL request status aliases used by the interlibrary loans module</p>
512
    [% CASE 'AR_CANCELLATION' %]
512
    [% CASE 'AR_CANCELLATION' %]
513
        <p>Reasons why an article request might have been cancelled</p>
513
        <p>Reasons why an article request might have been cancelled</p>
514
    [% CASE 'DISCHARGE_CANCELLATION' %]
515
        <p>Reasons why a discharge can be cancelled</p>
514
    [% CASE 'HSBND_FREQ' %]
516
    [% CASE 'HSBND_FREQ' %]
515
        <p>Frequencies used by the housebound module. They are displayed on the housebound tab in the patron account in staff.</p>
517
        <p>Frequencies used by the housebound module. They are displayed on the housebound tab in the patron account in staff.</p>
516
    [% CASE 'ITEMTYPECAT' %]
518
    [% CASE 'ITEMTYPECAT' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (-1 / +71 lines)
Lines 75-80 Link Here
75
                    <tr>
75
                    <tr>
76
                        <th>Requested</th>
76
                        <th>Requested</th>
77
                        <th>Validated</th>
77
                        <th>Validated</th>
78
                        <th>Cancelled</th>
79
                        <th>Reason of cancellation</th>
80
                        <th>Cancel</th>
78
                    </tr>
81
                    </tr>
79
                </thead>
82
                </thead>
80
                <tbody>
83
                <tbody>
Lines 82-88 Link Here
82
                        <tr>
85
                        <tr>
83
                            <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
86
                            <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
84
                            <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
87
                            <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
85
                        </tr>
88
                            <td>[% d.cancelled | $KohaDates with_hours = 1 %]</td>
89
                            <td>[% d.cancellation_reason | html %]</td>
90
                            <td>
91
                                [% IF d.cancelled %]
92
                                    <i> Cancelled </i>
93
                                [% ELSE %]
94
                                    <a
95
                                        class="cancel-discharge delete btn btn-default btn-xs"
96
                                        data-borrowernumber="[% patron.borrowernumber | html %]"
97
                                        data-bs-target="#cancelDischargeModal"
98
                                        data-bs-toggle="modal"
99
                                        data-discharge_id="[% d.discharge_id | html %]"
100
                                    >
101
                                        <i class="fa fa-trash-can"></i>
102
                                        Cancel
103
                                    </a>
104
                                [% END %]
105
                            </td></tr
106
                        >
86
                    [% END %]
107
                    [% END %]
87
                </tbody>
108
                </tbody>
88
            </table>
109
            </table>
Lines 90-98 Link Here
90
    [% END %]
111
    [% END %]
91
[% END %]
112
[% END %]
92
113
114
<div class="modal fade" id="cancelDischargeModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
115
    <div class="modal-dialog modal-lg">
116
        <div class="modal-content">
117
            <div class="modal-header">
118
                <h1 class="modal-title" id="exampleModalLabel">Confirm deletion</h1>
119
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
120
            </div>
121
            <form id="cancel_modal_form" method="post" action="discharge.pl">
122
                <div class="modal-body">
123
                    [% INCLUDE 'csrf-token.inc' %]
124
                    <input name="op" type="hidden" value="cud-cancel-discharge" />
125
                    <div id="cancel_dicharge_alert" class="alert alert-danger" style="display:none;"></div>
126
                    <fieldset class="action">
127
                        <p>Are you sure you want to cancel this discharge ? Borrower will again have right to check out books after this.</p>
128
                        [% SET discharge_cancellation = AuthorisedValues.GetAuthValueDropbox('DISCHARGE_CANCELLATION') %]
129
                        [% IF discharge_cancellation.count %]
130
                            <label for="cancellation-reason">Cancellation reason: </label>
131
                            <select class="cancellation-reason" name="cancellation-reason" id="modal-cancellation-reason">
132
                                [% FOREACH reason IN discharge_cancellation %]
133
                                    <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
134
                                [% END %]
135
                            </select>
136
                        [% ELSE %]
137
                            <div class="alert alert-warning audio-alert-warning"> You must define at least one authorized value for the category DISCHARGE_CANCELLATION </div>
138
                        [% END %]
139
                    </fieldset>
140
                </div>
141
                <div class="modal-footer">
142
                    <input id="cancelModalConfirmBtn" type="submit" class="btn btn-danger" value="Confirm cancellation" />
143
                    <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
144
                    <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
145
        <button type="button" class="btn btn-primary">Save changes</button> -->
146
                </div>
147
            </form>
148
        </div>
149
    </div>
150
</div>
151
93
[% MACRO jsinclude BLOCK %]
152
[% MACRO jsinclude BLOCK %]
94
    [% INCLUDE 'str/members-menu.inc' %]
153
    [% INCLUDE 'str/members-menu.inc' %]
95
    [% Asset.js("js/members-menu.js") | $raw %]
154
    [% Asset.js("js/members-menu.js") | $raw %]
155
    <script>
156
        $(".cancel-discharge").on("click", function (e) {
157
            e.preventDefault;
158
            cancel_link = $(this);
159
            let discharge_id = cancel_link.data("discharge_id");
160
            let borrowernumber = cancel_link.data("borrowernumber");
161
            $("#cancel_modal_form").append('<input type="hidden" name="discharge_id" value="' + discharge_id + '">');
162
            $("#cancel_modal_form").append('<input type="hidden" name="borrowernumber" value="' + borrowernumber + '">');
163
            return false;
164
        });
165
    </script>
96
[% END %]
166
[% END %]
97
167
98
[% INCLUDE 'intranet-bottom.inc' %]
168
[% 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 67-72 output_and_exit_if_error( Link Here
67
68
68
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
69
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
69
70
71
if ( $op eq "cud-cancel-discharge" ) {
72
    unless ( Koha::Patron::Discharge::is_cancelled( { discharge_id => $discharge_id } ) ) {
73
        Koha::Patron::Discharge::cancel(
74
            {
75
                discharge_id   => $discharge_id,
76
                borrowernumber => $borrowernumber,
77
            }
78
        );
79
    }
80
}
81
70
# Generating discharge if needed
82
# Generating discharge if needed
71
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
83
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
72
    my $is_discharged = Koha::Patron::Discharge::is_discharged(
84
    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