MT 2146 :Adding index on issn
[koha.git] / serials / routing-preview.pl
blob2ec03002effa585291151077bee5c4c2e1b660e3
1 #!/usr/bin/perl
3 # Routing Preview.pl script used to view a routing list after creation
4 # lets one print out routing slip and create (in this instance) the heirarchy
5 # of reserves for the serial
6 use strict;
7 use warnings;
8 use CGI;
9 use C4::Koha;
10 use C4::Auth;
11 use C4::Dates;
12 use C4::Output;
13 use C4::Acquisition;
14 use C4::Reserves;
15 use C4::Circulation;
16 use C4::Context;
17 use C4::Members;
18 use C4::Biblio;
19 use C4::Items;
20 use C4::Serials;
21 use URI::Escape;
22 use C4::Branch;
24 my $query = new CGI;
25 my $subscriptionid = $query->param('subscriptionid');
26 my $issue = $query->param('issue');
27 my $routingid;
28 my $ok = $query->param('ok');
29 my $edit = $query->param('edit');
30 my $delete = $query->param('delete');
31 my $dbh = C4::Context->dbh;
33 if($delete){
34 delroutingmember($routingid,$subscriptionid);
35 my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
36 $sth->execute($subscriptionid);
37 print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
40 if($edit){
41 print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
44 my ($routing, @routinglist) = getroutinglist($subscriptionid);
45 my $subs = GetSubscription($subscriptionid);
46 my ($count,@serials) = GetSerials($subscriptionid);
47 my ($template, $loggedinuser, $cookie);
49 if($ok){
50 # get biblio information....
51 my $biblio = $subs->{'biblionumber'};
53 if (C4::Context->preference('RoutingListAddReserves')){
54 # get existing reserves .....
55 my ($count,$reserves) = GetReservesFromBiblionumber($biblio);
56 my $totalcount = $count;
57 foreach my $res (@$reserves) {
58 if ($res->{'found'} eq 'W') {
59 $count--;
62 my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio);
63 my @itemresults = GetItemsInfo($subs->{'biblionumber'}, 'intra');
64 my $branch = $itemresults[0]->{'holdingbranch'};
65 my $branchname = GetBranchName($branch);
66 my $const = 'o';
67 my $notes;
68 my $title = $subs->{'bibliotitle'};
69 for(my $i=0;$i<$routing;$i++){
70 my $sth = $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ?");
71 $sth->execute($biblio,$routinglist[$i]->{'borrowernumber'});
72 my $data = $sth->fetchrow_hashref;
74 # warn "$routinglist[$i]->{'borrowernumber'} is the same as $data->{'borrowernumber'}";
75 if($routinglist[$i]->{'borrowernumber'} == $data->{'borrowernumber'}){
76 ModReserve($routinglist[$i]->{'ranking'},$biblio,$routinglist[$i]->{'borrowernumber'},$branch);
77 } else {
78 AddReserve($branch,$routinglist[$i]->{'borrowernumber'},$biblio,$const,\@bibitems,$routinglist[$i]->{'ranking'},'',$notes,$title);
83 ($template, $loggedinuser, $cookie)
84 = get_template_and_user({template_name => "serials/routing-preview-slip.tmpl",
85 query => $query,
86 type => "intranet",
87 authnotrequired => 0,
88 flagsrequired => {serials => 1},
89 debug => 1,
90 });
91 $template->param("libraryname"=>$branchname);
92 } else {
93 ($template, $loggedinuser, $cookie)
94 = get_template_and_user({template_name => "serials/routing-preview.tmpl",
95 query => $query,
96 type => "intranet",
97 authnotrequired => 0,
98 flagsrequired => {serials => 1},
99 debug => 1,
103 my @results;
104 my $data;
105 for(my $i=0;$i<$routing;$i++){
106 $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
107 $data->{'location'}=$data->{'branchcode'};
108 $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
109 $data->{'routingid'}=$routinglist[$i]->{'routingid'};
110 $data->{'subscriptionid'}=$subscriptionid;
111 push(@results, $data);
114 my $routingnotes = $serials[0]->{'routingnotes'};
115 $routingnotes =~ s/\n/\<br \/\>/g;
117 $template->param(
118 title => $subs->{'bibliotitle'},
119 issue => $issue,
120 issue_escaped => URI::Escape::uri_escape($issue),
121 subscriptionid => $subscriptionid,
122 memberloop => \@results,
123 routingnotes => $routingnotes,
126 output_html_with_http_headers $query, $cookie, $template->output;