3 # This file is part of Koha.
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
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.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use C4
::Bookseller qw
/GetBookSellerFromId/;
25 use C4
::Dates qw
/format_date/;
29 use C4
::Search qw
/enabled_staff_search_views/;
30 use Date
::Calc qw
/Today Day_of_Year Week_of_Year Add_Delta_Days/;
34 my $op = $query->param('op') || q{};
35 my $issueconfirmed = $query->param('issueconfirmed');
36 my $dbh = C4
::Context
->dbh;
37 my $subscriptionid = $query->param('subscriptionid');
39 if ( $op and $op eq "close" ) {
40 C4
::Serials
::CloseSubscription
( $subscriptionid );
41 } elsif ( $op and $op eq "reopen" ) {
42 C4
::Serials
::ReopenSubscription
( $subscriptionid );
45 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
47 # Permission needed if it is a deletion (del) : delete_subscription
48 # Permission needed otherwise : *
49 my $permission = ($op eq "del") ?
"delete_subscription" : "*";
51 my ($template, $loggedinuser, $cookie)
52 = get_template_and_user
({template_name
=> "serials/subscription-detail.tmpl",
56 flagsrequired
=> {serials
=> $permission},
61 my $subs = GetSubscription
($subscriptionid);
62 $subs->{enddate
} ||= GetExpirationDate
($subscriptionid);
64 my ($totalissues,@serialslist) = GetSerials
($subscriptionid);
65 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
68 if ($$subs{'cannotedit'}){
69 carp
"Attempt to delete subscription $subscriptionid by ".C4
::Context
->userenv->{'id'}." not allowed";
70 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
74 # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
75 my $strictlyexpired = HasSubscriptionStrictlyExpired
($subscriptionid);
76 my $linkedissues = CountIssues
($subscriptionid);
77 my $countitems = HasItems
($subscriptionid);
78 if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
79 $template->param(NEEDSCONFIRMATION
=> 1);
80 if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
81 if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); }
82 if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); }
84 $issueconfirmed = "1";
86 # If it's ok to delete the subscription, we do so
87 if ($issueconfirmed eq "1") {
88 &DelSubscription
($subscriptionid);
89 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
93 my $hasRouting = check_routing
($subscriptionid);
95 (undef, $cookie, undef, undef)
96 = checkauth
($query, 0, {catalogue
=> 1}, "intranet");
98 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
100 for my $date ( qw(startdate enddate firstacquidate histstartdate histenddate) ) {
101 $$subs{$date} = format_date
($$subs{$date}) if $date && $$subs{$date};
103 $subs->{location
} = GetKohaAuthorisedValueLib
("LOC",$subs->{location
});
104 $subs->{abouttoexpire
} = abouttoexpire
($subs->{subscriptionid
});
105 $template->param(%{ $subs });
106 $template->param(biblionumber_for_new_subscription
=> $subs->{bibnum
});
107 my @irregular_issues = split /,/, $subs->{irregularity
};
109 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
110 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
112 my $default_bib_view = get_default_view
();
114 my ( $order, $bookseller, $tmpl_infos );
115 if ( defined $subscriptionid ) {
116 my $lastOrderNotReceived = GetLastOrderNotReceivedFromSubscriptionid
$subscriptionid;
117 my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid
$subscriptionid;
118 if ( defined $lastOrderNotReceived ) {
119 my $basket = GetBasket
$lastOrderNotReceived->{basketno
};
120 my $bookseller = GetBookSellerFromId
$basket->{booksellerid
};
121 ( $tmpl_infos->{valuegsti_ordered
}, $tmpl_infos->{valuegste_ordered
} ) = get_value_with_gst_params
( $lastOrderNotReceived->{ecost
}, $lastOrderNotReceived->{gstrate
}, $bookseller );
122 $tmpl_infos->{valuegsti_ordered
} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered
} );
123 $tmpl_infos->{valuegste_ordered
} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered
} );
124 $tmpl_infos->{budget_name_ordered
} = GetBudgetName
$lastOrderNotReceived->{budget_id
};
125 $tmpl_infos->{basketno
} = $lastOrderNotReceived->{basketno
};
126 $tmpl_infos->{ordered_exists
} = 1;
128 if ( defined $lastOrderReceived ) {
129 my $basket = GetBasket
$lastOrderReceived->{basketno
};
130 my $bookseller = GetBookSellerFromId
$basket->{booksellerid
};
131 ( $tmpl_infos->{valuegsti_spent
}, $tmpl_infos->{valuegste_spent
} ) = get_value_with_gst_params
( $lastOrderReceived->{unitprice
}, $lastOrderReceived->{gstrate
}, $bookseller );
132 $tmpl_infos->{valuegsti_spent
} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent
} );
133 $tmpl_infos->{valuegste_spent
} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent
} );
134 $tmpl_infos->{budget_name_spent
} = GetBudgetName
$lastOrderReceived->{budget_id
};
135 $tmpl_infos->{invoiceid
} = $lastOrderReceived->{invoiceid
};
136 $tmpl_infos->{spent_exists
} = 1;
141 subscriptionid
=> $subscriptionid,
142 serialslist
=> \
@serialslist,
143 hasRouting
=> $hasRouting,
144 routing
=> C4
::Context
->preference("RoutingSerials"),
145 totalissues
=> $totalissues,
146 cannotedit
=> (not C4
::Serials
::can_edit_subscription
( $subs )),
147 frequency
=> $frequency,
148 numberpattern
=> $numberpattern,
149 has_X
=> ($numberpattern->{'numberingmethod'} =~ /{X}/) ?
1 : 0,
150 has_Y
=> ($numberpattern->{'numberingmethod'} =~ /{Y}/) ?
1 : 0,
151 has_Z
=> ($numberpattern->{'numberingmethod'} =~ /{Z}/) ?
1 : 0,
152 intranetstylesheet
=> C4
::Context
->preference('intranetstylesheet'),
153 intranetcolorstylesheet
=> C4
::Context
->preference('intranetcolorstylesheet'),
154 irregular_issues
=> scalar @irregular_issues,
155 default_bib_view
=> $default_bib_view,
156 (uc(C4
::Context
->preference("marcflavour"))) => 1,
157 show_acquisition_details
=> defined $tmpl_infos->{ordered_exists
} || defined $tmpl_infos->{spent_exists
} ?
1 : 0,
158 basketno
=> $order->{basketno
},
162 output_html_with_http_headers
$query, $cookie, $template->output;
164 sub get_default_view
{
165 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
166 my %views = C4
::Search
::enabled_staff_search_views
();
167 if ( $defaultview eq 'isbd' && $views{can_view_ISBD
} ) {
170 elsif ( $defaultview eq 'marc' && $views{can_view_MARC
} ) {
173 elsif ( $defaultview eq 'labeled_marc' && $views{can_view_labeledMARC
} ) {
174 return 'labeledMARCdetail';
179 sub get_value_with_gst_params
{
182 my $bookseller = shift;
183 if ( $bookseller->{listincgst
} ) {
184 return ( $value, $value / ( 1 + $gstrate ) );
186 return ( $value * ( 1 + $gstrate ), $value );
193 my $bookseller = shift;
194 if ( $bookseller->{invoiceincgst
} ) {
195 return $value / ( 1 + $gstrate );
204 my $bookseller = shift;
205 if ( $bookseller->{invoiceincgst
} ) {
206 return $value / ( 1 + $gstrate ) * $gstrate;
208 return $value * ( 1 + $gstrate ) - $value;