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>.
24 use C4
::Dates qw
/format_date/;
28 use C4
::Search qw
/enabled_staff_search_views/;
30 use Koha
::Acquisition
::Bookseller
;
32 use Date
::Calc qw
/Today Day_of_Year Week_of_Year Add_Delta_Days/;
36 my $op = $query->param('op') || q{};
37 my $issueconfirmed = $query->param('issueconfirmed');
38 my $dbh = C4
::Context
->dbh;
39 my $subscriptionid = $query->param('subscriptionid');
41 if ( $op and $op eq "close" ) {
42 C4
::Serials
::CloseSubscription
( $subscriptionid );
43 } elsif ( $op and $op eq "reopen" ) {
44 C4
::Serials
::ReopenSubscription
( $subscriptionid );
47 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
49 # Permission needed if it is a deletion (del) : delete_subscription
50 # Permission needed otherwise : *
51 my $permission = ($op eq "del") ?
"delete_subscription" : "*";
53 my ($template, $loggedinuser, $cookie)
54 = get_template_and_user
({template_name
=> "serials/subscription-detail.tt",
58 flagsrequired
=> {serials
=> $permission},
63 my $subs = GetSubscription
($subscriptionid);
64 $subs->{enddate
} ||= GetExpirationDate
($subscriptionid);
66 my ($totalissues,@serialslist) = GetSerials
($subscriptionid);
67 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
70 if ($$subs{'cannotedit'}){
71 carp
"Attempt to delete subscription $subscriptionid by ".C4
::Context
->userenv->{'id'}." not allowed";
72 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
76 # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
77 my $strictlyexpired = HasSubscriptionStrictlyExpired
($subscriptionid);
78 my $linkedissues = CountIssues
($subscriptionid);
79 my $countitems = HasItems
($subscriptionid);
80 if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
81 $template->param(NEEDSCONFIRMATION
=> 1);
82 if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
83 if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); }
84 if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); }
86 $issueconfirmed = "1";
88 # If it's ok to delete the subscription, we do so
89 if ($issueconfirmed eq "1") {
90 &DelSubscription
($subscriptionid);
91 print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
95 my $hasRouting = check_routing
($subscriptionid);
97 (undef, $cookie, undef, undef)
98 = checkauth
($query, 0, {catalogue
=> 1}, "intranet");
100 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
102 for my $date ( qw(startdate enddate firstacquidate histstartdate histenddate) ) {
103 $$subs{$date} = format_date
($$subs{$date}) if $date && $$subs{$date};
105 $subs->{location
} = GetKohaAuthorisedValueLib
("LOC",$subs->{location
});
106 $subs->{abouttoexpire
} = abouttoexpire
($subs->{subscriptionid
});
107 $template->param(%{ $subs });
108 $template->param(biblionumber_for_new_subscription
=> $subs->{bibnum
});
109 my @irregular_issues = split /;/, $subs->{irregularity
};
111 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
112 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
114 my $default_bib_view = get_default_view
();
116 my ( $order, $bookseller, $tmpl_infos );
117 if ( defined $subscriptionid ) {
118 my $lastOrderNotReceived = GetLastOrderNotReceivedFromSubscriptionid
$subscriptionid;
119 my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid
$subscriptionid;
120 if ( defined $lastOrderNotReceived ) {
121 my $basket = GetBasket
$lastOrderNotReceived->{basketno
};
122 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $basket->{booksellerid
} });
123 ( $tmpl_infos->{valuegsti_ordered
}, $tmpl_infos->{valuegste_ordered
} ) = get_value_with_gst_params
( $lastOrderNotReceived->{ecost
}, $lastOrderNotReceived->{gstrate
}, $bookseller );
124 $tmpl_infos->{valuegsti_ordered
} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered
} );
125 $tmpl_infos->{valuegste_ordered
} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered
} );
126 $tmpl_infos->{budget_name_ordered
} = GetBudgetName
$lastOrderNotReceived->{budget_id
};
127 $tmpl_infos->{basketno
} = $lastOrderNotReceived->{basketno
};
128 $tmpl_infos->{ordered_exists
} = 1;
130 if ( defined $lastOrderReceived ) {
131 my $basket = GetBasket
$lastOrderReceived->{basketno
};
132 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $basket->{booksellerid
} });
133 ( $tmpl_infos->{valuegsti_spent
}, $tmpl_infos->{valuegste_spent
} ) = get_value_with_gst_params
( $lastOrderReceived->{unitprice
}, $lastOrderReceived->{gstrate
}, $bookseller );
134 $tmpl_infos->{valuegsti_spent
} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent
} );
135 $tmpl_infos->{valuegste_spent
} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent
} );
136 $tmpl_infos->{budget_name_spent
} = GetBudgetName
$lastOrderReceived->{budget_id
};
137 $tmpl_infos->{invoiceid
} = $lastOrderReceived->{invoiceid
};
138 $tmpl_infos->{spent_exists
} = 1;
142 my $additional_fields = Koha
::AdditionalField
->all( { tablename
=> 'subscription' } );
143 for my $field ( @
$additional_fields ) {
144 if ( $field->{authorised_value_category
} ) {
145 $field->{authorised_value_choices
} = GetAuthorisedValues
( $field->{authorised_value_category
} );
148 $template->param( additional_fields_for_subscription
=> $additional_fields );
151 subscriptionid
=> $subscriptionid,
152 serialslist
=> \
@serialslist,
153 hasRouting
=> $hasRouting,
154 routing
=> C4
::Context
->preference("RoutingSerials"),
155 totalissues
=> $totalissues,
156 cannotedit
=> (not C4
::Serials
::can_edit_subscription
( $subs )),
157 frequency
=> $frequency,
158 numberpattern
=> $numberpattern,
159 has_X
=> ($numberpattern->{'numberingmethod'} =~ /{X}/) ?
1 : 0,
160 has_Y
=> ($numberpattern->{'numberingmethod'} =~ /{Y}/) ?
1 : 0,
161 has_Z
=> ($numberpattern->{'numberingmethod'} =~ /{Z}/) ?
1 : 0,
162 intranetstylesheet
=> C4
::Context
->preference('intranetstylesheet'),
163 intranetcolorstylesheet
=> C4
::Context
->preference('intranetcolorstylesheet'),
164 irregular_issues
=> scalar @irregular_issues,
165 default_bib_view
=> $default_bib_view,
166 (uc(C4
::Context
->preference("marcflavour"))) => 1,
167 show_acquisition_details
=> defined $tmpl_infos->{ordered_exists
} || defined $tmpl_infos->{spent_exists
} ?
1 : 0,
168 basketno
=> $order->{basketno
},
172 output_html_with_http_headers
$query, $cookie, $template->output;
174 sub get_default_view
{
175 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
176 my %views = C4
::Search
::enabled_staff_search_views
();
177 if ( $defaultview eq 'isbd' && $views{can_view_ISBD
} ) {
180 elsif ( $defaultview eq 'marc' && $views{can_view_MARC
} ) {
183 elsif ( $defaultview eq 'labeled_marc' && $views{can_view_labeledMARC
} ) {
184 return 'labeledMARCdetail';
189 sub get_value_with_gst_params
{
192 my $bookseller = shift;
193 if ( $bookseller->{listincgst
} ) {
194 return ( $value, $value / ( 1 + $gstrate ) );
196 return ( $value * ( 1 + $gstrate ), $value );
203 my $bookseller = shift;
204 if ( $bookseller->{invoiceincgst
} ) {
205 return $value / ( 1 + $gstrate );
214 my $bookseller = shift;
215 if ( $bookseller->{invoiceincgst
} ) {
216 return $value / ( 1 + $gstrate ) * $gstrate;
218 return $value * ( 1 + $gstrate ) - $value;