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

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