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

(-)a/C4/Letters.pm (-14 / +29 lines)
Lines 819-832 sub _parseletter { Link Here
819
    }
819
    }
820
820
821
    while ( my ($field, $val) = each %$values ) {
821
    while ( my ($field, $val) = each %$values ) {
822
        my $replacetablefield = "<<$table.$field>>";
823
        my $replacefield = "<<$field>>";
824
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
822
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
825
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
823
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
826
            #Therefore adding the test on biblio. This includes biblioitems,
824
            #Therefore adding the test on biblio. This includes biblioitems,
827
            #but excludes items. Removed unneeded global and lookahead.
825
            #but excludes items. Removed unneeded global and lookahead.
828
826
829
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
827
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
828
829
        # Dates replacement
830
        my $replacedby   = defined ($val) ? $val : '';
830
        my $replacedby   = defined ($val) ? $val : '';
831
        if (    $replacedby
831
        if (    $replacedby
832
            and not $replacedby =~ m|0000-00-00|
832
            and not $replacedby =~ m|0000-00-00|
Lines 835-853 sub _parseletter { Link Here
835
        {
835
        {
836
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
836
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
837
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
837
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
838
            eval {
838
            my $re_dateonly_filter = qr{ $field( \s* \| \s* dateonly\s*)?>> }xms;
839
                $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
839
840
            };
840
            for my $letter_field ( qw( title content ) ) {
841
            warn "$replacedby seems to be a date but an error occurs on generating it ($@)" if $@;
841
                my $filter_string_used = q{};
842
                if ( $letter->{ $letter_field } =~ $re_dateonly_filter ) {
843
                    # We overwrite $dateonly if the filter exists and we have a time in the datetime
844
                    $filter_string_used = $1 || q{};
845
                    $dateonly = $1 unless $dateonly;
846
                }
847
                eval {
848
                    $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
849
                };
850
851
                if ( $letter->{ $letter_field } ) {
852
                    $letter->{ $letter_field } =~ s/\Q<<$table.$field$filter_string_used>>\E/$replacedby/g;
853
                    $letter->{ $letter_field } =~ s/\Q<<$field$filter_string_used>>\E/$replacedby/g;
854
                }
855
            }
856
        }
857
        # Other fields replacement
858
        else {
859
            for my $letter_field ( qw( title content ) ) {
860
                if ( $letter->{ $letter_field } ) {
861
                    $letter->{ $letter_field }   =~ s/<<$table.$field>>/$replacedby/g;
862
                    $letter->{ $letter_field }   =~ s/<<$field>>/$replacedby/g;
863
                }
864
            }
842
        }
865
        }
843
        ($letter->{title}  ) and do {
844
            $letter->{title}   =~ s/$replacetablefield/$replacedby/g;
845
            $letter->{title}   =~ s/$replacefield/$replacedby/g;
846
        };
847
        ($letter->{content}) and do {
848
            $letter->{content} =~ s/$replacetablefield/$replacedby/g;
849
            $letter->{content} =~ s/$replacefield/$replacedby/g;
850
        };
851
    }
866
    }
852
867
853
    if ($table eq 'borrowers' && $letter->{content}) {
868
    if ($table eq 'borrowers' && $letter->{content}) {
(-)a/t/db_dependent/Letters.t (-4 / +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 => 65;
21
use Test::More tests => 68;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 141-147 my $letters = C4::Letters::GetLetters(); Link Here
141
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
141
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
142
142
143
my $title = q|<<branches.branchname>> - <<status>>|;
143
my $title = q|<<branches.branchname>> - <<status>>|;
144
my $content = q|Dear <<borrowers.firstname>> <<borrowers.surname>>,
144
my $content = q{Dear <<borrowers.firstname>> <<borrowers.surname>>,
145
According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible.
145
According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible.
146
146
147
<<branches.branchname>>
147
<<branches.branchname>>
Lines 155-161 The following item(s) is/are currently <<status>>: Link Here
155
Thank-you for your prompt attention to this matter.
155
Thank-you for your prompt attention to this matter.
156
Don't forget your date of birth: <<borrowers.dateofbirth>>.
156
Don't forget your date of birth: <<borrowers.dateofbirth>>.
157
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
157
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
158
|;
158
};
159
159
160
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('CPL','my module','my code','my name',1,?,?,'email')|, undef, $title, $content );
160
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('CPL','my module','my code','my name',1,?,?,'email')|, undef, $title, $content );
161
$letters = C4::Letters::GetLetters();
161
$letters = C4::Letters::GetLetters();
Lines 279-284 The following item(s) is/are currently $substitute->{status}: Link Here
279
Thank-you for your prompt attention to this matter.
279
Thank-you for your prompt attention to this matter.
280
Don't forget your date of birth: | . output_pref({ dt => $date, dateonly => 1 }) . q|.
280
Don't forget your date of birth: | . output_pref({ dt => $date, dateonly => 1 }) . q|.
281
Look at this wonderful biblio timestamp: | . output_pref({ dt => $date }) . ".\n";
281
Look at this wonderful biblio timestamp: | . output_pref({ dt => $date }) . ".\n";
282
282
is( $prepared_letter->{title}, $my_title_letter, 'GetPreparedLetter returns the title correctly' );
283
is( $prepared_letter->{title}, $my_title_letter, 'GetPreparedLetter returns the title correctly' );
283
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
284
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
284
285
Lines 294-299 $prepared_letter = GetPreparedLetter(( Link Here
294
$my_content_letter = qq|This is a SMS for an $substitute->{status}|;
295
$my_content_letter = qq|This is a SMS for an $substitute->{status}|;
295
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
296
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
296
297
298
$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test_date','TEST_DATE','Test dates','Test dates','This one only contains the date: <<biblio.timestamp | dateonly>>.');});
299
$prepared_letter = GetPreparedLetter((
300
    module                 => 'test_date',
301
    branchcode             => '',
302
    letter_code            => 'test_date',
303
    tables                 => $tables,
304
    substitute             => $substitute,
305
    repeat                 => $repeat,
306
));
307
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
308
309
$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp | dateonly>>.' WHERE code = 'test_date';});
310
$prepared_letter = GetPreparedLetter((
311
    module                 => 'test_date',
312
    branchcode             => '',
313
    letter_code            => 'test_date',
314
    tables                 => $tables,
315
    substitute             => $substitute,
316
    repeat                 => $repeat,
317
));
318
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
319
320
$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp|dateonly >>.' WHERE code = 'test_date';});
321
$prepared_letter = GetPreparedLetter((
322
    module                 => 'test_date',
323
    branchcode             => '',
324
    letter_code            => 'test_date',
325
    tables                 => $tables,
326
    substitute             => $substitute,
327
    repeat                 => $repeat,
328
));
329
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
330
297
$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimacquisition','TESTACQCLAIM','Acquisition Claim','Item Not Received','<<aqbooksellers.name>>|<<aqcontacts.name>>|<order>Ordernumber <<aqorders.ordernumber>> (<<biblio.title>>) (<<aqorders.quantity>> ordered)</order>');});
331
$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimacquisition','TESTACQCLAIM','Acquisition Claim','Item Not Received','<<aqbooksellers.name>>|<<aqcontacts.name>>|<order>Ordernumber <<aqorders.ordernumber>> (<<biblio.title>>) (<<aqorders.quantity>> ordered)</order>');});
298
332
299
my $booksellerid = C4::Bookseller::AddBookseller(
333
my $booksellerid = C4::Bookseller::AddBookseller(
300
- 

Return to bug 13622