@@ -, +, @@ compatible --- C4/Letters.pm | 6 ++ C4/Members.pm | 58 +++++++------ t/db_dependent/Letters/TemplateToolkit.t | 138 ++++++++++++++++++++++++++++++- 3 files changed, 178 insertions(+), 24 deletions(-) --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -1548,6 +1548,12 @@ sub _get_tt_params { plural => 'old_checkouts', fk => 'itemnumber', }, + overdues => { + module => 'Koha::Checkouts', + singular => 'overdue', + plural => 'overdues', + fk => 'itemnumber', + }, borrower_modifications => { module => 'Koha::Patron::Modifications', singular => 'patron_modification', --- a/C4/Members.pm +++ a/C4/Members.pm @@ -1232,39 +1232,50 @@ sub IssueSlip { $b->{issuedate} <=> $a->{issuedate} : $s; } @issues; - my ($letter_code, %repeat); + my ($letter_code, %repeat, %loops); if ( $quickslip ) { $letter_code = 'ISSUEQSLIP'; - %repeat = ( - 'checkedout' => [ map { + my @checkouts = map { 'biblio' => $_, 'items' => $_, 'biblioitems' => $_, 'issues' => $_, - }, grep { $_->{'now'} } @issues ], + }, grep { $_->{'now'} } @issues; + %repeat = ( + checkedout => \@checkouts, # History syntax + ); + %loops = ( + issues => [ map { $_->{issues}{itemnumber} } @checkouts ], # TT syntax ); } else { + my @checkouts = map { + 'biblio' => $_, + 'items' => $_, + 'biblioitems' => $_, + 'issues' => $_, + }, grep { !$_->{'overdue'} } @issues; + my @overdues = map { + 'biblio' => $_, + 'items' => $_, + 'biblioitems' => $_, + 'issues' => $_, + }, grep { $_->{'overdue'} } @issues; + my $news = GetNewsToDisplay( "slip", $branch ); + my @news = map { + $_->{'timestamp'} = $_->{'newdate'}; + { opac_news => $_ } + } @$news; $letter_code = 'ISSUESLIP'; - %repeat = ( - 'checkedout' => [ map { - 'biblio' => $_, - 'items' => $_, - 'biblioitems' => $_, - 'issues' => $_, - }, grep { !$_->{'overdue'} } @issues ], - - 'overdue' => [ map { - 'biblio' => $_, - 'items' => $_, - 'biblioitems' => $_, - 'issues' => $_, - }, grep { $_->{'overdue'} } @issues ], - - 'news' => [ map { - $_->{'timestamp'} = $_->{'newdate'}; - { opac_news => $_ } - } @{ GetNewsToDisplay("slip",$branch) } ], + %repeat = ( + checkedout => \@checkouts, + overdue => \@overdues, + news => \@news, + ); + %loops = ( + issues => [ map { $_->{issues}{itemnumber} } @checkouts ], + overdues => [ map { $_->{issues}{itemnumber} } @overdues ], + opac_news => [ map { $_->{opac_news}{idnew} } @news ], ); } @@ -1277,6 +1288,7 @@ sub IssueSlip { 'borrowers' => $borrowernumber, }, repeat => \%repeat, + loops => \%loops, ); } --- a/t/db_dependent/Letters/TemplateToolkit.t +++ a/t/db_dependent/Letters/TemplateToolkit.t @@ -318,7 +318,7 @@ subtest 'loops' => sub { }; subtest 'regression tests' => sub { - plan tests => 5; + plan tests => 6; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower' } ); @@ -348,6 +348,19 @@ subtest 'regression tests' => sub { itemcallnumber => 'itemcallnumber2', } )->store->unblessed; + my $biblio3 = Koha::Biblio->new({title => 'Test Biblio 3'})->store->unblessed; + my $biblioitem3 = Koha::Biblioitem->new({biblionumber => $biblio3->{biblionumber}})->store()->unblessed; + my $item3 = Koha::Item->new( + { + biblionumber => $biblio3->{biblionumber}, + biblioitemnumber => $biblioitem3->{biblioitemnumber}, + barcode => 'another_t_barcode_3', + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + itype => 'BK', + itemcallnumber => 'itemcallnumber3', + } + )->store->unblessed; C4::Context->_new_userenv('xxx'); C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); @@ -613,6 +626,129 @@ EOF is( $tt_letter_for_item1->{content}, $letter_for_item1->{content}, ); is( $tt_letter_for_item2->{content}, $letter_for_item2->{content}, ); }; + + subtest 'ISSUESLIP|checkedout|repeat' => sub { + plan tests => 2; + + my $code = 'ISSUESLIP'; + + my $branchcode = $library->{branchcode}; + + Koha::News->delete; + my $news_item = Koha::NewsItem->new({ branchcode => $branchcode, title => "A wonderful news", content => "This is the wonderful news." })->store; + + # historic syntax + my $template = <<> +Checked out to <> <> <> <>
+(<>)
+ +<>
+ +

Checked Out

+ +

+<>
+Barcode: <>
+Date due: <>
+

+
+ +

Overdues

+ +

+<>
+Barcode: <>
+Date due: <>
+

+
+ +
+ +

News

+ +
+
<>
+

<>

+

Posted on <>

+
+
+
+EOF + + reset_template( { template => $template, code => $code, module => 'circulation' } ); + + C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout + my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} ); + + C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout + my $yesterday = dt_from_string->subtract( days => 1 ); + C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue + my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} ); + + # Cleanup + AddReturn( $item1->{barcode} ); + AddReturn( $item2->{barcode} ); + AddReturn( $item3->{barcode} ); + + # TT syntax + my $tt_template = <[% branch.branchname %] +Checked out to [% borrower.title %] [% borrower.firstname %] [% borrower.initials %] [% borrower.surname %]
+([% borrower.cardnumber %])
+ +[% today | \$KohaDates with_hours => 1 %]
+ +

Checked Out

+[% FOREACH checkout IN checkouts %] +[%~ SET item = checkout.item %] +[%~ SET biblio = checkout.item.biblio %] +

+[% biblio.title %]
+Barcode: [% item.barcode %]
+Date due: [% checkout.date_due | \$KohaDates %]
+

+[% END %] + +

Overdues

+[% FOREACH overdue IN overdues %] +[%~ SET item = overdue.item %] +[%~ SET biblio = overdue.item.biblio %] +

+[% biblio.title %]
+Barcode: [% item.barcode %]
+Date due: [% overdue.date_due | \$KohaDates %]
+

+[% END %] + +
+ +

News

+[% FOREACH n IN news %] +
+
[% n.title %]
+

[% n.content %]

+

Posted on [% n.timestamp | \$KohaDates %]

+
+
+[% END %] +EOF + + reset_template( { template => $tt_template, code => $code, module => 'circulation' } ); + + C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout + my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} ); + + C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout + C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue + my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} ); + + # There is too many line breaks generated by the historic syntax + $second_slip->{content} =~ s|

\n\n\n

|

\n\n

|s; + + is( $first_tt_slip->{content}, $first_slip->{content}, ); + is( $second_tt_slip->{content}, $second_slip->{content}, ); + }; }; sub reset_template { --