@@ -, +, @@
- Add POD
- Add tests
---
Koha/Patron.pm | 30 +++++++++++++++++++++-
.../prog/en/includes/members-toolbar.inc | 4 ++-
members/readingrec.pl | 15 ++++++-----
3 files changed, 41 insertions(+), 8 deletions(-)
--- a/Koha/Patron.pm
+++ a/Koha/Patron.pm
@@ -30,7 +30,7 @@ use C4::Log;
use Koha::AuthUtils;
use Koha::Checkouts;
use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions::Password;
use Koha::Holds;
use Koha::Old::Checkouts;
@@ -875,6 +875,34 @@ sub checkouts {
return Koha::Checkouts->_new_from_dbic( $checkouts );
}
+sub todays_checkouts { # FIXME Must be moved to Koha::Old::Checkouts->filter_by_returned_today?
+ my ( $self ) = @_;
+ my $dt_today = dt_from_string;
+ my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+ return $self->old_checkouts->search(
+ {
+ returndate => {
+ -between => [
+ $dtf->format_datetime(
+ $dt_today->set( hour => 0, minute => 0, second => 0 )
+ ),
+ $dtf->format_datetime(
+ $dt_today->set(
+ hour => 23,
+ minute => 59,
+ second => 59
+ )
+ )
+ ]
+ }
+ },
+ {
+ order_by => { -desc => 'date_due' },
+ prefetch => 'item'
+ }
+ );
+}
+
=head3 pending_checkouts
my $pending_checkouts = $patron->pending_checkouts
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc
@@ -85,8 +85,10 @@
[% IF Koha.Preference('intranetreadinghistory') %]
[%IF ( privacy == 2 ) %]
Export today's checked in barcodes
- [% ELSE %]
+ [% ELSIF patron.todays_checkouts.size > 0 %]
Export today's checked in barcodes
+ [% ELSE %]
+ Export today's checked in barcodes
[% END %]
[% END %]
--- a/members/readingrec.pl
+++ a/members/readingrec.pl
@@ -58,7 +58,7 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
my $order = 'date_due desc';
-my $limit = 0;
+my $limit = 0; # FIXME This variable is useless
my $issues = ();
# Do not request the old issues of anonymous patron
if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ){
@@ -73,16 +73,19 @@ if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ){
if ( $op eq 'export_barcodes' ) {
# FIXME This should be moved out of this script
if ( $patron->privacy < 2) {
- my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
- my @barcodes =
- map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
- my $borrowercardnumber = $patron->cardnumber;
+ my $dt_today = dt_from_string;
+ my $todays_checkouts = $patron->todays_checkouts;
+ my @barcodes = $todays_checkouts->get_column('item.barcode');
my $delimiter = "\n";
binmode( STDOUT, ":encoding(UTF-8)" );
print $input->header(
-type => 'application/octet-stream',
-charset => 'utf-8',
- -attachment => "$today-$borrowercardnumber-checkinexport.txt"
+ -attachment => sprintf(
+ "%s-%s-checkinexport.txt",
+ output_pref({ dt => $dt_today, dateformat => 'iso', dateonly => 1 }),
+ $patron->cardnumber
+ ),
);
my $content = join $delimiter, uniq(@barcodes);
--