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

(-)a/Koha/Account.pm (-1 / +1 lines)
Lines 396-402 sub add_credit { Link Here
396
                my $account_offset = Koha::Account::Offset->new(
396
                my $account_offset = Koha::Account::Offset->new(
397
                    {
397
                    {
398
                        credit_id => $line->id,
398
                        credit_id => $line->id,
399
                        type   => $Koha::Account::offset_type->{$credit_type},
399
                        type   => $Koha::Account::offset_type->{$credit_type} // $Koha::Account::offset_type->{CREDIT},
400
                        amount => $amount
400
                        amount => $amount
401
                    }
401
                    }
402
                )->store();
402
                )->store();
(-)a/admin/credit_types.pl (+131 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright 2020 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 Try::Tiny;
23
24
use C4::Context;
25
use C4::Auth;
26
use C4::Output;
27
28
use Koha::Account::CreditType;
29
use Koha::Account::CreditTypes;
30
31
my $input = new CGI;
32
my $code  = $input->param('code');
33
my $op    = $input->param('op') || 'list';
34
my @messages;
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name   => "admin/credit_types.tt",
39
        query           => $input,
40
        type            => "intranet",
41
        authnotrequired => 0,
42
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
43
        debug           => 1,
44
    }
45
);
46
47
my $credit_type;
48
if ($code) {
49
    $credit_type = Koha::Account::CreditTypes->find($code);
50
}
51
52
if ( $op eq 'add_form' ) {
53
54
    my $selected_branches =
55
      $credit_type ? $credit_type->get_library_limits : undef;
56
    my $branches =
57
      Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
58
    my @branches_loop;
59
    foreach my $branch (@$branches) {
60
        my $selected =
61
          ( $selected_branches
62
              && grep { $_->branchcode eq $branch->{branchcode} }
63
              @{ $selected_branches->as_list } ) ? 1 : 0;
64
        push @branches_loop,
65
          {
66
            branchcode => $branch->{branchcode},
67
            branchname => $branch->{branchname},
68
            selected   => $selected,
69
          };
70
    }
71
72
    $template->param(
73
        credit_type    => $credit_type,
74
        branches_loop => \@branches_loop
75
    );
76
}
77
elsif ( $op eq 'add_validate' ) {
78
    my $description           = $input->param('description');
79
    my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
80
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
81
82
    if ( not defined $credit_type ) {
83
        $credit_type = Koha::Account::CreditType->new( { code => $code } );
84
    }
85
    $credit_type->description($description);
86
    $credit_type->can_be_added_manually($can_be_added_manually);
87
88
    try {
89
        $credit_type->store;
90
        $credit_type->replace_library_limits( \@branches );
91
        push @messages, { type => 'message', code => 'success_on_saving' };
92
    }
93
    catch {
94
        push @messages, { type => 'error', code => 'error_on_saving' };
95
    };
96
    $op = 'list';
97
}
98
elsif ( $op eq 'archive' ) {
99
    try {
100
        $credit_type->archived(1)->store();
101
        push @messages, { code => 'success_on_archive', type => 'message' };
102
    }
103
    catch {
104
        push @messages, { code => 'error_on_archive', type => 'alert' };
105
106
    };
107
    $op = 'list';
108
}
109
elsif ( $op eq 'unarchive' ) {
110
    try {
111
        $credit_type->archived(0)->store();
112
        push @messages, { code => 'success_on_restore', type => 'message' };
113
    }
114
    catch {
115
        push @messages, { code => 'error_on_restore', type => 'alert' };
116
    };
117
    $op = 'list';
118
}
119
120
if ( $op eq 'list' ) {
121
    my $credit_types = Koha::Account::CreditTypes->search();
122
    $template->param( credit_types => $credit_types, );
123
}
124
125
$template->param(
126
    code     => $code,
127
    messages => \@messages,
128
    op       => $op,
129
);
130
131
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/atomicupdate/bug-17702.perl (+9 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    if (!column_exists('account_credit_types', 'archived')) {
4
        $dbh->do('ALTER TABLE account_credit_types ADD COLUMN archived tinyint(1) NOT NULL DEFAULT 0 AFTER is_system');
5
    }
6
7
    SetVersion( $DBversion );
8
    print "Upgrade to $DBversion done (Bug 17702 - Add column account_credit_types.archived)\n";
9
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 56-61 Link Here
56
        <ul>
56
        <ul>
57
            [% IF ( CAN_user_parameters_manage_accounts ) %]
57
            [% IF ( CAN_user_parameters_manage_accounts ) %]
58
                <li><a href="/cgi-bin/koha/admin/debit_types.pl">Debit types</a></li>
58
                <li><a href="/cgi-bin/koha/admin/debit_types.pl">Debit types</a></li>
59
                <li><a href="/cgi-bin/koha/admin/credit_types.pl">Credit types</a></li>
59
            [% END %]
60
            [% END %]
60
            [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_parameters_manage_cash_registers ) %]
61
            [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_parameters_manage_cash_registers ) %]
61
                <li><a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a></li>
62
                <li><a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 113-118 Link Here
113
                [% IF ( CAN_user_parameters_manage_accounts ) %]
113
                [% IF ( CAN_user_parameters_manage_accounts ) %]
114
                    <dt><a href="/cgi-bin/koha/admin/debit_types.pl">Debit types</a></dt>
114
                    <dt><a href="/cgi-bin/koha/admin/debit_types.pl">Debit types</a></dt>
115
                    <dd>Define debit types.</dd>
115
                    <dd>Define debit types.</dd>
116
                    <dt><a href="/cgi-bin/koha/admin/credit_types.pl">Credit types</a></dt>
117
                    <dd>Define credit types.</dd>
116
                [% END %]
118
                [% END %]
117
                [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_parameters_manage_cash_registers ) %]
119
                [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_parameters_manage_cash_registers ) %]
118
                    <dt><a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a></dt>
120
                    <dt><a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/credit_types.tt (+222 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Branches %]
4
[% PROCESS i18n.inc %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Administration &rsaquo;
8
    [% IF op =='add_form' %]
9
       [% t('Credit types') %] &rsaquo;
10
       [% IF credit_type.code %]
11
           [% t('Modify credit type') %]
12
       [% ELSE %]
13
           [% t('New credit type') %]
14
       [% END %]
15
    [% ELSE %]
16
       [% t('Credit types') %]
17
    [% END %]
18
</title>
19
[% INCLUDE 'doc-head-close.inc' %]
20
</head>
21
22
<body id="admin_credit_types" class="admin">
23
[% INCLUDE 'header.inc' %]
24
[% INCLUDE 'prefs-admin-search.inc' %]
25
26
<div id="breadcrumbs">
27
    <a href="/cgi-bin/koha/mainpage.pl">[% t('Home') %]</a>
28
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">[% t('Administration') %]</a>
29
&rsaquo; <a href="/cgi-bin/koha/admin/credit_types.pl">[% t('Credit types') %]</a>
30
[% IF op == 'add_form' %]
31
&rsaquo; [% IF credit_type.code %][% t('Modify credit type') %][% ELSE %][% t('New credit type') %][% END %]
32
[% END %]
33
</div>
34
35
<div class="main container-fluid">
36
    <div class="row">
37
        <div class="col-sm-10 col-sm-push-2">
38
            <main>
39
40
                [% FOREACH m IN messages %]
41
                <div class="dialog [% m.type | html %]">
42
                    [% SWITCH m.code %]
43
                    [% CASE 'success_on_saving' %]
44
                        [% t('Credit type saved successfully.') %]
45
                    [% CASE 'error_on_saving' %]
46
                        [% t('An error occurred when saving this credit type.') %]
47
                    [% CASE 'success_on_archive' %]
48
                        [% t('Credit type archived successfully.') %]
49
                    [% CASE 'success_on_restore' %]
50
                        [% t('Credit type restored successfully.') %]
51
                    [% CASE %]
52
                        [% m.code | html %]
53
                    [% END %]
54
                </div>
55
                [% END %]
56
57
                [% IF op == 'add_form' %]
58
                    [% IF credit_type %]
59
                        <h3>[% t('Modify a credit type') %]</h3>
60
                    [% ELSE %]
61
                        <h3>[% t('New credit type') %]</h3>
62
                    [% END %]
63
64
                    <form action="/cgi-bin/koha/admin/credit_types.pl" name="Aform" method="post" class="validated">
65
                        <input type="hidden" name="op" value="add_validate" />
66
                        <fieldset class="rows">
67
                            <ol>
68
                                <li>
69
                                    <label for="code" class="required">[% t('Credit type code:') %] </label>
70
                                    [% IF credit_type %]
71
                                        <strong>[% credit_type.code | html %]</strong>
72
                                        <input type="hidden" name="code" value="[% code | html %]" />
73
                                    [% ELSE %]
74
                                    <input type="text" name="code" id="code" size="80" maxlength="64" class="required" required="required"><span class="required">[% t('Required. Maximum length is 64 letters') %]</span>
75
                                    [% END %]
76
                                </li>
77
                                <li>
78
                                    <label for="description" class="required">[% t('Description:') %] </label>
79
                                    <input type="text" name="description" id="description" required="required" class="required" size="80" maxlength="100" value="[% credit_type.description | html %]" /> <span class="required">[% t('Required') %]</span>
80
                                </li>
81
                                <li>
82
                                    <label for="can_be_added_manually">[% t('Can be manually added ?') %] </label>
83
                                    [% IF credit_type.can_be_added_manually %]
84
                                        <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" checked="checked" value="1" />
85
                                    [% ELSE %]
86
                                        <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" value="1" />
87
                                    [% END %]
88
                                </li>
89
                                <li>
90
                                    <label for="branches">[% t('Libraries limitation:') %] </label>
91
                                    <select id="branches" name="branches" multiple size="10">
92
                                        <option value="">[% t('All libraries') %]</option>
93
                                        [% FOREACH branch IN branches_loop %]
94
                                        [% IF ( branch.selected ) %]
95
                                        <option selected="selected" value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
96
                                        [% ELSE %]
97
                                        <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
98
                                        [% END %]
99
                                        [% END %]
100
                                    </select>
101
                                    <span>[% t("Select 'All libraries' if this credit type should be available at all libraries. Otherwise select libraries you want to associate credit type with.") %]</span>
102
                                </li>
103
                            </ol>
104
                        </fieldset>
105
106
                        <fieldset class="action">
107
                            <button id="save_credit_type" class="btn btn-default"><i class="fa fa-save"></i> [% t('Save') %]</button>
108
                            <a class="cancel btn-link" href="/cgi-bin/koha/admin/credit_types.pl"><i class="fa fa-times"></i> [% t('Cancel') %]</a>
109
                        </fieldset>
110
                    </form>
111
                [% END %]
112
113
                [% IF op == 'list' %]
114
                    <div id="toolbar" class="btn-toolbar">
115
                        <a class="btn btn-default" id="newcredittype" href="/cgi-bin/koha/admin/credit_types.pl?op=add_form"><i class="fa fa-plus"></i> [% t('New credit type') %]</a>
116
                    </div>
117
118
                    <h3>[% t('Account credit types') %]</h3>
119
                    [% IF credit_types.count %]
120
                        <table id="table_credit_types">
121
                            <thead>
122
                                <th>[% t('Archived') %]</th>
123
                                <th>[% t('System') %]</th>
124
                                <th>[% t('Code') %]</th>
125
                                <th>[% t('Description') %]</th>
126
                                <th>[% t('Available for') %]</th>
127
                                <th>[% t('Library limitations') %]</th>
128
                                <th>[% t('Actions') %]</th>
129
                            </thead>
130
                            <tbody>
131
                                [% FOREACH credit_type IN credit_types %]
132
                                <tr>
133
                                    <td>[% credit_type.archived | html %]</td>
134
                                    <td>[% credit_type.is_system | html %]</td>
135
                                    <td>[% credit_type.code | html %]</td>
136
                                    <td>[% credit_type.description | html %]</td>
137
                                    <td>[% IF credit_type.can_be_added_manually %][% t('Manual credit') %][% END %]</td>
138
                                    <td>
139
                                        [% IF credit_type.library_limits.count > 0 %]
140
                                            [% library_limits_str = "" %]
141
                                            [% FOREACH library IN credit_type.library_limits %]
142
                                                [%- IF loop.first -%]
143
                                                [% library_limits_str = library.branchname _ " (" _ library.branchcode _ ")" %]
144
                                                [% ELSE %]
145
                                                [% library_limits_str = library_limits_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %]
146
                                                [% END %]
147
                                            [% END %]
148
                                            <span class="library_limitation" title="[% library_limits_str | html %]">
149
                                                [% limits_count = credit_type.library_limits.count %]
150
                                                [% tnx('{count} library limitation', '{count} library limitations', limits_count, { count => limits_count }) %]
151
                                        [% ELSE %]
152
                                            [% t('No limitation') %]
153
                                        [% END %]
154
                                    </td>
155
                                    <td class="actions">
156
                                        [% IF !credit_type.is_system && !credit_type.archived %]
157
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=add_form&amp;code=[% credit_type.code | uri %]&type=credit"><i class="fa fa-pencil"></i> [% t('Edit') %]</a>
158
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=archive&amp;code=[% credit_type.code | uri %]"><i class="fa fa-archive"></i> [% t('Archive') %]</a>
159
                                        [% ELSIF credit_type.archived %]
160
                                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=unarchive&amp;code=[% credit_type.code | uri %]"><i class="fa fa-undo"></i> [% t('Restore') %]</a>
161
                                        [% END %]
162
                                    </td>
163
                                </tr>
164
                                [% END %]
165
                            </tbody>
166
                        </table>
167
                    [% ELSE %]
168
                        <div class="dialog message">
169
                            [% t('There are no account credit types defined.') %]
170
                            <a href="/cgi-bin/koha/admin/credit_types.pl?op=add_form">[% t('Create new credit type') %]</a>
171
                        </div>
172
                    [% END %]
173
                [% END %]
174
            </main>
175
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
176
177
        <div class="col-sm-2 col-sm-pull-10">
178
            <aside>
179
                [% INCLUDE 'admin-menu.inc' %]
180
            </aside>
181
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
182
    </div> <!-- /.row -->
183
184
[% MACRO jsinclude BLOCK %]
185
    [% Asset.js("js/admin-menu.js") | $raw %]
186
    [% INCLUDE 'datatables.inc' %]
187
188
    <script>
189
        $(document).ready(function() {
190
            var txtActivefilter = _("Filter system credit types");
191
            var txtInactivefilter = _("Show all credit types");
192
            var table_credit_types = $("#table_credit_types").dataTable($.extend(true, {}, dataTablesDefaults, {
193
                "aoColumnDefs": [
194
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
195
                    { "aTargets": [ 0, 1 ], "bSortable": false, "bVisible": false },
196
                ],
197
                "aaSorting": [[ 0, "asc" ],[ 2, "asc" ]],
198
                "sDom": 'C<"top pager"ilpfB><"#filter_s">tr<"bottom pager"ip>',
199
                "iDisplayLength": 20,
200
                "sPaginationType": "full_numbers"
201
            }));
202
            $("#filter_s").html('<p><a href="#" id="filter_system"><i class="fa fa-filter"></i> '+txtActivefilter+'</a>');
203
            $('#filter_system').click(function(e) {
204
                e.preventDefault();
205
                if ($(this).hasClass('filtered')) {
206
                    var filteredValue = '';
207
                    $(this).html('<i class="fa fa-filter"></i> '+txtActivefilter);
208
                } else { //Not filtered. Let's do it!
209
                    var filteredValue = '0';
210
                    $(this).html('<i class="fa fa-filter"></i> '+txtInactivefilter);
211
                }
212
                table_credit_types.fnFilter(filteredValue, 1, false, false);
213
                $(this).toggleClass('filtered');
214
            });
215
216
            //Start filtered
217
            $('#filter_system').click();
218
        });
219
    </script>
220
[% END %]
221
222
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/members/mancredit.pl (-2 / +1 lines)
Lines 116-122 if ($add) { Link Here
116
else {
116
else {
117
117
118
    my @credit_types = Koha::Account::CreditTypes->search_with_library_limits(
118
    my @credit_types = Koha::Account::CreditTypes->search_with_library_limits(
119
        { can_be_added_manually => 1 },
119
        { can_be_added_manually => 1, archived => 0 },
120
        {}, $library_id );
120
        {}, $library_id );
121
121
122
    $template->param(
122
    $template->param(
123
- 

Return to bug 17702