View | Details | Raw Unified | Return to bug 17969
Collapse All | Expand All

(-)a/C4/Letters.pm (+19 lines)
Lines 1585-1590 sub _get_tt_params { Link Here
1585
    return $params;
1585
    return $params;
1586
}
1586
}
1587
1587
1588
sub get_item_content {
1589
    my ( $params ) = @_;
1590
    my $item = $params->{item};
1591
    my $dateonly = $params->{dateonly} || 0;
1592
    my $item_content_fields = $params->{item_content_fields} || [];
1593
1594
    return unless $item;
1595
1596
    my @item_info = map {
1597
        $_ =~ /^date|date$/
1598
          ? eval {
1599
            output_pref(
1600
                { dt => dt_from_string( $item->{$_} ), dateonly => $dateonly } );
1601
          }
1602
          : $item->{$_}
1603
          || ''
1604
    } @$item_content_fields;
1605
    return join( "\t", @item_info ) . "\n";
1606
}
1588
1607
1589
1;
1608
1;
1590
__END__
1609
__END__
(-)a/misc/cronjobs/advance_notices.pl (-14 / +4 lines)
Lines 255-262 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
255
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
255
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
256
            my $titles = "";
256
            my $titles = "";
257
            while ( my $item_info = $sth->fetchrow_hashref()) {
257
            while ( my $item_info = $sth->fetchrow_hashref()) {
258
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
258
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
259
              $titles .= join("\t",@item_info) . "\n";
260
            }
259
            }
261
260
262
            ## Get branch info for borrowers home library.
261
            ## Get branch info for borrowers home library.
Lines 289-296 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
289
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
288
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
290
            my $titles = "";
289
            my $titles = "";
291
            while ( my $item_info = $sth->fetchrow_hashref()) {
290
            while ( my $item_info = $sth->fetchrow_hashref()) {
292
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
291
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
293
              $titles .= join("\t",@item_info) . "\n";
294
            }
292
            }
295
293
296
            ## Get branch info for borrowers home library.
294
            ## Get branch info for borrowers home library.
Lines 355-362 PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) { Link Here
355
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
353
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
356
    my $titles = "";
354
    my $titles = "";
357
    while ( my $item_info = $sth->fetchrow_hashref()) {
355
    while ( my $item_info = $sth->fetchrow_hashref()) {
358
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
356
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
359
      $titles .= join("\t",@item_info) . "\n";
360
    }
357
    }
361
358
362
    ## Get branch info for borrowers home library.
359
    ## Get branch info for borrowers home library.
Lines 412-419 PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) { Link Here
412
    $sth->execute($borrowernumber,'0');
409
    $sth->execute($borrowernumber,'0');
413
    my $titles = "";
410
    my $titles = "";
414
    while ( my $item_info = $sth->fetchrow_hashref()) {
411
    while ( my $item_info = $sth->fetchrow_hashref()) {
415
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
412
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
416
      $titles .= join("\t",@item_info) . "\n";
417
    }
413
    }
418
414
419
    ## Get branch info for borrowers home library.
415
    ## Get branch info for borrowers home library.
Lines 492-503 sub parse_letter { Link Here
492
    );
488
    );
493
}
489
}
494
490
495
sub format_date {
496
    my $date_string = shift;
497
    my $dt=dt_from_string($date_string);
498
    return output_pref($dt);
499
}
500
501
=head2 get_branch_info
491
=head2 get_branch_info
502
492
503
=cut
493
=cut
(-)a/misc/cronjobs/overdue_notices.pl (-5 / +2 lines)
Lines 663-673 END_SQL Link Here
663
                      last;
663
                      last;
664
                    }
664
                    }
665
                    $j++;
665
                    $j++;
666
                    my @item_info = map { $_ =~ /^date|date$/ ?
666
667
                                           eval { output_pref( { dt => dt_from_string( $item_info->{$_} ), dateonly => 1 } ); }
667
                    $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields, dateonly => 1 } );
668
                                           :
669
                                           $item_info->{$_} || '' } @item_content_fields;
670
                    $titles .= join("\t", @item_info) . "\n";
671
                    $itemcount++;
668
                    $itemcount++;
672
                    push @items, $item_info;
669
                    push @items, $item_info;
673
                }
670
                }
(-)a/t/db_dependent/Letters.t (-2 / +37 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 79;
21
use Test::More tests => 80;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 489-491 is($err2, 1, "Successfully sent serial notification"); Link Here
489
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
489
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
491
}
491
}
492
- 
492
493
subtest 'get_item_content' => sub {
494
    plan tests => 2;
495
496
    t::lib::Mocks::mock_preference('dateformat', 'metric');
497
    t::lib::Mocks::mock_preference('timeformat', '24hr');
498
    my @items = (
499
        {date_due => '2041-01-01 12:34', title => 'a first title', barcode => 'a_first_barcode', author => 'a_first_author', itemnumber => 1 },
500
        {date_due => '2042-01-02 23:45', title => 'a second title', barcode => 'a_second_barcode', author => 'a_second_author', itemnumber => 2 },
501
    );
502
    my @item_content_fields = qw( date_due title barcode author itemnumber );
503
504
    my $items_content;
505
    for my $item ( @items ) {
506
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields } );
507
    }
508
509
    my $expected_items_content = <<EOF;
510
01/01/2041 12:34\ta first title\ta_first_barcode\ta_first_author\t1
511
02/01/2042 23:45\ta second title\ta_second_barcode\ta_second_author\t2
512
EOF
513
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info with time (default)' );
514
515
516
    $items_content = q||;
517
    for my $item ( @items ) {
518
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields, dateonly => 1, } );
519
    }
520
521
    $expected_items_content = <<EOF;
522
01/01/2041\ta first title\ta_first_barcode\ta_first_author\t1
523
02/01/2042\ta second title\ta_second_barcode\ta_second_author\t2
524
EOF
525
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
526
527
};

Return to bug 17969