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

(-)a/C4/Letters.pm (+80 lines)
Lines 116-121 sub GetLetters { Link Here
116
    return \%letters;
116
    return \%letters;
117
}
117
}
118
118
119
=head2 GetLetter( %params )
120
121
    retrieves the letter template
122
123
    %params hash:
124
      module => letter module, mandatory
125
      letter_code => letter code, mandatory
126
      branchcode => for letter selection, if missing default system letter taken
127
    Return value:
128
      letter fields hashref (title & content useful)
129
130
=cut
131
132
sub GetLetter {
133
    my %params = @_;
134
135
    my $module      = $params{module} or croak "No module";
136
    my $letter_code = $params{letter_code} or croak "No letter_code";
137
    my $branchcode  = $params{branchcode} || '';
138
139
    my $letter = getletter( $module, $letter_code, $branchcode )
140
        or warn( "No $module $letter_code letter"),
141
            return;
142
143
    return $letter;
144
}
145
119
my %letter;
146
my %letter;
120
sub getletter {
147
sub getletter {
121
    my ( $module, $code, $branchcode ) = @_;
148
    my ( $module, $code, $branchcode ) = @_;
Lines 409-414 sub SendAlerts { Link Here
409
436
410
=head2 GetPreparedLetter( %params )
437
=head2 GetPreparedLetter( %params )
411
438
439
    retrieves letter template and performs substituion processing
440
412
    %params hash:
441
    %params hash:
413
      module => letter module, mandatory
442
      module => letter module, mandatory
414
      letter_code => letter code, mandatory
443
      letter_code => letter code, mandatory
Lines 436-449 sub GetPreparedLetter { Link Here
436
    my $module      = $params{module} or croak "No module";
465
    my $module      = $params{module} or croak "No module";
437
    my $letter_code = $params{letter_code} or croak "No letter_code";
466
    my $letter_code = $params{letter_code} or croak "No letter_code";
438
    my $branchcode  = $params{branchcode} || '';
467
    my $branchcode  = $params{branchcode} || '';
468
    my $tables = $params{tables};
469
    my $substitute = $params{substitute};
470
    my $repeat = $params{repeat};
439
471
440
    my $letter = getletter( $module, $letter_code, $branchcode )
472
    my $letter = getletter( $module, $letter_code, $branchcode )
441
        or warn( "No $module $letter_code letter"),
473
        or warn( "No $module $letter_code letter"),
442
            return;
474
            return;
443
475
476
    my $prepared_letter = GetProcessedLetter(
477
        module => $module,
478
        letter_code => $letter_code,
479
        letter => $letter,
480
        branchcode => $branchcode,
481
        tables => $tables,
482
        substitute => $substitute,
483
        repeat => $repeat
484
    );
485
486
    return $prepared_letter; 
487
}
488
489
=head2 GetProcessedLetter( %params )
490
491
    given a letter, with possible pre-processing do standard processing
492
    allows one to perform letter template processing beforehand
493
494
    %params hash:
495
      module => letter module, mandatory
496
      letter_code => letter code, mandatory
497
      letter => letter, mandatory
498
      branchcode => for letter selection, if missing default system letter taken
499
      tables => a hashref with table names as keys. Values are either:
500
        - a scalar - primary key value
501
        - an arrayref - primary key values
502
        - a hashref - full record
503
      substitute => custom substitution key/value pairs
504
      repeat => records to be substituted on consecutive lines:
505
        - an arrayref - tries to guess what needs substituting by
506
          taking remaining << >> tokensr; not recommended
507
        - a hashref token => @tables - replaces <token> << >> << >> </token>
508
          subtemplate for each @tables row; table is a hashref as above
509
      want_librarian => boolean,  if set to true triggers librarian details
510
        substitution from the userenv
511
    Return value:
512
      letter fields hashref (title & content useful)
513
514
=cut
515
516
sub GetProcessedLetter {
517
    my %params = @_;
518
519
    my $module      = $params{module} or croak "No module";
520
    my $letter_code = $params{letter_code} or croak "No letter_code";
521
    my $letter = $params{letter} or croak "No letter";
522
    my $branchcode  = $params{branchcode} || '';
444
    my $tables = $params{tables};
523
    my $tables = $params{tables};
445
    my $substitute = $params{substitute};
524
    my $substitute = $params{substitute};
446
    my $repeat = $params{repeat};
525
    my $repeat = $params{repeat};
526
447
    $tables || $substitute || $repeat
527
    $tables || $substitute || $repeat
448
      or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ),
528
      or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ),
449
         return;
529
         return;
(-)a/misc/cronjobs/overdue_notices.pl (-4 / +11 lines)
Lines 432-437 END_SQL Link Here
432
                next PERIOD;
432
                next PERIOD;
433
            }
433
            }
434
434
435
            my $letter_template = C4::Letters::GetLetter (
436
                module => 'circulation',
437
                letter_code => $overdue_rules->{"letter$i"},
438
                branchcode => $branchcode
439
            );
440
435
            # $letter->{'content'} is the text of the mail that is sent.
441
            # $letter->{'content'} is the text of the mail that is sent.
436
            # this text contains fields that are replaced by their value. Those fields must be written between brackets
442
            # this text contains fields that are replaced by their value. Those fields must be written between brackets
437
            # The following fields are available :
443
            # The following fields are available :
Lines 503-508 END_SQL Link Here
503
509
504
                my $letter = parse_letter(
510
                my $letter = parse_letter(
505
                    {   letter_code     => $overdue_rules->{"letter$i"},
511
                    {   letter_code     => $overdue_rules->{"letter$i"},
512
                        letter          => $letter_template,
506
                        borrowernumber  => $borrowernumber,
513
                        borrowernumber  => $borrowernumber,
507
                        branchcode      => $branchcode,
514
                        branchcode      => $branchcode,
508
                        items           => \@items,
515
                        items           => \@items,
Lines 671-677 sub parse_letter { Link Here
671
    my $currency_format;
678
    my $currency_format;
672
    if ($params->{'letter'}->{'content'} =~ m/<fine>(.*)<\/fine>/o) { # process any fine tags...
679
    if ($params->{'letter'}->{'content'} =~ m/<fine>(.*)<\/fine>/o) { # process any fine tags...
673
        $currency_format = $1;
680
        $currency_format = $1;
674
        $params->{'letter'}->{'content'} =~ s/<fine>.*<\/fine>/<<item.fine>>/o;
681
        $params->{'letter'}->{'content'} =~ s/<fine>.*<\/fine>/<<items.fine>>/o;
675
    }
682
    }
676
683
677
    my @item_tables;
684
    my @item_tables;
Lines 696-708 sub parse_letter { Link Here
696
        }
703
        }
697
    }
704
    }
698
705
699
    return C4::Letters::GetPreparedLetter (
706
    return C4::Letters::GetProcessedLetter (
700
        module => 'circulation',
707
        module => 'circulation',
701
        letter_code => $params->{'letter_code'},
708
        letter_code => $params->{'letter_code'},
709
        letter => $params->{'letter'},
702
        branchcode => $params->{'branchcode'},
710
        branchcode => $params->{'branchcode'},
703
        tables => \%tables,
711
        tables => \%tables,
704
        substitute => $substitute,
712
        substitute => $substitute,
705
        repeat => { item => \@item_tables },
713
        repeat => { item => \@item_tables }
706
    );
714
    );
707
}
715
}
708
716
709
- 

Return to bug 8378