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

(-)a/C4/Letters.pm (-14 / +29 lines)
Lines 801-814 sub _parseletter { Link Here
801
    }
801
    }
802
802
803
    while ( my ($field, $val) = each %$values ) {
803
    while ( my ($field, $val) = each %$values ) {
804
        my $replacetablefield = "<<$table.$field>>";
805
        my $replacefield = "<<$field>>";
806
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
804
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
807
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
805
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
808
            #Therefore adding the test on biblio. This includes biblioitems,
806
            #Therefore adding the test on biblio. This includes biblioitems,
809
            #but excludes items. Removed unneeded global and lookahead.
807
            #but excludes items. Removed unneeded global and lookahead.
810
808
811
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
809
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
810
811
        # Dates replacement
812
        my $replacedby   = defined ($val) ? $val : '';
812
        my $replacedby   = defined ($val) ? $val : '';
813
        if (    $replacedby
813
        if (    $replacedby
814
            and not $replacedby =~ m|0000-00-00|
814
            and not $replacedby =~ m|0000-00-00|
Lines 817-835 sub _parseletter { Link Here
817
        {
817
        {
818
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
818
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
819
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
819
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
820
            eval {
820
            my $re_dateonly_filter = qr{ $field( \s* \| \s* dateonly\s*)?>> }xms;
821
                $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
821
822
            };
822
            for my $letter_field ( qw( title content ) ) {
823
            warn "$replacedby seems to be a date but an error occurs on generating it ($@)" if $@;
823
                my $filter_string_used = q{};
824
                if ( $letter->{ $letter_field } =~ $re_dateonly_filter ) {
825
                    # We overwrite $dateonly if the filter exists and we have a time in the datetime
826
                    $filter_string_used = $1 || q{};
827
                    $dateonly = $1 unless $dateonly;
828
                }
829
                eval {
830
                    $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
831
                };
832
833
                if ( $letter->{ $letter_field } ) {
834
                    $letter->{ $letter_field } =~ s/\Q<<$table.$field$filter_string_used>>\E/$replacedby/g;
835
                    $letter->{ $letter_field } =~ s/\Q<<$field$filter_string_used>>\E/$replacedby/g;
836
                }
837
            }
838
        }
839
        # Other fields replacement
840
        else {
841
            for my $letter_field ( qw( title content ) ) {
842
                if ( $letter->{ $letter_field } ) {
843
                    $letter->{ $letter_field }   =~ s/<<$table.$field>>/$replacedby/g;
844
                    $letter->{ $letter_field }   =~ s/<<$field>>/$replacedby/g;
845
                }
846
            }
824
        }
847
        }
825
        ($letter->{title}  ) and do {
826
            $letter->{title}   =~ s/$replacetablefield/$replacedby/g;
827
            $letter->{title}   =~ s/$replacefield/$replacedby/g;
828
        };
829
        ($letter->{content}) and do {
830
            $letter->{content} =~ s/$replacetablefield/$replacedby/g;
831
            $letter->{content} =~ s/$replacefield/$replacedby/g;
832
        };
833
    }
848
    }
834
849
835
    if ($table eq 'borrowers' && $letter->{content}) {
850
    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 => 58;
21
use Test::More tests => 61;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 137-143 my $letters = C4::Letters::GetLetters(); Link Here
137
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
137
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
138
138
139
my $title = q|<<branches.branchname>> - <<status>>|;
139
my $title = q|<<branches.branchname>> - <<status>>|;
140
my $content = q|Dear <<borrowers.firstname>> <<borrowers.surname>>,
140
my $content = q{Dear <<borrowers.firstname>> <<borrowers.surname>>,
141
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.
141
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.
142
142
143
<<branches.branchname>>
143
<<branches.branchname>>
Lines 151-157 The following item(s) is/are currently <<status>>: Link Here
151
Thank-you for your prompt attention to this matter.
151
Thank-you for your prompt attention to this matter.
152
Don't forget your date of birth: <<borrowers.dateofbirth>>.
152
Don't forget your date of birth: <<borrowers.dateofbirth>>.
153
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
153
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
154
|;
154
};
155
155
156
$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 );
156
$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 );
157
$letters = C4::Letters::GetLetters();
157
$letters = C4::Letters::GetLetters();
Lines 260-265 The following item(s) is/are currently $substitute->{status}: Link Here
260
Thank-you for your prompt attention to this matter.
260
Thank-you for your prompt attention to this matter.
261
Don't forget your date of birth: | . output_pref({ dt => $date, dateonly => 1 }) . q|.
261
Don't forget your date of birth: | . output_pref({ dt => $date, dateonly => 1 }) . q|.
262
Look at this wonderful biblio timestamp: | . output_pref({ dt => $date }) . ".\n";
262
Look at this wonderful biblio timestamp: | . output_pref({ dt => $date }) . ".\n";
263
263
is( $prepared_letter->{title}, $my_title_letter, 'GetPreparedLetter returns the title correctly' );
264
is( $prepared_letter->{title}, $my_title_letter, 'GetPreparedLetter returns the title correctly' );
264
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
265
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
265
266
Lines 275-280 $prepared_letter = GetPreparedLetter(( Link Here
275
$my_content_letter = qq|This is a SMS for an $substitute->{status}|;
276
$my_content_letter = qq|This is a SMS for an $substitute->{status}|;
276
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
277
is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns the content correctly' );
277
278
279
$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>>.');});
280
$prepared_letter = GetPreparedLetter((
281
    module                 => 'test_date',
282
    branchcode             => '',
283
    letter_code            => 'test_date',
284
    tables                 => $tables,
285
    substitute             => $substitute,
286
    repeat                 => $repeat,
287
));
288
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
289
290
$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp | dateonly>>.' WHERE code = 'test_date';});
291
$prepared_letter = GetPreparedLetter((
292
    module                 => 'test_date',
293
    branchcode             => '',
294
    letter_code            => 'test_date',
295
    tables                 => $tables,
296
    substitute             => $substitute,
297
    repeat                 => $repeat,
298
));
299
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
300
301
$dbh->do(q{UPDATE letter SET content = 'And also this one:<<timestamp|dateonly >>.' WHERE code = 'test_date';});
302
$prepared_letter = GetPreparedLetter((
303
    module                 => 'test_date',
304
    branchcode             => '',
305
    letter_code            => 'test_date',
306
    tables                 => $tables,
307
    substitute             => $substitute,
308
    repeat                 => $repeat,
309
));
310
is( $prepared_letter->{content}, q|This one only contains the date: | . output_pref({ dt => $date, dateonly => 1 }) . q|.| );
311
278
$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>');});
312
$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>');});
279
313
280
my $booksellerid = C4::Bookseller::AddBookseller(
314
my $booksellerid = C4::Bookseller::AddBookseller(
281
- 

Return to bug 13622