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
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.
26 use C4
::Auth
qw(check_cookie_auth);
27 use C4
::Biblio
qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
29 qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
36 my ( $auth_status, $sessionID ) =
37 check_cookie_auth
( $input->cookie('CGISESSID'),
38 { circulate
=> 'circulate_remaining_permissions' } );
40 if ( $auth_status ne "ok" ) {
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') ]
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' );
63 date_due < now() as date_due_overdue,
87 DATEDIFF( issuedate, CURRENT_DATE() ) AS not_issued_today
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 )
97 if ( @borrowernumber == 1 ) {
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');
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
} );
121 $can_renew_error eq 'too_soon'
124 dt
=> GetSoonestRenewDate
( $c->{borrowernumber
}, $c->{itemnumber
} ),
130 my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
131 GetRenewCount
( $c->{borrowernumber
}, $c->{itemnumber
} );
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{},
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
} ),
164 date_due_formatted
=> output_pref
(
166 dt
=> dt_from_string
( $c->{date_due
} ),
170 subtitle
=> GetRecordValue
(
172 GetMarcBiblio
( $c->{biblionumber
} ),
173 GetFrameworkCode
( $c->{biblionumber
} )
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 );
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 );
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);