Bug 26604: "Generate next" button gives error on serials-collection.pl
[koha.git] / admin / edi_ean_accounts.pl
bloba7edcf25f20dc95d160e52cf82f26f8d684a2aeb
1 #!/usr/bin/perl
3 # Copyright 2012, 2014 Mark Gavillet & PTFS Europe Ltd
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>.
20 use Modern::Perl;
21 use CGI;
22 use C4::Auth;
23 use C4::Output;
24 use Koha::Database;
26 my $input = CGI->new();
28 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30 template_name => 'admin/edi_ean_accounts.tt',
31 query => $input,
32 type => 'intranet',
33 flagsrequired => { acquisition => 'edi_manage' },
37 my $schema = Koha::Database->new()->schema();
39 my $id = scalar $input->param('id');
40 my $op = scalar $input->param('op') || 'display';
42 if ( $op eq 'ean_form' ) {
43 my $e = $schema->resultset('EdifactEan')->find($id);
44 my @branches = $schema->resultset('Branch')->search(
45 undef,
47 columns => [ 'branchcode', 'branchname' ],
48 order_by => 'branchname',
51 $template->param(
52 ean_form => 1,
53 branches => \@branches,
54 ean => $e,
57 elsif ( $op eq 'delete_confirm' ) {
58 my $e = $schema->resultset('EdifactEan')->find($id);
59 $template->param(
60 delete_confirm => 1,
61 ean => $e,
64 else {
65 if ( $op eq 'save' ) {
66 my $change = $id;
67 if ($change) {
68 $schema->resultset('EdifactEan')->find($id)->update(
70 branchcode => scalar $input->param('branchcode') || undef,
71 description => scalar $input->param('description'),
72 ean => scalar $input->param('ean'),
73 id_code_qualifier => scalar $input->param('id_code_qualifier'),
77 else {
78 my $new_ean = $schema->resultset('EdifactEan')->new(
80 branchcode => scalar $input->param('branchcode') || undef,
81 description => scalar $input->param('description'),
82 ean => scalar $input->param('ean'),
83 id_code_qualifier => scalar $input->param('id_code_qualifier'),
86 $new_ean->insert();
89 elsif ( $op eq 'delete_confirmed' ) {
90 my $e = $schema->resultset('EdifactEan')->find($id);
91 $e->delete if $e;
93 my @eans = $schema->resultset('EdifactEan')->search(
94 {},
96 join => 'branch',
99 $template->param( display => 1 );
100 $template->param( eans => \@eans );
103 $template->param(
104 code_qualifiers => [
106 code => '14',
107 description => 'EAN International',
110 code => '31B',
111 description => 'US SAN Agency',
114 code => '91',
115 description => 'Assigned by supplier',
118 code => '92',
119 description => 'Assigned by buyer',
124 output_html_with_http_headers( $input, $cookie, $template->output );