View | Details | Raw Unified | Return to bug 17702
Collapse All | Expand All

(-)a/admin/account_types.pl (+130 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright 2016 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
use C4::Context;
23
use C4::Auth;
24
use C4::Output;
25
26
use Koha::Account::CreditTypes;
27
use Koha::Account::DebitTypes;
28
29
my $input     = new CGI;
30
my $type_code = $input->param('type_code');
31
my $op        = $input->param('op') || 'list';
32
my $type      = $input->param('type');
33
my @messages;
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {   template_name   => "admin/account_types.tt",
37
        query           => $input,
38
        type            => "intranet",
39
        authnotrequired => 0,
40
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
41
        debug           => 1,
42
    }
43
);
44
45
#my $dbh = C4::Context->dbh;
46
if ( $op eq 'add_form' ) {
47
    my $account_type;
48
    if ($type_code) {
49
        if ($type eq "debit") {
50
            $account_type = Koha::Account::DebitTypes->find($type_code);
51
        } else {
52
            $account_type = Koha::Account::CreditTypes->find($type_code);
53
        }
54
    }
55
    $template->param( account_type => $account_type );
56
    $template->param( type => $type );
57
} elsif ( $op eq 'add_validate' ) {
58
    my $description           = $input->param('description');
59
    my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
60
    my $default_amount;
61
    if ($type eq "debit") {
62
        $default_amount = $input->param('default_amount') || undef;
63
    }
64
65
    my $account_type;
66
    if($type eq "debit") {
67
        $account_type = Koha::Account::DebitTypes->find($type_code);
68
        if (not defined $account_type) {
69
            $account_type = Koha::Account::DebitType->new( { type_code => $type_code } );
70
        }
71
    } else {
72
        $account_type = Koha::Account::CreditTypes->find($type_code);
73
        if (not defined $account_type) {
74
             $account_type = Koha::Account::CreditType->new( { type_code => $type_code } );
75
        }
76
    }
77
    $account_type->description($description);
78
    $account_type->can_be_added_manually($can_be_added_manually);
79
    if($type eq "debit") {
80
        $account_type->default_amount($default_amount);
81
    }
82
    eval { $account_type->store; };
83
    if ($@) {
84
        push @messages, { type => 'error', code => 'error_on_saving' };
85
    } else {
86
        push @messages, { type => 'message', code => 'success_on_saving' };
87
    }
88
    $op          = 'list';
89
} elsif ( $op eq 'delete_confirm' ) {
90
    my $account_type;
91
    if($type eq "debit") {
92
        $account_type = Koha::Account::DebitTypes->find($type_code);
93
    } else {
94
        $account_type = Koha::Account::CreditTypes->find($type_code);
95
    }
96
    $template->param( account_type => $account_type );
97
    $template->param( type => $type );
98
} elsif ( $op eq 'delete_confirmed' ) {
99
    my $account_type;
100
    if($type eq "debit") {
101
        $account_type = Koha::Account::DebitTypes->find($type_code);
102
    } else {
103
        $account_type = Koha::Account::CreditTypes->find($type_code);
104
    }
105
    my $deleted = eval { $account_type->delete; };
106
107
    if ( $@ or not $deleted ) {
108
        push @messages, { type => 'error', code => 'error_on_delete' };
109
    } else {
110
        push @messages, { type => 'message', code => 'success_on_delete' };
111
    }
112
    $op = 'list';
113
}
114
115
if ( $op eq 'list' ) {
116
    my $credit_types = Koha::Account::CreditTypes->search();
117
    my $debit_types = Koha::Account::DebitTypes->search();
118
    $template->param(
119
        debit_types  => $debit_types,
120
        credit_types => $credit_types,
121
    );
122
}
123
124
$template->param(
125
    type_code   => $type_code,
126
    messages    => \@messages,
127
    op          => $op,
128
);
129
130
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 34-39 Link Here
34
    <li><a href="/cgi-bin/koha/admin/transport-cost-matrix.pl">Transport cost matrix</a></li>
34
    <li><a href="/cgi-bin/koha/admin/transport-cost-matrix.pl">Transport cost matrix</a></li>
35
    <li><a href="/cgi-bin/koha/admin/item_circulation_alerts.pl">Item circulation alerts</a></li>
35
    <li><a href="/cgi-bin/koha/admin/item_circulation_alerts.pl">Item circulation alerts</a></li>
36
    <li><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></li>
36
    <li><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></li>
37
    <li><a href="/cgi-bin/koha/admin/account_types.pl">Account types</a></li>
37
</ul>
38
</ul>
38
39
39
<h5>Catalog</h5>
40
<h5>Catalog</h5>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/account_types.tt (+210 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; [% IF op =='add_form' %]Account types &rsaquo; [% IF account_type.type_code %] Modify account [% type %] type[% ELSE %] New account [% type %] type[% END %][% ELSE %][% IF op == 'delete_confirm' %]Account types &rsaquo; Confirm deletion of account [% type %]type[% ELSE %] Account types[% END %][% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
5
[% INCLUDE 'datatables.inc' %]
6
<script type="text/javascript">
7
//<![CDATA[
8
    $(document).ready(function() {
9
        $("#table_credit_types, #table_debit_types").dataTable($.extend(true, {}, dataTablesDefaults, {
10
            "aoColumnDefs": [
11
                { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
12
            ],
13
            "aaSorting": [[ 1, "asc" ]],
14
            "iDisplayLength": 10,
15
            "sPaginationType": "full_numbers"
16
        }));
17
    });
18
//]]>
19
</script>
20
</head>
21
<body id="admin_account_types" class="admin">
22
[% INCLUDE 'header.inc' %]
23
[% INCLUDE 'cat-search.inc' %]
24
25
<div id="breadcrumbs">
26
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
27
    &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
28
    &rsaquo; <a href="/cgi-bin/koha/admin/account_types.pl">Account types</a>
29
    [% IF op == 'add_form' %]
30
    &rsaquo; [% IF account_type.type_code %]Modify[% ELSE %]New[% END %] Account [% type %] type
31
    [% ELSIF op == 'delete_confirm' %]
32
    &rsaquo; Confirm deletion of account [% type %] type
33
    [% END %]
34
</div>
35
36
<div id="doc3" class="yui-t2">
37
38
   <div id="bd">
39
    <div id="yui-main">
40
    <div class="yui-b">
41
42
[% FOR m IN messages %]
43
    <div class="dialog [% m.type %]">
44
        [% SWITCH m.code %]
45
        [% CASE 'error_on_saving' %]
46
            An error occurred when saving this account type.
47
        [% CASE 'error_on_delete' %]
48
            An error occurred when deleting this account type. Check the logs.
49
        [% CASE 'success_on_saving' %]
50
            Account type saved successfully.
51
        [% CASE 'success_on_delete' %]
52
            Account type deleted successfully.
53
        [% CASE %]
54
            [% m.code %]
55
        [% END %]
56
    </div>
57
[% END %]
58
59
[% IF op == 'add_form' %]
60
    [% IF account_type %]
61
        <h1>Modify an account [% type %] type</h1>
62
    [% ELSE %]
63
        <h1>New account [% type %] type</h1>
64
    [% END %]
65
66
    <form action="/cgi-bin/koha/admin/account_types.pl" name="Aform" method="post" class="validated">
67
        <input type="hidden" name="op" value="add_validate" />
68
        <input type="hidden" name="type" value="[% type %]" />
69
        <fieldset class="rows">
70
            <ol>
71
                <li>
72
                    <label for="type_code" class="required">Account [% type %] type code: </label>
73
                    [% IF account_type %]
74
                        <strong>[% account_type.type_code %]</strong>
75
                        <input type="hidden" name="type_code" value="[% type_code %]" />
76
                    [% ELSE %]
77
                    <input type="text" name="type_code" id="type_code" size="10" maxlength="5" class="required" required="required"><span class="required">Required. Maximum length is 5 letters</span>
78
                    [% END %]
79
                </li>
80
                [% IF type == 'debit' %]
81
                <li>
82
                    <label for="default_amount">Default amount: </label>
83
                    <input type="text" name="default_amount" id="default_amount" size="80" maxlength="100" value="[% account_type.default_amount |html %]" />
84
                </li>
85
                [% END %]
86
                <li>
87
                    <label for="description" class="required">Description: </label>
88
                    <input type="text" name="description" id="description" required="required" class="required" size="80" maxlength="100" value="[% account_type.description |html %]" /> <span class="required">Required</span>
89
                </li>
90
                <li>
91
                    <label for="can_be_added_manually">Can be added manually? </label>
92
                    [% IF account_type.can_be_added_manually %]
93
                        <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" checked="checked" value="1" />
94
                    [% ELSE %]
95
                        <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" value="1" />
96
                    [% END %]
97
                </li>
98
            </ol>
99
        </fieldset>
100
101
        <fieldset class="action">
102
            <button id="save_account_type" class="btn"><i class="fa fa-save"></i> Save</button>
103
            <a class="cancel btn-link" href="/cgi-bin/koha/admin/account_types.pl"><i class="fa fa-times"></i> Cancel</a>
104
        </fieldset>
105
    </form>
106
[% END %]
107
108
[% IF op == 'delete_confirm' %]
109
    <div class="dialog alert">
110
        <h3>Delete account [% type %] type "[% account_type.description %]?"</h3>
111
        <table>
112
            <tr><th>Account type code</th>
113
                <td>[% account_type.type_code %]</td>
114
            </tr>
115
            <tr><th>Account type description</th>
116
                <td>[% account_type.description %]</td>
117
            </tr>
118
        </table>
119
        <form action="/cgi-bin/koha/admin/account_types.pl" method="post">
120
            <input type="hidden" name="op" value="delete_confirmed" />
121
            <input type="hidden" name="type_code" value="[% account_type.type_code %]" />
122
            <input type="hidden" name="type" value="[% type %]" />
123
            <button type="submit" class="btn approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
124
        </form>
125
        <form action="/cgi-bin/koha/admin/account_types.pl" method="get">
126
            <button type=submit" class="btn deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
127
        </form>
128
    </div>
129
[% END %]
130
131
[% IF op == 'list' %]
132
133
    <div id="toolbar" class="btn-toolbar">
134
        <a class="btn btn-small" id="newdebittype" href="/cgi-bin/koha/admin/account_types.pl?op=add_form&type=debit"><i class="fa fa-plus"></i> New debit type</a>
135
        <a class="btn btn-small" id="newcreditype" href="/cgi-bin/koha/admin/account_types.pl?op=add_form&type=credit"><i class="fa fa-plus"></i> New credit type</a>
136
    </div>
137
138
    <h2>Account debit types</h2>
139
        [% IF debit_types.count %]
140
        <table id="table_debit_types">
141
            <thead>
142
                <th>Account type code</th>
143
                <th>Description</th>
144
                <th>Default amount</th>
145
                <th>Can be added manually</th>
146
                <th>Actions</th>
147
            </thead>
148
            <tbody>
149
                [% FOREACH debit_type IN debit_types %]
150
                <tr>
151
                    <td>[% debit_type.type_code %]</td>
152
                    <td>[% debit_type.description %]</td>
153
                    <td>[% debit_type.default_amount %]</td>
154
                    <td>[% IF debit_type.can_be_added_manually %]Yes[% ELSE %]No[% END %]</td>
155
                    <td class="actions">
156
                        <a class="btn btn-mini" href="/cgi-bin/koha/admin/account_types.pl?op=add_form&amp;type_code=[% debit_type.type_code %]&type=debit"><i class="fa fa-pencil"></i> Edit</a>
157
                        [% IF debit_type.can_be_deleted %]
158
                            <a class="btn btn-mini" href="/cgi-bin/koha/admin/account_types.pl?op=delete_confirm&amp;type_code=[% debit_type.type_code %]&type=debit"><i class="fa fa-trash"></i> Delete</a>
159
                        [% END %]
160
                    </td>
161
                </tr>
162
                [% END %]
163
            </tbody>
164
        </table>
165
    [% ELSE %]
166
        <div class="dialog message">
167
            There are no account debit types defined. <a href="/cgi-bin/koha/admin/account_types.pl?op=add_form&type=debit">Create new debit type</a>
168
        </div>
169
    [% END %]
170
171
     <h2>Account credit types</h2>
172
         [% IF credit_types.count %]
173
         <table id="table_credit_types">
174
             <thead>
175
                 <th>Account type code</th>
176
                 <th>Description</th>
177
                 <th>Can be added manually</th>
178
                 <th>Actions</th>
179
             </thead>
180
             <tbody>
181
                 [% FOREACH credit_type IN credit_types %]
182
                 <tr>
183
                     <td>[% credit_type.type_code %]</td>
184
                     <td>[% credit_type.description %]</td>
185
                     <td>[% IF credit_type.can_be_added_manually %]Yes[% ELSE %]No[% END %]</td>
186
                     <td class="actions">
187
                         <a class="btn btn-mini" href="/cgi-bin/koha/admin/account_types.pl?op=add_form&amp;type_code=[% credit_type.type_code %]&type=credit"><i class="fa fa-pencil"></i> Edit</a>
188
                         [% IF credit_type.can_be_deleted %]
189
                             <a class="btn btn-mini" href="/cgi-bin/koha/admin/account_types.pl?op=delete_confirm&amp;type_code=[% credit_type.type_code %]&type=credit"><i class="fa fa-trash"></i> Delete</a>
190
                         [% END %]
191
                     </td>
192
                 </tr>
193
                 [% END %]
194
             </tbody>
195
         </table>
196
     [% ELSE %]
197
         <div class="dialog message">
198
             There are no account credit types defined. <a href="/cgi-bin/koha/admin/account_types.pl?op=add_form&type=credit">Create new credit type</a>
199
         </div>
200
     [% END %]
201
202
[% END %]
203
204
</div>
205
</div>
206
<div class="yui-b">
207
[% INCLUDE 'admin-menu.inc' %]
208
</div>
209
</div>
210
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-1 / +2 lines)
Lines 55-60 Link Here
55
                    <dd>Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types</dd>
55
                    <dd>Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types</dd>
56
                    <dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt>
56
                    <dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt>
57
                    <dd>Define cities and towns that your patrons live in.</dd>
57
                    <dd>Define cities and towns that your patrons live in.</dd>
58
                    <dt><a href="/cgi-bin/koha/admin/account_types.pl">Account types</a></dt>
59
                    <dd>Define debit and credit types.</dd>
58
                </dl>
60
                </dl>
59
                [% IF CAN_user_plugins %]
61
                [% IF CAN_user_plugins %]
60
                    <h3>Plugins</h3>
62
                    <h3>Plugins</h3>
61
- 

Return to bug 17702