From 03c0c99383b7bfc4d1f324f53b2f14da2ce9d578 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 'hold to pull' notices printed out automatically for librarians. These notices will be based on the data in the tmp_holdsqueue table. As each new row is added to tmp_holdsqueue, a notice for that given row is printed. The system will have the ability to define a separate printer for each branchcode, so in theory each library could receive holds to pull notices printed automatically at holding library for that item, assuming they have set up the ability to print over the LAN, WAN, or Internet. --- C4/Installer/PerlDependencies.pm | 5 + .../data/mysql/en/mandatory/sample_notices.sql | 1 + installer/data/mysql/kohastructure.sql | 3 +- installer/data/mysql/updatedatabase.pl | 24 +++ .../holds/print_holds_to_pull_on_demand.pl | 165 ++++++++++++++++++++ 5 files changed, 197 insertions(+), 1 deletions(-) create mode 100755 misc/cronjobs/holds/print_holds_to_pull_on_demand.pl diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 62168c9..991ca64 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -534,6 +534,11 @@ our $PERL_DEPS = { 'required' => '1', 'min_ver' => '0.03', }, + 'Net::Printer' => { + 'usage' => 'Push to printer', + 'required' => '0', + 'min_ver' => '1.11', + }, }; 1; diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 6fa0a54..0055859 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -9,6 +9,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> items due soon'), ('reserves', 'HOLD', 'Hold Available for Pickup', 'Hold Available for Pickup at <>', 'Dear <> <>,\r\n\r\nYou have a hold available for pickup as of <>:\r\n\r\nTitle: <>\r\nAuthor: <>\r\nCopy: <>\r\nLocation: <>\r\n<>\r\n<>\r\n<>\r\n<> <>'), ('reserves', 'HOLD_PRINT', 'Hold Available for Pickup (print notice)', 'Hold Available for Pickup (print notice)', '<>\r\n<>\r\n<>\r\n\r\n\r\nChange Service Requested\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<> <>\r\n<>\r\n<> <>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<> <> <>\r\n\r\nYou have a hold available for pickup as of <>:\r\n\r\nTitle: <>\r\nAuthor: <>\r\nCopy: <>\r\n'), +('reserves', 'HOLD_TO_PULL', 'Hold to Pull (push to print notice )', 'Hold to Pull (push to print notice )', 'Hold to pull at <>\r\nFor <> <> ( <> )\r\n<> by <>'), ('circulation','CHECKIN','Item Check-in (Digest)','Check-ins','The following items have been checked in:\r\n----\r\n<>\r\n----\r\nThank you.'), ('circulation','CHECKOUT','Item Check-out (Digest)','Checkouts','The following items have been checked out:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'), ('reserves', 'HOLDPLACED', 'Hold Placed on Item', 'Hold Placed on Item','A hold has been placed on the following item : <> (<>) by the user <> <> (<>).'), diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e1105a5..64f1dcc 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2304,7 +2304,8 @@ CREATE TABLE `tmp_holdsqueue` ( `holdingbranch` varchar(10) default NULL, `pickbranch` varchar(10) default NULL, `notes` text, - `item_level_request` tinyint(4) NOT NULL default 0 + `item_level_request` tinyint(4) NOT NULL default 0, + `printed` tinyint(1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 4da22e7..17c19f6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5452,6 +5452,30 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE tmp_holdsqueue ADD printed BOOLEAN NULL AFTER item_level_request"); + $dbh->do("INSERT INTO `letter` ( + `module` , + `code` , + `branchcode` , + `name` , + `is_html` , + `title` , + `content` + ) + VALUES ( + 'reserves', 'HOLD_TO_PULL', '', 'Hold to Pull', '0', 'Hold to Pull', 'Hold to pull at <> + + For <> <> ( <> ) + + <> by <>' + )"); + + print "Upgrade to $DBversion done (Add print holds to pull notices on demand feature)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/misc/cronjobs/holds/print_holds_to_pull_on_demand.pl b/misc/cronjobs/holds/print_holds_to_pull_on_demand.pl new file mode 100755 index 0000000..217bb6b --- /dev/null +++ b/misc/cronjobs/holds/print_holds_to_pull_on_demand.pl @@ -0,0 +1,165 @@ +#!/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 tmp_holdsqueue WHERE printed IS NULL"; +my $sth = $dbh->prepare($query); +$sth->execute(); + +my $set_printed_query = " + UPDATE tmp_holdsqueue + SET printed = 1 + WHERE biblionumber = ? + AND itemnumber = ? + AND borrowernumber = ? + AND reservedate = ? + AND holdingbranch = ? +"; +my $set_printed_sth = $dbh->prepare($set_printed_query); + +while ( my $hold = $sth->fetchrow_hashref() ) { + print "\nFound Notice to Print\n" + if ($verbose); + print "Borrowernumber: " . $hold->{'borrowernumber'} . "\n" if ($verbose); + print "Biblionumber: " . $hold->{'biblionumber'} . "\n" if ($verbose); + print "Holding Branch: " . $hold->{'holdingbranch'} . "\n" if ($verbose); + + my $borrower = + C4::Members::GetMember( 'borrowernumber' => $hold->{'borrowernumber'} ); + + my $letter = GetPreparedLetter( + module => 'reserves', + letter_code => 'HOLD_TO_PULL', + branchcode => $hold->{holdingbranch}, + tables => { + 'branches' => $hold->{'holdingbranch'}, + 'biblio' => $hold->{'biblionumber'}, + 'biblioitems' => $hold->{'biblionumber'}, + 'items' => $hold->{'itemnumber'}, + 'borrowers' => $borrower, + } + ); + + if ( defined( $printers{ $hold->{holdingbranch} } ) ) { + unless ($test) { + my $result = + $printers{ $hold->{'holdingbranch'} } + ->printstring( $letter->{'content'} ); + my $error = $printers{ $hold->{'holdingbranch'} }->printerror(); + + unless ($error) { + $set_printed_sth->execute( + $hold->{'biblionumber'}, $hold->{'itemnumber'}, + $hold->{'borrowernumber'}, $hold->{'reservedate'}, + $hold->{'holdingbranch'} + ); + } + else { + warn "ERROR: $error"; + } + } + else { + print "TEST MODE, notice will not be printed\n"; + } + } + else { + print "WARNING: No printer defined for branchcode " + . $hold->{'holdingbranch'} + if ($verbose); + } + +} + +__END__ + +=head1 NAME + +Print Holds to Pull on Demand + +=head1 SYNOPSIS + +print_holds_to_pull_on_demand.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_to_pull_on_demand.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.2.5