3 # Copyright 2020 Koha Development Team
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use Koha
::Account
::CreditType
;
29 use Koha
::Account
::CreditTypes
;
32 my $code = $input->param('code');
33 my $op = $input->param('op') || 'list';
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
38 template_name
=> "admin/credit_types.tt",
41 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
48 $credit_type = Koha
::Account
::CreditTypes
->find($code);
51 if ( $op eq 'add_form' ) {
53 my $selected_branches =
54 $credit_type ?
$credit_type->get_library_limits : undef;
56 Koha
::Libraries
->search( {}, { order_by
=> ['branchname'] } )->unblessed;
58 foreach my $branch (@
$branches) {
61 && grep { $_->branchcode eq $branch->{branchcode
} }
62 @
{ $selected_branches->as_list } ) ?
1 : 0;
65 branchcode
=> $branch->{branchcode
},
66 branchname
=> $branch->{branchname
},
67 selected
=> $selected,
72 credit_type
=> $credit_type,
73 branches_loop
=> \
@branches_loop
76 elsif ( $op eq 'add_validate' ) {
77 my $description = $input->param('description');
78 my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
79 my $credit_number_enabled = $input->param('credit_number_enabled') || 0;
80 my @branches = grep { $_ ne q{} } $input->multi_param('branches');
82 if ( not defined $credit_type ) {
83 $credit_type = Koha
::Account
::CreditType
->new( { code
=> $code } );
85 unless ($credit_type->is_system) {
86 $credit_type->description($description);
87 $credit_type->can_be_added_manually($can_be_added_manually);
89 $credit_type->credit_number_enabled($credit_number_enabled);
93 unless ($credit_type->is_system) {
94 $credit_type->replace_library_limits( \
@branches );
96 push @messages, { type
=> 'message', code
=> 'success_on_saving' };
99 push @messages, { type
=> 'error', code
=> 'error_on_saving' };
103 elsif ( $op eq 'archive' ) {
105 $credit_type->archived(1)->store();
106 push @messages, { code
=> 'success_on_archive', type
=> 'message' };
109 push @messages, { code
=> 'error_on_archive', type
=> 'alert' };
114 elsif ( $op eq 'unarchive' ) {
116 $credit_type->archived(0)->store();
117 push @messages, { code
=> 'success_on_restore', type
=> 'message' };
120 push @messages, { code
=> 'error_on_restore', type
=> 'alert' };
125 if ( $op eq 'list' ) {
126 my $credit_types = Koha
::Account
::CreditTypes
->search();
127 $template->param( credit_types
=> $credit_types, );
132 messages
=> \
@messages,
136 output_html_with_http_headers
$input, $cookie, $template->output;