3 # Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
5 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use List::MoreUtils qw( uniq );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use Koha::BiblioFrameworks;
28 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
30 template_name => "recalls/recalls_to_pull.tt",
33 flagsrequired => { recalls => 'manage_recalls' },
38 my $op = $query->param('op') || 'list';
39 my $recall_id = $query->param('recall_id');
40 if ( $op eq 'cancel' ) {
41 my $recall = Koha::Recalls->find( $recall_id );
42 if ( $recall->in_transit ) {
43 C4::Items::ModItemTransfer(
44 $recall->item->itemnumber, $recall->item->holdingbranch,
45 $recall->item->homebranch, 'RecallCancellation'
48 $recall->set_cancelled;
52 if ( $op eq 'list' ) {
53 my @recalls = Koha::Recalls->search({ status => [ 'requested','overdue','in_transit' ] })->as_list;
56 foreach my $recall ( @recalls ) {
57 if ( $seen_bib{$recall->biblio_id} ){
58 # we've already looked at the recalls on this biblio
61 # this is an unseen biblio
62 $seen_bib{$recall->biblio_id}++;
64 # get recall data about this biblio
65 my $biblio = $recall->biblio;
66 my @this_bib_recalls = $biblio->recalls->search(
67 { status => [ 'requested', 'overdue', 'in_transit' ] },
68 { order_by => { -asc => 'created_date' } }
70 my $recalls_count = scalar @this_bib_recalls;
71 my @unique_patrons = uniq @this_bib_recalls ;
72 my $patrons_count = scalar @unique_patrons;
73 my $first_recall = $this_bib_recalls[0];
83 my @items = $biblio->items->as_list;
84 foreach my $item ( @items ) {
85 if ( $item->can_be_waiting_recall and !$item->checkout ) {
86 # if item can be pulled to fulfill recall, collect item data
88 push( @callnumbers, $item->itemcallnumber ) if ( $item->itemcallnumber );
89 push( @copynumbers, $item->copynumber ) if ( $item->copynumber );
90 push( @enumchrons, $item->enumchron ) if ( $item->enumchron );
91 push( @itemtypes, $item->effective_itemtype ) if ( $item->effective_itemtype );
92 push( @locations, $item->location ) if ( $item->location );
93 push( @libraries, $item->holdingbranch ) if ( $item->holdingbranch );
97 if ( $items_count > 0 ) {
98 # don't push data if there are no items available for this recall
103 items_count => $items_count,
104 recalls_count => $recalls_count,
105 patrons_count => $patrons_count,
106 pull_count => $items_count <= $recalls_count ? $items_count : $recalls_count,
107 first_recall => $first_recall,
108 callnumbers => [ uniq @callnumbers ],
109 copynumbers => [ uniq @copynumbers ],
110 enumchrons => [ uniq @enumchrons ],
111 itemtypes => [ uniq @itemtypes ],
112 locations => [ uniq @locations ],
113 libraries => [ uniq @libraries ],
119 recalls => \@pull_list,
123 # Checking if there is a Fast Cataloging Framework
124 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
126 # writing the template
127 output_html_with_http_headers $query, $cookie, $template->output;