Bug 22082: ambiguous column in patron stats
[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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Auth;
24 use C4::Output;
25 use Koha::Database;
26
27 my $input = CGI->new();
28
29 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30     {
31         template_name   => 'admin/edi_ean_accounts.tt',
32         query           => $input,
33         type            => 'intranet',
34         authnotrequired => 0,
35         flagsrequired   => { acquisition => 'edi_manage' },
36     }
37 );
38
39 my $schema = Koha::Database->new()->schema();
40
41 my $id = scalar $input->param('id');
42 my $op = scalar $input->param('op') || 'display';
43
44 if ( $op eq 'ean_form' ) {
45     my $e        = $schema->resultset('EdifactEan')->find($id);
46     my @branches = $schema->resultset('Branch')->search(
47         undef,
48         {
49             columns  => [ 'branchcode', 'branchname' ],
50             order_by => 'branchname',
51         }
52     );
53     $template->param(
54         ean_form => 1,
55         branches => \@branches,
56         ean      => $e,
57     );
58 }
59 elsif ( $op eq 'delete_confirm' ) {
60     my $e = $schema->resultset('EdifactEan')->find($id);
61     $template->param(
62         delete_confirm => 1,
63         ean            => $e,
64     );
65 }
66 else {
67     if ( $op eq 'save' ) {
68         my $change = $id;
69         if ($change) {
70             $schema->resultset('EdifactEan')->find($id)->update(
71                 {
72                     branchcode        => scalar $input->param('branchcode') || undef,
73                     description       => scalar $input->param('description'),
74                     ean               => scalar $input->param('ean'),
75                     id_code_qualifier => scalar $input->param('id_code_qualifier'),
76                 }
77             );
78         }
79         else {
80             my $new_ean = $schema->resultset('EdifactEan')->new(
81                 {
82                     branchcode        => scalar $input->param('branchcode') || undef,
83                     description       => scalar $input->param('description'),
84                     ean               => scalar $input->param('ean'),
85                     id_code_qualifier => scalar $input->param('id_code_qualifier'),
86                 }
87             );
88             $new_ean->insert();
89         }
90     }
91     elsif ( $op eq 'delete_confirmed' ) {
92         my $e = $schema->resultset('EdifactEan')->find($id);
93         $e->delete if $e;
94     }
95     my @eans = $schema->resultset('EdifactEan')->search(
96         {},
97         {
98             join => 'branch',
99         }
100     );
101     $template->param( display => 1 );
102     $template->param( eans    => \@eans );
103 }
104
105 $template->param(
106     code_qualifiers => [
107         {
108             code        => '14',
109             description => 'EAN International',
110         },
111         {
112             code        => '31B',
113             description => 'US SAN Agency',
114         },
115         {
116             code        => '91',
117             description => 'Assigned by supplier',
118         },
119         {
120             code        => '92',
121             description => 'Assigned by buyer',
122         },
123     ]
124 );
125
126 output_html_with_http_headers( $input, $cookie, $template->output );