@@ -, +, @@ --- 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 --- a/admin/account_types.pl +++ a/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; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ a/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
    --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt +++ a/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' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ a/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

    --