synching deletedborrowers table with borrowers table
[koha.git] / C4 / Print.pm
blob21fd8c24e3d7b5ca7ecb7a3692feb59af6a30fec
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
21 use strict;
22 require Exporter;
24 use C4::Context;
25 use C4::Circulation;
26 use C4::Members;
27 use C4::Dates qw(format_date);
29 use vars qw($VERSION @ISA @EXPORT);
31 # set the version for version checking
32 # set the version for version checking
33 $VERSION = 3.00;
35 =head1 NAME
37 C4::Print - Koha module dealing with printing
39 =head1 SYNOPSIS
41 use C4::Print;
43 =head1 DESCRIPTION
45 The functions in this module handle sending text to a printer.
47 =head1 FUNCTIONS
49 =over 2
51 =cut
53 @ISA = qw(Exporter);
54 @EXPORT = qw(&remoteprint &printreserve &printslip);
56 =item remoteprint
58 &remoteprint($items, $borrower);
60 Prints the list of items in C<$items> to a printer.
62 C<$borrower> is a reference-to-hash giving information about a patron.
63 This may be gotten from C<&GetMemberDetails>. The patron's name
64 will be printed in the output.
66 C<$items> is a reference-to-list, where each element is a
67 reference-to-hash describing a borrowed item. C<$items> may be gotten
68 from C<&GetBorrowerIssues>.
70 =cut
72 # FIXME - It'd be nifty if this could generate pretty PostScript.
73 sub remoteprint ($$) {
74 my ($items, $borrower) = @_;
76 (return)
77 unless ( C4::Context->boolean_preference('printcirculationslips') );
78 my $queue = '';
80 # FIXME - If 'queue' is undefined or empty, then presumably it should
81 # mean "use the default queue", whatever the default is. Presumably
82 # the default depends on the physical location of the machine.
83 # FIXME - Perhaps "print to file" should be a supported option. Just
84 # set the queue to "file" (or " file", if real queues aren't allowed
85 # to have spaces in them). Or perhaps if $queue eq "" and
86 # $env->{file} ne "", then that should mean "print to $env->{file}".
87 if ( $queue eq "" || $queue eq 'nulllp' ) {
88 open( PRINTER, ">/tmp/kohaiss" );
90 else {
92 # FIXME - This assumes that 'lpr' exists, and works as expected.
93 # This is a reasonable assumption, but only because every other
94 # printing package has a wrapper script called 'lpr'. It'd still
95 # be better to be able to customize this.
96 open( PRINTER, "| lpr -P $queue > /dev/null" )
97 or die "Couldn't write to queue:$queue!\n";
100 # print $queue;
101 #open (FILE,">/tmp/$file");
102 my $i = 0;
103 # FIXME - This is HLT-specific. Put this stuff in a customizable
104 # site-specific file somewhere.
105 print PRINTER "Horowhenua Library Trust\r\n";
106 print PRINTER "Phone: 368-1953\r\n";
107 print PRINTER "Fax: 367-9218\r\n";
108 print PRINTER "Email: renewals\@library.org.nz\r\n\r\n\r\n";
109 print PRINTER "$borrower->{'cardnumber'}\r\n";
110 print PRINTER
111 "$borrower->{'title'} $borrower->{'initials'} $borrower->{'surname'}\r\n";
113 # FIXME - Use for ($i = 0; $items->[$i]; $i++)
114 # Or better yet, foreach $item (@{$items})
115 while ( $items->[$i] ) {
117 # print $i;
118 my $itemdata = $items->[$i];
120 # FIXME - This is just begging for a Perl format.
121 print PRINTER "$i $itemdata->{'title'}\r\n";
122 print PRINTER "$itemdata->{'barcode'}";
123 print PRINTER " " x 15;
124 print PRINTER "$itemdata->{'date_due'}\r\n";
125 $i++;
127 print PRINTER "\r\n" x 7 ;
128 close PRINTER;
130 #system("lpr /tmp/$file");
133 sub printreserve {
134 my ( $branchname, $bordata, $itemdata ) = @_;
135 my $printer = '';
136 (return) unless ( C4::Context->boolean_preference('printreserveslips') );
137 if ( $printer eq "" || $printer eq 'nulllp' ) {
138 open( PRINTER, ">>/tmp/kohares" )
139 or die "Could not write to /tmp/kohares";
141 else {
142 open( PRINTER, "| lpr -P $printer >/dev/null" )
143 or die "Couldn't write to queue:$!\n";
145 my @da = localtime();
146 my $todaysdate = "$da[2]:$da[1] " . C4::Dates->today();
147 my $slip = <<"EOF";
148 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149 Date: $todaysdate;
151 ITEM RESERVED:
152 $itemdata->{'title'} ($itemdata->{'author'})
153 barcode: $itemdata->{'barcode'}
155 COLLECT AT: $branchname
157 BORROWER:
158 $bordata->{'surname'}, $bordata->{'firstname'}
159 card number: $bordata->{'cardnumber'}
160 Phone: $bordata->{'phone'}
161 $bordata->{'streetaddress'}
162 $bordata->{'suburb'}
163 $bordata->{'town'}
164 $bordata->{'emailaddress'}
167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169 print PRINTER $slip;
170 close PRINTER;
171 return $slip;
174 =item printslip
176 &printslip($borrowernumber)
178 print a slip for the given $borrowernumber
180 =cut
183 sub printslip ($) {
184 my ( $borrowernumber ) = shift;
185 my ( $borrower, $flags ) = GetMemberDetails( $borrowernumber);
186 my ($countissues,$issueslist) = GetPendingIssues($borrowernumber);
187 foreach my $it (@$issueslist){
188 $it->{'date_due'}=format_date($it->{'date_due'});
190 my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
191 remoteprint(\@issues, $borrower );
194 END { } # module clean-up code here (global destructor)
197 __END__
199 =back
201 =head1 AUTHOR
203 Koha Developement team <info@koha.org>
205 =head1 SEE ALSO
207 C4::Circulation::Circ2(3)
209 =cut