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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt (-1 / +2 lines)
Lines 50-56 Link Here
50
50
51
        [% IF error %]
51
        [% IF error %]
52
            <div class="dialog alert">
52
            <div class="dialog alert">
53
                Unable to place a recall. Check your circulation rules.
53
                Unable to place a recall. Check your system preferences and circulation rules.
54
            </div>
54
            </div>
55
        [% END %]
55
        [% END %]
56
56
Lines 194-199 Link Here
194
            [% IF recalls.count %]
194
            [% IF recalls.count %]
195
                <form method="post" action="/cgi-bin/koha/recalls/request.pl">
195
                <form method="post" action="/cgi-bin/koha/recalls/request.pl">
196
                    <input type="hidden" name="op" value="cancel_multiple_recalls">
196
                    <input type="hidden" name="op" value="cancel_multiple_recalls">
197
                    <input type="hidden" name="biblionumber" value="[% biblio.biblionumber | html %]" />
197
                    <input type="checkbox" id="select_all"> <span id="select_all_text">Select all</span>
198
                    <input type="checkbox" id="select_all"> <span id="select_all_text">Select all</span>
198
                    [% INCLUDE 'recalls.inc' %]
199
                    [% INCLUDE 'recalls.inc' %]
199
                    <fieldset class="action">
200
                    <fieldset class="action">
(-)a/misc/cronjobs/recalls/convert_reserves_to_recalls.pl (+115 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2021 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Getopt::Long;
22
23
BEGIN {
24
    # find Koha's Perl modules
25
    # test carefully before changing this
26
    use FindBin;
27
    eval { require "$FindBin::Bin/../kohalib.pl" };
28
}
29
30
# This script converts reserves to recalls when a record has a set minimum number of reserves placed.
31
# It DOES NOT CHECK if this is a legal recall. It assumes that the same rules that apply to reserves, also apply to recalls.
32
33
use Koha::Script -cron;
34
use Koha::DateUtils;
35
use Koha::Recalls;
36
use C4::Log;
37
38
my $min = 1;
39
my $verbose;
40
41
GetOptions(
42
    'min|m=i' => \$min,
43
    'verbose|v' => \$verbose
44
) or pod2usage(1);
45
46
cronlogaction();
47
48
# get reserves where there is more than $min reserves on one biblio
49
my @bib_reserves = Koha::Holds->search({}, {
50
    select => [
51
        'biblionumber',
52
        { count => 'biblionumber', -as => 'bibcount' }
53
    ],
54
    group_by => 'biblionumber',
55
    having => { 'bibcount' => { '>=', $min } },
56
});
57
58
my $count = 0;
59
foreach my $bib ( @bib_reserves ) {
60
    $bib = $bib->unblessed;
61
    if ( $bib->{bibcount} >= $min ) {
62
        # "Currently, if all items on a record are unavailable and there are $min or more holds on that same record, then we place a recall"
63
64
        my @reserves = Koha::Holds->search({ biblionumber => $bib->{biblionumber} }, { order_by -=> { -asc => 'reservedate' } });
65
        my $reserve_to_convert = $reserves[0];
66
        foreach my $res ( @reserves ) {
67
            # "Generally, we place the recall on the item that has been on loan for the longest."
68
            if ( dt_from_string($res->reservedate) < dt_from_string($reserve_to_convert->reservedate) ) {
69
                $reserve_to_convert = $res;
70
            }
71
        }
72
73
        my $patron = Koha::Patrons->find( $reserve_to_convert->borrowernumber );
74
        my $item;
75
        my $can_convert;
76
        if ( $reserve_to_convert->item_level_hold ) {
77
            $item = Koha::Items->find( $reserve_to_convert->itemnumber );
78
            if ( $item->checkout ) {
79
                # item-level reserve can be recalled because the relevant item is unavailable
80
                $can_convert = 1;
81
            }
82
        } else {
83
            my @items = Koha::Items->search({ biblionumber => $reserve_to_convert->biblionumber });
84
            my $items_unavailable = 0;
85
            foreach ( @items ) {
86
                if ( $_->checkout or $_->itemlost or $_->withdrawn or $_->notforloan ) {
87
                    # item is unavailable to be checked out right now
88
                    $items_unavailable++;
89
                }
90
            }
91
            if ( $items_unavailable > 0 and $items_unavailable == scalar @items ) {
92
                # all items must be unavailable for this reserve to be converted to a recall
93
                $can_convert = 1;
94
            }
95
        }
96
        my $biblio = Koha::Biblios->find( $reserve_to_convert->biblionumber );
97
        if ( $can_convert ) {
98
            my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
99
                patron => $patron,
100
                biblio => $biblio,
101
                branchcode => $reserve_to_convert->branchcode,
102
                item => $item,
103
                expirationdate => $reserve_to_convert->expirationdate,
104
                interface => 'commandline',
105
            });
106
            $reserve_to_convert->cancel({ cancellation_reason => 'RECALLED' });
107
            $count++;
108
            if ( $verbose ) {
109
                my $reserve_id = $reserve_to_convert->reserve_id;
110
                my $biblionumber = $reserve_to_convert->biblionumber;
111
                print "$count. Hold $reserve_id converted to recall on biblio $biblionumber.\n";
112
            }
113
        }
114
    }
115
}
(-)a/recalls/request.pl (-7 / +7 lines)
Lines 47-53 my $error = $input->param('error'); Link Here
47
if ( $op eq 'cancel_multiple_recalls' ) {
47
if ( $op eq 'cancel_multiple_recalls' ) {
48
    foreach my $id ( @recall_ids ) {
48
    foreach my $id ( @recall_ids ) {
49
        my $recall = Koha::Recalls->find( $id )->set_cancelled;
49
        my $recall = Koha::Recalls->find( $id )->set_cancelled;
50
        $biblionumber = $recall->biblionumber;
50
        $biblionumber = $input->param('biblionumber');
51
    }
51
    }
52
}
52
}
53
elsif ( $op eq 'patron_select' ) {
53
elsif ( $op eq 'patron_select' ) {
Lines 60-71 elsif ( $op eq 'patron_select' ) { Link Here
60
            if ( !$biblio->can_be_recalled({ patron => $patron }) ) {
60
            if ( !$biblio->can_be_recalled({ patron => $patron }) ) {
61
                $error = 1;
61
                $error = 1;
62
            }
62
            }
63
63
        } else {
64
            $template->param(
64
            $error = 1;
65
                patron => $patron,
66
                error => $error,
67
            );
68
        }
65
        }
66
        $template->param(
67
            patron => $patron,
68
            error => $error,
69
        );
69
    } else {
70
    } else {
70
        print $input->redirect("/cgi-bin/koha/recalls/request.pl?biblionumber=$biblionumber");
71
        print $input->redirect("/cgi-bin/koha/recalls/request.pl?biblionumber=$biblionumber");
71
    }
72
    }
72
- 

Return to bug 31415