Bug 12224: Some code improvements
[koha-ffzg.git] / members / printslip.pl
index 389f5a6..c89765b 100755 (executable)
@@ -84,43 +84,38 @@ if ( $print eq 'checkinslip' ) {
     my $checkinslip_branch = $session->param('branch') ? $session->param('branch') : $branch;
 
     # get today's checkins
-    my $today_start = dt_from_string->set( hour => 0, minute => 0, second => 0 );
-    my $today_end = dt_from_string->set( hour => 23, minute => 59, second => 0 );
-    $today_start = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_start );
-    $today_end = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_end );
-    my $todays_checkins = Koha::Old::Checkouts->search({
+    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+    my $today = dt_from_string;
+    my $today_start = $today->clone->set( hour => 0, minute => 0, second => 0 );
+    my $today_end   = $today->clone->set( hour => 23, minute => 59, second => 0 );
+    $today_start = $dtf->format_datetime( $today_start );
+    $today_end   = $dtf->format_datetime( $today_end );
+    my @todays_checkins = $patron->old_checkouts->search({
         returndate => {
             '>=' => $today_start,
             '<=' => $today_end,
         },
-        borrowernumber => $borrowernumber,
         branchcode => $checkinslip_branch,
     });
 
-    my @checkins;
-    while ( my $c = $todays_checkins->next ) {
-        push @checkins, {
-            biblio => $c->item->biblio->unblessed,
-            items => $c->item->unblessed,
-        };
-    }
-    my %repeat = (
-        checkedin => \@checkins,
+    my %loops = (
+        old_issues => [ map { $_->itemnumber } @todays_checkins ],
     );
 
     my $letter = C4::Letters::GetPreparedLetter(
-        module => 'circulation',
+        module      => 'circulation',
         letter_code => 'CHECKINSLIP',
-        branchcode => $checkinslip_branch,
-        tables => {
-            branches => $checkinslip_branch,
+        branchcode  => $checkinslip_branch,
+        lang        => $patron->lang,
+        tables      => {
+            branches  => $checkinslip_branch,
             borrowers => $borrowernumber,
         },
-        repeat => \%repeat,
+        loops                  => \%loops,
         message_transport_type => 'print'
     );
 
-    $slip = $letter->{content};
+    $slip    = $letter->{content};
     $is_html = $letter->{is_html};
 
 } elsif (my $letter = IssueSlip ($session->param('branch') || $branch, $borrowernumber, $print eq "qslip")) {