|
Lines 1-12
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
# Copyright 2009-2010 Kyle Hall |
3 |
# Copyright 2015 ByWater Solutions |
| 4 |
# |
4 |
# |
| 5 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
| 6 |
# |
6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
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 |
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 |
9 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 10 |
# version. |
10 |
# version. |
| 11 |
# |
11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|
Lines 31-103
use Getopt::Long;
Link Here
|
| 31 |
use Pod::Usage; |
31 |
use Pod::Usage; |
| 32 |
use Net::Printer; |
32 |
use Net::Printer; |
| 33 |
|
33 |
|
| 34 |
use C4::Context; |
|
|
| 35 |
use C4::Members qw(GetMember); |
| 36 |
use C4::Letters qw(GetPreparedLetter); |
34 |
use C4::Letters qw(GetPreparedLetter); |
| 37 |
use Koha::Database; |
35 |
|
|
|
36 |
use Koha::DateUtils; |
| 37 |
use Koha::Holds; |
| 38 |
use Koha::Printers; |
| 39 |
use Koha::Borrowers; |
| 38 |
|
40 |
|
| 39 |
my $help = 0; |
41 |
my $help = 0; |
| 40 |
my $test = 0; |
42 |
my $test = 0; |
| 41 |
my $verbose = 0; |
43 |
my $verbose = 0; |
| 42 |
my @printers; |
44 |
my @printers; |
|
|
45 |
|
| 43 |
GetOptions( |
46 |
GetOptions( |
| 44 |
"help|?" => \$help, |
47 |
"help|?" => \$help, |
| 45 |
"verbose|v" => \$verbose, |
48 |
"verbose|v" => \$verbose, |
| 46 |
"test|t" => \$test, |
49 |
"test|t" => \$test, |
| 47 |
"printer|p=s" => \@printers, |
50 |
"printer|p=s" => \@printers, |
| 48 |
); |
51 |
); |
|
|
52 |
|
| 49 |
pod2usage(1) if $help; |
53 |
pod2usage(1) if $help; |
| 50 |
pod2usage(1) unless @printers; |
54 |
pod2usage(1) unless @printers; |
| 51 |
|
55 |
|
| 52 |
my $schema = Koha::Database->new()->schema(); |
|
|
| 53 |
|
| 54 |
my %printers; |
56 |
my %printers; |
| 55 |
foreach my $p (@printers) { |
57 |
foreach my $p (@printers) { |
| 56 |
my ( $branchcode, $printer_id ) = split( /:/, $p ); |
58 |
my ( $branchcode, $printer_id ) = split( /:/, $p ); |
| 57 |
$printers{$branchcode} = $schema->resultset('Printer')->find($printer_id); |
59 |
$printers{$branchcode} = Koha::Printers->find($printer_id); |
| 58 |
} |
60 |
} |
| 59 |
|
61 |
|
| 60 |
my $dbh = C4::Context->dbh; |
62 |
my $holds = Koha::Holds->search( { printed => undef } ); |
| 61 |
my $query = "SELECT * FROM reserves WHERE printed IS NULL"; |
|
|
| 62 |
my $sth = $dbh->prepare($query); |
| 63 |
$sth->execute(); |
| 64 |
|
| 65 |
my $set_printed_query = " |
| 66 |
UPDATE reserves |
| 67 |
SET printed = NOW() |
| 68 |
WHERE reserve_id = ? |
| 69 |
"; |
| 70 |
my $set_printed_sth = $dbh->prepare($set_printed_query); |
| 71 |
|
63 |
|
| 72 |
while ( my $hold = $sth->fetchrow_hashref() ) { |
64 |
while ( my $hold = $holds->next() ) { |
| 73 |
if ($verbose) { |
65 |
if ($verbose) { |
| 74 |
say "\nFound Notice to Print"; |
66 |
say "\nFound Notice to Print"; |
| 75 |
say "Borrowernumber: " . $hold->{'borrowernumber'}; |
67 |
say "Borrowernumber: " . $hold->borrowernumber; |
| 76 |
say "Biblionumber: " . $hold->{'biblionumber'}; |
68 |
say "Biblionumber: " . $hold->biblionumber; |
| 77 |
say "Branch: " . $hold->{'branchcode'}; |
69 |
say "Branch: " . $hold->branchcode; |
| 78 |
} |
70 |
} |
| 79 |
|
71 |
|
| 80 |
my $borrower = |
72 |
my $borrower = Koha::Borrowers->find( $hold->borrowernumber ); |
| 81 |
C4::Members::GetMember( 'borrowernumber' => $hold->{'borrowernumber'} ); |
|
|
| 82 |
|
73 |
|
| 83 |
my $letter = GetPreparedLetter( |
74 |
my $letter = GetPreparedLetter( |
| 84 |
module => 'reserves', |
75 |
module => 'reserves', |
| 85 |
letter_code => 'HOLD_PLACED_PRINT', |
76 |
letter_code => 'HOLD_PLACED_PRINT', |
| 86 |
branchcode => $hold->{branchcode}, |
77 |
branchcode => $hold->branchcode, |
| 87 |
tables => { |
78 |
tables => { |
| 88 |
branches => $hold->{'branchcode'}, |
79 |
branches => $hold->branchcode, |
| 89 |
biblio => $hold->{'biblionumber'}, |
80 |
biblio => $hold->biblionumber, |
| 90 |
biblioitems => $hold->{'biblionumber'}, |
81 |
biblioitems => $hold->biblionumber, |
| 91 |
items => $hold->{'itemnumber'}, |
82 |
items => $hold->itemnumber, |
| 92 |
borrowers => $borrower, |
83 |
borrowers => $borrower->unblessed, |
| 93 |
reserves => $hold, |
84 |
reserves => $hold->unblessed, |
| 94 |
|
85 |
|
| 95 |
} |
86 |
} |
| 96 |
); |
87 |
); |
| 97 |
|
88 |
|
| 98 |
if ( defined( $printers{ $hold->{branchcode} } ) ) { |
89 |
if ( defined( $printers{ $hold->branchcode } ) ) { |
| 99 |
unless ($test) { |
90 |
unless ($test) { |
| 100 |
my ( $success, $error ) = $printers{ $hold->{'branchcode'} }->print( |
91 |
my ( $success, $error ) = $printers{ $hold->branchcode }->print( |
| 101 |
{ |
92 |
{ |
| 102 |
data => $letter->{content}, |
93 |
data => $letter->{content}, |
| 103 |
is_html => $letter->{is_html}, |
94 |
is_html => $letter->{is_html}, |
|
Lines 105-111
while ( my $hold = $sth->fetchrow_hashref() ) {
Link Here
|
| 105 |
); |
96 |
); |
| 106 |
|
97 |
|
| 107 |
if ($success) { |
98 |
if ($success) { |
| 108 |
$set_printed_sth->execute( $hold->{'reserve_id'} ); |
99 |
my $ts = output_pref( { dt => dt_from_string(), dateformat => 'iso', timeformat => '24h' } ); |
|
|
100 |
$hold->printed($ts); |
| 101 |
$hold->store(); |
| 109 |
} |
102 |
} |
| 110 |
else { |
103 |
else { |
| 111 |
warn "ERROR: $error"; |
104 |
warn "ERROR: $error"; |
|
Lines 117-124
while ( my $hold = $sth->fetchrow_hashref() ) {
Link Here
|
| 117 |
} |
110 |
} |
| 118 |
} |
111 |
} |
| 119 |
else { |
112 |
else { |
| 120 |
say "WARNING: No printer defined for branchcode " |
113 |
say "WARNING: No printer defined for branchcode " . $hold->branchcode |
| 121 |
. $hold->{'branchcode'} |
|
|
| 122 |
if ($verbose); |
114 |
if ($verbose); |
| 123 |
} |
115 |
} |
| 124 |
|
116 |
|