From f9abf527683a4bd34e57d4e60803527942e2d848 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 | 188 ++++---- .../prog/en/modules/admin/debit_types.tt | 446 +++++++++--------- 5 files changed, 340 insertions(+), 312 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 e75edbe04ce..03f0a8b38d3 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 @@ -5,22 +5,27 @@ [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] -[% FILTER collapse %] - [% SWITCH op %] +<title + >[% FILTER collapse %] + [% SWITCH op %] [% CASE 'add_form' %] [% IF field %] - [% tx("Modify field '{field_name}'", { field_name = field.name }) | html %] › + [% tx("Modify field '{field_name}'", { field_name = field.name }) | html %] + › [% ELSE %] - [% t("New field") | html %] › + [% t("New field") | html %] + › [% END %] - [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] › + [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] + › [% CASE 'list' %] - [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] › - [% END %] - [% t("Additional fields") | html %] › - [% t("Administration") | html %] › - [% t("Koha") | html %] -[% END %] + [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] + › + [% END %] + [% t("Additional fields") | html %] + › [% t("Administration") | html %] › [% t("Koha") | html %] + [% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -30,7 +35,7 @@ [% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %] - [% WRAPPER 'header.inc' %] +[% WRAPPER 'header.inc' %] [% INCLUDE 'cat-search.inc' %] [% END %] @@ -40,39 +45,36 @@ Administration [% END %] [% SWITCH op %] - [% CASE 'add_form' %] + [% CASE 'add_form' %] + [% WRAPPER breadcrumb_item %] + Additional fields + [% END %] + [% IF field %] [% WRAPPER breadcrumb_item %] - Additional fields + [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] [% END %] - [% IF field %] - [% WRAPPER breadcrumb_item %] - [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] - [% END %] - [% WRAPPER breadcrumb_item bc_active= 1 %] - [% tx("Modify field '{field_name}'", { field_name = field.name }) | html %] - [% END %] - [% ELSE %] - [% WRAPPER breadcrumb_item %] - [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] - [% END %] - [% WRAPPER breadcrumb_item bc_active= 1 %] - [% t("New field" ) | html %] - [% END %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + [% tx("Modify field '{field_name}'", { field_name = field.name }) | html %] [% END %] - - [% CASE 'list' %] + [% ELSE %] [% WRAPPER breadcrumb_item %] - Additional fields + [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] [% END %] [% WRAPPER breadcrumb_item bc_active= 1 %] - [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] + [% t("New field" ) | html %] [% END %] - - [% CASE %] - [% WRAPPER breadcrumb_item bc_active= 1 %] - Additional fields - [% END %] - + [% END %] + [% CASE 'list' %] + [% WRAPPER breadcrumb_item %] + Additional fields + [% END %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + [% tx("Table '{table_name}'", { table_name = tablename } ) | html %] + [% END %] + [% CASE %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + Additional fields + [% END %] [% END %] [% END #/ WRAPPER breadcrumbs %] [% END #/ WRAPPER sub-header.inc %] @@ -111,12 +113,14 @@ [% IF op == 'list_tables' %] [% IF CAN_user_acquisition_order_manage || CAN_user_serials_edit_subscription || CAN_user_updatecharges_remaining_permissions || CAN_user_erm %] -

Additional fields

+

Additional fields

-
- [% BLOCK table_option %] -
  • [% content | $raw %] ([% value | html %])
  • - [% END %] +
    + [% BLOCK table_option %] +
  • [% content | $raw %] ([% value | html %])
  • + [% END %] [% IF CAN_user_acquisition_order_manage || CAN_user_acquisition_edit_invoices %]

    Acquisitions

      @@ -143,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 %] @@ -155,11 +164,11 @@
      [% WRAPPER table_option value="subscription" %]Subscriptions[% END %]
    - [% END %] -
    - [% ELSE %] - Additional permissions are required for editing additional fields - [% END %] + [% END %]
    + [% ELSE %] + Additional permissions are required for editing additional fields + [% END %] [% ELSIF op == 'list' %]

    Additional fields for '[% tablename | html %]'

    [% IF fields %] @@ -189,28 +198,36 @@ [% field.marcfield | html %] [% SWITCH field.marcfield_mode %] - [% CASE 'get' %]Get value from MARC record - [% CASE 'set' %]Save value to MARC record + [% CASE 'get' %] + Get value from MARC record + [% CASE 'set' %] + Save value to MARC record [% END %] [% END %] [% IF show_searchable %] - - [% IF field.searchable %]Yes[% ELSE %]No[% END %] - + [% IF field.searchable %]Yes[% ELSE %]No[% END %] [% END %] - - [% IF field.repeatable %]Yes[% ELSE %]No[% END %] - + [% IF field.repeatable %]Yes[% ELSE %]No[% END %] Edit - Delete + Delete [% END %] - - + [% ELSE %] [% IF tablename %]There are no additional fields defined for this table.[% END %] [% END %] @@ -290,39 +307,42 @@ [% END %] - [% END %] [% MACRO jsinclude BLOCK %] [% INCLUDE "datatables.inc" %] [% Asset.js("js/form-submit.js") | $raw %] [% END %] -[% INCLUDE 'intranet-bottom.inc' %] \ No newline at end of file +[% INCLUDE 'intranet-bottom.inc' %] 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 1666160f112..13afb7e1be9 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,241 +55,240 @@ [% 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 %] -[% INCLUDE 'intranet-bottom.inc' %] +[% INCLUDE 'intranet-bottom.inc' %] \ No newline at end of file -- 2.48.1