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

(-)a/Koha/Account/CreditType.pm (+74 lines)
Line 0 Link Here
1
package Koha::Account::CreditType;
2
3
# Copyright PTFS Europe 2019
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use List::Util qw/any/;
22
23
use Koha::Database;
24
use Koha::Exceptions;
25
26
use base qw(Koha::Object Koha::Object::Limit::Library);
27
28
=head1 NAME
29
30
Koha::Account::CreditType - Koha Account credit type Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 delete
39
40
Overridden delete method to prevent system default deletions
41
42
=cut
43
44
sub delete {
45
    my ($self) = @_;
46
47
    Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system;
48
49
    return $self->SUPER::delete;
50
}
51
52
=head3 _library_limits
53
54
Configurable library limits
55
56
=cut
57
58
sub _library_limits {
59
    return {
60
        class   => "AccountCreditTypesBranch",
61
        id      => "credit_type_code",
62
        library => "branchcode",
63
    };
64
}
65
66
=head3 type
67
68
=cut
69
70
sub _type {
71
    return 'AccountCreditType';
72
}
73
74
1;
(-)a/Koha/Account/CreditTypes.pm (+71 lines)
Line 0 Link Here
1
package Koha::Account::CreditTypes;
2
3
# Copyright PTFS Europe 2019
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use List::Util qw/any/;
22
23
use Koha::Database;
24
use Koha::Account::CreditType;
25
26
use base qw(Koha::Objects Koha::Objects::Limit::Library);
27
28
=head1 NAME
29
30
Koha::Account::CreditTypes - Koha Account credit types Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=head3 delete
37
38
Overridden delete method to prevent system default deletions
39
40
=cut
41
42
sub delete {
43
    my ($self) = @_;
44
45
    my @set = $self->as_list;
46
    for my $type (@set) {
47
        if ( $type->is_system ) {
48
            Koha::Exceptions::CannotDeleteDefault->throw;
49
        }
50
    }
51
52
    return $self->SUPER::delete;
53
}
54
55
=head3 type
56
57
=cut
58
59
sub _type {
60
    return 'AccountCreditType';
61
}
62
63
=head3 object_class
64
65
=cut
66
67
sub object_class {
68
    return 'Koha::Account::CreditType';
69
}
70
71
1;
(-)a/Koha/Schema/Result/AccountCreditType.pm (-1 / +10 lines)
Lines 108-113 __PACKAGE__->has_many( Link Here
108
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-14 09:59:52
108
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-14 09:59:52
109
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Uycu/23b681kWHNX+/gNiw
109
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Uycu/23b681kWHNX+/gNiw
110
110
111
__PACKAGE__->add_columns(
112
    '+is_system' => { is_boolean => 1 }
113
);
114
115
sub koha_objects_class {
116
    'Koha::Account::CreditTypes';
117
}
118
sub koha_object_class {
119
    'Koha::Account::CreditType';
120
}
111
121
112
# You can replace this text with custom code or comments, and it will be preserved on regeneration
113
1;
122
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt (-38 / +49 lines)
Lines 12-67 Link Here
12
[% INCLUDE 'header.inc' %]
12
[% INCLUDE 'header.inc' %]
13
[% INCLUDE 'patron-search.inc' %]
13
[% INCLUDE 'patron-search.inc' %]
14
14
15
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Manual credit</div>
15
<div id="breadcrumbs">
16
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
17
    <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo;
18
    Manual credit
19
</div>
16
20
17
<div class="main container-fluid">
21
<div class="main container-fluid">
18
    <div class="row">
22
    <div class="row">
19
        <div class="col-sm-10 col-sm-push-2">
23
        <div class="col-sm-10 col-sm-push-2">
20
            <main>
24
            <main>
21
25
22
[% INCLUDE 'members-toolbar.inc' %]
26
            [% INCLUDE 'members-toolbar.inc' %]
23
27
            
24
<!-- The manual invoice and credit buttons -->
28
            <!-- The manual invoice and credit buttons -->
25
<div class="statictabs">
29
            <div class="statictabs">
26
<ul>
30
                <ul>
27
    <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li>
31
                    <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li>
28
    <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li>
32
                    <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li>
29
    <li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li>
33
                    <li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li>
30
    <li class="active"><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li>
34
                    <li class="active"><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li>
31
</ul>
35
                </ul>
32
<div class="tabs-container">
36
                <div class="tabs-container">
33
37
                
34
<form action="/cgi-bin/koha/members/mancredit.pl" method="post" id="mancredit">
38
                <form action="/cgi-bin/koha/members/mancredit.pl" method="post" id="mancredit">
35
<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
39
                    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
36
    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
40
                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
37
41
                
38
<fieldset class="rows">
42
                    <fieldset class="rows">
39
<legend>Manual credit</legend><ol>
43
                        <legend>Manual credit</legend>
40
	<li><label for="type">Credit type: </label><select name="type" id="type">
44
                        <ol>
41
<option value="credit">Credit</option>
45
                            <li>
42
<option value="forgiven">Forgiven</option>
46
                                <label for="type">Credit type: </label>
43
</select></li>
47
                                <select name="type" id="type">
44
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
48
                                    [% FOREACH credit_type IN credit_types %]
45
	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
49
                                    <option value="[% credit_type.code | html %]">[% credit_type.description | html %]</option>
46
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
50
                                    [% END %]
47
    <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
51
                                </select>
48
</ol></fieldset>
52
                            </li>
49
53
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
50
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
54
                            <li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
51
</form>
55
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
52
56
                            <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
53
</div></div>
57
                        </ol>
54
58
                    </fieldset>
59
                
60
                    <fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
61
                </form>
62
                
63
                </div>
64
            </div>
65
                
55
            </main>
66
            </main>
56
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
67
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
57
68
            
58
        <div class="col-sm-2 col-sm-pull-10">
69
        <div class="col-sm-2 col-sm-pull-10">
59
            <aside>
70
            <aside>
60
                [% INCLUDE 'circ-menu.inc' %]
71
                [% INCLUDE 'circ-menu.inc' %]
61
            </aside>
72
            </aside>
62
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
73
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
63
     </div> <!-- /.row -->
74
    </div> <!-- /.row -->
64
75
            
65
[% MACRO jsinclude BLOCK %]
76
[% MACRO jsinclude BLOCK %]
66
    [% INCLUDE 'str/members-menu.inc' %]
77
    [% INCLUDE 'str/members-menu.inc' %]
67
    [% Asset.js("js/members-menu.js") | $raw %]
78
    [% Asset.js("js/members-menu.js") | $raw %]
Lines 72-76 Link Here
72
        });
83
        });
73
    </script>
84
    </script>
74
[% END %]
85
[% END %]
75
86
    
76
[% INCLUDE 'intranet-bottom.inc' %]
87
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/members/mancredit.pl (-35 / +54 lines)
Lines 3-9 Link Here
3
#written 11/1/2000 by chris@katipo.oc.nz
3
#written 11/1/2000 by chris@katipo.oc.nz
4
#script to display borrowers account details
4
#script to display borrowers account details
5
5
6
7
# Copyright 2000-2002 Katipo Communications
6
# Copyright 2000-2002 Katipo Communications
8
# Copyright 2010 BibLibre
7
# Copyright 2010 BibLibre
9
#
8
#
Lines 35-52 use C4::Items; Link Here
35
use Koha::Items;
34
use Koha::Items;
36
use Koha::Patrons;
35
use Koha::Patrons;
37
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
38
use Koha::Token;
37
use Koha::Account::CreditTypes;
39
38
40
my $input=new CGI;
39
use Koha::Token;
41
40
42
my ($template, $loggedinuser, $cookie) = get_template_and_user(
41
my $input = new CGI;
42
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
    {
43
    {
44
        template_name   => "members/mancredit.tt",
44
        template_name   => "members/mancredit.tt",
45
        query           => $input,
45
        query           => $input,
46
        type            => "intranet",
46
        type            => "intranet",
47
        authnotrequired => 0,
47
        authnotrequired => 0,
48
        flagsrequired   => { borrowers     => 'edit_borrowers',
48
        flagsrequired   => {
49
                             updatecharges => 'remaining_permissions' }
49
            borrowers     => 'edit_borrowers',
50
            updatecharges => 'remaining_permissions'
51
        }
50
    }
52
    }
51
);
53
);
52
54
Lines 54-78 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; Link Here
54
my $borrowernumber = $input->param('borrowernumber');
56
my $borrowernumber = $input->param('borrowernumber');
55
my $patron         = Koha::Patrons->find($borrowernumber);
57
my $patron         = Koha::Patrons->find($borrowernumber);
56
58
57
output_and_exit_if_error( $input, $cookie, $template,
59
output_and_exit_if_error(
58
    { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
60
    $input, $cookie,
59
61
    $template,
60
my $add = $input->param('add');
62
    {
63
        module         => 'members',
64
        logged_in_user => $logged_in_user,
65
        current_patron => $patron
66
    }
67
);
61
68
62
if ($add){
69
my $library_id =
70
  C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
63
71
72
my $add = $input->param('add');
73
if ($add) {
64
    output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' )
74
    output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' )
65
        unless Koha::Token->new->check_csrf( {
75
      unless Koha::Token->new->check_csrf(
76
        {
66
            session_id => scalar $input->cookie('CGISESSID'),
77
            session_id => scalar $input->cookie('CGISESSID'),
67
            token  => scalar $input->param('csrf_token'),
78
            token      => scalar $input->param('csrf_token'),
68
        });
79
        }
80
      );
69
81
70
    # Note: If the logged in user is not allowed to see this patron an invoice can be forced
82
# Note: If the logged in user is not allowed to see this patron an invoice can be forced
71
    # Here we are trusting librarians not to hack the system
83
# Here we are trusting librarians not to hack the system
72
    my $barcode = $input->param('barcode');
84
    my $barcode = $input->param('barcode');
73
    my $item_id;
85
    my $item_id;
74
    if ($barcode) {
86
    if ($barcode) {
75
        my $item = Koha::Items->find({barcode => $barcode});
87
        my $item = Koha::Items->find( { barcode => $barcode } );
76
        $item_id = $item->itemnumber if $item;
88
        $item_id = $item->itemnumber if $item;
77
    }
89
    }
78
    my $description = $input->param('desc');
90
    my $description = $input->param('desc');
Lines 80-109 if ($add){ Link Here
80
    my $amount      = $input->param('amount') || 0;
92
    my $amount      = $input->param('amount') || 0;
81
    my $type        = $input->param('type');
93
    my $type        = $input->param('type');
82
94
83
    my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
95
    $patron->account->add_credit(
84
96
        {
85
    $patron->account->add_credit({
97
            amount      => $amount,
86
        amount      => $amount,
98
            description => $description,
87
        description => $description,
99
            item_id     => $item_id,
88
        item_id     => $item_id,
100
            library_id  => $library_id,
89
        library_id  => $library_id,
101
            note        => $note,
90
        note        => $note,
102
            type        => $type,
91
        type        => $type,
103
            user_id     => $logged_in_user->id,
92
        user_id     => $logged_in_user->id,
104
            interface   => C4::Context->interface
93
        interface   => C4::Context->interface
105
        }
94
    });
106
    );
95
107
96
    if ( C4::Context->preference('AccountAutoReconcile') ) {
108
    if ( C4::Context->preference('AccountAutoReconcile') ) {
97
        $patron->account->reconcile_balance;
109
        $patron->account->reconcile_balance;
98
    }
110
    }
99
111
100
    print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
112
    print $input->redirect(
113
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
114
    exit;
115
}
116
else {
117
118
    my @credit_types = Koha::Account::CreditTypes->search_with_library_limits(
119
        { can_be_added_manually => 1 },
120
        {}, $library_id );
101
121
102
} else {
103
    $template->param(
122
    $template->param(
104
        patron     => $patron,
123
        patron       => $patron,
105
        finesview  => 1,
124
        credit_types => \@credit_types,
106
        csrf_token => Koha::Token->new->generate_csrf(
125
        finesview    => 1,
126
        csrf_token   => Koha::Token->new->generate_csrf(
107
            { session_id => scalar $input->cookie('CGISESSID') }
127
            { session_id => scalar $input->cookie('CGISESSID') }
108
        ),
128
        ),
109
    );
129
    );
110
- 

Return to bug 23805