Bug 29144: Adjust libraries form
[koha-ffzg.git] / admin / credit_types.pl
index 75baff9..27f6edf 100755 (executable)
 
 use Modern::Perl;
 use CGI qw ( -utf8 );
-use Try::Tiny;
+use Try::Tiny qw( catch try );
 
 use C4::Context;
-use C4::Auth;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
 
 use Koha::Account::CreditType;
 use Koha::Account::CreditTypes;
 
-my $input = new CGI;
+my $input = CGI->new;
 my $code  = $input->param('code');
 my $op    = $input->param('op') || 'list';
 my @messages;
@@ -38,9 +38,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         template_name   => "admin/credit_types.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
-        debug           => 1,
+        flagsrequired   => { parameters => 'manage_accounts' },
     }
 );
 
@@ -77,17 +75,23 @@ if ( $op eq 'add_form' ) {
 elsif ( $op eq 'add_validate' ) {
     my $description           = $input->param('description');
     my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
+    my $credit_number_enabled = $input->param('credit_number_enabled') || 0;
     my @branches = grep { $_ ne q{} } $input->multi_param('branches');
 
     if ( not defined $credit_type ) {
         $credit_type = Koha::Account::CreditType->new( { code => $code } );
     }
-    $credit_type->description($description);
-    $credit_type->can_be_added_manually($can_be_added_manually);
+    unless ($credit_type->is_system) {
+        $credit_type->description($description);
+        $credit_type->can_be_added_manually($can_be_added_manually);
+    }
+    $credit_type->credit_number_enabled($credit_number_enabled);
 
     try {
         $credit_type->store;
-        $credit_type->replace_library_limits( \@branches );
+        unless ($credit_type->is_system) {
+            $credit_type->replace_library_limits( \@branches );
+        }
         push @messages, { type => 'message', code => 'success_on_saving' };
     }
     catch {