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-46
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 $confirm = 0; |
44 |
my $confirm = 0; |
43 |
my @printers; |
45 |
my @printers; |
|
|
46 |
|
44 |
GetOptions( |
47 |
GetOptions( |
45 |
"help|?" => \$help, |
48 |
"help|?" => \$help, |
46 |
"verbose|v" => \$verbose, |
49 |
"verbose|v" => \$verbose, |
Lines 48-107
GetOptions(
Link Here
|
48 |
"confirm|c" => \$confirm, |
51 |
"confirm|c" => \$confirm, |
49 |
"printer|p=s" => \@printers, |
52 |
"printer|p=s" => \@printers, |
50 |
); |
53 |
); |
|
|
54 |
|
51 |
pod2usage(1) if $help; |
55 |
pod2usage(1) if $help; |
52 |
pod2usage(1) unless @printers; |
56 |
pod2usage(1) unless @printers; |
53 |
pod2usage(1) unless ( $test || $confirm ); |
57 |
pod2usage(1) unless ( $test || $confirm ); |
54 |
pod2usage(1) if ( $test && $confirm ); |
58 |
pod2usage(1) if ( $test && $confirm ); |
55 |
|
59 |
|
56 |
my $schema = Koha::Database->new()->schema(); |
|
|
57 |
|
58 |
my %printers; |
60 |
my %printers; |
59 |
foreach my $p (@printers) { |
61 |
foreach my $p (@printers) { |
60 |
my ( $branchcode, $printer_id ) = split( /:/, $p ); |
62 |
my ( $branchcode, $printer_id ) = split( /:/, $p ); |
61 |
$printers{$branchcode} = $schema->resultset('Printer')->find($printer_id); |
63 |
$printers{$branchcode} = Koha::Printers->find($printer_id); |
62 |
} |
64 |
} |
63 |
|
65 |
|
64 |
my $dbh = C4::Context->dbh; |
66 |
my $holds = Koha::Holds->search( { printed => undef } ); |
65 |
my $query = "SELECT * FROM reserves WHERE printed IS NULL"; |
|
|
66 |
my $sth = $dbh->prepare($query); |
67 |
$sth->execute(); |
68 |
|
69 |
my $set_printed_query = " |
70 |
UPDATE reserves |
71 |
SET printed = NOW() |
72 |
WHERE reserve_id = ? |
73 |
"; |
74 |
my $set_printed_sth = $dbh->prepare($set_printed_query); |
75 |
|
67 |
|
76 |
while ( my $hold = $sth->fetchrow_hashref() ) { |
68 |
while ( my $hold = $holds->next() ) { |
77 |
if ($verbose) { |
69 |
if ($verbose) { |
78 |
say "\nFound Notice to Print"; |
70 |
say "\nFound Notice to Print"; |
79 |
say "Borrowernumber: " . $hold->{'borrowernumber'}; |
71 |
say "Borrowernumber: " . $hold->borrowernumber; |
80 |
say "Biblionumber: " . $hold->{'biblionumber'}; |
72 |
say "Biblionumber: " . $hold->biblionumber; |
81 |
say "Branch: " . $hold->{'branchcode'}; |
73 |
say "Branch: " . $hold->branchcode; |
82 |
} |
74 |
} |
83 |
|
75 |
|
84 |
my $borrower = |
76 |
my $borrower = Koha::Borrowers->find( $hold->borrowernumber ); |
85 |
C4::Members::GetMember( 'borrowernumber' => $hold->{'borrowernumber'} ); |
|
|
86 |
|
77 |
|
87 |
my $letter = GetPreparedLetter( |
78 |
my $letter = GetPreparedLetter( |
88 |
module => 'reserves', |
79 |
module => 'reserves', |
89 |
letter_code => 'HOLD_PLACED_PRINT', |
80 |
letter_code => 'HOLD_PLACED_PRINT', |
90 |
branchcode => $hold->{branchcode}, |
81 |
branchcode => $hold->branchcode, |
91 |
tables => { |
82 |
tables => { |
92 |
branches => $hold->{'branchcode'}, |
83 |
branches => $hold->branchcode, |
93 |
biblio => $hold->{'biblionumber'}, |
84 |
biblio => $hold->biblionumber, |
94 |
biblioitems => $hold->{'biblionumber'}, |
85 |
biblioitems => $hold->biblionumber, |
95 |
items => $hold->{'itemnumber'}, |
86 |
items => $hold->itemnumber, |
96 |
borrowers => $borrower, |
87 |
borrowers => $borrower->unblessed, |
97 |
reserves => $hold, |
88 |
reserves => $hold->unblessed, |
98 |
|
89 |
|
99 |
} |
90 |
} |
100 |
); |
91 |
); |
101 |
|
92 |
|
102 |
if ( defined( $printers{ $hold->{branchcode} } ) ) { |
93 |
if ( defined( $printers{ $hold->branchcode } ) ) { |
103 |
unless ($test) { |
94 |
unless ($test) { |
104 |
my ( $success, $error ) = $printers{ $hold->{'branchcode'} }->print( |
95 |
my ( $success, $error ) = $printers{ $hold->branchcode }->print( |
105 |
{ |
96 |
{ |
106 |
data => $letter->{content}, |
97 |
data => $letter->{content}, |
107 |
is_html => $letter->{is_html}, |
98 |
is_html => $letter->{is_html}, |
Lines 109-115
while ( my $hold = $sth->fetchrow_hashref() ) {
Link Here
|
109 |
); |
100 |
); |
110 |
|
101 |
|
111 |
if ($success) { |
102 |
if ($success) { |
112 |
$set_printed_sth->execute( $hold->{'reserve_id'} ); |
103 |
my $ts = output_pref( { dt => dt_from_string(), dateformat => 'iso', timeformat => '24h' } ); |
|
|
104 |
$hold->printed($ts); |
105 |
$hold->store(); |
113 |
} |
106 |
} |
114 |
else { |
107 |
else { |
115 |
warn "ERROR: $error"; |
108 |
warn "ERROR: $error"; |
Lines 121-128
while ( my $hold = $sth->fetchrow_hashref() ) {
Link Here
|
121 |
} |
114 |
} |
122 |
} |
115 |
} |
123 |
else { |
116 |
else { |
124 |
say "WARNING: No printer defined for branchcode " |
117 |
say "WARNING: No printer defined for branchcode " . $hold->branchcode |
125 |
. $hold->{'branchcode'} |
|
|
126 |
if ($verbose); |
118 |
if ($verbose); |
127 |
} |
119 |
} |
128 |
|
120 |
|