From e6127b1bc000827d244f4116193e342c61c8e833 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 16 Sep 2014 12:51:13 -0400 Subject: [PATCH] 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 Signed-off-by: Laurie McKee Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Members.pm | 20 ++++++ C4/Overdues.pm | 71 +++++++++++++++++++ Koha/Template/Plugin/Borrowers.pm | 12 +++- .../prog/en/includes/members-toolbar.inc | 11 ++- .../prog/en/modules/circ/printslip.tt | 4 +- members/print_overdues.pl | 67 +++++++++++++++++ misc/cronjobs/overdue_notices.pl | 71 +------------------ 7 files changed, 183 insertions(+), 73 deletions(-) create mode 100755 members/print_overdues.pl diff --git a/C4/Members.pm b/C4/Members.pm index 5fb176475e..55d4166f5a 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -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; diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 80c6be0615..330e6bd9af 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -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 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_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__ diff --git a/Koha/Template/Plugin/Borrowers.pm b/Koha/Template/Plugin/Borrowers.pm index b8f3de5d03..3e2c59bded 100644 --- a/Koha/Template/Plugin/Borrowers.pm +++ b/Koha/Template/Plugin/Borrowers.pm @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc index 1fee40db9c..635c927f35 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -1,4 +1,5 @@ [% USE Koha %] +[% USE Borrowers %] [% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]