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

(-)a/C4/Letters.pm (+19 lines)
Lines 1638-1643 sub _get_tt_params { Link Here
1638
    return $params;
1638
    return $params;
1639
}
1639
}
1640
1640
1641
sub get_item_content {
1642
    my ( $params ) = @_;
1643
    my $item = $params->{item};
1644
    my $dateonly = $params->{dateonly} || 0;
1645
    my $item_content_fields = $params->{item_content_fields} || [];
1646
1647
    return unless $item;
1648
1649
    my @item_info = map {
1650
        $_ =~ /^date|date$/
1651
          ? eval {
1652
            output_pref(
1653
                { dt => dt_from_string( $item->{$_} ), dateonly => $dateonly } );
1654
          }
1655
          : $item->{$_}
1656
          || ''
1657
    } @$item_content_fields;
1658
    return join( "\t", @item_info ) . "\n";
1659
}
1641
1660
1642
1;
1661
1;
1643
__END__
1662
__END__
(-)a/misc/cronjobs/advance_notices.pl (-14 / +4 lines)
Lines 256-263 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
256
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
256
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
257
            my $titles = "";
257
            my $titles = "";
258
            while ( my $item_info = $sth->fetchrow_hashref()) {
258
            while ( my $item_info = $sth->fetchrow_hashref()) {
259
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
259
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
260
              $titles .= join("\t",@item_info) . "\n";
261
            }
260
            }
262
261
263
            ## Get branch info for borrowers home library.
262
            ## Get branch info for borrowers home library.
Lines 290-297 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
290
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
289
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
291
            my $titles = "";
290
            my $titles = "";
292
            while ( my $item_info = $sth->fetchrow_hashref()) {
291
            while ( my $item_info = $sth->fetchrow_hashref()) {
293
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
292
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
294
              $titles .= join("\t",@item_info) . "\n";
295
            }
293
            }
296
294
297
            ## Get branch info for borrowers home library.
295
            ## Get branch info for borrowers home library.
Lines 356-363 PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) { Link Here
356
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
354
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
357
    my $titles = "";
355
    my $titles = "";
358
    while ( my $item_info = $sth->fetchrow_hashref()) {
356
    while ( my $item_info = $sth->fetchrow_hashref()) {
359
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
357
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
360
      $titles .= join("\t",@item_info) . "\n";
361
    }
358
    }
362
359
363
    ## Get branch info for borrowers home library.
360
    ## Get branch info for borrowers home library.
Lines 413-420 PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) { Link Here
413
    $sth->execute($borrowernumber,'0');
410
    $sth->execute($borrowernumber,'0');
414
    my $titles = "";
411
    my $titles = "";
415
    while ( my $item_info = $sth->fetchrow_hashref()) {
412
    while ( my $item_info = $sth->fetchrow_hashref()) {
416
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
413
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
417
      $titles .= join("\t",@item_info) . "\n";
418
    }
414
    }
419
415
420
    ## Get branch info for borrowers home library.
416
    ## Get branch info for borrowers home library.
Lines 495-506 sub parse_letter { Link Here
495
    );
491
    );
496
}
492
}
497
493
498
sub format_date {
499
    my $date_string = shift;
500
    my $dt=dt_from_string($date_string);
501
    return output_pref($dt);
502
}
503
504
=head2 get_branch_info
494
=head2 get_branch_info
505
495
506
=cut
496
=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 / +35 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 => 82;
21
use Test::More tests => 83;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 626-630 subtest 'SendQueuedMessages' => sub { Link Here
626
        status => 'sent'
626
        status => 'sent'
627
    })->next()->to_address();
627
    })->next()->to_address();
628
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
628
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
629
};
630
631
subtest 'get_item_content' => sub {
632
    plan tests => 2;
633
634
    t::lib::Mocks::mock_preference('dateformat', 'metric');
635
    t::lib::Mocks::mock_preference('timeformat', '24hr');
636
    my @items = (
637
        {date_due => '2041-01-01 12:34', title => 'a first title', barcode => 'a_first_barcode', author => 'a_first_author', itemnumber => 1 },
638
        {date_due => '2042-01-02 23:45', title => 'a second title', barcode => 'a_second_barcode', author => 'a_second_author', itemnumber => 2 },
639
    );
640
    my @item_content_fields = qw( date_due title barcode author itemnumber );
641
642
    my $items_content;
643
    for my $item ( @items ) {
644
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields } );
645
    }
646
647
    my $expected_items_content = <<EOF;
648
01/01/2041 12:34\ta first title\ta_first_barcode\ta_first_author\t1
649
02/01/2042 23:45\ta second title\ta_second_barcode\ta_second_author\t2
650
EOF
651
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info with time (default)' );
652
653
654
    $items_content = q||;
655
    for my $item ( @items ) {
656
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields, dateonly => 1, } );
657
    }
629
658
659
    $expected_items_content = <<EOF;
660
01/01/2041\ta first title\ta_first_barcode\ta_first_author\t1
661
02/01/2042\ta second title\ta_second_barcode\ta_second_author\t2
662
EOF
663
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
630
};
664
};
631
- 

Return to bug 17969