Bug 20772: Display and edit of price_paid
[koha.git] / catalogue / getitem-ajax.pl
blob10df69ef75731af18b473c20c1e1133f463fe19f
1 #!/usr/bin/perl
3 # Copyright BibLibre 2012
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;
21 use CGI qw ( -utf8 );
22 use JSON;
24 use C4::Auth;
25 use C4::Biblio;
26 use C4::Items;
27 use C4::Koha;
28 use C4::Output;
29 use Koha::Libraries;
31 use Koha::AuthorisedValues;
32 use Koha::ItemTypes;
34 my $cgi = new CGI;
36 my ( $status, $cookie, $sessionID ) = C4::Auth::check_api_auth( $cgi, { acquisition => 'order_receive' } );
37 unless ($status eq "ok") {
38 print $cgi->header(-type => 'application/json', -status => '403 Forbidden');
39 print to_json({ auth_status => $status });
40 exit 0;
43 my $item = {};
44 my $itemnumber = $cgi->param('itemnumber');
46 if($itemnumber) {
47 my $acq_fw = GetMarcStructure(1, 'ACQ');
48 my $fw = ($acq_fw) ? 'ACQ' : '';
49 $item = GetItem($itemnumber);
51 if($item->{homebranch}) {
52 $item->{homebranchname} = Koha::Libraries->find($item->{homebranch})->branchname;
55 if($item->{holdingbranch}) {
56 $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
59 my $descriptions;
60 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
61 $item->{notforloan} = $descriptions->{lib} // '';
63 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
64 $item->{restricted} = $descriptions->{lib} // '';
66 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
67 $item->{location} = $descriptions->{lib} // '';
69 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
70 $item->{collection} = $descriptions->{lib} // '';
72 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
73 $item->{materials} = $descriptions->{lib} // '';
75 my $itemtype = Koha::ItemTypes->find( $item->{itype} );
76 $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
79 my $json_text = to_json( $item, { utf8 => 1 } );
81 output_with_http_headers $cgi, undef, $json_text, 'json';