3 # Copyright 2014 ByWater Solutions
5 # This file is part of Koha.
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.
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.
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>.
25 use C4
::Auth
qw(check_cookie_auth);
27 use C4
::Circulation
qw(GetTransfers);
37 my ( $auth_status, $sessionID ) =
38 check_cookie_auth
( $input->cookie('CGISESSID'),
39 { circulate
=> 'circulate_remaining_permissions' } );
41 if ( $auth_status ne "ok" ) {
45 my $branch = C4
::Context
->userenv->{'branch'};
47 my $schema = Koha
::Database
->new()->schema();
50 qw
/reservedate title itemcallnumber barcode expirationdate priority/;
52 my $borrowernumber = $input->param('borrowernumber');
53 my $offset = $input->param('iDisplayStart');
54 my $results_per_page = $input->param('iDisplayLength');
55 my $sorting_direction = $input->param('sSortDir_0') || 'desc';
56 my $iSortCol = $input->param('iSortCol_0') // 0;
57 my $sorting_column = $sort_columns[$iSortCol] // 'reservedate';
59 binmode STDOUT
, ":encoding(UTF-8)";
60 print $input->header( -type
=> 'text/plain', -charset
=> 'UTF-8' );
62 my $holds_rs = Koha
::Holds
->search(
63 { borrowernumber
=> $borrowernumber },
65 order_by
=> { "-$sorting_direction" => $sorting_column }
70 while ( my $h = $holds_rs->next() ) {
71 my $item = $h->item();
73 my $biblionumber = $h->biblio()->biblionumber();
77 my $itemtype = Koha
::ItemTypes
->find( $h->itemtype );
78 $itemtype_limit = $itemtype->translated_description;
81 my $libraries = Koha
::Libraries
->search({}, { order_by
=> ['branchname'] })->unblessed;
82 for my $library ( @
$libraries ) {
83 $library->{selected
} = 1 if $library->{branchcode
} eq $h->branchcode();
86 my $biblio = $h->biblio();
87 my @subtitles = split(/ \| /, $biblio->subtitle() // '');
89 DT_RowId
=> $h->reserve_id(),
90 biblionumber
=> $biblionumber,
91 title
=> $biblio->title(),
92 subtitle
=> \
@subtitles,
93 medium
=> $biblio->medium() // '',
94 part_number
=> $biblio->part_number() // '',
95 part_name
=> $biblio->part_name() // '',
96 author
=> $biblio->author(),
97 reserve_id
=> $h->reserve_id(),
98 branchcode
=> $h->branch()->branchname(),
99 branches
=> $libraries,
100 reservedate
=> $h->reservedate(),
101 expirationdate
=> $h->expirationdate(),
102 suspend
=> $h->suspend(),
103 suspend_until
=> $h->suspend_until(),
104 found
=> $h->found(),
105 waiting
=> $h->is_waiting(),
106 waiting_at
=> $h->branch()->branchname(),
107 waiting_here
=> $h->branch()->branchcode() eq $branch,
108 priority
=> $h->priority(),
109 itemtype_limit
=> $itemtype_limit,
110 reservedate_formatted
=> $h->reservedate() ? output_pref
(
111 { dt
=> dt_from_string
( $h->reservedate() ), dateonly
=> 1 }
114 suspend_until_formatted
=> $h->suspend_until() ? output_pref
(
115 { dt
=> dt_from_string
( $h->suspend_until() ), dateonly
=> 1 }
118 expirationdate_formatted
=> $h->expirationdate() ? output_pref
(
119 { dt
=> dt_from_string
( $h->expirationdate() ), dateonly
=> 1 }
124 $hold->{transfered
} = 0;
125 $hold->{not_transfered
} = 0;
128 $hold->{itemnumber
} = $item->itemnumber();
129 $hold->{barcode
} = $item->barcode();
130 $hold->{itemtype
} = $item->effective_itemtype();
131 $hold->{enumchron
} = $item->enumchron();
132 $hold->{itemcallnumber
} = $item->itemcallnumber() || q{};
134 my ( $transferred_when, $transferred_from, $transferred_to ) =
135 GetTransfers
( $item->itemnumber() );
136 if ($transferred_when) {
137 $hold->{color
} = 'transferred';
138 $hold->{transferred
} = 1;
139 $hold->{date_sent
} = output_pref
( dt_from_string
($transferred_when) );
140 $hold->{from_branch
} = Koha
::Libraries
->find($transferred_from)->branchname;
142 elsif ( $item->holding_branch() && $item->holding_branch()->branchcode() ne
143 $h->branch()->branchcode() )
145 $hold->{not_transferred
} = 1;
146 $hold->{not_transferred_by
} = $h->item()->holding_branch()->branchname();
150 push( @holds, $hold );
154 $data->{'iTotalRecords'} = scalar @holds;
155 $data->{'iTotalDisplayRecords'} = scalar @holds;
156 $data->{'sEcho'} = $input->param('sEcho') || undef;
157 $data->{'aaData'} = \
@holds;
159 print to_json
($data);