Bug 39177: Add additional fields to credit types
Test plan, k-t-d: 1) Before defining any additional fields for account_credit_types, confirm that the 'Additional fields' section does not appear when attempting to add a new or edit an existing credit type. 2) Add a new additional field to 'account_credit_types': <staff_url>/cgi-bin/koha/admin/additional-fields.pl?tablename=account_credit_types 3) Click 'New field'. Add a name. Click Save. 4) Repeat step 2 but repeatable. Repeat again for 2 more of AV category (one repeatable, one not repeatable) 5) Edit an account credit type: <staff_url>/cgi-bin/koha/admin/credit_types.pl?op=add_form&code=MANUAL 6) Input various values in the different additional fields. Click 'Submit' 7) Edit the same credit type again and note the additional fields added in the previous step are visible <staff_url>/cgi-bin/koha/admin/credit_types.pl?op=add_form&code=MANUAL Sponsored-by: PTFS Europe <https://ptfs-europe.com> Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk> Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
bfd333133e
commit
ad85f9f20e
|
|
@ -22,7 +22,7 @@ use Modern::Perl;
|
|||
use Koha::Database;
|
||||
use Koha::Exceptions;
|
||||
|
||||
use base qw(Koha::Object Koha::Object::Limit::Library);
|
||||
use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object Koha::Object::Limit::Library);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use Modern::Perl;
|
|||
use Koha::Database;
|
||||
use Koha::Account::CreditType;
|
||||
|
||||
use base qw(Koha::Objects Koha::Objects::Limit::Library);
|
||||
use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects Koha::Objects::Limit::Library);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use C4::Output qw( output_html_with_http_headers );
|
|||
|
||||
use Koha::Account::CreditType;
|
||||
use Koha::Account::CreditTypes;
|
||||
use Koha::AdditionalFields;
|
||||
|
||||
my $input = CGI->new;
|
||||
my $code = $input->param('code');
|
||||
|
|
@ -42,6 +43,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
|||
}
|
||||
);
|
||||
|
||||
my @additional_fields = Koha::AdditionalFields->search( { tablename => 'account_credit_types' } )->as_list;
|
||||
$template->param( additional_fields => \@additional_fields, );
|
||||
|
||||
my $credit_type;
|
||||
if ($code) {
|
||||
$credit_type = Koha::Account::CreditTypes->find($code);
|
||||
|
|
@ -66,9 +70,12 @@ if ( $op eq 'add_form' ) {
|
|||
};
|
||||
}
|
||||
|
||||
my @additional_field_values = $credit_type ? $credit_type->get_additional_field_values_for_template : ();
|
||||
|
||||
$template->param(
|
||||
credit_type => $credit_type,
|
||||
branches_loop => \@branches_loop
|
||||
credit_type => $credit_type,
|
||||
branches_loop => \@branches_loop,
|
||||
additional_field_values => @additional_field_values,
|
||||
);
|
||||
} elsif ( $op eq 'cud-add_validate' ) {
|
||||
my $description = $input->param('description');
|
||||
|
|
@ -90,6 +97,10 @@ if ( $op eq 'add_form' ) {
|
|||
unless ( $credit_type->is_system ) {
|
||||
$credit_type->replace_library_limits( \@branches );
|
||||
}
|
||||
|
||||
my @additional_fields = $credit_type->prepare_cgi_additional_field_values( $input, 'account_credit_types' );
|
||||
$credit_type->set_additional_fields( \@additional_fields );
|
||||
|
||||
push @messages, { type => 'message', code => 'success_on_saving' };
|
||||
} catch {
|
||||
push @messages, { type => 'error', code => 'error_on_saving' };
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@
|
|||
[% WRAPPER table_option value="accountlines:debit" %]Account lines (debit)[% END %]
|
||||
[% END %]
|
||||
[% IF ( CAN_user_parameters_manage_accounts ) %]
|
||||
[% WRAPPER table_option value="account_credit_types" %]Account credit types[% END %]
|
||||
[% WRAPPER table_option value="account_debit_types" %]Account debit types[% END %]
|
||||
[% END %]
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -143,7 +143,9 @@
|
|||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
|
||||
[% IF additional_fields.size %]
|
||||
[% INCLUDE 'additional-fields-entry.inc' available=additional_fields values=additional_field_values wrap_fieldset=1 %]
|
||||
[% END %]
|
||||
<fieldset class="action">
|
||||
<button id="save_credit_type" class="btn btn-primary">Save</button>
|
||||
<a class="cancel" href="/cgi-bin/koha/admin/credit_types.pl">Cancel</a>
|
||||
|
|
@ -165,6 +167,9 @@
|
|||
<th>System</th>
|
||||
<th>Code</th>
|
||||
<th>Description</th>
|
||||
[% IF additional_fields.size %]
|
||||
<th>Additional fields</th>
|
||||
[% END %]
|
||||
<th>Available for</th>
|
||||
<th>Credit number enabled</th>
|
||||
<th>Library limitations</th>
|
||||
|
|
@ -177,6 +182,17 @@
|
|||
<td>[% credit_type.is_system | html %]</td>
|
||||
<td>[% credit_type.code | html %]</td>
|
||||
<td>[%- PROCESS credit_type_description credit_type = credit_type -%]</td>
|
||||
[% IF additional_fields.size %]
|
||||
<td>
|
||||
[% IF credit_type.additional_field_values.count > 0 %]
|
||||
[% FOREACH additional_field IN credit_type.additional_field_values %]
|
||||
<div><span class="label">[% additional_field.field.name | html %]</span>: [% additional_field.value | html %]</div>
|
||||
[% END %]
|
||||
[% ELSE %]
|
||||
<span>No additional fields</span>
|
||||
[% END %]
|
||||
</td>
|
||||
[% END %]
|
||||
<td>[% IF credit_type.can_be_added_manually %]Manual credit[% END %]</td>
|
||||
<td>[% IF credit_type.credit_number_enabled %]Yes[% ELSE %]No[% END %]</td>
|
||||
<td>
|
||||
|
|
@ -236,6 +252,7 @@
|
|||
|
||||
[% MACRO jsinclude BLOCK %]
|
||||
[% Asset.js("js/admin-menu.js") | $raw %]
|
||||
[% Asset.js("js/additional-fields-entry.js") | $raw %]
|
||||
[% INCLUDE 'datatables.inc' %]
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue