3 # Copyright 2017 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use Koha
::Subscriptions
;
27 use Koha
::Acquisition
::Booksellers
;
28 use Koha
::AdditionalField
;
33 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
34 template_name
=> 'serials/subscription-batchedit.tt',
38 flagsrequired
=> {serials
=> 'edit_subscription'},
41 my @subscriptionids = $cgi->multi_param('subscriptionid');
44 foreach my $subscriptionid (@subscriptionids) {
45 my $subscription = Koha
::Subscriptions
->find($subscriptionid);
47 push @subscriptions, $subscription if $subscription;
50 my $additional_fields = Koha
::AdditionalField
->all({tablename
=> 'subscription'});
52 my $batchedit = $cgi->param('batchedit');
55 aqbooksellerid
=> scalar $cgi->param('booksellerid'),
56 location
=> scalar $cgi->param('location'),
57 branchcode
=> scalar $cgi->param('branchcode'),
58 itemtype
=> scalar $cgi->param('itemtype'),
59 notes
=> scalar $cgi->param('notes'),
60 internalnotes
=> scalar $cgi->param('internalnotes'),
61 serialsadditems
=> scalar $cgi->param('serialsadditems'),
62 enddate
=> dt_from_string
(scalar $cgi->param('enddate')),
65 my $field_values = {};
66 foreach my $field (@
$additional_fields) {
67 my $value = $cgi->param('field_' . $field->{id
});
68 $field_values->{$field->{id
}} = $value;
71 foreach my $subscription (@subscriptions) {
72 next unless C4
::Serials
::can_edit_subscription
( $subscription->unblessed ); # This should be moved to Koha::Subscription->can_edit
73 while (my ($key, $value) = each %params) {
74 if (defined $value and $value ne '') {
75 $subscription->$key($value);
79 foreach my $field (@
$additional_fields) {
80 my $value = $field_values->{$field->{id
}};
81 if (defined $value and $value ne '') {
82 $field->{values} //= {};
83 $field->{values}->{$subscription->subscriptionid} = $value;
90 foreach my $field (@
$additional_fields) {
91 if (defined $field->{values}) {
92 $field->insert_values();
96 my $redirect_url = $cgi->param('referrer') // '/cgi-bin/koha/serials/serials-home.pl';
97 print $cgi->redirect($redirect_url);
102 subscriptions
=> \
@subscriptions,
103 booksellers
=> [ Koha
::Acquisition
::Booksellers
->search() ],
104 additional_fields
=> $additional_fields,
105 referrer
=> scalar $cgi->param('referrer'),
108 output_html_with_http_headers
$cgi, $cookie, $template->output;