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

(-)a/C4/Letters.pm (+19 lines)
Lines 1632-1637 sub _get_tt_params { Link Here
1632
    return $params;
1632
    return $params;
1633
}
1633
}
1634
1634
1635
sub get_item_content {
1636
    my ( $params ) = @_;
1637
    my $item = $params->{item};
1638
    my $dateonly = $params->{dateonly} || 0;
1639
    my $item_content_fields = $params->{item_content_fields} || [];
1640
1641
    return unless $item;
1642
1643
    my @item_info = map {
1644
        $_ =~ /^date|date$/
1645
          ? eval {
1646
            output_pref(
1647
                { dt => dt_from_string( $item->{$_} ), dateonly => $dateonly } );
1648
          }
1649
          : $item->{$_}
1650
          || ''
1651
    } @$item_content_fields;
1652
    return join( "\t", @item_info ) . "\n";
1653
}
1635
1654
1636
1;
1655
1;
1637
__END__
1656
__END__
(-)a/misc/cronjobs/advance_notices.pl (-14 / +4 lines)
Lines 258-265 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
258
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
258
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
259
            my $titles = "";
259
            my $titles = "";
260
            while ( my $item_info = $sth->fetchrow_hashref()) {
260
            while ( my $item_info = $sth->fetchrow_hashref()) {
261
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
261
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
262
              $titles .= join("\t",@item_info) . "\n";
263
            }
262
            }
264
263
265
            ## Get branch info for borrowers home library.
264
            ## Get branch info for borrowers home library.
Lines 292-299 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
292
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
291
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
293
            my $titles = "";
292
            my $titles = "";
294
            while ( my $item_info = $sth->fetchrow_hashref()) {
293
            while ( my $item_info = $sth->fetchrow_hashref()) {
295
              my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
294
                $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
296
              $titles .= join("\t",@item_info) . "\n";
297
            }
295
            }
298
296
299
            ## Get branch info for borrowers home library.
297
            ## Get branch info for borrowers home library.
Lines 358-365 PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) { Link Here
358
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
356
    $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
359
    my $titles = "";
357
    my $titles = "";
360
    while ( my $item_info = $sth->fetchrow_hashref()) {
358
    while ( my $item_info = $sth->fetchrow_hashref()) {
361
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
359
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
362
      $titles .= join("\t",@item_info) . "\n";
363
    }
360
    }
364
361
365
    ## Get branch info for borrowers home library.
362
    ## Get branch info for borrowers home library.
Lines 415-422 PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) { Link Here
415
    $sth->execute($borrowernumber,'0');
412
    $sth->execute($borrowernumber,'0');
416
    my $titles = "";
413
    my $titles = "";
417
    while ( my $item_info = $sth->fetchrow_hashref()) {
414
    while ( my $item_info = $sth->fetchrow_hashref()) {
418
      my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
415
        $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
419
      $titles .= join("\t",@item_info) . "\n";
420
    }
416
    }
421
417
422
    ## Get branch info for borrowers home library.
418
    ## Get branch info for borrowers home library.
Lines 497-508 sub parse_letter { Link Here
497
    );
493
    );
498
}
494
}
499
495
500
sub format_date {
501
    my $date_string = shift;
502
    my $dt=dt_from_string($date_string);
503
    return output_pref($dt);
504
}
505
506
=head2 get_branch_info
496
=head2 get_branch_info
507
497
508
=cut
498
=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 => 75;
21
use Test::More tests => 76;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 649-653 subtest 'SendQueuedMessages' => sub { Link Here
649
        status => 'sent'
649
        status => 'sent'
650
    })->next()->to_address();
650
    })->next()->to_address();
651
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
651
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
652
};
653
654
subtest 'get_item_content' => sub {
655
    plan tests => 2;
656
657
    t::lib::Mocks::mock_preference('dateformat', 'metric');
658
    t::lib::Mocks::mock_preference('timeformat', '24hr');
659
    my @items = (
660
        {date_due => '2041-01-01 12:34', title => 'a first title', barcode => 'a_first_barcode', author => 'a_first_author', itemnumber => 1 },
661
        {date_due => '2042-01-02 23:45', title => 'a second title', barcode => 'a_second_barcode', author => 'a_second_author', itemnumber => 2 },
662
    );
663
    my @item_content_fields = qw( date_due title barcode author itemnumber );
664
665
    my $items_content;
666
    for my $item ( @items ) {
667
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields } );
668
    }
669
670
    my $expected_items_content = <<EOF;
671
01/01/2041 12:34\ta first title\ta_first_barcode\ta_first_author\t1
672
02/01/2042 23:45\ta second title\ta_second_barcode\ta_second_author\t2
673
EOF
674
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info with time (default)' );
675
676
677
    $items_content = q||;
678
    for my $item ( @items ) {
679
        $items_content .= C4::Letters::get_item_content( { item => $item, item_content_fields => \@item_content_fields, dateonly => 1, } );
680
    }
652
681
682
    $expected_items_content = <<EOF;
683
01/01/2041\ta first title\ta_first_barcode\ta_first_author\t1
684
02/01/2042\ta second title\ta_second_barcode\ta_second_author\t2
685
EOF
686
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
653
};
687
};
654
- 

Return to bug 17969