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

(-)a/C4/Letters.pm (-14 / +29 lines)
Lines 788-801 sub _parseletter { Link Here
788
    }
788
    }
789
789
790
    while ( my ($field, $val) = each %$values ) {
790
    while ( my ($field, $val) = each %$values ) {
791
        my $replacetablefield = "<<$table.$field>>";
792
        my $replacefield = "<<$field>>";
793
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
791
        $val =~ s/\p{P}$// if $val && $table=~/biblio/;
794
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
792
            #BZ 9886: Assuming that we want to eliminate ISBD punctuation here
795
            #Therefore adding the test on biblio. This includes biblioitems,
793
            #Therefore adding the test on biblio. This includes biblioitems,
796
            #but excludes items. Removed unneeded global and lookahead.
794
            #but excludes items. Removed unneeded global and lookahead.
797
795
798
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
796
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
797
798
        # Dates replacement
799
        my $replacedby   = defined ($val) ? $val : '';
799
        my $replacedby   = defined ($val) ? $val : '';
800
        if (    $replacedby
800
        if (    $replacedby
801
            and not $replacedby =~ m|0000-00-00|
801
            and not $replacedby =~ m|0000-00-00|
Lines 804-822 sub _parseletter { Link Here
804
        {
804
        {
805
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
805
            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
806
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
806
            my $dateonly = defined $1 ? 0 : 1; #$1 refers to the capture group wrapped in parentheses. In this case, that's the hours, minutes, seconds.
807
            eval {
807
            my $re_dateonly_filter = qr{ $field( \s* \| \s* dateonly\s*)?>> }xms;
808
                $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
808
809
            };
809
            for my $letter_field ( qw( title content ) ) {
810
            warn "$replacedby seems to be a date but an error occurs on generating it ($@)" if $@;
810
                my $filter_string_used = q{};
811
                if ( $letter->{ $letter_field } =~ $re_dateonly_filter ) {
812
                    # We overwrite $dateonly if the filter exists and we have a time in the datetime
813
                    $filter_string_used = $1 || q{};
814
                    $dateonly = $1 unless $dateonly;
815
                }
816
                eval {
817
                    $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
818
                };
819
820
                if ( $letter->{ $letter_field } ) {
821
                    $letter->{ $letter_field } =~ s/\Q<<$table.$field$filter_string_used>>\E/$replacedby/g;
822
                    $letter->{ $letter_field } =~ s/\Q<<$field$filter_string_used>>\E/$replacedby/g;
823
                }
824
            }
825
        }
826
        # Other fields replacement
827
        else {
828
            for my $letter_field ( qw( title content ) ) {
829
                if ( $letter->{ $letter_field } ) {
830
                    $letter->{ $letter_field }   =~ s/<<$table.$field>>/$replacedby/g;
831
                    $letter->{ $letter_field }   =~ s/<<$field>>/$replacedby/g;
832
                }
833
            }
811
        }
834
        }
812
        ($letter->{title}  ) and do {
813
            $letter->{title}   =~ s/$replacetablefield/$replacedby/g;
814
            $letter->{title}   =~ s/$replacefield/$replacedby/g;
815
        };
816
        ($letter->{content}) and do {
817
            $letter->{content} =~ s/$replacetablefield/$replacedby/g;
818
            $letter->{content} =~ s/$replacefield/$replacedby/g;
819
        };
820
    }
835
    }
821
836
822
    if ($table eq 'borrowers' && $letter->{content}) {
837
    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