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

(-)a/C4/Installer.pm (+1 lines)
Lines 307-312 sub load_sql_in_order { Link Here
307
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userflags.sql";
307
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userflags.sql";
308
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql";
308
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql";
309
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql";
309
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql";
310
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql";
310
    foreach my $file (@fnames) {
311
    foreach my $file (@fnames) {
311
        #      warn $file;
312
        #      warn $file;
312
        undef $/;
313
        undef $/;
(-)a/Koha/Exceptions.pm (-1 / +10 lines)
Lines 4-9 use Modern::Perl; Link Here
4
4
5
use Exception::Class (
5
use Exception::Class (
6
6
7
    # General exceptions
7
    'Koha::Exceptions::Exception' => {
8
    'Koha::Exceptions::Exception' => {
8
        description => 'Something went wrong!',
9
        description => 'Something went wrong!',
9
    },
10
    },
Lines 12-18 use Exception::Class ( Link Here
12
        isa => 'Koha::Exceptions::Exception',
13
        isa => 'Koha::Exceptions::Exception',
13
        description => 'Same object already exists',
14
        description => 'Same object already exists',
14
    },
15
    },
15
16
    'Koha::Exceptions::CannotDeleteDefault' => {
17
        isa => 'Koha::Exceptions::Exception',
18
        description => 'The default value cannot be deleted'
19
    },
20
    'Koha::Exceptions::MissingParameter' => {
21
        isa => 'Koha::Exceptions::Exception',
22
        description => 'A required parameter is missing'
23
    },
24
    # Virtualshelves exceptions
16
    'Koha::Exceptions::Virtualshelves::DuplicateObject' => {
25
    'Koha::Exceptions::Virtualshelves::DuplicateObject' => {
17
        isa => 'Koha::Exceptions::DuplicateObject',
26
        isa => 'Koha::Exceptions::DuplicateObject',
18
        description => "Duplicate shelf object",
27
        description => "Duplicate shelf object",
(-)a/Koha/RefundLostItemFeeRule.pm (+63 lines)
Line 0 Link Here
1
package Koha::RefundLostItemFeeRule;
2
3
# Copyright Theke Solutions 2016
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
22
use Koha::Database;
23
use Koha::Exceptions;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::RefundLostItemFeeRule - Koha RefundLostItemFeeRule object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'RefundLostItemFeeRule';
43
}
44
45
=head3 delete
46
47
This is an overloaded delete method. It throws an exception if the wildcard
48
branch is passed (it can only be modified, but not deleted).
49
50
=cut
51
52
sub delete {
53
    my ($self) = @_;
54
55
    if ( $self->branchcode eq '*' ) {
56
        Koha::Exceptions::CannotDeleteDefault->throw;
57
    }
58
59
    return $self->SUPER::delete($self);
60
}
61
62
63
1;
(-)a/Koha/RefundLostItemFeeRules.pm (+145 lines)
Line 0 Link Here
1
package Koha::RefundLostItemFeeRules;
2
3
# Copyright Theke Solutions 2016
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
22
use Koha::Database;
23
use Koha::Exceptions;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'RefundLostItemFeeRule';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::RefundLostItemFeeRule';
51
}
52
53
=head3 should_refund
54
55
Koha::RefundLostItemFeeRules->should_refund()
56
57
Returns a boolean telling if the fee needs to be refund given the
58
passed params, and the current rules/sysprefs configuration.
59
60
=cut
61
62
sub should_refund {
63
64
    my $self = shift;
65
    my $params = shift;
66
67
    return $self->_effective_branch_rule( $self->_choose_branch( $params ) );
68
}
69
70
71
=head3 _effective_branch_rule
72
73
Koha::RefundLostItemFeeRules->_effective_branch_rule
74
75
Given a branch, returns a boolean representing the resulting rule.
76
It tries the branch-specific first. Then falls back to the defined default.
77
78
=cut
79
80
sub _effective_branch_rule {
81
82
    my $self   = shift;
83
    my $branch = shift;
84
85
    my $specific_rule = $self->find({ branchcode => $branch });
86
87
    return ( defined $specific_rule )
88
                ? $specific_rule->refund
89
                : $self->_default_rule;
90
}
91
92
=head3 _choose_branch
93
94
my $branch = Koha::RefundLostItemFeeRules->_choose_branch({
95
                current_branch => 'current_branch_code',
96
                item_home_branch => 'item_home_branch',
97
                item_holding_branch => 'item_holding_branch'
98
});
99
100
Helper function that determines the branch to be used to apply the rule.
101
102
=cut
103
104
sub _choose_branch {
105
106
    my $self = shift;
107
    my $param = shift;
108
109
    my $behaviour = Koha::Config::SysPrefs
110
                        ->find( 'RefundLostOnReturnControl' )
111
                        ->value // 'CheckinLibrary';
112
113
    my $param_mapping = {
114
           CheckinLibrary => 'current_branch',
115
           ItemHomeBranch => 'item_home_branch',
116
        ItemHoldingBranch => 'item_holding_branch'
117
    };
118
119
    my $branch = $param->{ $param_mapping->{ $behaviour } };
120
121
    if ( !defined $branch ) {
122
        Koha::Exceptions::MissingParameter->throw(
123
            "$behaviour requires the " .
124
            $param_mapping->{ $behaviour } .
125
            " param"
126
        );
127
    }
128
129
    return $branch;
130
}
131
132
=head3 _default_rule (internal)
133
134
This function returns the default rule defined for refunding lost
135
item fees on return.
136
137
=cut
138
139
sub _default_rule {
140
    my $self = shift;
141
142
    return $self->find({ branchcode => '*' })->refund;
143
}
144
145
1;
(-)a/Koha/Schema/Result/RefundLostItemFeeRule.pm (+66 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::RefundLostItemFeeRule;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::RefundLostItemFeeRule
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<refund_lost_item_fee_rules>
19
20
=cut
21
22
__PACKAGE__->table("refund_lost_item_fee_rules");
23
24
=head1 ACCESSORS
25
26
=head2 branchcode
27
28
  data_type: 'varchar'
29
  default_value: (empty string)
30
  is_nullable: 0
31
  size: 10
32
33
=head2 refund
34
35
  data_type: 'tinyint'
36
  default_value: 0
37
  is_nullable: 0
38
39
=cut
40
41
__PACKAGE__->add_columns(
42
  "branchcode",
43
  { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 },
44
  "refund",
45
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
46
);
47
48
=head1 PRIMARY KEY
49
50
=over 4
51
52
=item * L</branchcode>
53
54
=back
55
56
=cut
57
58
__PACKAGE__->set_primary_key("branchcode");
59
60
61
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-05-31 02:45:35
62
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K+2D3R+JxrovgvjdqA8xdw
63
64
65
# You can replace this text with custom code or comments, and it will be preserved on regeneration
66
1;
(-)a/installer/data/mysql/kohastructure.sql (+11 lines)
Lines 868-873 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
868
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
868
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
869
869
870
--
870
--
871
-- Table structure for table `refund_lost_item_fee_rules`
872
--
873
874
DROP TABLE IF EXISTS `refund_lost_item_fee_rules`;
875
CREATE TABLE `refund_lost_item_fee_rules` ( -- refund lost item fee rules tbale
876
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
877
  `refund` tinyint(1) NOT NULL default 0, -- control wether to refund lost item fees on return
878
  PRIMARY KEY  (`branchcode`)
879
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
880
881
--
871
-- Table structure for table `items`
882
-- Table structure for table `items`
872
--
883
--
873
884
(-)a/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql (-1 / +2 lines)
Line 0 Link Here
0
- 
1
-- Default refund lost item fee rule
2
INSERT INTO refund_lost_item_fee_rules (branchcode,refund) VALUES ( '*', '1' );

Return to bug 14048