Fix to stop a silent failing of issuing when an item from a branch is checked out...
[koha.git] / serials / subscription-detail.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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use CGI;
20 use C4::Auth;
21 use C4::Koha;
22 use C4::Date;
23 use C4::Serials;
24 use C4::Output;
25 use C4::Context;
26 use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
27 #use Date::Manip;
28
29 my $query = new CGI;
30 my $op = $query->param('op');
31 my $dbh = C4::Context->dbh;
32 my $sth;
33 # my $id;
34 my ($template, $loggedinuser, $cookie, $subs);
35 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
36     $firstacquidate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength,
37     $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
38     $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
39     $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
40     $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere,$letter,$manualhistory,$histstartdate,$enddate,$missinglist,$recievedlist,$opacnote,$librariannote);
41
42 $subscriptionid = $query->param('subscriptionid');
43
44 my $subs = &GetSubscription($subscriptionid);
45 if ($op eq 'del') {
46     if ($subs->{'cannotedit'}){
47       warn "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
48       print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
49     }  
50     &DelSubscription($subscriptionid);
51     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
52     exit;
53
54 }
55 my ($routing, @routinglist) = getroutinglist($subscriptionid);
56 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
57 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
58 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
59
60 ($template, $loggedinuser, $cookie)
61 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
62                 query => $query,
63                 type => "intranet",
64                 authnotrequired => 0,
65                 flagsrequired => {serials => 1},
66                 debug => 1,
67                 });
68
69 my ($user, $cookie, $sessionID, $flags)
70     = checkauth($query, 0, {catalogue => 1}, "intranet");
71
72 my $weekarrayjs='';
73 my $count = 0;
74 my ($year, $month, $day) = Today;
75 my $firstday = Day_of_Year($year,$month,$day);
76 my ($wkno,$yr) = Week_of_Year($year,$month,$day); # week starting monday
77 my $weekno = $wkno;
78 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
79             $count = $i;
80             if($wkno > 52){$year++; $wkno=1;}
81             if($count>365){$count=$i-365;}
82             my ($y,$m,$d) =  Add_Delta_Days($year,1,1, $count - 1);#Date_NthDayOfYear($year,$count);
83             my $output = "$y-$m-$d";
84             $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
85             $wkno++;
86     }
87 chop($weekarrayjs);
88
89 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
90
91 $subs->{startdate}=format_date($subs->{startdate});
92 $subs->{firstacquidate}=format_date($subs->{firstacquidate});
93 $subs->{histstartdate}=format_date($subs->{histstartdate});
94 $subs->{enddate}=format_date($subs->{enddate});
95 $subs->{abouttoexpire}=abouttoexpire($subs->{subscriptionid});
96 # Done in Serials.pm
97 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') && 
98 #         C4::Context->userenv && 
99 #         C4::Context->userenv->{flags} !=1  && 
100 #         C4::Context->userenv->{branch} && $subs->{branchcode} &&
101 #         (C4::Context->userenv->{branch} ne $subs->{branchcode}));
102
103 $template->param($subs);
104
105 $template->param(
106     routing => $routing,
107     serialslist => \@serialslist,
108     totalissues => $totalissues,
109     hemisphere => $hemisphere,
110     );
111 $template->param(
112             "periodicity".($subs->{periodicity}?$subs->{periodicity}:'0') => 1,
113             "arrival".$subs->{dow} => 1,
114             "numberpattern".$subs->{numberpattern} => 1,
115             intranetstylesheet => C4::Context->preference("intranetstylesheet"),
116             intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), 
117             );
118
119 output_html_with_http_headers $query, $cookie, $template->output;