Bug 12933: Add ability to print overdue slip from staff intranet

Some librarians would like to be able to print an overdues slip from the
staff intranet. This slip would be defined as the print transport
version of the ODUE slip.

Test Plan:
1) Apply this patch
2) Locate a patron with overdues
3) Define a print version of the OVERDUES_SLIP slip
4) Try Print > Print overdues

Signed-off-by: Amy Purvis <APurvis@galencollege.edu>
Signed-off-by: Laurie McKee <lmckee@littleelm.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle M Hall 2014-09-16 12:51:13 -04:00 committed by Tomas Cohen Arazi
parent b8891b9275
commit e6127b1bc0
7 changed files with 183 additions and 73 deletions

View File

@ -108,6 +108,7 @@ BEGIN {
GetBorrowersWithEmail
HasOverdues
GetOverdues
);
#Modify data
@ -2552,6 +2553,25 @@ WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|;
return $cnt eq '0E0'? 0: $cnt;
}
sub GetOverdues {
my ( $borrowernumber ) = @_;
my $sql = "
SELECT *
FROM issues, items, biblio, biblioitems
WHERE items.itemnumber=issues.itemnumber
AND biblio.biblionumber = items.biblionumber
AND biblio.biblionumber = biblioitems.biblionumber
AND issues.borrowernumber = ?
AND date_due < NOW()
";
my $sth = C4::Context->dbh->prepare( $sql );
$sth->execute( $borrowernumber );
return $sth->fetchall_arrayref({});
}
END { } # module clean-up code here (global destructor)
1;

View File

@ -25,12 +25,14 @@ use Date::Calc qw/Today Date_to_Days/;
use Date::Manip qw/UnixDate/;
use List::MoreUtils qw( uniq );
use POSIX qw( floor ceil );
use Locale::Currency::Format 1.28;
use C4::Circulation;
use C4::Context;
use C4::Accounts;
use C4::Log; # logaction
use C4::Debug;
use C4::Budgets qw(GetCurrency);
use vars qw($VERSION @ISA @EXPORT);
@ -55,6 +57,7 @@ BEGIN {
&RemoveNotifyLine
&AddNotifyLine
&GetOverdueMessageTransportTypes
&parse_letter
);
# subs to remove
@ -952,6 +955,74 @@ sub GetOverdueMessageTransportTypes {
return \@mtts;
}
=head2 parse_letter
parses the letter template, replacing the placeholders with data
specific to this patron, biblio, or item for overdues
named parameters:
letter - required hashref
borrowernumber - required integer
substitute - optional hashref of other key/value pairs that should
be substituted in the letter content
returns the C<letter> hashref, with the content updated to reflect the
substituted keys and values.
=cut
sub parse_letter {
my $params = shift;
foreach my $required (qw( letter_code borrowernumber )) {
return unless ( exists $params->{$required} && $params->{$required} );
}
my $substitute = $params->{'substitute'} || {};
$substitute->{today} ||= C4::Dates->new()->output("syspref");
my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
if ( my $p = $params->{'branchcode'} ) {
$tables{'branches'} = $p;
}
my $currencies = GetCurrency();
my $currency_format;
$currency_format = $currencies->{currency} if defined($currencies);
my @item_tables;
if ( my $i = $params->{'items'} ) {
my $item_format = '';
foreach my $item (@$i) {
my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
$params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
$item_format = $1;
}
$item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
# if active currency isn't correct ISO code fallback to sprintf
$item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
push @item_tables, {
'biblio' => $item->{'biblionumber'},
'biblioitems' => $item->{'biblionumber'},
'items' => $item,
'issues' => $item->{'itemnumber'},
};
}
}
return C4::Letters::GetPreparedLetter (
module => 'circulation',
letter_code => $params->{'letter_code'},
branchcode => $params->{'branchcode'},
tables => \%tables,
substitute => $substitute,
repeat => { item => \@item_tables },
message_transport_type => $params->{message_transport_type},
);
}
1;
__END__

View File

@ -22,7 +22,8 @@ use Modern::Perl;
use base qw( Template::Plugin );
use Koha::Borrower::Debarments qw//;
use Koha::Borrower::Debarments qw();
use C4::Members qw(HasOverdues);
=pod
@ -48,4 +49,13 @@ sub IsDebarred {
return Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber});
}
sub HasOverdues {
my ( $self, $borrowernumber ) = @_;
return unless $borrowernumber;
return C4::Members::HasOverdues($borrowernumber);
}
1;

View File

@ -1,4 +1,5 @@
[% USE Koha %]
[% USE Borrowers %]
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
<script type="text/javascript">
//<![CDATA[
@ -58,6 +59,11 @@ $(document).ready(function(){
$(".btn-group").removeClass("open");
return false;
});
$("#print_overdues").click(function(){
window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=[% borrowernumber %]", "printwindow");
$(".btn-group").removeClass("open");
return false;
});
$("#searchtohold").click(function(){
searchToHold();
return false;
@ -153,7 +159,10 @@ function searchToHold(){
<ul class="dropdown-menu">
[% IF ( CAN_user_borrowers ) %]<li><a id="printsummary" href="#">Print summary</a></li>[% END %]
<li><a id="printslip" href="#">Print slip</a></li>
<li><a id="printquickslip" href="#">Print quick slip</a></li>
<li><a id="printquickslip" href="#">Print quick slip[% Borrowers.HasOverdues( borrowernumber ) %]</a></li>
[% IF Borrowers.HasOverdues( borrowernumber ) %]
<li><a id="print_overdues" href="#">Print overdues</a></li>
[% END %]
</ul>
</div>
<a id="searchtohold" class="btn btn-small" href="#"><i class="fa fa-search"></i> Search to hold</a>

View File

@ -1,11 +1,13 @@
[% USE Koha %]
[% INCLUDE 'doc-head-open.inc' %]
[% IF ( caller = 'hold-transfer' ) %]
[% IF ( caller == 'hold-transfer' ) %]
<title>Koha &rsaquo; Circulation &rsaquo; Hold transfer print receipt</title>
[% ELSIF ( caller == 'transfer' ) %]
<title>Koha &rsaquo; Circulation &rsaquo; Transfers print receipt</title>
[% ELSIF ( caller == 'members' ) %]
<title>Koha &rsaquo; Members &rsaquo; Print receipt for [% borrowernumber %]</title>
[% ELSIF ( title ) %]
<title>Koha &rsaquo; Members &rsaquo; [% title %]</title>
[% END %]
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

67
members/print_overdues.pl Executable file
View File

@ -0,0 +1,67 @@
#!/usr/bin/perl
# Copyright 2014 ByWater Solutions
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use CGI;
use C4::Context;
use C4::Auth;
use C4::Output;
use C4::Members qw(GetOverdues);
use C4::Overdues qw(parse_letter);
my $input = new CGI;
my $flagsrequired = { circulate => "circulate_remaining_permissions" };
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "circ/printslip.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => $flagsrequired,
debug => 1,
}
);
my $borrowernumber = $input->param('borrowernumber');
my $branchcode = C4::Context->userenv->{'branch'};
my $overdues = GetOverdues($borrowernumber);
my $letter = parse_letter(
{
letter_code => 'OVERDUES_SLIP',
borrowernumber => $borrowernumber,
branchcode => $branchcode,
items => $overdues,
message_transport_type => 'print',
}
);
$template->param(
slip => $letter->{content},
title => $letter->{name},
plain => !$letter->{is_html},
borrowernumber => $borrowernumber,
);
output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -43,10 +43,10 @@ use C4::Debug;
use C4::Letters;
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
use C4::Budgets qw(GetCurrency);
use C4::Log;
use Koha::Borrower::Debarments qw(AddUniqueDebarment);
use Koha::DateUtils;
use Koha::Calendar;
use C4::Log;
=head1 NAME
@ -829,75 +829,6 @@ if ( defined $htmlfilename ) {
These methods are internal to the operation of overdue_notices.pl.
=head2 parse_letter
parses the letter template, replacing the placeholders with data
specific to this patron, biblio, or item
named parameters:
letter - required hashref
borrowernumber - required integer
substitute - optional hashref of other key/value pairs that should
be substituted in the letter content
returns the C<letter> hashref, with the content updated to reflect the
substituted keys and values.
=cut
sub parse_letter {
my $params = shift;
foreach my $required (qw( letter_code borrowernumber )) {
return unless ( exists $params->{$required} && $params->{$required} );
}
my $substitute = $params->{'substitute'} || {};
$substitute->{today} ||= C4::Dates->new()->output("syspref");
my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
if ( my $p = $params->{'branchcode'} ) {
$tables{'branches'} = $p;
}
my $currencies = GetCurrency();
my $currency_format;
$currency_format = $currencies->{currency} if defined($currencies);
my @item_tables;
if ( my $i = $params->{'items'} ) {
my $item_format = '';
foreach my $item (@$i) {
my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
$params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
$item_format = $1;
}
$item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
# if active currency isn't correct ISO code fallback to sprintf
$item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
push @item_tables, {
'biblio' => $item->{'biblionumber'},
'biblioitems' => $item->{'biblionumber'},
'items' => $item,
'issues' => $item->{'itemnumber'},
};
}
}
return C4::Letters::GetPreparedLetter (
module => 'circulation',
letter_code => $params->{'letter_code'},
branchcode => $params->{'branchcode'},
tables => \%tables,
substitute => $substitute,
repeat => { item => \@item_tables },
message_transport_type => $params->{message_transport_type},
);
}
=head2 prepare_letter_for_printing
returns a string of text appropriate for printing in the event that an