Bug 7284 follow-up, DBrev number
[koha.git] / C4 / Print.pm
blobf8108161c2fb81605365fe74022e737920009a24
1 package C4::Print;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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 2 of the License, or (at your option) any later
10 # version.
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.
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.
20 use strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Context;
23 use C4::Members;
24 use C4::Dates qw(format_date);
26 use vars qw($VERSION @ISA @EXPORT);
28 BEGIN {
29 # set the version for version checking
30 $VERSION = 3.01;
31 require Exporter;
32 @ISA = qw(Exporter);
33 @EXPORT = qw(&remoteprint &printreserve &printslip);
36 =head1 NAME
38 C4::Print - Koha module dealing with printing
40 =head1 SYNOPSIS
42 use C4::Print;
44 =head1 DESCRIPTION
46 The functions in this module handle sending text to a printer.
48 =head1 FUNCTIONS
50 =head2 remoteprint
52 &remoteprint($items, $borrower);
54 Prints the list of items in C<$items> to a printer.
56 C<$borrower> is a reference-to-hash giving information about a patron.
57 This may be gotten from C<&GetMemberDetails>. The patron's name
58 will be printed in the output.
60 C<$items> is a reference-to-list, where each element is a
61 reference-to-hash describing a borrowed item. C<$items> may be gotten
62 from C<&GetBorrowerIssues>.
64 =cut
66 # FIXME - It'd be nifty if this could generate pretty PostScript.
67 sub remoteprint ($$) {
68 my ($items, $borrower) = @_;
70 (return)
71 unless ( C4::Context->boolean_preference('printcirculationslips') );
72 my $queue = '';
74 # FIXME - If 'queue' is undefined or empty, then presumably it should
75 # mean "use the default queue", whatever the default is. Presumably
76 # the default depends on the physical location of the machine.
77 # FIXME - Perhaps "print to file" should be a supported option. Just
78 # set the queue to "file" (or " file", if real queues aren't allowed
79 # to have spaces in them). Or perhaps if $queue eq "" and
80 # $env->{file} ne "", then that should mean "print to $env->{file}".
81 if ( $queue eq "" || $queue eq 'nulllp' ) {
82 return;
83 #open( PRINTER, ">/tmp/kohaiss" );
85 else {
87 # FIXME - This assumes that 'lpr' exists, and works as expected.
88 # This is a reasonable assumption, but only because every other
89 # printing package has a wrapper script called 'lpr'. It'd still
90 # be better to be able to customize this.
91 open( PRINTER, "| lpr -P $queue > /dev/null" )
92 or die "Couldn't write to queue:$queue!\n";
95 # print $queue;
96 #open (FILE,">/tmp/$file");
97 my $i = 0;
98 # FIXME - This is HLT-specific. Put this stuff in a customizable
99 # site-specific file somewhere.
100 print PRINTER "Horowhenua Library Trust\r\n";
101 print PRINTER "Phone: 368-1953\r\n";
102 print PRINTER "Fax: 367-9218\r\n";
103 print PRINTER "Email: renewals\@library.org.nz\r\n\r\n\r\n";
104 print PRINTER "$borrower->{'cardnumber'}\r\n";
105 print PRINTER
106 "$borrower->{'title'} $borrower->{'initials'} $borrower->{'surname'}\r\n";
108 # FIXME - Use for ($i = 0; $items->[$i]; $i++)
109 # Or better yet, foreach $item (@{$items})
110 while ( $items->[$i] ) {
112 # print $i;
113 my $itemdata = $items->[$i];
115 # FIXME - This is just begging for a Perl format.
116 print PRINTER "$i $itemdata->{'title'}\r\n";
117 print PRINTER "$itemdata->{'barcode'}";
118 print PRINTER " " x 15;
119 print PRINTER "$itemdata->{'date_due'}\r\n";
120 $i++;
122 print PRINTER "\r\n" x 7 ;
123 close PRINTER;
125 #system("lpr /tmp/$file");
128 sub printreserve {
130 # FIXME - make useful
131 return;
133 my ( $branchname, $bordata, $itemdata ) = @_;
134 my $printer = '';
135 (return) unless ( C4::Context->boolean_preference('printreserveslips') );
136 if ( $printer eq "" || $printer eq 'nulllp' ) {
137 open( PRINTER, ">>/tmp/kohares" )
138 or die "Could not write to /tmp/kohares";
140 else {
141 open( PRINTER, "| lpr -P $printer >/dev/null" )
142 or die "Couldn't write to queue:$!\n";
144 my @da = localtime();
145 my $todaysdate = "$da[2]:$da[1] " . C4::Dates->today();
146 my $slip = <<"EOF";
147 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148 Date: $todaysdate;
150 ITEM RESERVED:
151 $itemdata->{'title'} ($itemdata->{'author'})
152 barcode: $itemdata->{'barcode'}
154 COLLECT AT: $branchname
156 BORROWER:
157 $bordata->{'surname'}, $bordata->{'firstname'}
158 card number: $bordata->{'cardnumber'}
159 Phone: $bordata->{'phone'}
160 $bordata->{'streetaddress'}
161 $bordata->{'suburb'}
162 $bordata->{'town'}
163 $bordata->{'emailaddress'}
166 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168 print PRINTER $slip;
169 close PRINTER;
170 return $slip;
173 =head2 printslip
175 &printslip($borrowernumber)
177 print a slip for the given $borrowernumber
179 =cut
182 sub printslip ($) {
184 #FIXME - make useful
186 my $borrowernumber = shift;
187 my $borrower = GetMemberDetails($borrowernumber);
188 my $issueslist = GetPendingIssues($borrowernumber);
189 foreach my $it (@$issueslist){
190 $it->{'date_due'}=format_date($it->{'date_due'});
192 my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
193 remoteprint(\@issues, $borrower );
196 END { } # module clean-up code here (global destructor)
199 __END__
201 =head1 AUTHOR
203 Koha Development Team <http://koha-community.org/>
205 =head1 SEE ALSO
207 C4::Circulation::Circ2(3)
209 =cut