3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 # Routing Preview.pl script used to view a routing list after creation
19 # lets one print out routing slip and create (in this instance) the hierarchy
20 # of reserves for the serial
24 use C4::Auth qw( get_template_and_user );
25 use C4::Output qw( output_html_with_http_headers );
26 use C4::Reserves qw( AddReserve ModReserve );
28 use C4::Serials qw( delroutingmember getroutinglist GetSubscription GetSerials check_routing );
36 my $subscriptionid = $query->param('subscriptionid');
37 my $issue = $query->param('issue');
39 my $ok = $query->param('ok');
40 my $edit = $query->param('edit');
41 my $delete = $query->param('delete');
42 my $dbh = C4::Context->dbh;
45 delroutingmember($routingid,$subscriptionid);
46 my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
47 $sth->execute($subscriptionid);
48 print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
52 print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
55 my @routinglist = getroutinglist($subscriptionid);
56 my $subs = GetSubscription($subscriptionid);
57 my ($tmp ,@serials) = GetSerials($subscriptionid);
58 my ($template, $loggedinuser, $cookie);
62 # get biblio information....
63 my $biblionumber = $subs->{'bibnum'};
65 my $biblio = Koha::Biblios->find( $biblionumber );
66 my $items = $biblio->items->search_ordered;
69 ? $items->next->holding_branch->branchcode
70 : $subs->{branchcode};
71 $library = Koha::Libraries->find($branch);
73 if (C4::Context->preference('RoutingListAddReserves')){
74 # get existing reserves .....
76 my $holds = $biblio->current_holds;
77 my $count = $holds->count;
78 while ( my $hold = $holds->next ) {
79 $count-- if $hold->is_waiting;
82 my $title = $subs->{'bibliotitle'};
83 for my $routing ( @routinglist ) {
84 my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
85 $sth->execute($biblionumber,$routing->{borrowernumber});
86 my $reserve = $sth->fetchrow_hashref;
88 if($routing->{borrowernumber} == $reserve->{borrowernumber}){
90 rank => $routing->{ranking},
91 biblionumber => $biblionumber,
92 borrowernumber => $routing->{borrowernumber},
98 branchcode => $branch,
99 borrowernumber => $routing->{borrowernumber},
100 biblionumber => $biblionumber,
101 priority => $routing->{ranking},
110 ($template, $loggedinuser, $cookie)
111 = get_template_and_user({template_name => "serials/routing-preview-slip.tt",
114 flagsrequired => {serials => '*'},
117 ($template, $loggedinuser, $cookie)
118 = get_template_and_user({template_name => "serials/routing-preview.tt",
121 flagsrequired => {serials => '*'},
125 $template->param( libraryname => $library->branchname ) if $library;
128 for my $routing (@routinglist) {
129 my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
130 $member->{name} = "$member->{firstname} $member->{surname}";
131 push @{$memberloop}, $member;
134 my $routingnotes = $serials[0]->{'routingnotes'};
135 $routingnotes =~ s/\n/\<br \/\>/g;
138 title => $subs->{'bibliotitle'},
140 issue_escaped => URI::Escape::uri_escape_utf8($issue),
141 subscriptionid => $subscriptionid,
142 memberloop => $memberloop,
143 routingnotes => $routingnotes,
144 hasRouting => check_routing($subscriptionid),
145 (uc(C4::Context->preference("marcflavour"))) => 1
148 output_html_with_http_headers $query, $cookie, $template->output;