From 86ece7d2e547032458757c5850c5c4d48ea4df37 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 10 Oct 2019 17:14:23 +0100 Subject: [PATCH] Bug 23049: Account types configuration - Admin page MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test plan: 1) Go to admin home, note there is new Debit types page in Accounting section 2) Go to any other admin page and confirm there is link to Debit types in the admin menu as well 3) Go to Debit types page 4) You should see a datatable listing existing debit types, ensure they are working as expected. 5) Try to create, edit and delete some debit types. Note: Some debit types cannot be deleted as they are needed for koha functionality. Signed-off-by: Séverine QUEUNE Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Account/DebitType.pm | 16 +- Koha/Account/DebitTypes.pm | 3 +- admin/debit_types.pl | 125 ++++++++++ .../prog/en/includes/admin-menu.inc | 7 +- .../prog/en/modules/admin/admin-home.tt | 66 ++--- .../prog/en/modules/admin/debit_types.tt | 232 ++++++++++++++++++ 6 files changed, 414 insertions(+), 35 deletions(-) create mode 100755 admin/debit_types.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt diff --git a/Koha/Account/DebitType.pm b/Koha/Account/DebitType.pm index 59bb5c1e5e..6324ec57cb 100644 --- a/Koha/Account/DebitType.pm +++ b/Koha/Account/DebitType.pm @@ -23,7 +23,7 @@ use List::Util qw/any/; use Koha::Database; use Koha::Exceptions; -use base qw(Koha::Object); +use base qw(Koha::Object Koha::Object::Limit::Library); =head1 NAME @@ -49,6 +49,20 @@ sub delete { return $self->SUPER::delete; } +=head3 _library_limits + +Configurable library limits + +=cut + +sub _library_limits { + return { + class => "AccountDebitTypesBranch", + id => "debit_type_code", + library => "branchcode", + }; +} + =head3 type =cut diff --git a/Koha/Account/DebitTypes.pm b/Koha/Account/DebitTypes.pm index 2e6eb2c9b6..f19bce0382 100644 --- a/Koha/Account/DebitTypes.pm +++ b/Koha/Account/DebitTypes.pm @@ -21,8 +21,9 @@ use Modern::Perl; use List::Util qw/any/; use Koha::Database; +use Koha::Account::DebitType; -use base qw(Koha::Objects); +use base qw(Koha::Objects Koha::Objects::Limit::Library); =head1 NAME diff --git a/admin/debit_types.pl b/admin/debit_types.pl new file mode 100755 index 0000000000..fdb79f8800 --- /dev/null +++ b/admin/debit_types.pl @@ -0,0 +1,125 @@ +#! /usr/bin/perl + +# Copyright 2019 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); +use C4::Context; +use C4::Auth; +use C4::Output; + +use Koha::Account::DebitTypes; + +my $input = new CGI; +my $code = $input->param('code'); +my $op = $input->param('op') || 'list'; +my @messages; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "admin/debit_types.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 'parameters_remaining_permissions' }, + debug => 1, + } +); + +my $debit_type; +if ($code) { + $debit_type = Koha::Account::DebitTypes->find($code); +} + +if ( $op eq 'add_form' ) { + + my $selected_branches = + $debit_type ? $debit_type->get_library_limits : undef; + my $branches = + Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; + my @branches_loop; + foreach my $branch (@$branches) { + my $selected = + ( $selected_branches + && grep { $_->branchcode eq $branch->{branchcode} } + @{ $selected_branches->as_list } ) ? 1 : 0; + push @branches_loop, + { + branchcode => $branch->{branchcode}, + branchname => $branch->{branchname}, + selected => $selected, + }; + } + + $template->param( + debit_type => $debit_type, + branches_loop => \@branches_loop + ); +} +elsif ( $op eq 'add_validate' ) { + my $description = $input->param('description'); + my $can_be_added_manually = $input->param('can_be_added_manually') || 0; + my $default_amount = $input->param('default_amount') || undef; + my @branches = grep { $_ ne q{} } $input->multi_param('branches'); + + if ( not defined $debit_type ) { + $debit_type = Koha::Account::DebitType->new( { code => $code } ); + } + $debit_type->description($description); + $debit_type->can_be_added_manually($can_be_added_manually); + $debit_type->default_amount($default_amount); + + eval { + $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' }; + } + $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' }; + } + else { + push @messages, { type => 'message', code => 'success_on_delete' }; + } + $op = 'list'; +} + +if ( $op eq 'list' ) { + my $debit_types = Koha::Account::DebitTypes->search(); + $template->param( debit_types => $debit_types ); +} + +$template->param( + code => $code, + messages => \@messages, + op => $op, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index 1578c2db7f..f24f3e83fc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -51,10 +51,13 @@ [% END %] - [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) %] + [% IF ( CAN_user_parameters_manage_accounts || ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) ) %]
Accounting
    - [% IF ( CAN_user_cash_management_manage_cash_registers ) %] + [% IF ( CAN_user_parameters_manage_accounts ) %] +
  • Debit types
  • + [% END %] + [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) %]
  • Cash registers
  • [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 4095e516e9..5059cbfa34 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -69,42 +69,46 @@ [% IF ( CAN_user_parameters_manage_patron_categories || CAN_user_parameters_manage_circ_rules || CAN_user_parameters_manage_patron_attributes || CAN_user_parameters_manage_transfers || CAN_user_parameters_manage_item_circ_alerts || CAN_user_parameters_manage_cities ) %]

Patrons and circulation

- [% IF ( CAN_user_parameters_manage_patron_categories ) %] -
Patron categories
-
Define patron categories.
- [% END %] - [% IF ( CAN_user_parameters_manage_circ_rules ) %] -
Circulation and fines rules
-
Define circulation and fines rules for combinations of libraries, patron categories, and item types
- [% END %] - [% IF ( CAN_user_parameters_manage_patron_attributes ) %] -
Patron attribute types
-
Define extended attributes (identifiers and statistical categories) for patron records
- [% END %] - [% IF ( CAN_user_parameters_manage_transfers ) %] -
Library transfer limits
-
Limit the ability to transfer items between libraries based on the library sending, the library receiving, and the item type involved. These rules only go into effect if the preference UseBranchTransferLimits is set to ON.
-
Transport cost matrix
-
Define transport costs between branches
- [% END %] - [% IF ( CAN_user_parameters_manage_item_circ_alerts ) %] -
Item circulation alerts
-
Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types
- [% END %] - [% IF ( CAN_user_parameters_manage_cities ) %] -
Cities and towns
-
Define cities and towns that your patrons live in.
- [% END %] + [% IF ( CAN_user_parameters_manage_patron_categories ) %] +
Patron categories
+
Define patron categories.
+ [% END %] + [% IF CAN_user_parameters_manage_circ_rules %] +
Circulation and fines rules
+
Define circulation and fines rules for combinations of libraries, patron categories, and item types
+ [% END %] + [% IF ( CAN_user_parameters_manage_patron_attributes ) %] +
Patron attribute types
+
Define extended attributes (identifiers and statistical categories) for patron records
+ [% END %] + [% IF ( CAN_user_parameters_manage_transfers ) %] +
Library transfer limits
+
Limit the ability to transfer items between libraries based on the library sending, the library receiving, and the item type involved. These rules only go into effect if the preference UseBranchTransferLimits is set to ON.
+
Transport cost matrix
+
Define transport costs between branches
+ [% END %] + [% IF ( CAN_user_parameters_manage_item_circ_alerts ) %] +
Item circulation alerts
+
Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types
+ [% END %] + [% IF ( CAN_user_parameters_manage_cities ) %] +
Cities and towns
+
Define cities and towns that your patrons live in.
+ [% END %]
[% END %] - [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) %] + [% IF ( CAN_user_parameters_manage_accounts || ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) ) %]

Accounting

- [% IF ( CAN_user_cash_management_manage_cash_registers ) %] -
Cash registers
-
Define cash registers
- [% END %] + [% IF ( CAN_user_parameters_manage_accounts ) %] +
Debit types
+
Define debit types.
+ [% END %] + [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) %] +
Cash registers
+
Define cash registers
+ [% END %]
[% END %] 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 new file mode 100644 index 0000000000..aa5c401f2f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt @@ -0,0 +1,232 @@ +[% USE raw %] +[% USE Asset %] +[% USE Branches %] +[% USE Price %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › + [% IF op =='add_form' %] + Debit types › + [% IF debit_type.code %] + Modify debit type + [% ELSE %] + New debit type + [% END %] + [% ELSE %] + [% IF op == 'delete_confirm' %] + Debit types › Confirm deletion of debit type + [% ELSE %] + Debit types + [% END %] + [% END %] + +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'prefs-admin-search.inc' %] + + + +
+
+
+
+ + [% FOREACH m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'error_on_saving' %] + An error occurred when saving this debit type. + [% CASE 'error_on_delete' %] + An error occurred when deleting this debit type. Check the logs. + [% CASE 'success_on_saving' %] + Debit type saved successfully. + [% CASE 'success_on_delete' %] + Debit type deleted successfully. + [% CASE %] + [% m.code | html %] + [% END %] +
+ [% END %] + + [% IF op == 'add_form' %] + [% IF debit_type %] +

Modify a debit type

+ [% ELSE %] +

New debit type

+ [% END %] + +
+ +
+
    +
  1. + + [% IF debit_type %] + [% debit_type.code | html %] + + [% ELSE %] + Required. Maximum length is 64 letters + [% END %] +
  2. +
  3. + + +
  4. +
  5. + + Required +
  6. +
  7. + + [% IF debit_type.can_be_added_manually %] + + [% ELSE %] + + [% END %] +
  8. +
  9. + + + Select 'All libraries' if this debit type should be available at all libraries. Otherwise select libraries you want to associate debit type with. +
  10. +
+
+ +
+ + Cancel +
+
+ [% END %] + + [% IF op == 'delete_confirm' %] +
+

Delete debit type "[% debit_type.description | html %]?"

+ + + + + + + +
Debit type code[% debit_type.code | html %]
Debit type description[% debit_type.description | html %]
+
+ + + +
+
+ +
+
+ [% END %] + + [% IF op == 'list' %] + + +

Account debit types

+ [% IF debit_types.count %] + + + + + + + + + + + [% FOREACH debit_type IN debit_types %] + + + + + + + + + [% END %] + +
CodeDescriptionDefault amountCan be added manuallyLibrary limitationsActions
[% debit_type.code | html %][% debit_type.description | html %][% debit_type.default_amount | $Price %][% IF debit_type.can_be_added_manually %]Yes[% ELSE %]No[% 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.is_system %] + Edit + Delete + [% END %] +
+ [% ELSE %] +
+ There are no account debit types defined. Create new debit type +
+ [% END %] + [% END %] +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] + + +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] -- 2.39.5