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

(-)a/C4/Letters.pm (-3 / +33 lines)
Lines 721-727 sub GetPreparedLetter { Link Here
721
721
722
sub _substitute_tables {
722
sub _substitute_tables {
723
    my ( $letter, $tables ) = @_;
723
    my ( $letter, $tables ) = @_;
724
    while ( my ($table, $param) = each %$tables ) {
724
725
    foreach my $table (keys %$tables) {
726
        my $param = $tables->{$table};
725
        next unless $param;
727
        next unless $param;
726
728
727
        my $ref = ref $param;
729
        my $ref = ref $param;
Lines 729-736 sub _substitute_tables { Link Here
729
        my $values;
731
        my $values;
730
        if ($ref && $ref eq 'HASH') {
732
        if ($ref && $ref eq 'HASH') {
731
            $values = $param;
733
            $values = $param;
732
        }
734
        } elsif ($ref && $ref eq 'ARRAY') {
733
        else {
735
            my $tag = $table;
736
737
            my $hash_ref = pop($param);
738
            foreach my $table (keys %$hash_ref) {
739
                my $param = $hash_ref->{$table};
740
                if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) {
741
                    my $subcontent = $1;
742
743
                    my $sth = _parseletter_sth($table);
744
                    unless ($sth) {
745
                        warn "_parseletter_sth('$table') failed to return a valid sth.  No substitution will be done for that table.";
746
                        return;
747
                    }
748
749
                    $sth->execute( $param );
750
                    my @lines;
751
                    while( $values = $sth->fetchrow_hashref)
752
                    {
753
                        my %subletter = ( title => '', content => $subcontent );
754
                        my $line = _parseletter ( \%subletter, $table, $values );
755
                        push @lines, $line->{content};
756
                    }
757
                    $letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se;
758
                    my $temp;
759
                }
760
            }
761
        }else {
762
            my @pk;
734
            my $sth = _parseletter_sth($table);
763
            my $sth = _parseletter_sth($table);
735
            unless ($sth) {
764
            unless ($sth) {
736
                warn "_parseletter_sth('$table') failed to return a valid sth.  No substitution will be done for that table.";
765
                warn "_parseletter_sth('$table') failed to return a valid sth.  No substitution will be done for that table.";
Lines 762-767 sub _parseletter_sth { Link Here
762
    ($table eq 'biblioitems'  ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
791
    ($table eq 'biblioitems'  ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
763
    ($table eq 'items'        ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
792
    ($table eq 'items'        ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
764
    ($table eq 'issues'       ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
793
    ($table eq 'issues'       ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
794
    ($table eq 'accountlines' ) ? "SELECT * , FORMAT(amountoutstanding, 2) as amountoutstanding FROM $table WHERE date = DATE(NOW()) AND amountoutstanding > 0 AND itemnumber = ?" :
765
    ($table eq 'old_issues'   ) ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
795
    ($table eq 'old_issues'   ) ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
766
    ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
796
    ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
767
    ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
797
    ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
(-)a/misc/cronjobs/overdue_notices.pl (-5 / +49 lines)
Lines 556-563 END_SQL Link Here
556
                        next;
556
                        next;
557
                    }
557
                    }
558
                }
558
                }
559
559
                if (defined $borrowernumber && $borrowernumber eq $data->{'borrowernumber'}){
560
                if (defined $borrowernumber && $borrowernumber eq $data->{'borrowernumber'}){
560
# we have already dealt with this borrower
561
                    # we have already dealt with this borrower
561
                    $verbose and warn "already dealt with this borrower $borrowernumber";
562
                    $verbose and warn "already dealt with this borrower $borrowernumber";
562
                    next;
563
                    next;
563
                }
564
                }
Lines 668-677 END_SQL Link Here
668
                @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) }
669
                @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) }
669
                    unless @message_transport_types;
670
                    unless @message_transport_types;
670
671
672
                #calculate letter fee
673
                my $noticefee = 0;
674
                if ($letter->{'fee'}){
675
                    $noticefee = $letter->{'fee'};
676
                } else {
677
                    if (C4::Context->preference('DefaultNoticeFee')){
678
                        $noticefee = C4::Context->preference('DefaultNoticeFee');
679
                    }
680
                }
681
682
                #total of fines
683
                my $userfines = 0;
684
                my $dbh   = C4::Context->dbh();
685
                my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines where date = DATE(NOW()) AND itemnumber IS NOT NULL AND amountoutstanding > 0 AND borrowernumber=?|;
686
                my $sth = $dbh->prepare($query);
687
                $sth->execute( $borrowernumber );
688
                my $fine = $sth->fetchrow_hashref();
689
                if ($fine->{fineamount}) {
690
                    $userfines = $fine->{fineamount};
691
                }
692
                $userfines = $userfines + $noticefee;
671
693
672
                my $print_sent = 0; # A print notice is not yet sent for this patron
694
                my $print_sent = 0; # A print notice is not yet sent for this patron
673
                for my $mtt ( @message_transport_types ) {
695
                for my $mtt ( @message_transport_types ) {
674
675
                    my $letter = parse_letter(
696
                    my $letter = parse_letter(
676
                        {   letter_code     => $overdue_rules->{"letter$i"},
697
                        {   letter_code     => $overdue_rules->{"letter$i"},
677
                            borrowernumber  => $borrowernumber,
698
                            borrowernumber  => $borrowernumber,
Lines 681-686 END_SQL Link Here
681
                                                bib             => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'?
702
                                                bib             => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'?
682
                                                'items.content' => $titles,
703
                                                'items.content' => $titles,
683
                                                'count'         => $itemcount,
704
                                                'count'         => $itemcount,
705
                                                'total'         => sprintf("%.2f", $userfines),
706
                                                'noticefee'     => $noticefee,
684
                                               },
707
                                               },
685
                            message_transport_type => $mtt,
708
                            message_transport_type => $mtt,
686
                        }
709
                        }
Lines 873-879 sub parse_letter { Link Here
873
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
896
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
874
                $item_format = $1;
897
                $item_format = $1;
875
            }
898
            }
876
877
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
899
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
878
            # if active currency isn't correct ISO code fallback to sprintf
900
            # if active currency isn't correct ISO code fallback to sprintf
879
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
901
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
Lines 887-899 sub parse_letter { Link Here
887
        }
909
        }
888
    }
910
    }
889
911
912
    #find all fines to create invoice table
913
    my $dbh   = C4::Context->dbh();
914
    my $sth = $dbh->prepare( <<"END_SQL" );
915
SELECT items.biblionumber, items.itemnumber
916
FROM items,accountlines
917
 where date = DATE(NOW())
918
  AND accountlines.itemnumber IS NOT NULL
919
  AND amountoutstanding > 0
920
  AND items.itemnumber = accountlines.itemnumber
921
  AND borrowernumber=? group by items.itemnumber
922
END_SQL
923
924
    $sth->execute($params->{'borrowernumber'});
925
    my @account_tables;
926
    while ( my $item = $sth->fetchrow_hashref() ) {
927
        push @account_tables, {
928
            'biblio' => $item->{'biblionumber'},
929
            'items' => $item->{'itemnumber'},
930
            'accountlines' => [{'accountlines' => $item->{'itemnumber'}}],
931
        };
932
    }
933
890
    return C4::Letters::GetPreparedLetter (
934
    return C4::Letters::GetPreparedLetter (
891
        module => 'circulation',
935
        module => 'circulation',
892
        letter_code => $params->{'letter_code'},
936
        letter_code => $params->{'letter_code'},
893
        branchcode => $params->{'branchcode'},
937
        branchcode => $params->{'branchcode'},
894
        tables => \%tables,
938
        tables => \%tables,
895
        substitute => $substitute,
939
        substitute => $substitute,
896
        repeat => { item => \@item_tables },
940
        repeat => { item => \@item_tables,
941
                    itemaccountlines => \@account_tables},
897
        message_transport_type => $params->{message_transport_type},
942
        message_transport_type => $params->{message_transport_type},
898
    );
943
    );
899
}
944
}
900
- 

Return to bug 12770