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

(-)a/misc/cronjobs/overdue_notices.pl (-54 / +73 lines)
Lines 39-45 use C4::Context; Link Here
39
use C4::Dates qw/format_date/;
39
use C4::Dates qw/format_date/;
40
use C4::Debug;
40
use C4::Debug;
41
use C4::Letters;
41
use C4::Letters;
42
use C4::Overdues qw(GetFine);
42
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
43
use C4::Budgets qw(GetCurrency);
43
use C4::Budgets qw(GetCurrency);
44
44
45
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
45
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
Lines 454-459 END_SQL Link Here
454
    # my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' );
454
    # my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' );
455
    while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
455
    while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
456
      PERIOD: foreach my $i ( 1 .. 3 ) {
456
      PERIOD: foreach my $i ( 1 .. 3 ) {
457
            my $print_sent = 0; # We never sent a print notice
457
458
458
            $verbose and warn "branch '$branchcode', pass $i\n";
459
            $verbose and warn "branch '$branchcode', pass $i\n";
459
            my $mindays = $overdue_rules->{"delay$i"};    # the notice will be sent after mindays days (grace period)
460
            my $mindays = $overdue_rules->{"delay$i"};    # the notice will be sent after mindays days (grace period)
Lines 475-481 END_SQL Link Here
475
            # <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode> <country>
476
            # <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode> <country>
476
477
477
            my $borrower_sql = <<'END_SQL';
478
            my $borrower_sql = <<'END_SQL';
478
SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email
479
SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber
479
FROM   issues,borrowers,categories
480
FROM   issues,borrowers,categories
480
WHERE  issues.borrowernumber=borrowers.borrowernumber
481
WHERE  issues.borrowernumber=borrowers.borrowernumber
481
AND    borrowers.categorycode=categories.categorycode
482
AND    borrowers.categorycode=categories.categorycode
Lines 571-633 END_SQL Link Here
571
                }
572
                }
572
                $sth2->finish;
573
                $sth2->finish;
573
574
574
                $letter = parse_letter(
575
                my @message_transport_types = @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i) };
575
                    {   letter_code     => $overdue_rules->{"letter$i"},
576
                @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) }
576
                        borrowernumber  => $borrowernumber,
577
                    unless @message_transport_types;
577
                        branchcode      => $branchcode,
578
578
                        items           => \@items,
579
                for my $mtt ( @message_transport_types ) {
579
                        substitute      => {    # this appears to be a hack to overcome incomplete features in this code.
580
580
                                            bib             => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'?
581
                    my $letter = parse_letter(
581
                                            'items.content' => $titles,
582
                        {   letter_code     => $overdue_rules->{"letter$i"},
582
                                            'count'         => $itemcount,
583
                            borrowernumber  => $borrowernumber,
583
                                           }
584
                            branchcode      => $branchcode,
585
                            items           => \@items,
586
                            substitute      => {    # this appears to be a hack to overcome incomplete features in this code.
587
                                                bib             => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'?
588
                                                'items.content' => $titles,
589
                                                'count'         => $itemcount,
590
                                               },
591
                            message_transport_type => $mtt,
592
                        }
593
                    );
594
                    unless ($letter) {
595
                        $verbose and warn "Message '$overdue_rules->{letter$i}' content not found";
596
597
                        # might as well skip while PERIOD, no other borrowers are going to work.
598
                        # FIXME : Does this mean a letter must be defined in order to trigger a debar ?
599
                        next PERIOD;
584
                    }
600
                    }
585
                );
586
                unless ($letter) {
587
                    $verbose and warn "Message '$overdue_rules->{letter$i}' content not found";
588
601
589
                    # might as well skip while PERIOD, no other borrowers are going to work.
602
                    if ( $exceededPrintNoticesMaxLines ) {
590
                    # FIXME : Does this mean a letter must be defined in order to trigger a debar ?
603
                      $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items.";
591
                    next PERIOD;
604
                    }
592
                }
593
                
594
                if ( $exceededPrintNoticesMaxLines ) {
595
                  $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items.";
596
                }
597
605
598
                my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'};
606
                    my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'};
599
                if (@misses) {
607
                    if (@misses) {
600
                    $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses;
608
                        $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses;
601
                }
609
                    }
602
610
603
                if ( !$nomail && scalar @emails_to_use ) {
611
                    if ($nomail) {
604
                    C4::Letters::EnqueueLetter(
612
                        push @output_chunks,
605
                        {   letter                 => $letter,
613
                          prepare_letter_for_printing(
606
                            borrowernumber         => $borrowernumber,
614
                          {   letter         => $letter,
607
                            message_transport_type => 'email',
615
                              borrowernumber => $borrowernumber,
608
                            from_address           => $admin_email_address,
616
                              firstname      => $data->{'firstname'},
609
                            to_address             => join(',', @emails_to_use),
617
                              lastname       => $data->{'surname'},
618
                              address1       => $data->{'address'},
619
                              address2       => $data->{'address2'},
620
                              city           => $data->{'city'},
621
                              postcode       => $data->{'zipcode'},
622
                              country        => $data->{'country'},
623
                              email          => $notice_email,
624
                              itemcount      => $itemcount,
625
                              titles         => $titles,
626
                              outputformat   => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : defined $text_filename ? 'text' : '',
627
                            }
628
                          );
629
                    } else {
630
                        if ( ($mtt eq 'email' and not scalar @emails_to_use) or ($mtt eq 'sms' and not $data->{smsalertnumber}) ) {
631
                            # email or sms is requested but not exist, do a print.
632
                            $mtt = 'print';
610
                        }
633
                        }
611
                    );
634
                        unless ( $mtt eq 'print' and $print_sent == 1 ) {
612
                } else {
635
                            # Just sent a print if not already done.
613
                    # if not sent by email then print
636
                            C4::Letters::EnqueueLetter(
614
                    push @output_chunks,
637
                                {   letter                 => $letter,
615
                      prepare_letter_for_printing(
638
                                    borrowernumber         => $borrowernumber,
616
                        {   letter         => $letter,
639
                                    message_transport_type => $mtt,
617
                            borrowernumber => $borrowernumber,
640
                                    from_address           => $admin_email_address,
618
                            firstname      => $data->{'firstname'},
641
                                    to_address             => join(',', @emails_to_use),
619
                            lastname       => $data->{'surname'},
642
                                }
620
                            address1       => $data->{'address'},
643
                            );
621
                            address2       => $data->{'address2'},
644
                            # A print notice should be sent only once per overdue level.
622
                            city           => $data->{'city'},
645
                            # Without this check, a print could be sent twice or more if the library checks sms and email and print and the patron has no email or sms number.
623
                            postcode       => $data->{'zipcode'},
646
                            $print_sent = 1 if $mtt eq 'print';
624
                            country        => $data->{'country'},
625
                            email          => $notice_email,
626
                            itemcount      => $itemcount,
627
                            titles         => $titles,
628
                            outputformat   => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : defined $text_filename ? 'text' : '',
629
                        }
647
                        }
630
                      );
648
                    }
631
                }
649
                }
632
            }
650
            }
633
            $sth->finish;
651
            $sth->finish;
Lines 763-768 sub parse_letter { Link Here
763
        tables => \%tables,
781
        tables => \%tables,
764
        substitute => $substitute,
782
        substitute => $substitute,
765
        repeat => { item => \@item_tables },
783
        repeat => { item => \@item_tables },
784
        message_transport_type => $params->{message_transport_type},
766
    );
785
    );
767
}
786
}
768
787
Lines 792-797 sub prepare_letter_for_printing { Link Here
792
    }
811
    }
793
812
794
    my $return;
813
    my $return;
814
    chomp $params->{titles};
795
    if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) {
815
    if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) {
796
        if ($csv->combine(
816
        if ($csv->combine(
797
                $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'},  $params->{'address2'}, $params->{'postcode'},
817
                $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'},  $params->{'address2'}, $params->{'postcode'},
798
- 

Return to bug 10832