Bug 25729: Prevent Charges/Fees.t to fail on slow server
[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 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         flagsrequired   => { acquisition => 'edi_manage' },
34     }
35 );
36
37 my $schema = Koha::Database->new()->schema();
38
39 my $id = scalar $input->param('id');
40 my $op = scalar $input->param('op') || 'display';
41
42 if ( $op eq 'ean_form' ) {
43     my $e        = $schema->resultset('EdifactEan')->find($id);
44     my @branches = $schema->resultset('Branch')->search(
45         undef,
46         {
47             columns  => [ 'branchcode', 'branchname' ],
48             order_by => 'branchname',
49         }
50     );
51     $template->param(
52         ean_form => 1,
53         branches => \@branches,
54         ean      => $e,
55     );
56 }
57 elsif ( $op eq 'delete_confirm' ) {
58     my $e = $schema->resultset('EdifactEan')->find($id);
59     $template->param(
60         delete_confirm => 1,
61         ean            => $e,
62     );
63 }
64 else {
65     if ( $op eq 'save' ) {
66         my $change = $id;
67         if ($change) {
68             $schema->resultset('EdifactEan')->find($id)->update(
69                 {
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'),
74                 }
75             );
76         }
77         else {
78             my $new_ean = $schema->resultset('EdifactEan')->new(
79                 {
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'),
84                 }
85             );
86             $new_ean->insert();
87         }
88     }
89     elsif ( $op eq 'delete_confirmed' ) {
90         my $e = $schema->resultset('EdifactEan')->find($id);
91         $e->delete if $e;
92     }
93     my @eans = $schema->resultset('EdifactEan')->search(
94         {},
95         {
96             join => 'branch',
97         }
98     );
99     $template->param( display => 1 );
100     $template->param( eans    => \@eans );
101 }
102
103 $template->param(
104     code_qualifiers => [
105         {
106             code        => '14',
107             description => 'EAN International',
108         },
109         {
110             code        => '31B',
111             description => 'US SAN Agency',
112         },
113         {
114             code        => '91',
115             description => 'Assigned by supplier',
116         },
117         {
118             code        => '92',
119             description => 'Assigned by buyer',
120         },
121     ]
122 );
123
124 output_html_with_http_headers( $input, $cookie, $template->output );