3 # Copyright 2019 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use C4::Auth qw(check_cookie_auth haspermission get_session);
28 use Koha::AuthorisedValues;
34 my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID') );
35 if( $auth_status ne 'ok' ) {
36 print CGI::header( '-status' => '401' );
40 my $session = get_session($sessionID);
41 my $userid = $session->param('id');
45 $userid, { circulate => 'circulate_remaining_permissions' }
47 || haspermission( $userid, { borrowers => 'edit_borrowers' } )
53 my @sort_columns = qw/title notes created_on updated_on/;
55 my $borrowernumber = $input->param('borrowernumber');
56 my $offset = $input->param('iDisplayStart');
57 my $results_per_page = $input->param('iDisplayLength') || -1;
59 my $sorting_column = $input->param('iSortCol_0') || q{};
61 ( $sorting_column && $sort_columns[$sorting_column] )
62 ? $sort_columns[$sorting_column]
65 my $sorting_direction = $input->param('sSortDir_0') || q{};
66 $sorting_direction = $sorting_direction eq 'asc' ? 'asc' : 'desc';
68 $results_per_page = undef if ( $results_per_page == -1 );
70 binmode STDOUT, ":encoding(UTF-8)";
71 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
84 LEFT JOIN items USING ( itemnumber )
85 LEFT JOIN biblio USING ( biblionumber )
86 LEFT JOIN biblioitems USING ( biblionumber )
87 WHERE return_claims.borrowernumber = ?
88 ORDER BY $sorting_column $sorting_direction
91 my $dbh = C4::Context->dbh();
92 my $sth = $dbh->prepare($sql);
93 $sth->execute($borrowernumber);
98 while ( my $claim = $sth->fetchrow_hashref() ) {
99 $claim->{created_on_formatted} = output_pref( { dt => dt_from_string( $claim->{created_on} ) } ) if $claim->{created_on};
100 $claim->{updated_on_formatted} = output_pref( { dt => dt_from_string( $claim->{updated_on} ) } ) if $claim->{updated_on};
101 $claim->{resolved_on_formatted} = output_pref( { dt => dt_from_string( $claim->{resolved_on} ) } ) if $claim->{resolved_on};
103 my $patron = $claim->{resolved_by} ? Koha::Patrons->find( $claim->{resolved_by} ) : undef;
104 $claim->{resolved_by_data} = $patron->unblessed if $patron;
106 my $resolution = $claim->{resolution}
107 ? Koha::AuthorisedValues->find(
109 category => 'RETURN_CLAIM_RESOLUTION',
110 authorised_value => $claim->{resolution},
114 $claim->{resolution_data} = $resolution->unblessed if $resolution;
116 $claim->{resolved_on} ? $resolved++ : $unresolved++;
118 push( @return_claims, $claim );
122 iTotalRecords => scalar @return_claims,
123 iTotalDisplayRecords => scalar @return_claims,
124 sEcho => $input->param('sEcho') || undef,
125 aaData => \@return_claims,
126 resolved => $resolved,
127 unresolved => $unresolved
130 print to_json($data);