Bug 25501: Supress warnings on installing translation
[koha.git] / svc / return_claims
blobe1971ef9bf2495cfc7dc6320c7bdf5599c73bc55
1 #!/usr/bin/perl
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
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>.
20 use Modern::Perl;
22 use CGI;
23 use JSON qw(to_json);
25 use C4::Auth qw(check_cookie_auth haspermission get_session);
26 use C4::Context;
28 use Koha::AuthorisedValues;
29 use Koha::DateUtils;
30 use Koha::Patrons;
32 my $input = new CGI;
34 my ( $auth_status, $sessionID ) =
35 check_cookie_auth( $input->cookie('CGISESSID') );
37 my $session = get_session($sessionID);
38 my $userid = $session->param('id');
40 unless (
41 haspermission(
42 $userid, { circulate => 'circulate_remaining_permissions' }
44 || haspermission( $userid, { borrowers => 'edit_borrowers' } )
47 exit 0;
50 my @sort_columns = qw/title notes created_on updated_on/;
52 my $borrowernumber = $input->param('borrowernumber');
53 my $offset = $input->param('iDisplayStart');
54 my $results_per_page = $input->param('iDisplayLength') || -1;
56 my $sorting_column = $input->param('iSortCol_0') || q{};
57 $sorting_column =
58 ( $sorting_column && $sort_columns[$sorting_column] )
59 ? $sort_columns[$sorting_column]
60 : 'created_on';
62 my $sorting_direction = $input->param('sSortDir_0') || q{};
63 $sorting_direction = $sorting_direction eq 'asc' ? 'asc' : 'desc';
65 $results_per_page = undef if ( $results_per_page == -1 );
67 binmode STDOUT, ":encoding(UTF-8)";
68 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
70 my $sql = qq{
71 SELECT
72 return_claims.*,
74 biblio.biblionumber,
75 biblio.title,
76 biblio.author,
78 items.enumchron,
79 items.barcode
80 FROM return_claims
81 LEFT JOIN items USING ( itemnumber )
82 LEFT JOIN biblio USING ( biblionumber )
83 LEFT JOIN biblioitems USING ( biblionumber )
84 WHERE return_claims.borrowernumber = ?
85 ORDER BY $sorting_column $sorting_direction
88 my $dbh = C4::Context->dbh();
89 my $sth = $dbh->prepare($sql);
90 $sth->execute($borrowernumber);
92 my $resolved = 0;
93 my $unresolved = 0;
94 my @return_claims;
95 while ( my $claim = $sth->fetchrow_hashref() ) {
96 $claim->{created_on_formatted} = output_pref( { dt => dt_from_string( $claim->{created_on} ) } ) if $claim->{created_on};
97 $claim->{updated_on_formatted} = output_pref( { dt => dt_from_string( $claim->{updated_on} ) } ) if $claim->{updated_on};
98 $claim->{resolved_on_formatted} = output_pref( { dt => dt_from_string( $claim->{resolved_on} ) } ) if $claim->{resolved_on};
100 my $patron = $claim->{resolved_by} ? Koha::Patrons->find( $claim->{resolved_by} ) : undef;
101 $claim->{resolved_by_data} = $patron->unblessed if $patron;
103 my $resolution = $claim->{resolution}
104 ? Koha::AuthorisedValues->find(
106 category => 'RETURN_CLAIM_RESOLUTION',
107 authorised_value => $claim->{resolution},
110 : undef;
111 $claim->{resolution_data} = $resolution->unblessed if $resolution;
113 $claim->{resolved_on} ? $resolved++ : $unresolved++;
115 push( @return_claims, $claim );
118 my $data = {
119 iTotalRecords => scalar @return_claims,
120 iTotalDisplayRecords => scalar @return_claims,
121 sEcho => $input->param('sEcho') || undef,
122 aaData => \@return_claims,
123 resolved => $resolved,
124 unresolved => $unresolved
127 print to_json($data);