From ea57ddc1e7b18b2a5cf0c02a6122b3e04cf0f5b8 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 3 Jul 2012 11:01:17 -0400 Subject: [PATCH] Bug 8352 - Add automatic printing of 'hold to pull' notices Adds the ability to have a notice printed automatically after a hold has been placed. The system has the ability to define a separate printer for each branchcode, so each library can receive a printed notice for any holds placed, assuming they have set up the ability to print over the LAN, WAN, or Internet. Notices are printed to the pickup library. Signed-off-by: Alex Arnaud --- C4/Installer/PerlDependencies.pm | 5 + installer/data/mysql/atomicupdate/bug_8352.sql | 8 + .../data/mysql/en/mandatory/sample_notices.sql | 2 + installer/data/mysql/kohastructure.sql | 2 + misc/cronjobs/holds/print_holds.pl | 159 ++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_8352.sql create mode 100755 misc/cronjobs/holds/print_holds.pl diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index c1d03c7..73d7b47 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -621,6 +621,11 @@ our $PERL_DEPS = { 'usage' => 'OpacSelfRegistration', 'required' => '1', 'min_ver' => '0.22', + }, + 'Net::Printer' => { + 'usage' => 'Push to printer', + 'required' => '0', + 'min_ver' => '1.11', }, 'File::Temp' => { 'usage' => 'Plugins', diff --git a/installer/data/mysql/atomicupdate/bug_8352.sql b/installer/data/mysql/atomicupdate/bug_8352.sql new file mode 100644 index 0000000..46fe717 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_8352.sql @@ -0,0 +1,8 @@ +ALTER TABLE reserves ADD printed BOOLEAN NULL AFTER suspend_until; + +INSERT INTO letter ( module, code, branchcode, name, is_html, title, content ) VALUES ( + 'reserves', 'HOLD_PLACED_PRINT', '', 'Hold Placed ( Auto-Print )', '0', 'Hold Placed ( Auto-Print )', 'Hold to pull at <> + +For <> <> ( <> ) + +<> by <>'); diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 50bee6b..f589bcb 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -162,3 +162,5 @@ VALUES ( 'circulation', 'OVERDUES_SLIP', '', 'Overdues Slip', '0', 'OVERDUES_SLI "<>" by <>, <>, Barcode: <> Fine: <> ', 'print' ); +INSERT INTO `letter` (`module`,`code`,`branchcode`,`name`,`is_html`,`title`,`content`) +VALUES ('reserves', 'HOLD_PLACED_PRINT', 'Hold Placed ( Auto-Print )', 'Hold Placed ( Auto-Print )', 'Hold to pull at <>\r\nFor <> <> ( <> )\r\n<> by <>'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index fa44ff7..7443dfe 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1663,6 +1663,7 @@ CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no) `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no) `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely) + `printed` tinyint(1) DEFAULT NULL, PRIMARY KEY (`reserve_id`), KEY `old_reserves_borrowernumber` (`borrowernumber`), KEY `old_reserves_biblionumber` (`biblionumber`), @@ -1838,6 +1839,7 @@ CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha `lowestPriority` tinyint(1) NOT NULL, `suspend` BOOLEAN NOT NULL DEFAULT 0, `suspend_until` DATETIME NULL DEFAULT NULL, + `printed` tinyint(1) DEFAULT NULL, PRIMARY KEY (`reserve_id`), KEY priorityfoundidx (priority,found), KEY `borrowernumber` (`borrowernumber`), diff --git a/misc/cronjobs/holds/print_holds.pl b/misc/cronjobs/holds/print_holds.pl new file mode 100755 index 0000000..05d0db6 --- /dev/null +++ b/misc/cronjobs/holds/print_holds.pl @@ -0,0 +1,159 @@ +#!/usr/bin/perl + +# Copyright 2009-2010 Kyle Hall +# +# 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 2 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; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} + +use Getopt::Long; +use Pod::Usage; +use Net::Printer; + +use C4::Context; +use C4::Members qw(GetMember); +use C4::Letters qw(GetPreparedLetter); + +my $help = 0; +my $test = 0; +my $verbose = 0; +my @printers; +GetOptions( + "help|?" => \$help, + "verbose|v" => \$verbose, + "test|t" => \$test, + "printer|p=s" => \@printers, +); +pod2usage(1) if $help; +pod2usage(1) unless @printers; + +my %printers; +foreach my $p (@printers) { + my ( $branchcode, $printer, $server, $port ) = split( /,/, $p ); + my %options; + $options{'printer'} = $printer if ($printer); + $options{'server'} = $server if ($server); + $options{'port'} = $port if ($port); + $printers{$branchcode} = new Net::Printer(%options); +} + +my $dbh = C4::Context->dbh; +my $query = "SELECT * FROM reserves WHERE printed IS NULL"; +my $sth = $dbh->prepare($query); +$sth->execute(); + +my $set_printed_query = " + UPDATE reserves + SET printed = 1 + WHERE reserve_id = ? +"; +my $set_printed_sth = $dbh->prepare($set_printed_query); + +while ( my $hold = $sth->fetchrow_hashref() ) { + if ($verbose) { + print "\nFound Notice to Print\n"; + print "Borrowernumber: " . $hold->{'borrowernumber'} . "\n"; + print "Biblionumber: " . $hold->{'biblionumber'} . "\n"; + print "Branch: " . $hold->{'branchcode'} . "\n"; + } + + my $borrower = + C4::Members::GetMember( 'borrowernumber' => $hold->{'borrowernumber'} ); + + my $letter = GetPreparedLetter( + module => 'reserves', + letter_code => 'HOLD_PLACED_PRINT', + branchcode => $hold->{branchcode}, + tables => { + 'branches' => $hold->{'branchcode'}, + 'biblio' => $hold->{'biblionumber'}, + 'biblioitems' => $hold->{'biblionumber'}, + 'items' => $hold->{'itemnumber'}, + 'borrowers' => $borrower, + } + ); + + if ( defined( $printers{ $hold->{branchcode} } ) ) { + unless ($test) { + my $result = + $printers{ $hold->{'branchcode'} } + ->printstring( $letter->{'content'} ); + my $error = $printers{ $hold->{'branchcode'} }->printerror(); + + unless ($error) { + $set_printed_sth->execute( $hold->{'reserve_id'} ); + } + else { + warn "ERROR: $error"; + } + } + else { + print "TEST MODE, notice will not be printed\n"; + print $letter->{'content'} . "\n"; + } + } + else { + print "WARNING: No printer defined for branchcode " + . $hold->{'branchcode'} + if ($verbose); + } + +} + +__END__ + +=head1 NAME + +Print Holds + +=head1 SYNOPSIS + +print_holds.pl --printer ,,, + +=head1 OPTIONS + +=over 8 + +=item B<-help> + +Print a brief help message and exits. + +=item B<-printer> + +Adds a printer, the value is the branchcode, printer name, server name and server port separated by commas. + +e.g. print_holds.pl --printer MPL,lp,printserver,515 --printer CPL,lp2,printserver,516 + +would add printers for branchcodes MPL and CPL. If a printer is not defined for a given branch, notices for +that branch will not be printed. + +=head1 DESCRIPTION + +B will print on-demand notices for items in the holds queue as they appear. + +=head1 AUTHOR + +Kyle M Hall + +=cut -- 1.7.10.4