-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathrecalls_to_pull.pl
executable file
·140 lines (124 loc) · 5.22 KB
/
recalls_to_pull.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
#
# This file is part of Koha.
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use List::MoreUtils qw( uniq );
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Koha::BiblioFrameworks;
my $query = CGI->new;
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
{
template_name => "recalls/recalls_to_pull.tt",
query => $query,
type => "intranet",
flagsrequired => { recalls => 'manage_recalls' },
debug => 1,
}
);
my $op = $query->param('op') || 'list';
my $recall_id = $query->param('recall_id');
if ( $op eq 'cud-cancel' ) {
my $recall = Koha::Recalls->find($recall_id);
if ( $recall->in_transit ) {
C4::Items::ModItemTransfer(
$recall->item->itemnumber, $recall->item->holdingbranch,
$recall->item->homebranch, 'RecallCancellation'
);
}
$recall->set_cancelled;
$op = 'list';
}
if ( $op eq 'list' ) {
my @recalls = Koha::Recalls->search( { status => [ 'requested', 'overdue' ] } )->as_list;
my @pull_list;
my %seen_bib;
foreach my $recall (@recalls) {
if ( $seen_bib{ $recall->biblio_id } ) {
# we've already looked at the recalls on this biblio
next;
} else {
# this is an unseen biblio
$seen_bib{ $recall->biblio_id }++;
# get recall data about this biblio
my $biblio = $recall->biblio;
my @this_bib_recalls = $biblio->recalls->search(
{ status => [ 'requested', 'overdue' ] },
{ order_by => { -asc => 'created_date' } }
)->as_list;
my $recalls_count = scalar @this_bib_recalls;
my @unique_patrons = uniq @this_bib_recalls;
my $patrons_count = scalar @unique_patrons;
my $first_recall = $this_bib_recalls[0];
my $items_count = 0;
my @callnumbers;
my @copynumbers;
my @enumchrons;
my @itemtypes;
my @locations;
my @libraries;
my @items = $biblio->items->as_list;
foreach my $item (@items) {
if (
$item->can_be_waiting_recall
and !$item->checkout
and Koha::Recalls->search(
{ item_id => $item->id, status => [ 'waiting', 'in_transit' ], completed => 0 }
)->count == 0
)
{
# if item can be pulled to fulfill recall, collect item data
$items_count++;
push( @callnumbers, $item->itemcallnumber ) if ( $item->itemcallnumber );
push( @copynumbers, $item->copynumber ) if ( $item->copynumber );
push( @enumchrons, $item->enumchron ) if ( $item->enumchron );
push( @itemtypes, $item->effective_itemtype ) if ( $item->effective_itemtype );
push( @locations, $item->location ) if ( $item->location );
push( @libraries, $item->holdingbranch ) if ( $item->holdingbranch );
}
}
if ( $items_count > 0 ) {
# don't push data if there are no items available for this recall
# get unique values
push(
@pull_list,
{
biblio => $biblio,
items_count => $items_count,
recalls_count => $recalls_count,
patrons_count => $patrons_count,
pull_count => $items_count <= $recalls_count ? $items_count : $recalls_count,
first_recall => $first_recall,
callnumbers => [ uniq @callnumbers ],
copynumbers => [ uniq @copynumbers ],
enumchrons => [ uniq @enumchrons ],
itemtypes => [ uniq @itemtypes ],
locations => [ uniq @locations ],
libraries => [ uniq @libraries ],
}
);
}
}
}
$template->param(
recalls => \@pull_list,
);
}
# Checking if there is a Fast Cataloging Framework
$template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find('FA');
# writing the template
output_html_with_http_headers $query, $cookie, $template->output;