Bug 7736 [QA Followup] - Fix column headers, values and spelling
[koha.git] / admin / edi_accounts.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011,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_accounts.tt',
32         query           => $input,
33         type            => 'intranet',
34         authnotrequired => 0,
35         flagsrequired   => { acquisition => 'edi_manage' },
36     }
37 );
38
39 my $op = $input->param('op');
40 $op ||= 'display';
41 my $schema = Koha::Database->new()->schema();
42
43 if ( $op eq 'acct_form' ) {
44     show_account();
45     $template->param( acct_form => 1 );
46     my @vendors = $schema->resultset('Aqbookseller')->search(
47         undef,
48         {
49             columns => [ 'name', 'id' ],
50             order_by => { -asc => 'name' }
51         }
52     );
53     $template->param( vendors => \@vendors );
54 }
55 elsif ( $op eq 'delete_confirm' ) {
56     show_account();
57     $template->param( delete_confirm => 1 );
58 }
59 else {
60     if ( $op eq 'save' ) {
61
62         # validate & display
63         my $id     = $input->param('id');
64         my $fields = {
65             description        => $input->param('description'),
66             host               => $input->param('host'),
67             username           => $input->param('username'),
68             password           => $input->param('password'),
69             vendor_id          => $input->param('vendor_id'),
70             upload_directory   => $input->param('upload_directory'),
71             download_directory => $input->param('download_directory'),
72             san                => $input->param('san'),
73             transport          => $input->param('transport'),
74             quotes_enabled     => defined $input->param('quotes_enabled'),
75             invoices_enabled   => defined $input->param('invoices_enabled'),
76             orders_enabled     => defined $input->param('orders_enabled'),
77             responses_enabled  => defined $input->param('responses_enabled'),
78             auto_orders        => defined $input->param('auto_orders'),
79             id_code_qualifier  => $input->param('id_code_qualifier'),
80         };
81
82         if ($id) {
83             $schema->resultset('VendorEdiAccount')->search(
84                 {
85                     id => $id,
86                 }
87             )->update_all($fields);
88         }
89         else {    # new record
90             $schema->resultset('VendorEdiAccount')->create($fields);
91         }
92     }
93     elsif ( $op eq 'delete_confirmed' ) {
94
95         $schema->resultset('VendorEdiAccount')
96           ->search( { id => $input->param('id'), } )->delete_all;
97     }
98
99     # we do a default dispaly after deletes and saves
100     # as well as when thats all you want
101     $template->param( display => 1 );
102     my @ediaccounts = $schema->resultset('VendorEdiAccount')->search(
103         {},
104         {
105             join => 'vendor',
106         }
107     );
108     $template->param( ediaccounts => \@ediaccounts );
109 }
110
111 $template->param(
112     code_qualifiers => [
113         {
114             code        => '14',
115             description => 'EAN International',
116         },
117         {
118             code        => '31B',
119             description => 'US SAN Agency',
120         },
121         {
122             code        => '91',
123             description => 'Assigned by supplier',
124         },
125         {
126             code        => '92',
127             description => 'Assigned by buyer',
128         },
129     ]
130 );
131
132 output_html_with_http_headers( $input, $cookie, $template->output );
133
134 sub get_account {
135     my $id = shift;
136
137     my $account = $schema->resultset('VendorEdiAccount')->find($id);
138     if ($account) {
139         return $account;
140     }
141
142     # passing undef will default to add
143     return;
144 }
145
146 sub show_account {
147     my $acct_id = $input->param('id');
148     if ($acct_id) {
149         my $acct = $schema->resultset('VendorEdiAccount')->find($acct_id);
150         if ($acct) {
151             $template->param( account => $acct );
152         }
153     }
154     return;
155 }