Bug 11068: Update MARC21 es-ES default frameworks fields and translation
[koha.git] / svc / checkouts
blob11f0895a583e9a65815403c32f2c85ab584d1dc7
1 #!/usr/bin/perl
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 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
10 # version.
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.
20 use strict;
21 use warnings;
23 use CGI;
24 use JSON qw(to_json);
26 use C4::Auth qw(check_cookie_auth);
27 use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
28 use C4::Circulation
29 qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
30 use C4::Context;
32 use Koha::DateUtils;
34 my $input = new CGI;
36 my ( $auth_status, $sessionID ) =
37 check_cookie_auth( $input->cookie('CGISESSID'),
38 { circulate => 'circulate_remaining_permissions' } );
40 if ( $auth_status ne "ok" ) {
41 exit 0;
44 my @sort_columns = qw/date_due title itype issuedate branchcode itemcallnumber/;
46 my @borrowernumber = $input->param('borrowernumber');
47 my $offset = $input->param('iDisplayStart');
48 my $results_per_page = $input->param('iDisplayLength') || -1;
49 my $sorting_column = $sort_columns[ $input->param('iSortCol_0') ]
50 || 'issuedate';
51 my $sorting_direction = $input->param('sSortDir_0') eq 'asc' ? 'asc' : 'desc';
53 $results_per_page = undef if ( $results_per_page == -1 );
55 binmode STDOUT, ":encoding(UTF-8)";
56 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
58 my @parameters;
59 my $sql = '
60 SELECT
61 issuedate,
62 date_due,
63 date_due < now() as date_due_overdue,
64 issues.timestamp,
66 biblionumber,
67 biblio.title,
68 author,
70 itemnumber,
71 barcode,
72 itemnotes,
73 itemcallnumber,
74 replacementprice,
76 issues.branchcode,
77 branchname,
79 itype,
80 itemtype,
82 borrowernumber,
83 surname,
84 firstname,
85 cardnumber,
87 DATEDIFF( issuedate, CURRENT_DATE() ) AS not_issued_today
88 FROM issues
89 LEFT JOIN items USING ( itemnumber )
90 LEFT JOIN biblio USING ( biblionumber )
91 LEFT JOIN biblioitems USING ( biblionumber )
92 LEFT JOIN borrowers USING ( borrowernumber )
93 LEFT JOIN branches ON ( issues.branchcode = branches.branchcode )
94 WHERE borrowernumber
97 if ( @borrowernumber == 1 ) {
98 $sql .= '= ?';
100 else {
101 $sql .= ' IN (' . join( ',', ('?') x @borrowernumber ) . ') ';
103 push( @parameters, @borrowernumber );
105 $sql .= " ORDER BY $sorting_column $sorting_direction ";
107 my $dbh = C4::Context->dbh();
108 my $sth = $dbh->prepare($sql);
109 $sth->execute(@parameters);
111 my $item_level_itypes = C4::Context->preference('item-level_itypes');
113 my @checkouts_today;
114 my @checkouts_previous;
115 while ( my $c = $sth->fetchrow_hashref() ) {
116 my ($charge) = GetIssuingCharges( $c->{itemnumber}, $c->{borrowernumber} );
118 my ( $can_renew, $can_renew_error ) =
119 CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} );
120 my $can_renew_date =
121 $can_renew_error eq 'too_soon'
122 ? output_pref(
124 dt => GetSoonestRenewDate( $c->{borrowernumber}, $c->{itemnumber} ),
125 as_due_date => 1
128 : undef;
130 my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
131 GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
133 my $checkout = {
134 DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber},
135 title => $c->{title},
136 author => $c->{author},
137 barcode => $c->{barcode},
138 itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype},
139 itemnotes => $c->{itemnotes},
140 branchcode => $c->{branchcode},
141 branchname => $c->{branchname},
142 itemcallnumber => $c->{itemcallnumber} || q{},
143 charge => $charge,
144 price => $c->{replacementprice} || q{},
145 can_renew => $can_renew,
146 can_renew_error => $can_renew_error,
147 can_renew_date => $can_renew_date,
148 itemnumber => $c->{itemnumber},
149 borrowernumber => $c->{borrowernumber},
150 biblionumber => $c->{biblionumber},
151 issuedate => $c->{issuedate},
152 date_due => $c->{date_due},
153 date_due_overdue => $c->{date_due_overdue} ? JSON::true : JSON::false,
154 timestamp => $c->{timestamp},
155 renewals_count => $renewals_count,
156 renewals_allowed => $renewals_allowed,
157 renewals_remaining => $renewals_remaining,
158 issuedate_formatted => output_pref(
160 dt => dt_from_string( $c->{issuedate} ),
161 as_due_date => 1
164 date_due_formatted => output_pref(
166 dt => dt_from_string( $c->{date_due} ),
167 as_due_date => 1
170 subtitle => GetRecordValue(
171 'subtitle',
172 GetMarcBiblio( $c->{biblionumber} ),
173 GetFrameworkCode( $c->{biblionumber} )
175 borrower => {
176 surname => $c->{surname},
177 firstname => $c->{firstname},
178 cardnumber => $c->{cardnumber},
180 issued_today => !$c->{not_issued_today},
183 if ( $c->{not_issued_today} ) {
184 push( @checkouts_previous, $checkout );
186 else {
187 push( @checkouts_today, $checkout );
191 @checkouts_today = reverse(@checkouts_today)
192 if ( C4::Context->preference('todaysIssuesDefaultSortOrder') eq 'desc' );
193 @checkouts_previous = reverse(@checkouts_previous)
194 if ( C4::Context->preference('previousIssuesDefaultSortOrder') eq 'desc' );
196 my @checkouts = ( @checkouts_today, @checkouts_previous );
198 my $data;
199 $data->{'iTotalRecords'} = scalar @checkouts;
200 $data->{'iTotalDisplayRecords'} = scalar @checkouts;
201 $data->{'sEcho'} = $input->param('sEcho') || undef;
202 $data->{'aaData'} = \@checkouts;
204 print to_json($data);