3 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
5 # Copyright 2014 ByWater Solutions
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 use C4::Auth qw(check_cookie_auth);
29 use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
30 use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount);
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 @sort_columns = qw/date_due title itype issuedate branchcode itemcallnumber/;
47 my @borrowernumber = $input->param('borrowernumber');
48 my $offset = $input->param('iDisplayStart');
49 my $results_per_page = $input->param('iDisplayLength') || -1;
50 my $sorting_column = $sort_columns[ $input->param('iSortCol_0') ]
52 my $sorting_direction = $input->param('sSortDir_0') eq 'asc' ? 'asc' : 'desc';
54 $results_per_page = undef if ( $results_per_page == -1 );
56 binmode STDOUT, ":encoding(UTF-8)";
57 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
86 LEFT JOIN items USING ( itemnumber )
87 LEFT JOIN biblio USING ( biblionumber )
88 LEFT JOIN biblioitems USING ( biblionumber )
89 LEFT JOIN borrowers USING ( borrowernumber )
90 LEFT JOIN branches ON ( issues.branchcode = branches.branchcode )
94 if ( @borrowernumber == 1 ) {
98 $sql = ' IN (' . join( ',', ('?') x @borrowernumber ) . ') ';
100 push( @parameters, @borrowernumber );
102 $sql .= " ORDER BY $sorting_column $sorting_direction ";
104 my $dbh = C4::Context->dbh();
105 my $sth = $dbh->prepare($sql);
106 $sth->execute( @parameters );
108 my $item_level_itypes = C4::Context->preference('item-level_itypes');
111 while ( my $c = $sth->fetchrow_hashref() ) {
112 my ($charge) = GetIssuingCharges( $c->{itemnumber}, $c->{borrowernumber} );
114 my ( $can_renew, $can_renew_error ) =
115 CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
117 my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
118 GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
122 DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber},
123 title => $c->{title},
124 author => $c->{author},
125 barcode => $c->{barcode},
126 itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype},
127 itemnotes => $c->{itemnotes},
128 branchcode => $c->{branchcode},
129 branchname => $c->{branchname},
130 itemcallnumber => $c->{itemcallnumber} || q{},
132 price => $c->{replacementprice} || q{},
133 can_renew => $can_renew,
134 can_renew_error => $can_renew_error,
135 itemnumber => $c->{itemnumber},
136 borrowernumber => $c->{borrowernumber},
137 biblionumber => $c->{biblionumber},
138 issuedate => $c->{issuedate},
139 date_due => $c->{date_due},
140 renewals_count => $renewals_count,
141 renewals_allowed => $renewals_allowed,
142 renewals_remaining => $renewals_remaining,
143 issuedate_formatted =>
144 output_pref( dt_from_string( $c->{issuedate} ) ),
145 date_due_formatted =>
146 output_pref_due( dt_from_string( $c->{date_due} ) ),
147 subtitle => GetRecordValue(
149 GetMarcBiblio( $c->{biblionumber} ),
150 GetFrameworkCode( $c->{biblionumber} )
153 surname => $c->{surname},
154 firstname => $c->{firstname},
155 cardnumber => $c->{cardnumber},
162 $data->{'iTotalRecords'} = scalar @checkouts; #FIXME
163 $data->{'iTotalDisplayRecords'} = scalar @checkouts;
164 $data->{'sEcho'} = $input->param('sEcho') || undef;
165 $data->{'aaData'} = \@checkouts;
167 print to_json($data);