@@ -, +, @@ section in the admin menu as well are working as expected. types cannot be deleted as they are needed for koha functionality. --- Koha/Account/DebitType.pm | 16 +- Koha/Account/DebitTypes.pm | 3 +- admin/debit_types.pl | 146 +++++++++++ .../prog/en/includes/admin-menu.inc | 7 +- .../prog/en/modules/admin/admin-home.tt | 66 ++--- .../prog/en/modules/admin/debit_types.tt | 234 ++++++++++++++++++ 6 files changed, 437 insertions(+), 35 deletions(-) create mode 100755 admin/debit_types.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt --- a/Koha/Account/DebitType.pm +++ a/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 --- a/Koha/Account/DebitTypes.pm +++ a/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 --- a/admin/debit_types.pl +++ a/admin/debit_types.pl @@ -0,0 +1,146 @@ +#! /usr/bin/perl + +# Copyright 2016 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 $type = $input->param('type'); +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, + } +); + +if ( $op eq 'add_form' ) { + my $debit_type; + if ($code) { + $debit_type = Koha::Account::DebitTypes->find($code); + } + + 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, + type => $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; + if ( $type eq "debit" ) { + $default_amount = $input->param('default_amount') || undef; + } + my @branches = grep { $_ ne q{} } $input->multi_param('branches'); + + my $debit_type; + $debit_type = Koha::Account::DebitTypes->find($code); + 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' ) { + my $debit_type; + if ( $type eq "debit" ) { + $debit_type = Koha::Account::DebitTypes->find($code); + } + else { + $debit_type = Koha::Account::CreditTypes->find($code); + } + $template->param( debit_type => $debit_type ); + $template->param( type => $type ); +} +elsif ( $op eq 'delete_confirmed' ) { + my $debit_type; + if ( $type eq "debit" ) { + $debit_type = Koha::Account::DebitTypes->find($code); + } + else { + $debit_type = Koha::Account::CreditTypes->find($code); + } + 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; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ a/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
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ a/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 %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt @@ -0,0 +1,234 @@ +[% 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' %] --