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
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($items, $borrower);
61 Prints the list of items in C<$items> to a printer.
63 C<$borrower> is a reference-to-hash giving information about a patron.
64 This may be gotten from C<&GetMemberDetails>. The patron's name
65 will be printed in the output.
67 C<$items> is a reference-to-list, where each element is a
68 reference-to-hash describing a borrowed item. C<$items> may be gotten
69 from C<&GetBorrowerIssues>.
73 # FIXME - It'd be nifty if this could generate pretty PostScript.
75 my ($items, $borrower ) = @_;
78 unless ( C4::Context->boolean_preference('printcirculationslips') );
81 # FIXME - If 'queue' is undefined or empty, then presumably it should
82 # mean "use the default queue", whatever the default is. Presumably
83 # the default depends on the physical location of the machine.
84 # FIXME - Perhaps "print to file" should be a supported option. Just
85 # set the queue to "file" (or " file", if real queues aren't allowed
86 # to have spaces in them). Or perhaps if $queue eq "" and
87 # $env->{file} ne "", then that should mean "print to $env->{file}".
88 if ( $queue eq "" || $queue eq 'nulllp' ) {
89 open( PRINTER, ">/tmp/kohaiss" );
93 # FIXME - This assumes that 'lpr' exists, and works as expected.
94 # This is a reasonable assumption, but only because every other
95 # printing package has a wrapper script called 'lpr'. It'd still
96 # be better to be able to customize this.
97 open( PRINTER, "| lpr -P $queue > /dev/null" )
98 or die "Couldn't write to queue:$queue!\n";
102 #open (FILE,">/tmp/$file");
104 # FIXME - This is HLT-specific. Put this stuff in a customizable
105 # site-specific file somewhere.
106 print PRINTER "Horowhenua Library Trust\r\n";
107 print PRINTER "Phone: 368-1953\r\n";
108 print PRINTER "Fax: 367-9218\r\n";
109 print PRINTER "Email: renewals\@library.org.nz\r\n\r\n\r\n";
110 print PRINTER "$borrower->{'cardnumber'}\r\n";
112 "$borrower->{'title'} $borrower->{'initials'} $borrower->{'surname'}\r\n";
114 # FIXME - Use for ($i = 0; $items->[$i]; $i++)
115 # Or better yet, foreach $item (@{$items})
116 while ( $items->[$i] ) {
119 my $itemdata = $items->[$i];
121 # FIXME - This is just begging for a Perl format.
122 print PRINTER "$i $itemdata->{'title'}\r\n";
123 print PRINTER "$itemdata->{'barcode'}";
124 print PRINTER " " x 15;
125 print PRINTER "$itemdata->{'date_due'}\r\n";
128 print PRINTER "\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
131 #system("lpr /tmp/$file");
135 my ( $branchname, $bordata, $itemdata ) = @_;
138 (return) unless ( C4::Context->boolean_preference('printreserveslips') );
139 if ( $printer eq "" || $printer eq 'nulllp' ) {
140 open( PRINTER, ">>/tmp/kohares" );
143 open( PRINTER, "| lpr -P $printer >/dev/null" )
144 or die "Couldn't write to queue:$!\n";
146 my @da = localtime( time() );
147 my $todaysdate = "$da[2]:$da[1] $da[3]/$da[4]/$da[5]";
149 #(1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
151 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155 $itemdata->{'title'} ($itemdata->{'author'})
156 barcode: $itemdata->{'barcode'}
158 COLLECT AT: $branchname
161 $bordata->{'surname'}, $bordata->{'firstname'}
162 card number: $bordata->{'cardnumber'}
163 Phone: $bordata->{'phone'}
164 $bordata->{'streetaddress'}
167 $bordata->{'emailaddress'}
170 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179 &printslip($borrowernumber)
181 print a slip for the given $borrowernumber
187 my ( $borrowernumber ) = @_;
188 my ( $borrower, $flags ) = GetMemberDetails( $borrowernumber);
189 my ($borrowerissues) = GetBorrowerIssues( $borrower );
190 my ($borroweriss2) = GetBorrowerIssues( $borrower );
194 foreach ( sort { $a <=> $b } keys %$borrowerissues ) {
195 $issues[$i] = $borrowerissues->{$_};
196 my $dd = $issues[$i]->{'date_due'};
198 #convert to nz style dates
199 #this should be set with some kinda config variable
200 my @tempdate = split( /-/, $dd );
201 $issues[$i]->{'date_due'} = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
204 foreach ( sort { $a <=> $b } keys %$borroweriss2 ) {
205 $issues[$i] = $borroweriss2->{$_};
206 my $dd = $issues[$i]->{'date_due'};
208 #convert to nz style dates
209 #this should be set with some kinda config variable
210 my @tempdate = split( /-/, $dd );
211 $issues[$i]->{'date_due'} = "$tempdate[2]/$tempdate[1]/$tempdate[0]";
214 remoteprint(\@issues, $borrower );
217 END { } # module clean-up code here (global destructor)
226 Koha Developement team <info@koha.org>
230 C4::Circulation::Circ2(3)