Bug 7736: Support Ordering via Edifact EDI messages
[koha.git] / admin / edi_ean_accounts.pl
blob35d90c01dfededee9b827d2027100a87d8acb34d
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 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.
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.
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.
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Auth;
24 use C4::Output;
25 use Koha::Database;
27 my $input = CGI->new();
29 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31 template_name => 'admin/edi_ean_accounts.tt',
32 query => $input,
33 type => 'intranet',
34 authnotrequired => 0,
35 flagsrequired => { acquisition => 'edi_manage' },
39 my $schema = Koha::Database->new()->schema();
40 my $op = $input->param('op');
41 $op ||= 'display';
43 if ( $op eq 'ean_form' ) {
44 show_ean();
45 $template->param( ean_form => 1 );
46 my @branches = $schema->resultset('Branch')->search(
47 undef,
49 columns => [ 'branchcode', 'branchname' ],
50 order_by => 'branchname',
53 $template->param( branches => \@branches );
54 $template->param(
55 code_qualifiers => [
57 code => '14',
58 description => 'EAN International',
61 code => '31B',
62 description => 'US SAN Agency',
65 code => '91',
66 description => 'Assigned by supplier',
69 code => '92',
70 description => 'Assigned by buyer',
76 elsif ( $op eq 'delete_confirm' ) {
77 show_ean();
78 $template->param( delete_confirm => 1 );
80 else {
81 if ( $op eq 'save' ) {
82 my $change = $input->param('oldean');
83 if ($change) {
84 editsubmit();
86 else {
87 addsubmit();
90 elsif ( $op eq 'delete_confirmed' ) {
91 delsubmit();
93 my @eans = $schema->resultset('EdifactEan')->search(
94 {},
96 join => 'branch',
99 $template->param( display => 1 );
100 $template->param( eans => \@eans );
103 output_html_with_http_headers( $input, $cookie, $template->output );
105 sub delsubmit {
106 my $ean = $schema->resultset('EdifactEan')->find(
108 branchcode => $input->param('branchcode'),
109 ean => $input->param('ean')
112 $ean->delete;
113 return;
116 sub addsubmit {
118 my $new_ean = $schema->resultset('EdifactEan')->new(
120 branchcode => $input->param('branchcode'),
121 ean => $input->param('ean'),
122 id_code_qualifier => $input->param('id_code_qualifier'),
125 $new_ean->insert();
126 return;
129 sub editsubmit {
130 $schema->resultset('EdifactEan')->search(
132 branchcode => $input->param('oldbranchcode'),
133 ean => $input->param('oldean'),
135 )->update_all(
137 branchcode => $input->param('branchcode'),
138 ean => $input->param('ean'),
139 id_code_qualifier => $input->param('id_code_qualifier'),
142 return;
145 sub show_ean {
146 my $branchcode = $input->param('branchcode');
147 my $ean = $input->param('ean');
148 if ( $branchcode && $ean ) {
149 my $e = $schema->resultset('EdifactEan')->find(
151 ean => $ean,
152 branchcode => $branchcode,
155 $template->param( ean => $e );
157 return;