From 5a693fb395ba228b2c95dc94afefcc2cfcfe4b66 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 17 Dec 2024 14:27:42 +0000 Subject: [PATCH] Bug 38457: Add additional fields to debit types Test plan, k-t-d: 1) Before defining any additional fields for account_debit_types, confirm that the 'Additional fields' section does not appear when attempting to add a new or edit an existing debit type. 2) Add a new additional field to 'account_debit_types': /cgi-bin/koha/admin/additional-fields.pl?tablename=account_debit_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 debit type: /cgi-bin/koha/admin/debit_types.pl?op=add_form&code=MANUAL 6) Input various values in the different additional fields. Click 'Submit' 7) Edit the same debit type again and note the additional fields added in the previous step are visible /cgi-bin/koha/admin/debit_types.pl?op=add_form&code=MANUAL Sponsored-by: PTFS Europe --- Koha/Account/DebitType.pm | 2 +- Koha/Account/DebitTypes.pm | 2 +- admin/debit_types.pl | 14 +- .../en/modules/admin/additional-fields.tt | 11 +- .../prog/en/modules/admin/debit_types.tt | 415 +++++++++--------- 5 files changed, 231 insertions(+), 213 deletions(-) diff --git a/Koha/Account/DebitType.pm b/Koha/Account/DebitType.pm index 1d5f7f14189..af04a646229 100644 --- a/Koha/Account/DebitType.pm +++ b/Koha/Account/DebitType.pm @@ -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 diff --git a/Koha/Account/DebitTypes.pm b/Koha/Account/DebitTypes.pm index 3860264d50e..200f990a5f6 100644 --- a/Koha/Account/DebitTypes.pm +++ b/Koha/Account/DebitTypes.pm @@ -22,7 +22,7 @@ use Modern::Perl; use Koha::Database; use Koha::Account::DebitType; -use base qw(Koha::Objects Koha::Objects::Limit::Library); +use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects Koha::Objects::Limit::Library); =head1 NAME diff --git a/admin/debit_types.pl b/admin/debit_types.pl index 9425f5cab83..6b19f3d8c00 100755 --- a/admin/debit_types.pl +++ b/admin/debit_types.pl @@ -27,6 +27,7 @@ use C4::Output qw( output_html_with_http_headers ); use Koha::Account::DebitType; use Koha::Account::DebitTypes; +use Koha::AdditionalFields; my $input = CGI->new; my $code = $input->param('code'); @@ -66,9 +67,14 @@ if ( $op eq 'add_form' ) { }; } + my @additional_fields = Koha::AdditionalFields->search( { tablename => 'account_debit_types' } )->as_list; + my @additional_field_values = $debit_type ? $debit_type->get_additional_field_values_for_template : (); + $template->param( - debit_type => $debit_type, - branches_loop => \@branches_loop + debit_type => $debit_type, + branches_loop => \@branches_loop, + additional_fields => \@additional_fields, + additional_field_values => @additional_field_values, ); } elsif ( $op eq 'cud-add_validate' ) { my $description = $input->param('description'); @@ -90,6 +96,10 @@ if ( $op eq 'add_form' ) { try { $debit_type->store; $debit_type->replace_library_limits( \@branches ); + + my @additional_fields = $debit_type->prepare_cgi_additional_field_values( $input, 'account_debit_types' ); + $debit_type->set_additional_fields( \@additional_fields ); + push @messages, { type => 'message', code => 'success_on_saving' }; } catch { push @messages, { type => 'error', code => 'error_on_saving' }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt index 8b97922eb2a..f7ec537e612 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt @@ -147,11 +147,16 @@ [% WRAPPER table_option value="erm_packages" %]Packages[% END %] [% END %] - [% IF CAN_user_updatecharges_remaining_permissions %] + [% IF CAN_user_updatecharges_remaining_permissions || CAN_user_parameters_manage_accounts %]

Patrons

    - [% WRAPPER table_option value="accountlines:credit" %]Account lines (credit)[% END %] - [% WRAPPER table_option value="accountlines:debit" %]Account lines (debit)[% END %] + [% IF CAN_user_updatecharges_remaining_permissions %] + [% WRAPPER table_option value="accountlines:credit" %]Account lines (credit)[% END %] + [% WRAPPER table_option value="accountlines:debit" %]Account lines (debit)[% END %] + [% END %] + [% IF ( CAN_user_parameters_manage_accounts ) %] + [% WRAPPER table_option value="account_debit_types" %]Account debit types[% END %] + [% END %]
[% END %] [% IF CAN_user_serials_edit_subscription %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt index dbe0198abee..17487e6831f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt @@ -7,20 +7,18 @@ [% SET footerjs = 1 %] [% PROCESS 'accounts.inc' %] [% INCLUDE 'doc-head-open.inc' %] -[% FILTER collapse %] - [% IF op =='add_form' %] - [% IF debit_type.code %] - [% tx("Modify debit type '{debit_type}'", { debit_type = debit_type.code }) | html %] - [% ELSE %] - [% t("New debit type") | html %] - [% END %] - › - [% END %] - [% t("Debit types") | html %] - › [% t("Administration") | html %] › [% t("Koha") | html %] - [% END %] +[% FILTER collapse %] + [% IF op =='add_form' %] + [% IF debit_type.code %] + [% tx("Modify debit type '{debit_type}'", { debit_type = debit_type.code }) | html %] + [% ELSE %] + [% t("New debit type") | html %] + [% END %] › + [% END %] + [% t("Debit types") | html %] › + [% t("Administration") | html %] › + [% t("Koha") | html %] +[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -46,6 +44,7 @@ New debit type [% END %] [% END %] + [% ELSE %] [% WRAPPER breadcrumb_item bc_active= 1 %] Debit types @@ -56,205 +55,209 @@ [% WRAPPER 'main-container.inc' aside='admin-menu' %] - [% FOREACH m IN messages %] -
- [% SWITCH m.code %] - [% CASE 'success_on_saving' %] - Debit type saved successfully. - [% CASE 'error_on_saving' %] - An error occurred when saving this debit type. Check the logs for details. - [% CASE 'success_on_archive' %] - Debit type archived successfully. - [% CASE 'success_on_restore' %] - Debit type restored successfully. - [% CASE %] - [% m.code | html %] - [% END %] -
- [% END %] - - [% IF op == 'add_form' %] - [% IF debit_type %] -

[% tx("Modify debit type '{debit_type}'", { debit_type = debit_type.code }) | html %]

- [% ELSE %] -

New debit type

- [% END %] - -
- [% INCLUDE 'csrf-token.inc' %] - -
-
    -
  1. - - [% IF debit_type %] - [% debit_type.code | html %] - - [% ELSE %] - Required. Maximum length is 64 letters - [% END %] -
  2. -
  3. - - -
  4. -
  5. - - [% IF debit_type && debit_type.is_system %] - [%- PROCESS debit_type_description debit_type = debit_type -%] - [% ELSE %] - Required - [% END %] -
  6. -
  7. - - [% IF debit_type.can_be_invoiced %] - - [% ELSE %] - - [% END %] -
  8. -
  9. - - [% IF debit_type.can_be_sold %] - - [% ELSE %] - - [% END %] -
  10. -
  11. - - [% IF debit_type.restricts_checkouts %] - - [% ELSE %] - - [% END %] -
  12. -
  13. - - -
    Select 'All libraries' if this debit type should be available at all libraries. Otherwise select libraries you want to associate debit type with.
    -
  14. -
-
- -
- - Cancel -
-
- [% END %] + [% FOREACH m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'success_on_saving' %] + Debit type saved successfully. + [% CASE 'error_on_saving' %] + An error occurred when saving this debit type. Check the logs for details. + [% CASE 'success_on_archive' %] + Debit type archived successfully. + [% CASE 'success_on_restore' %] + Debit type restored successfully. + [% CASE %] + [% m.code | html %] + [% END %] +
+ [% END %] - [% IF op == 'list' %] - + [% IF op == 'add_form' %] + [% IF debit_type %] +

[% tx("Modify debit type '{debit_type}'", { debit_type = debit_type.code }) | html %]

+ [% ELSE %] +

New debit type

+ [% END %] -

Debit types

- [% IF debit_types.count %] -
- - - - - - - - - - - - - - [% FOREACH debit_type IN debit_types %] - - - - - - - - - - - + [% END %] + +
Select 'All libraries' if this debit type should be available at all libraries. Otherwise select libraries you want to associate debit type with.
+ + + + [% IF additional_fields.size %] + [% INCLUDE 'additional-fields-entry.inc' available=additional_fields values=additional_field_values wrap_fieldset=1 %] [% END %] - -
ArchivedSystemCodeDescriptionDefault amountAvailable forLibrary limitationsBlocks checkouts?Actions
[% debit_type.archived | html %][% debit_type.is_system | html %][% debit_type.code | html %][%- PROCESS debit_type_description debit_type = debit_type -%][% debit_type.default_amount | $Price %][% IF debit_type.can_be_invoiced && debit_type.can_be_sold %] - Invoicing, Sale - [% ELSIF debit_type.can_be_invoiced %] - Invoicing - [% ELSIF debit_type.can_be_sold %] - Sale +
+ [% INCLUDE 'csrf-token.inc' %] + +
+
    +
  1. + + [% IF debit_type %] + [% debit_type.code | html %] + + [% ELSE %] + Required. Maximum length is 64 letters [% END %] -
- [% IF debit_type.library_limits.count > 0 %] - [% library_limits_str = "" %] - [% FOREACH library IN debit_type.library_limits %] - [%- IF loop.first -%] - [% library_limits_str = library.branchname _ " (" _ library.branchcode _ ")" %] - [% ELSE %] - [% library_limits_str = library_limits_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %] - [% END %] - [% END %] - - [% IF debit_type.library_limits.count > 1 %] - [% debit_type.library_limits.count | html %] library limitations - [% ELSE %] - [% debit_type.library_limits.count | html %] library limitation - [% END %] - + +
  • + + +
  • +
  • + + [% IF debit_type && debit_type.is_system %] + [%- PROCESS debit_type_description debit_type = debit_type -%] + [% ELSE %] + Required + [% END %] +
  • +
  • + + [% IF debit_type.can_be_invoiced %] + [% ELSE %] - No limitation + [% END %] -
  • + +
  • + + [% IF debit_type.can_be_sold %] + + [% ELSE %] + + [% END %] +
  • +
  • + [% IF debit_type.restricts_checkouts %] - Yes + [% ELSE %] - No + [% END %] -
  • - [% IF !debit_type.archived %] - Edit - [% IF !debit_type.is_system %] - - [% INCLUDE 'csrf-token.inc' %] - - - - + +
  • + + - - - - [% END %] -
  • - [% ELSE %] -
    There are no account debit types defined. Create new debit type
    - [% END %] - [% END %] +
    + + Cancel +
    + + [% END %] + + [% IF op == 'list' %] + + +

    Debit types

    + [% IF debit_types.count %] +
    + + + + + + + + + + + + + + [% FOREACH debit_type IN debit_types %] + + + + + + + + + + + + [% END %] + +
    ArchivedSystemCodeDescriptionDefault amountAvailable forLibrary limitationsBlocks checkouts?Actions
    [% debit_type.archived | html %][% debit_type.is_system | html %][% debit_type.code | html %][%- PROCESS debit_type_description debit_type = debit_type -%][% debit_type.default_amount | $Price %][% IF debit_type.can_be_invoiced && debit_type.can_be_sold %] + Invoicing, Sale + [% ELSIF debit_type.can_be_invoiced %] + Invoicing + [% ELSIF debit_type.can_be_sold %] + Sale + [% END %] + + [% IF debit_type.library_limits.count > 0 %] + [% library_limits_str = "" %] + [% FOREACH library IN debit_type.library_limits %] + [%- IF loop.first -%] + [% library_limits_str = library.branchname _ " (" _ library.branchcode _ ")" %] + [% ELSE %] + [% library_limits_str = library_limits_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %] + [% END %] + [% END %] + + [% IF debit_type.library_limits.count > 1 %] + [% debit_type.library_limits.count | html %] library limitations + [% ELSE %] + [% debit_type.library_limits.count | html %] library limitation + [% END %] + [% ELSE %] + No limitation + [% END %] + + [% IF debit_type.restricts_checkouts %] + Yes + [% ELSE %] + No + [% END %] + + [% IF !debit_type.archived %] + Edit + [% IF !debit_type.is_system %] +
    + [% INCLUDE 'csrf-token.inc' %] + + + +
    + [% END %] + [% ELSIF debit_type.archived %] +
    + [% INCLUDE 'csrf-token.inc' %] + + + +
    + [% END %] +
    +
    + [% ELSE %] +
    + There are no account debit types defined. Create new debit type +
    + [% END %] + [% END %] [% END %] [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] + [% Asset.js("js/additional-fields-entry.js") | $raw %] [% INCLUDE 'datatables.inc' %] + [% END %] -- 2.49.0