#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
-use strict;
-use warnings;
+use Modern::Perl;
use CGI;
use C4::Auth;
use C4::Output;
template_name => 'admin/edi_ean_accounts.tt',
query => $input,
type => 'intranet',
- authnotrequired => 0,
flagsrequired => { acquisition => 'edi_manage' },
}
);
my $schema = Koha::Database->new()->schema();
-my $op = $input->param('op');
-$op ||= 'display';
+
+my $id = scalar $input->param('id');
+my $op = scalar $input->param('op') || 'display';
if ( $op eq 'ean_form' ) {
- show_ean();
- $template->param( ean_form => 1 );
+ my $e = $schema->resultset('EdifactEan')->find($id);
my @branches = $schema->resultset('Branch')->search(
undef,
{
order_by => 'branchname',
}
);
- $template->param( branches => \@branches );
$template->param(
- code_qualifiers => [
- {
- code => '14',
- description => 'EAN International',
- },
- {
- code => '31B',
- description => 'US SAN Agency',
- },
- {
- code => '91',
- description => 'Assigned by supplier',
- },
- {
- code => '92',
- description => 'Assigned by buyer',
- },
- ]
+ ean_form => 1,
+ branches => \@branches,
+ ean => $e,
);
-
}
elsif ( $op eq 'delete_confirm' ) {
- show_ean();
- $template->param( delete_confirm => 1 );
+ my $e = $schema->resultset('EdifactEan')->find($id);
+ $template->param(
+ delete_confirm => 1,
+ ean => $e,
+ );
}
else {
if ( $op eq 'save' ) {
- my $change = $input->param('oldean');
+ my $change = $id;
if ($change) {
- editsubmit();
+ $schema->resultset('EdifactEan')->find($id)->update(
+ {
+ branchcode => scalar $input->param('branchcode') || undef,
+ description => scalar $input->param('description'),
+ ean => scalar $input->param('ean'),
+ id_code_qualifier => scalar $input->param('id_code_qualifier'),
+ }
+ );
}
else {
- addsubmit();
+ my $new_ean = $schema->resultset('EdifactEan')->new(
+ {
+ branchcode => scalar $input->param('branchcode') || undef,
+ description => scalar $input->param('description'),
+ ean => scalar $input->param('ean'),
+ id_code_qualifier => scalar $input->param('id_code_qualifier'),
+ }
+ );
+ $new_ean->insert();
}
}
elsif ( $op eq 'delete_confirmed' ) {
- delsubmit();
+ my $e = $schema->resultset('EdifactEan')->find($id);
+ $e->delete if $e;
}
my @eans = $schema->resultset('EdifactEan')->search(
{},
$template->param( eans => \@eans );
}
-output_html_with_http_headers( $input, $cookie, $template->output );
-
-sub delsubmit {
- my $ean = $schema->resultset('EdifactEan')->find(
+$template->param(
+ code_qualifiers => [
{
- branchcode => $input->param('branchcode'),
- ean => $input->param('ean')
- }
- );
- $ean->delete;
- return;
-}
-
-sub addsubmit {
-
- my $new_ean = $schema->resultset('EdifactEan')->new(
+ code => '14',
+ description => 'EAN International',
+ },
{
- branchcode => $input->param('branchcode'),
- ean => $input->param('ean'),
- id_code_qualifier => $input->param('id_code_qualifier'),
- }
- );
- $new_ean->insert();
- return;
-}
-
-sub editsubmit {
- $schema->resultset('EdifactEan')->search(
+ code => '31B',
+ description => 'US SAN Agency',
+ },
{
- branchcode => $input->param('oldbranchcode'),
- ean => $input->param('oldean'),
- }
- )->update_all(
+ code => '91',
+ description => 'Assigned by supplier',
+ },
{
- branchcode => $input->param('branchcode'),
- ean => $input->param('ean'),
- id_code_qualifier => $input->param('id_code_qualifier'),
- }
- );
- return;
-}
+ code => '92',
+ description => 'Assigned by buyer',
+ },
+ ]
+);
-sub show_ean {
- my $branchcode = $input->param('branchcode');
- my $ean = $input->param('ean');
- if ( $branchcode && $ean ) {
- my $e = $schema->resultset('EdifactEan')->find(
- {
- ean => $ean,
- branchcode => $branchcode,
- }
- );
- $template->param( ean => $e );
- }
- return;
-}
+output_html_with_http_headers( $input, $cookie, $template->output );