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
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Circ2;
28 use vars qw($VERSION @ISA @EXPORT);
30 # set the version for version checking
31 # set the version for version checking
32 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
33 shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
38 C4::Print - Koha module dealing with printing
46 The functions in this module handle sending text to a printer.
55 @EXPORT = qw(&remoteprint &printreserve &printslip);
59 &remoteprint($env, $items, $borrower);
61 Prints the list of items in C<$items> to a printer.
63 C<$env> is a reference-to-hash. C<$env-E<gt>{queue}> specifies the
64 queue to print to; if it is empty or has the special value C<nulllp>,
65 C<&remoteprint> will print to the file F</tmp/kohaiss>.
67 C<$borrower> is a reference-to-hash giving information about a patron.
68 This may be gotten from C<&getpatroninformation>. The patron's name
69 will be printed in the output.
71 C<$items> is a reference-to-list, where each element is a
72 reference-to-hash describing a borrowed item. C<$items> may be gotten
73 from C<¤tissues>.
78 # FIXME - It'd be nifty if this could generate pretty PostScript.
80 my ( $env, $items, $borrower ) = @_;
83 unless ( C4::Context->boolean_preference('printcirculationslips') );
84 my $queue = $env->{'queue'};
86 # FIXME - If 'queue' is undefined or empty, then presumably it should
87 # mean "use the default queue", whatever the default is. Presumably
88 # the default depends on the physical location of the machine.
89 # FIXME - Perhaps "print to file" should be a supported option. Just
90 # set the queue to "file" (or " file", if real queues aren't allowed
91 # to have spaces in them). Or perhaps if $queue eq "" and
92 # $env->{file} ne "", then that should mean "print to $env->{file}".
93 if ( $queue eq "" || $queue eq 'nulllp' ) {
94 open( PRINTER, ">/tmp/kohaiss" );
98 # FIXME - This assumes that 'lpr' exists, and works as expected.
99 # This is a reasonable assumption, but only because every other
100 # printing package has a wrapper script called 'lpr'. It'd still
101 # be better to be able to customize this.
102 open( PRINTER, "| lpr -P $queue > /dev/null" )
103 or die "Couldn't write to queue:$queue!\n";
107 #open (FILE,">/tmp/$file");
109 my $brdata = $env->{'brdata'}; # FIXME - Not used
110 # FIXME - This is HLT-specific. Put this stuff in a customizable
111 # site-specific file somewhere.
112 print PRINTER "Horowhenua Library Trust\r\n";
114 # print PRINTER "$brdata->{'branchname'}\r\n";
115 print PRINTER "Phone: 368-1953\r\n";
116 print PRINTER "Fax: 367-9218\r\n";
117 print PRINTER "Email: renewals\@library.org.nz\r\n\r\n\r\n";
118 print PRINTER "$borrower->{'cardnumber'}\r\n";
120 "$borrower->{'title'} $borrower->{'initials'} $borrower->{'surname'}\r\n";
122 # FIXME - Use for ($i = 0; $items->[$i]; $i++)
123 # Or better yet, foreach $item (@{$items})
124 while ( $items->[$i] ) {
127 my $itemdata = $items->[$i];
129 # FIXME - This is just begging for a Perl format.
130 print PRINTER "$i $itemdata->{'title'}\r\n";
131 print PRINTER "$itemdata->{'barcode'}";
132 print PRINTER " " x 15;
133 print PRINTER "$itemdata->{'date_due'}\r\n";
136 print PRINTER "\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
137 if ( $env->{'printtype'} eq "docket" ) {
139 #print chr(27).chr(105);
143 #system("lpr /tmp/$file");
147 my ( $env, $branchname, $bordata, $itemdata ) = @_;
149 my $printer = $env->{'printer'};
150 (return) unless ( C4::Context->boolean_preference('printreserveslips') );
151 if ( $printer eq "" || $printer eq 'nulllp' ) {
152 open( PRINTER, ">>/tmp/kohares" );
155 open( PRINTER, "| lpr -P $printer >/dev/null" )
156 or die "Couldn't write to queue:$!\n";
158 my @da = localtime( time() );
159 my $todaysdate = "$da[2]:$da[1] $da[3]/$da[4]/$da[5]";
161 #(1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 $itemdata->{'title'} ($itemdata->{'author'})
168 barcode: $itemdata->{'barcode'}
170 COLLECT AT: $branchname
173 $bordata->{'surname'}, $bordata->{'firstname'}
174 card number: $bordata->{'cardnumber'}
175 Phone: $bordata->{'phone'}
176 $bordata->{'streetaddress'}
179 $bordata->{'emailaddress'}
182 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191 &printslip($env, $borrowernumber)
193 print a slip for the given $borrowernumber
199 my ( $env, $borrowernumber ) = @_;
200 my ( $borrower, $flags ) = getpatroninformation( $env, $borrowernumber, 0 );
201 $env->{'todaysissues'} = 1;
202 my ($borrowerissues) = currentissues( $env, $borrower );
203 $env->{'nottodaysissues'} = 1;
204 $env->{'todaysissues'} = 0;
205 my ($borroweriss2) = currentissues( $env, $borrower );
206 $env->{'nottodaysissues'} = 0;
210 foreach ( sort { $a <=> $b } keys %$borrowerissues ) {
211 $issues[$i] = $borrowerissues->{$_};
212 my $dd = $issues[$i]->{'date_due'};
214 #convert to nz style dates
215 #this should be set with some kinda config variable
216 my @tempdate = split( /-/, $dd );
217 $issues[$i]->{'date_due'} = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
220 foreach ( sort { $a <=> $b } keys %$borroweriss2 ) {
221 $issues[$i] = $borroweriss2->{$_};
222 my $dd = $issues[$i]->{'date_due'};
224 #convert to nz style dates
225 #this should be set with some kinda config variable
226 my @tempdate = split( /-/, $dd );
227 $issues[$i]->{'date_due'} = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
230 remoteprint( $env, \@issues, $borrower );
233 END { } # module clean-up code here (global destructor)
242 Koha Developement team <info@koha.org>
246 C4::Circulation::Circ2(3)