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 $op = $query->param('op') || q{};
40 my $dbh = C4::Context->dbh;
42 if($op eq 'cud-delete'){
43 delroutingmember($routingid,$subscriptionid);
44 my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
45 $sth->execute($subscriptionid);
46 print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
49 if($op eq 'cud-edit'){
50 print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
53 my @routinglist = getroutinglist($subscriptionid);
54 my $subs = GetSubscription($subscriptionid);
55 my ($tmp ,@serials) = GetSerials($subscriptionid);
56 my ($template, $loggedinuser, $cookie);
59 if($op eq 'cud-save_and_preview'){
60 # get biblio information....
61 my $biblionumber = $subs->{'bibnum'};
63 my $biblio = Koha::Biblios->find( $biblionumber );
64 my $items = $biblio->items->search_ordered;
67 ? $items->next->holding_branch->branchcode
68 : $subs->{branchcode};
69 $library = Koha::Libraries->find($branch);
71 if (C4::Context->preference('RoutingListAddReserves')){
72 # get existing reserves .....
74 my $holds = $biblio->current_holds;
75 my $count = $holds->count;
76 while ( my $hold = $holds->next ) {
77 $count-- if $hold->is_waiting;
80 my $title = $subs->{'bibliotitle'};
81 for my $routing ( @routinglist ) {
82 my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
83 $sth->execute($biblionumber,$routing->{borrowernumber});
84 my $reserve = $sth->fetchrow_hashref;
86 if($routing->{borrowernumber} == $reserve->{borrowernumber}){
88 rank => $routing->{ranking},
89 biblionumber => $biblionumber,
90 borrowernumber => $routing->{borrowernumber},
96 branchcode => $branch,
97 borrowernumber => $routing->{borrowernumber},
98 biblionumber => $biblionumber,
99 priority => $routing->{ranking},
107 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid&print_routing_list_issue=" . $query->param('issue_escaped'));
109 } elsif ( $op eq 'print' ) {
110 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
112 template_name => "serials/routing-preview-slip.tt",
115 flagsrequired => { serials => '*' },
119 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
121 template_name => "serials/routing-preview.tt",
124 flagsrequired => { serials => '*' },
129 $template->param( libraryname => $library->branchname ) if $library;
132 for my $routing (@routinglist) {
133 my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
134 $member->{name} = "$member->{firstname} $member->{surname}";
135 push @{$memberloop}, $member;
138 my $routingnotes = $serials[0]->{'routingnotes'};
139 $routingnotes =~ s/\n/\<br \/\>/g;
142 title => $subs->{'bibliotitle'},
144 issue_escaped => URI::Escape::uri_escape_utf8($issue),
145 subscriptionid => $subscriptionid,
146 memberloop => $memberloop,
147 routingnotes => $routingnotes,
148 hasRouting => check_routing($subscriptionid),
149 (uc(C4::Context->preference("marcflavour"))) => 1
152 output_html_with_http_headers $query, $cookie, $template->output;