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

(-)a/C4/Members.pm (+19 lines)
Lines 109-114 BEGIN { Link Here
109
        GetBorrowersWithEmail
109
        GetBorrowersWithEmail
110
110
111
        HasOverdues
111
        HasOverdues
112
        GetOverdues
112
    );
113
    );
113
114
114
    #Modify data
115
    #Modify data
Lines 2572-2577 sub HasOverdues { Link Here
2572
    return $count;
2573
    return $count;
2573
}
2574
}
2574
2575
2576
sub GetOverdues {
2577
    my ( $borrowernumber ) = @_;
2578
2579
    my $sql = "
2580
        SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue
2581
        FROM issues,items,biblio, biblioitems
2582
        WHERE items.itemnumber=issues.itemnumber
2583
          AND biblio.biblionumber   = items.biblionumber
2584
          AND biblio.biblionumber   = biblioitems.biblionumber
2585
          AND issues.borrowernumber = ?
2586
    ";
2587
2588
    my $sth = C4::Context->dbh->prepare( $sql );
2589
    $sth->execute( $borrowernumber );
2590
2591
    return $sth->fetchall_arrayref({});
2592
}
2593
2575
END { }    # module clean-up code here (global destructor)
2594
END { }    # module clean-up code here (global destructor)
2576
2595
2577
1;
2596
1;
(-)a/C4/Overdues.pm (+71 lines)
Lines 24-35 use strict; Link Here
24
use Date::Calc qw/Today Date_to_Days/;
24
use Date::Calc qw/Today Date_to_Days/;
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 Locale::Currency::Format 1.28;
27
28
28
use C4::Circulation;
29
use C4::Circulation;
29
use C4::Context;
30
use C4::Context;
30
use C4::Accounts;
31
use C4::Accounts;
31
use C4::Log; # logaction
32
use C4::Log; # logaction
32
use C4::Debug;
33
use C4::Debug;
34
use C4::Budgets qw(GetCurrency);
33
35
34
use vars qw($VERSION @ISA @EXPORT);
36
use vars qw($VERSION @ISA @EXPORT);
35
37
Lines 53-58 BEGIN { Link Here
53
        &RemoveNotifyLine
55
        &RemoveNotifyLine
54
        &AddNotifyLine
56
        &AddNotifyLine
55
        &GetOverdueMessageTransportTypes
57
        &GetOverdueMessageTransportTypes
58
        &parse_letter
56
	);
59
	);
57
	# subs to remove
60
	# subs to remove
58
	push @EXPORT, qw(
61
	push @EXPORT, qw(
Lines 954-959 sub GetOverdueMessageTransportTypes { Link Here
954
    return \@mtts;
957
    return \@mtts;
955
}
958
}
956
959
960
=head2 parse_letter
961
962
parses the letter template, replacing the placeholders with data
963
specific to this patron, biblio, or item for overdues
964
965
named parameters:
966
  letter - required hashref
967
  borrowernumber - required integer
968
  substitute - optional hashref of other key/value pairs that should
969
    be substituted in the letter content
970
971
returns the C<letter> hashref, with the content updated to reflect the
972
substituted keys and values.
973
974
=cut
975
976
sub parse_letter {
977
    my $params = shift;
978
    foreach my $required (qw( letter_code borrowernumber )) {
979
        return unless ( exists $params->{$required} && $params->{$required} );
980
    }
981
982
    my $substitute = $params->{'substitute'} || {};
983
    $substitute->{today} ||= C4::Dates->new()->output("syspref");
984
985
    my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
986
    if ( my $p = $params->{'branchcode'} ) {
987
        $tables{'branches'} = $p;
988
    }
989
990
    my $currencies = GetCurrency();
991
    my $currency_format;
992
    $currency_format = $currencies->{currency} if defined($currencies);
993
994
    my @item_tables;
995
    if ( my $i = $params->{'items'} ) {
996
        my $item_format = '';
997
        foreach my $item (@$i) {
998
            my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
999
            if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
1000
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
1001
                $item_format = $1;
1002
            }
1003
1004
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
1005
            # if active currency isn't correct ISO code fallback to sprintf
1006
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
1007
1008
            push @item_tables, {
1009
                'biblio' => $item->{'biblionumber'},
1010
                'biblioitems' => $item->{'biblionumber'},
1011
                'items' => $item,
1012
                'issues' => $item->{'itemnumber'},
1013
            };
1014
        }
1015
    }
1016
1017
    return C4::Letters::GetPreparedLetter (
1018
        module => 'circulation',
1019
        letter_code => $params->{'letter_code'},
1020
        branchcode => $params->{'branchcode'},
1021
        tables => \%tables,
1022
        substitute => $substitute,
1023
        repeat => { item => \@item_tables },
1024
        message_transport_type => $params->{message_transport_type},
1025
    );
1026
}
1027
957
1;
1028
1;
958
__END__
1029
__END__
959
1030
(-)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 161-167 function searchToHold(){ Link Here
161
            <ul class="dropdown-menu">
167
            <ul class="dropdown-menu">
162
                [% IF ( CAN_user_borrowers ) %]<li><a id="printsummary" href="#">Print summary</a></li>[% END %]
168
                [% IF ( CAN_user_borrowers ) %]<li><a id="printsummary" href="#">Print summary</a></li>[% END %]
163
                <li><a id="printslip" href="#">Print slip</a></li>
169
                <li><a id="printslip" href="#">Print slip</a></li>
164
                <li><a id="printquickslip" href="#">Print quick slip</a></li>
170
                <li><a id="printquickslip" href="#">Print quick slip[%  Borrowers.HasOverdues( borrowernumber ) %]</a></li>
171
                [% IF Borrowers.HasOverdues( borrowernumber ) %]
172
                    <li><a id="print_overdues" href="#">Print overdues</a></li>
173
                [% END %]
165
            </ul>
174
            </ul>
166
    </div>
175
    </div>
167
    <a id="searchtohold" class="btn btn-small" href="#"><i class="icon-search"></i> Search to hold</a>
176
    <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 lines)
Lines 40-46 use C4::Dates qw/format_date/; Link Here
40
use C4::Debug;
40
use C4::Debug;
41
use C4::Letters;
41
use C4::Letters;
42
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
42
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
43
use C4::Budgets qw(GetCurrency);
44
43
45
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
44
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
46
use Koha::DateUtils;
45
use Koha::DateUtils;
Lines 803-877 if ( defined $htmlfilename ) { Link Here
803
802
804
These methods are internal to the operation of overdue_notices.pl.
803
These methods are internal to the operation of overdue_notices.pl.
805
804
806
=head2 parse_letter
807
808
parses the letter template, replacing the placeholders with data
809
specific to this patron, biblio, or item
810
811
named parameters:
812
  letter - required hashref
813
  borrowernumber - required integer
814
  substitute - optional hashref of other key/value pairs that should
815
    be substituted in the letter content
816
817
returns the C<letter> hashref, with the content updated to reflect the
818
substituted keys and values.
819
820
821
=cut
822
823
sub parse_letter {
824
    my $params = shift;
825
    foreach my $required (qw( letter_code borrowernumber )) {
826
        return unless ( exists $params->{$required} && $params->{$required} );
827
    }
828
829
    my $substitute = $params->{'substitute'} || {};
830
    $substitute->{today} ||= C4::Dates->new()->output("syspref");
831
832
    my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
833
    if ( my $p = $params->{'branchcode'} ) {
834
        $tables{'branches'} = $p;
835
    }
836
837
    my $currencies = GetCurrency();
838
    my $currency_format;
839
    $currency_format = $currencies->{currency} if defined($currencies);
840
841
    my @item_tables;
842
    if ( my $i = $params->{'items'} ) {
843
        my $item_format = '';
844
        foreach my $item (@$i) {
845
            my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
846
            if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
847
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
848
                $item_format = $1;
849
            }
850
851
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
852
            # if active currency isn't correct ISO code fallback to sprintf
853
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
854
855
            push @item_tables, {
856
                'biblio' => $item->{'biblionumber'},
857
                'biblioitems' => $item->{'biblionumber'},
858
                'items' => $item,
859
                'issues' => $item->{'itemnumber'},
860
            };
861
        }
862
    }
863
864
    return C4::Letters::GetPreparedLetter (
865
        module => 'circulation',
866
        letter_code => $params->{'letter_code'},
867
        branchcode => $params->{'branchcode'},
868
        tables => \%tables,
869
        substitute => $substitute,
870
        repeat => { item => \@item_tables },
871
        message_transport_type => $params->{message_transport_type},
872
    );
873
}
874
875
=head2 prepare_letter_for_printing
805
=head2 prepare_letter_for_printing
876
806
877
returns a string of text appropriate for printing in the event that an
807
returns a string of text appropriate for printing in the event that an
878
- 

Return to bug 12933