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

(-)a/C4/Members.pm (+20 lines)
Lines 108-113 BEGIN { Link Here
108
        GetBorrowersWithEmail
108
        GetBorrowersWithEmail
109
109
110
        HasOverdues
110
        HasOverdues
111
        GetOverdues
111
    );
112
    );
112
113
113
    #Modify data
114
    #Modify data
Lines 2552-2557 WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; Link Here
2552
    return $cnt eq '0E0'? 0: $cnt;
2553
    return $cnt eq '0E0'? 0: $cnt;
2553
}
2554
}
2554
2555
2556
sub GetOverdues {
2557
    my ( $borrowernumber ) = @_;
2558
2559
    my $sql = "
2560
        SELECT *
2561
        FROM issues, items, biblio, biblioitems
2562
        WHERE items.itemnumber=issues.itemnumber
2563
          AND biblio.biblionumber   = items.biblionumber
2564
          AND biblio.biblionumber   = biblioitems.biblionumber
2565
          AND issues.borrowernumber = ?
2566
          AND date_due < NOW()
2567
    ";
2568
2569
    my $sth = C4::Context->dbh->prepare( $sql );
2570
    $sth->execute( $borrowernumber );
2571
2572
    return $sth->fetchall_arrayref({});
2573
}
2574
2555
END { }    # module clean-up code here (global destructor)
2575
END { }    # module clean-up code here (global destructor)
2556
2576
2557
1;
2577
1;
(-)a/C4/Overdues.pm (+71 lines)
Lines 25-36 use Date::Calc qw/Today Date_to_Days/; Link Here
25
use Date::Manip qw/UnixDate/;
25
use Date::Manip qw/UnixDate/;
26
use List::MoreUtils qw( uniq );
26
use List::MoreUtils qw( uniq );
27
use POSIX qw( floor ceil );
27
use POSIX qw( floor ceil );
28
use Locale::Currency::Format 1.28;
28
29
29
use C4::Circulation;
30
use C4::Circulation;
30
use C4::Context;
31
use C4::Context;
31
use C4::Accounts;
32
use C4::Accounts;
32
use C4::Log; # logaction
33
use C4::Log; # logaction
33
use C4::Debug;
34
use C4::Debug;
35
use C4::Budgets qw(GetCurrency);
34
36
35
use vars qw($VERSION @ISA @EXPORT);
37
use vars qw($VERSION @ISA @EXPORT);
36
38
Lines 55-60 BEGIN { Link Here
55
      &RemoveNotifyLine
57
      &RemoveNotifyLine
56
      &AddNotifyLine
58
      &AddNotifyLine
57
      &GetOverdueMessageTransportTypes
59
      &GetOverdueMessageTransportTypes
60
      &parse_letter
58
    );
61
    );
59
62
60
    # subs to remove
63
    # subs to remove
Lines 952-957 sub GetOverdueMessageTransportTypes { Link Here
952
    return \@mtts;
955
    return \@mtts;
953
}
956
}
954
957
958
=head2 parse_letter
959
960
parses the letter template, replacing the placeholders with data
961
specific to this patron, biblio, or item for overdues
962
963
named parameters:
964
  letter - required hashref
965
  borrowernumber - required integer
966
  substitute - optional hashref of other key/value pairs that should
967
    be substituted in the letter content
968
969
returns the C<letter> hashref, with the content updated to reflect the
970
substituted keys and values.
971
972
=cut
973
974
sub parse_letter {
975
    my $params = shift;
976
    foreach my $required (qw( letter_code borrowernumber )) {
977
        return unless ( exists $params->{$required} && $params->{$required} );
978
    }
979
980
    my $substitute = $params->{'substitute'} || {};
981
    $substitute->{today} ||= C4::Dates->new()->output("syspref");
982
983
    my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
984
    if ( my $p = $params->{'branchcode'} ) {
985
        $tables{'branches'} = $p;
986
    }
987
988
    my $currencies = GetCurrency();
989
    my $currency_format;
990
    $currency_format = $currencies->{currency} if defined($currencies);
991
992
    my @item_tables;
993
    if ( my $i = $params->{'items'} ) {
994
        my $item_format = '';
995
        foreach my $item (@$i) {
996
            my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
997
            if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
998
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
999
                $item_format = $1;
1000
            }
1001
1002
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
1003
            # if active currency isn't correct ISO code fallback to sprintf
1004
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
1005
1006
            push @item_tables, {
1007
                'biblio' => $item->{'biblionumber'},
1008
                'biblioitems' => $item->{'biblionumber'},
1009
                'items' => $item,
1010
                'issues' => $item->{'itemnumber'},
1011
            };
1012
        }
1013
    }
1014
1015
    return C4::Letters::GetPreparedLetter (
1016
        module => 'circulation',
1017
        letter_code => $params->{'letter_code'},
1018
        branchcode => $params->{'branchcode'},
1019
        tables => \%tables,
1020
        substitute => $substitute,
1021
        repeat => { item => \@item_tables },
1022
        message_transport_type => $params->{message_transport_type},
1023
    );
1024
}
1025
955
1;
1026
1;
956
__END__
1027
__END__
957
1028
(-)a/Koha/Template/Plugin/Borrowers.pm (-1 / +11 lines)
Lines 22-28 use Modern::Perl; Link Here
22
22
23
use base qw( Template::Plugin );
23
use base qw( Template::Plugin );
24
24
25
use Koha::Borrower::Debarments qw//;
25
use Koha::Borrower::Debarments qw();
26
use C4::Members qw(HasOverdues);
26
27
27
=pod
28
=pod
28
29
Lines 48-51 sub IsDebarred { Link Here
48
    return Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber});
49
    return Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber});
49
}
50
}
50
51
52
sub HasOverdues {
53
    my ( $self, $borrowernumber ) = @_;
54
55
    return unless $borrowernumber;
56
57
    return C4::Members::HasOverdues($borrowernumber);
58
}
59
60
51
1;
61
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-1 / +10 lines)
Lines 1-4 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE Borrowers %]
2
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
3
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
3
<script type="text/javascript">
4
<script type="text/javascript">
4
//<![CDATA[
5
//<![CDATA[
Lines 58-63 $(document).ready(function(){ Link Here
58
        $(".btn-group").removeClass("open");
59
        $(".btn-group").removeClass("open");
59
        return false;
60
        return false;
60
    });
61
    });
62
    $("#print_overdues").click(function(){
63
        window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=[% borrowernumber %]", "printwindow");
64
        $(".btn-group").removeClass("open");
65
        return false;
66
    });
61
    $("#searchtohold").click(function(){
67
    $("#searchtohold").click(function(){
62
        searchToHold();
68
        searchToHold();
63
        return false;
69
        return false;
Lines 153-159 function searchToHold(){ Link Here
153
            <ul class="dropdown-menu">
159
            <ul class="dropdown-menu">
154
                [% IF ( CAN_user_borrowers ) %]<li><a id="printsummary" href="#">Print summary</a></li>[% END %]
160
                [% IF ( CAN_user_borrowers ) %]<li><a id="printsummary" href="#">Print summary</a></li>[% END %]
155
                <li><a id="printslip" href="#">Print slip</a></li>
161
                <li><a id="printslip" href="#">Print slip</a></li>
156
                <li><a id="printquickslip" href="#">Print quick slip</a></li>
162
                <li><a id="printquickslip" href="#">Print quick slip[%  Borrowers.HasOverdues( borrowernumber ) %]</a></li>
163
                [% IF Borrowers.HasOverdues( borrowernumber ) %]
164
                    <li><a id="print_overdues" href="#">Print overdues</a></li>
165
                [% END %]
157
            </ul>
166
            </ul>
158
    </div>
167
    </div>
159
    <a id="searchtohold" class="btn btn-small" href="#"><i class="icon-search"></i> Search to hold</a>
168
    <a id="searchtohold" class="btn btn-small" href="#"><i class="icon-search"></i> Search to hold</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt (-1 / +3 lines)
Lines 1-11 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% IF ( caller = 'hold-transfer' ) %]
3
[% IF ( caller == 'hold-transfer' ) %]
4
<title>Koha &rsaquo; Circulation &rsaquo; Hold transfer print receipt</title>
4
<title>Koha &rsaquo; Circulation &rsaquo; Hold transfer print receipt</title>
5
[% ELSIF ( caller == 'transfer' ) %]
5
[% ELSIF ( caller == 'transfer' ) %]
6
<title>Koha &rsaquo; Circulation &rsaquo; Transfers print receipt</title>
6
<title>Koha &rsaquo; Circulation &rsaquo; Transfers print receipt</title>
7
[% ELSIF ( caller == 'members' ) %]
7
[% ELSIF ( caller == 'members' ) %]
8
<title>Koha &rsaquo; Members &rsaquo; Print receipt for [% borrowernumber %]</title>
8
<title>Koha &rsaquo; Members &rsaquo; Print receipt for [% borrowernumber %]</title>
9
[% ELSIF ( title ) %]
10
<title>Koha &rsaquo; Members &rsaquo; [% title %]</title>
9
[% END %]
11
[% END %]
10
12
11
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
(-)a/members/print_overdues.pl (+67 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use CGI;
23
24
use C4::Context;
25
use C4::Auth;
26
use C4::Output;
27
use C4::Members qw(GetOverdues);
28
use C4::Overdues qw(parse_letter);
29
30
my $input = new CGI;
31
32
my $flagsrequired = { circulate => "circulate_remaining_permissions" };
33
34
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35
    {
36
        template_name   => "circ/printslip.tt",
37
        query           => $input,
38
        type            => "intranet",
39
        authnotrequired => 0,
40
        flagsrequired   => $flagsrequired,
41
        debug           => 1,
42
    }
43
);
44
45
my $borrowernumber = $input->param('borrowernumber');
46
my $branchcode     = C4::Context->userenv->{'branch'};
47
48
my $overdues = GetOverdues($borrowernumber);
49
50
my $letter = parse_letter(
51
    {
52
        letter_code            => 'OVERDUES_SLIP',
53
        borrowernumber         => $borrowernumber,
54
        branchcode             => $branchcode,
55
        items                  => $overdues,
56
        message_transport_type => 'print',
57
    }
58
);
59
60
$template->param(
61
    slip           => $letter->{content},
62
    title          => $letter->{name},
63
    plain          => !$letter->{is_html},
64
    borrowernumber => $borrowernumber,
65
);
66
67
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/misc/cronjobs/overdue_notices.pl (-71 / +1 lines)
Lines 43-52 use C4::Debug; Link Here
43
use C4::Letters;
43
use C4::Letters;
44
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
44
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
45
use C4::Budgets qw(GetCurrency);
45
use C4::Budgets qw(GetCurrency);
46
use C4::Log;
46
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
47
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
47
use Koha::DateUtils;
48
use Koha::DateUtils;
48
use Koha::Calendar;
49
use Koha::Calendar;
49
use C4::Log;
50
50
51
=head1 NAME
51
=head1 NAME
52
52
Lines 829-903 if ( defined $htmlfilename ) { Link Here
829
829
830
These methods are internal to the operation of overdue_notices.pl.
830
These methods are internal to the operation of overdue_notices.pl.
831
831
832
=head2 parse_letter
833
834
parses the letter template, replacing the placeholders with data
835
specific to this patron, biblio, or item
836
837
named parameters:
838
  letter - required hashref
839
  borrowernumber - required integer
840
  substitute - optional hashref of other key/value pairs that should
841
    be substituted in the letter content
842
843
returns the C<letter> hashref, with the content updated to reflect the
844
substituted keys and values.
845
846
847
=cut
848
849
sub parse_letter {
850
    my $params = shift;
851
    foreach my $required (qw( letter_code borrowernumber )) {
852
        return unless ( exists $params->{$required} && $params->{$required} );
853
    }
854
855
    my $substitute = $params->{'substitute'} || {};
856
    $substitute->{today} ||= C4::Dates->new()->output("syspref");
857
858
    my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
859
    if ( my $p = $params->{'branchcode'} ) {
860
        $tables{'branches'} = $p;
861
    }
862
863
    my $currencies = GetCurrency();
864
    my $currency_format;
865
    $currency_format = $currencies->{currency} if defined($currencies);
866
867
    my @item_tables;
868
    if ( my $i = $params->{'items'} ) {
869
        my $item_format = '';
870
        foreach my $item (@$i) {
871
            my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
872
            if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
873
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
874
                $item_format = $1;
875
            }
876
877
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
878
            # if active currency isn't correct ISO code fallback to sprintf
879
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
880
881
            push @item_tables, {
882
                'biblio' => $item->{'biblionumber'},
883
                'biblioitems' => $item->{'biblionumber'},
884
                'items' => $item,
885
                'issues' => $item->{'itemnumber'},
886
            };
887
        }
888
    }
889
890
    return C4::Letters::GetPreparedLetter (
891
        module => 'circulation',
892
        letter_code => $params->{'letter_code'},
893
        branchcode => $params->{'branchcode'},
894
        tables => \%tables,
895
        substitute => $substitute,
896
        repeat => { item => \@item_tables },
897
        message_transport_type => $params->{message_transport_type},
898
    );
899
}
900
901
=head2 prepare_letter_for_printing
832
=head2 prepare_letter_for_printing
902
833
903
returns a string of text appropriate for printing in the event that an
834
returns a string of text appropriate for printing in the event that an
904
- 

Return to bug 12933