From 52e6bbe978718870ca4e6bbcd369e4bd43d86c7d Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Wed, 23 Nov 2016 14:58:01 +0000 Subject: [PATCH] Bug 17702: Account types configuration - Admin page Test plan: 1) Go to admin home, note there is new Account types page in Patrons and circulation section 2) Go to any other admin page and confirm there is link to Account types in admin menu as welll 3) Go to Account types page 4) You should see two datatables, one for debit types and one for credit types, ensure the datatables are working corectly 5) Try to create, edit and delete some debit types, note, that some of them can't be deleted - they are neede for Koha internally 6) Do the same with credit types 7) Try to add some default amount to internal debits - like Acccount management fee, New card, ... 8) Go to Patron fines page and play with account type select, when you change thy account type, the description and amount should change as you set it on the admin page 9) Try to add some fees and ensure they are inserted corectly 10) Pay the inserted fees 11) Try to add manual credit and ensure it is added corectly --- admin/account_types.pl | 130 +++++++++++++ .../intranet-tmpl/prog/en/includes/admin-menu.inc | 1 + .../prog/en/modules/admin/account_types.tt | 210 +++++++++++++++++++++ .../prog/en/modules/admin/admin-home.tt | 2 + 4 files changed, 343 insertions(+) create mode 100755 admin/account_types.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt diff --git a/admin/account_types.pl b/admin/account_types.pl new file mode 100755 index 0000000..7cd395f --- /dev/null +++ b/admin/account_types.pl @@ -0,0 +1,130 @@ +#! /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::CreditTypes; +use Koha::Account::DebitTypes; + +my $input = new CGI; +my $type_code = $input->param('type_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/account_types.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 'parameters_remaining_permissions' }, + debug => 1, + } +); + +#my $dbh = C4::Context->dbh; +if ( $op eq 'add_form' ) { + my $account_type; + if ($type_code) { + if ($type eq "debit") { + $account_type = Koha::Account::DebitTypes->find($type_code); + } else { + $account_type = Koha::Account::CreditTypes->find($type_code); + } + } + $template->param( account_type => $account_type ); + $template->param( type => $type ); +} 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 $account_type; + if($type eq "debit") { + $account_type = Koha::Account::DebitTypes->find($type_code); + if (not defined $account_type) { + $account_type = Koha::Account::DebitType->new( { type_code => $type_code } ); + } + } else { + $account_type = Koha::Account::CreditTypes->find($type_code); + if (not defined $account_type) { + $account_type = Koha::Account::CreditType->new( { type_code => $type_code } ); + } + } + $account_type->description($description); + $account_type->can_be_added_manually($can_be_added_manually); + if($type eq "debit") { + $account_type->default_amount($default_amount); + } + eval { $account_type->store; }; + 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 $account_type; + if($type eq "debit") { + $account_type = Koha::Account::DebitTypes->find($type_code); + } else { + $account_type = Koha::Account::CreditTypes->find($type_code); + } + $template->param( account_type => $account_type ); + $template->param( type => $type ); +} elsif ( $op eq 'delete_confirmed' ) { + my $account_type; + if($type eq "debit") { + $account_type = Koha::Account::DebitTypes->find($type_code); + } else { + $account_type = Koha::Account::CreditTypes->find($type_code); + } + my $deleted = eval { $account_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 $credit_types = Koha::Account::CreditTypes->search(); + my $debit_types = Koha::Account::DebitTypes->search(); + $template->param( + debit_types => $debit_types, + credit_types => $credit_types, + ); +} + +$template->param( + type_code => $type_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 e736272..2faf61e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -34,6 +34,7 @@
  • Transport cost matrix
  • Item circulation alerts
  • Cities and towns
  • +
  • Account types
  • Catalog
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt new file mode 100644 index 0000000..5349be6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt @@ -0,0 +1,210 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › [% IF op =='add_form' %]Account types › [% IF account_type.type_code %] Modify account [% type %] type[% ELSE %] New account [% type %] type[% END %][% ELSE %][% IF op == 'delete_confirm' %]Account types › Confirm deletion of account [% type %]type[% ELSE %] Account types[% END %][% END %] +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
    + +
    +
    +
    + +[% FOR m IN messages %] +
    + [% SWITCH m.code %] + [% CASE 'error_on_saving' %] + An error occurred when saving this account type. + [% CASE 'error_on_delete' %] + An error occurred when deleting this account type. Check the logs. + [% CASE 'success_on_saving' %] + Account type saved successfully. + [% CASE 'success_on_delete' %] + Account type deleted successfully. + [% CASE %] + [% m.code %] + [% END %] +
    +[% END %] + +[% IF op == 'add_form' %] + [% IF account_type %] +

    Modify an account [% type %] type

    + [% ELSE %] +

    New account [% type %] type

    + [% END %] + +
    + + +
    +
      +
    1. + + [% IF account_type %] + [% account_type.type_code %] + + [% ELSE %] + Required. Maximum length is 5 letters + [% END %] +
    2. + [% IF type == 'debit' %] +
    3. + + +
    4. + [% END %] +
    5. + + Required +
    6. +
    7. + + [% IF account_type.can_be_added_manually %] + + [% ELSE %] + + [% END %] +
    8. +
    +
    + +
    + + Cancel +
    +
    +[% END %] + +[% IF op == 'delete_confirm' %] +
    +

    Delete account [% type %] type "[% account_type.description %]?"

    + + + + + + + +
    Account type code[% account_type.type_code %]
    Account type description[% account_type.description %]
    +
    + + + + +
    +
    + +
    +
    +[% END %] + +[% IF op == 'list' %] + + + +

    Account debit types

    + [% IF debit_types.count %] + + + + + + + + + + [% FOREACH debit_type IN debit_types %] + + + + + + + + [% END %] + +
    Account type codeDescriptionDefault amountCan be added manuallyActions
    [% debit_type.type_code %][% debit_type.description %][% debit_type.default_amount %][% IF debit_type.can_be_added_manually %]Yes[% ELSE %]No[% END %] + Edit + [% IF debit_type.can_be_deleted %] + Delete + [% END %] +
    + [% ELSE %] +
    + There are no account debit types defined. Create new debit type +
    + [% END %] + +

    Account credit types

    + [% IF credit_types.count %] + + + + + + + + + [% FOREACH credit_type IN credit_types %] + + + + + + + [% END %] + +
    Account type codeDescriptionCan be added manuallyActions
    [% credit_type.type_code %][% credit_type.description %][% IF credit_type.can_be_added_manually %]Yes[% ELSE %]No[% END %] + Edit + [% IF credit_type.can_be_deleted %] + Delete + [% END %] +
    + [% ELSE %] +
    + There are no account credit types defined. Create new credit type +
    + [% END %] + +[% END %] + +
    +
    +
    +[% INCLUDE 'admin-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] 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 6c128d6..ac86b96 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 @@ -55,6 +55,8 @@
    Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types
    Cities and towns
    Define cities and towns that your patrons live in.
    +
    Account types
    +
    Define debit and credit types.
    [% IF CAN_user_plugins %]

    Plugins

    -- 2.1.4