Bug 24545: Fix license statements
[koha.git] / admin / edi_ean_accounts.pl
1 #!/usr/bin/perl
2
3 # Copyright 2012, 2014 Mark Gavillet & PTFS Europe Ltd
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21 use CGI;
22 use C4::Auth;
23 use C4::Output;
24 use Koha::Database;
25
26 my $input = CGI->new();
27
28 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29     {
30         template_name   => 'admin/edi_ean_accounts.tt',
31         query           => $input,
32         type            => 'intranet',
33         authnotrequired => 0,
34         flagsrequired   => { acquisition => 'edi_manage' },
35     }
36 );
37
38 my $schema = Koha::Database->new()->schema();
39
40 my $id = scalar $input->param('id');
41 my $op = scalar $input->param('op') || 'display';
42
43 if ( $op eq 'ean_form' ) {
44     my $e        = $schema->resultset('EdifactEan')->find($id);
45     my @branches = $schema->resultset('Branch')->search(
46         undef,
47         {
48             columns  => [ 'branchcode', 'branchname' ],
49             order_by => 'branchname',
50         }
51     );
52     $template->param(
53         ean_form => 1,
54         branches => \@branches,
55         ean      => $e,
56     );
57 }
58 elsif ( $op eq 'delete_confirm' ) {
59     my $e = $schema->resultset('EdifactEan')->find($id);
60     $template->param(
61         delete_confirm => 1,
62         ean            => $e,
63     );
64 }
65 else {
66     if ( $op eq 'save' ) {
67         my $change = $id;
68         if ($change) {
69             $schema->resultset('EdifactEan')->find($id)->update(
70                 {
71                     branchcode        => scalar $input->param('branchcode') || undef,
72                     description       => scalar $input->param('description'),
73                     ean               => scalar $input->param('ean'),
74                     id_code_qualifier => scalar $input->param('id_code_qualifier'),
75                 }
76             );
77         }
78         else {
79             my $new_ean = $schema->resultset('EdifactEan')->new(
80                 {
81                     branchcode        => scalar $input->param('branchcode') || undef,
82                     description       => scalar $input->param('description'),
83                     ean               => scalar $input->param('ean'),
84                     id_code_qualifier => scalar $input->param('id_code_qualifier'),
85                 }
86             );
87             $new_ean->insert();
88         }
89     }
90     elsif ( $op eq 'delete_confirmed' ) {
91         my $e = $schema->resultset('EdifactEan')->find($id);
92         $e->delete if $e;
93     }
94     my @eans = $schema->resultset('EdifactEan')->search(
95         {},
96         {
97             join => 'branch',
98         }
99     );
100     $template->param( display => 1 );
101     $template->param( eans    => \@eans );
102 }
103
104 $template->param(
105     code_qualifiers => [
106         {
107             code        => '14',
108             description => 'EAN International',
109         },
110         {
111             code        => '31B',
112             description => 'US SAN Agency',
113         },
114         {
115             code        => '91',
116             description => 'Assigned by supplier',
117         },
118         {
119             code        => '92',
120             description => 'Assigned by buyer',
121         },
122     ]
123 );
124
125 output_html_with_http_headers( $input, $cookie, $template->output );