# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-use strict;
-use warnings;
+use Modern::Perl;
use CGI;
use C4::Auth;
use C4::Output;
);
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(
+ 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(
{},
);
output_html_with_http_headers( $input, $cookie, $template->output );
-
-sub delsubmit {
- my $ean = $schema->resultset('EdifactEan')->find(
- {
- branchcode => $input->param('branchcode'),
- ean => $input->param('ean')
- }
- );
- $ean->delete;
- return;
-}
-
-sub addsubmit {
-
- my $new_ean = $schema->resultset('EdifactEan')->new(
- {
- 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(
- {
- branchcode => $input->param('oldbranchcode'),
- ean => $input->param('oldean'),
- }
- )->update_all(
- {
- branchcode => $input->param('branchcode'),
- ean => $input->param('ean'),
- id_code_qualifier => $input->param('id_code_qualifier'),
- }
- );
- return;
-}
-
-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;
-}