use Modern::Perl;
use CGI qw ( -utf8 );
+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::DebitType;
use Koha::Account::DebitTypes;
-my $input = new CGI;
+my $input = CGI->new;
my $code = $input->param('code');
my $op = $input->param('op') || 'list';
my @messages;
template_name => "admin/debit_types.tt",
query => $input,
type => "intranet",
- authnotrequired => 0,
- flagsrequired => { parameters => 'parameters_remaining_permissions' },
- debug => 1,
+ flagsrequired => { parameters => 'manage_accounts' },
}
);
}
elsif ( $op eq 'add_validate' ) {
my $description = $input->param('description');
- my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
+ my $can_be_invoiced = $input->param('can_be_invoiced') || 0;
+ my $can_be_sold = $input->param('can_be_sold') || 0;
my $default_amount = $input->param('default_amount') || undef;
my @branches = grep { $_ ne q{} } $input->multi_param('branches');
$debit_type = Koha::Account::DebitType->new( { code => $code } );
}
$debit_type->description($description);
- $debit_type->can_be_added_manually($can_be_added_manually);
+ $debit_type->can_be_invoiced($can_be_invoiced);
+ $debit_type->can_be_sold($can_be_sold);
$debit_type->default_amount($default_amount);
- eval {
+ try {
$debit_type->store;
$debit_type->replace_library_limits( \@branches );
- };
- if ($@) {
- push @messages, { type => 'error', code => 'error_on_saving' };
- }
- else {
push @messages, { type => 'message', code => 'success_on_saving' };
}
+ catch {
+ push @messages, { type => 'error', code => 'error_on_saving' };
+ };
$op = 'list';
}
-elsif ( $op eq 'delete_confirm' ) {
- $template->param( debit_type => $debit_type );
-}
-elsif ( $op eq 'delete_confirmed' ) {
- my $deleted = eval { $debit_type->delete; };
-
- if ( $@ or not $deleted ) {
- push @messages, { type => 'error', code => 'error_on_delete' };
+elsif ( $op eq 'archive' ) {
+ try {
+ $debit_type->archived(1)->store();
+ push @messages, { code => 'success_on_archive', type => 'message' };
}
- else {
- push @messages, { type => 'message', code => 'success_on_delete' };
+ catch {
+ push @messages, { code => 'error_on_archive', type => 'alert' };
+
+ };
+ $op = 'list';
+}
+elsif ( $op eq 'unarchive' ) {
+ try {
+ $debit_type->archived(0)->store();
+ push @messages, { code => 'success_on_restore', type => 'message' };
}
+ catch {
+ push @messages, { code => 'error_on_restore', type => 'alert' };
+ };
$op = 'list';
}
if ( $op eq 'list' ) {
my $debit_types = Koha::Account::DebitTypes->search();
- $template->param( debit_types => $debit_types );
+ $template->param( debit_types => $debit_types, );
}
$template->param(