Bug 9259: Use is instead of is_deeply
[koha.git] / serials / routing-preview.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
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 heirarchy
20 # of reserves for the serial
21 use strict;
22 use warnings;
23 use CGI qw ( -utf8 );
24 use C4::Koha;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Acquisition;
28 use C4::Reserves;
29 use C4::Circulation;
30 use C4::Context;
31 use C4::Members;
32 use C4::Biblio;
33 use C4::Items;
34 use C4::Serials;
35 use URI::Escape;
36 use C4::Branch;
37
38 my $query = new CGI;
39 my $subscriptionid = $query->param('subscriptionid');
40 my $issue = $query->param('issue');
41 my $routingid;
42 my $ok = $query->param('ok');
43 my $edit = $query->param('edit');
44 my $delete = $query->param('delete');
45 my $dbh = C4::Context->dbh;
46
47 if($delete){
48     delroutingmember($routingid,$subscriptionid);
49     my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
50     $sth->execute($subscriptionid);
51     print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
52 }
53
54 if($edit){
55     print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
56 }
57
58 my @routinglist = getroutinglist($subscriptionid);
59 my $subs = GetSubscription($subscriptionid);
60 my ($tmp ,@serials) = GetSerials($subscriptionid);
61 my ($template, $loggedinuser, $cookie);
62
63 if($ok){
64     # get biblio information....
65     my $biblio = $subs->{'biblionumber'};
66         my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio);
67         my @itemresults = GetItemsInfo( $subs->{biblionumber} );
68         my $branch = $itemresults[0]->{'holdingbranch'};
69         my $branchname = GetBranchName($branch);
70
71         if (C4::Context->preference('RoutingListAddReserves')){
72                 # get existing reserves .....
73         my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblio });
74         my $count = scalar( @$reserves );
75         my $totalcount = $count;
76                 foreach my $res (@$reserves) {
77                         if ($res->{'found'} eq 'W') {
78                                 $count--;
79                         }
80                 }
81                 my $notes;
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($biblio,$routing->{borrowernumber});
86             my $reserve = $sth->fetchrow_hashref;
87
88             if($routing->{borrowernumber} == $reserve->{borrowernumber}){
89                 ModReserve({
90                     rank           => $routing->{ranking},
91                     biblionumber   => $biblio,
92                     borrowernumber => $routing->{borrowernumber},
93                     branchcode     => $branch
94                 });
95             } else {
96                 AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
97         }
98     }
99         }
100
101     ($template, $loggedinuser, $cookie)
102 = get_template_and_user({template_name => "serials/routing-preview-slip.tt",
103                                 query => $query,
104                                 type => "intranet",
105                                 authnotrequired => 0,
106                                 flagsrequired => {serials => '*'},
107                                 debug => 1,
108                                 });
109     $template->param("libraryname"=>$branchname);
110 } else {
111     ($template, $loggedinuser, $cookie)
112 = get_template_and_user({template_name => "serials/routing-preview.tt",
113                                 query => $query,
114                                 type => "intranet",
115                                 authnotrequired => 0,
116                                 flagsrequired => {serials => '*'},
117                                 debug => 1,
118                                 });
119 }
120
121 my $memberloop = [];
122 for my $routing (@routinglist) {
123     my $member = GetMember( borrowernumber => $routing->{borrowernumber} );
124     $member->{name}           = "$member->{firstname} $member->{surname}";
125     push @{$memberloop}, $member;
126 }
127
128 my $routingnotes = $serials[0]->{'routingnotes'};
129 $routingnotes =~ s/\n/\<br \/\>/g;
130
131 $template->param(
132     title => $subs->{'bibliotitle'},
133     issue => $issue,
134     issue_escaped => URI::Escape::uri_escape_utf8($issue),
135     subscriptionid => $subscriptionid,
136     memberloop => $memberloop,
137     routingnotes => $routingnotes,
138     generalroutingnote => C4::Context->preference('RoutingListNote'),
139     hasRouting => check_routing($subscriptionid),
140     (uc(C4::Context->preference("marcflavour"))) => 1
141     );
142
143 output_html_with_http_headers $query, $cookie, $template->output;