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