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::Items qw( GetItemsInfo );
29 use C4::Serials qw( delroutingmember getroutinglist GetSubscription GetSerials check_routing );
37 my $subscriptionid = $query->param('subscriptionid');
38 my $issue = $query->param('issue');
40 my $ok = $query->param('ok');
41 my $edit = $query->param('edit');
42 my $delete = $query->param('delete');
43 my $dbh = C4::Context->dbh;
46 delroutingmember($routingid,$subscriptionid);
47 my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
48 $sth->execute($subscriptionid);
49 print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
53 print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
56 my @routinglist = getroutinglist($subscriptionid);
57 my $subs = GetSubscription($subscriptionid);
58 my ($tmp ,@serials) = GetSerials($subscriptionid);
59 my ($template, $loggedinuser, $cookie);
63 # get biblio information....
64 my $biblionumber = $subs->{'bibnum'};
65 my @itemresults = GetItemsInfo( $biblionumber );
66 my $branch = @itemresults ? $itemresults[0]->{'holdingbranch'} : $subs->{branchcode};
67 $library = Koha::Libraries->find($branch);
69 if (C4::Context->preference('RoutingListAddReserves')){
70 # get existing reserves .....
72 my $biblio = Koha::Biblios->find( $biblionumber );
73 my $holds = $biblio->current_holds;
74 my $count = $holds->count;
75 while ( my $hold = $holds->next ) {
76 $count-- if $hold->is_waiting;
79 my $title = $subs->{'bibliotitle'};
80 for my $routing ( @routinglist ) {
81 my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
82 $sth->execute($biblionumber,$routing->{borrowernumber});
83 my $reserve = $sth->fetchrow_hashref;
85 if($routing->{borrowernumber} == $reserve->{borrowernumber}){
87 rank => $routing->{ranking},
88 biblionumber => $biblionumber,
89 borrowernumber => $routing->{borrowernumber},
95 branchcode => $branch,
96 borrowernumber => $routing->{borrowernumber},
97 biblionumber => $biblionumber,
98 priority => $routing->{ranking},
107 ($template, $loggedinuser, $cookie)
108 = get_template_and_user({template_name => "serials/routing-preview-slip.tt",
111 flagsrequired => {serials => '*'},
114 ($template, $loggedinuser, $cookie)
115 = get_template_and_user({template_name => "serials/routing-preview.tt",
118 flagsrequired => {serials => '*'},
122 $template->param( libraryname => $library->branchname ) if $library;
125 for my $routing (@routinglist) {
126 my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
127 $member->{name} = "$member->{firstname} $member->{surname}";
128 push @{$memberloop}, $member;
131 my $routingnotes = $serials[0]->{'routingnotes'};
132 $routingnotes =~ s/\n/\<br \/\>/g;
135 title => $subs->{'bibliotitle'},
137 issue_escaped => URI::Escape::uri_escape_utf8($issue),
138 subscriptionid => $subscriptionid,
139 memberloop => $memberloop,
140 routingnotes => $routingnotes,
141 hasRouting => check_routing($subscriptionid),
142 (uc(C4::Context->preference("marcflavour"))) => 1
145 output_html_with_http_headers $query, $cookie, $template->output;