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

(-)a/C4/Overdues.pm (-11 / +16 lines)
Lines 742-759 sub GetOverduesForBranch { Link Here
742
sub GetOverdueMessageTransportTypes {
742
sub GetOverdueMessageTransportTypes {
743
    my ( $branchcode, $categorycode, $letternumber ) = @_;
743
    my ( $branchcode, $categorycode, $letternumber ) = @_;
744
    return unless $categorycode and $letternumber;
744
    return unless $categorycode and $letternumber;
745
    my $dbh = C4::Context->dbh;
745
    my $rule = Koha::OverdueRules->search(
746
    my $sth = $dbh->prepare("
746
        {
747
        SELECT message_transport_type
747
            branchcode   => $branchcode,
748
        FROM overduerules odr LEFT JOIN overduerules_transport_types ott USING (overduerules_id)
748
            categorycode => $categorycode,
749
        WHERE branchcode = ?
749
            letternumber => $letternumber,
750
          AND categorycode = ?
750
        },
751
          AND letternumber = ?
751
        {
752
    ");
752
            join => 'overduerules_transport_types',
753
    $sth->execute( $branchcode, $categorycode, $letternumber );
753
        }
754
    )->next;
755
756
    return [] unless $rule;
757
758
    my $transport_types = $rule->transport_types;
754
    my @mtts;
759
    my @mtts;
755
    while ( my $mtt = $sth->fetchrow ) {
760
    while ( my $mtt = $transport_types->next ) {
756
        push @mtts, $mtt;
761
        push @mtts, $mtt->message_transport_type;
757
    }
762
    }
758
763
759
    # Put 'print' in first if exists
764
    # Put 'print' in first if exists
(-)a/Koha/OverdueRule.pm (+56 lines)
Line 0 Link Here
1
package Koha::OverdueRule;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::OverdueRule - Koha OverdueRule Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=head3 message_transport_types
35
36
my $transport_types = $rule->transport_types;
37
38
=cut
39
40
sub transport_types {
41
    my ( $self ) = @_;
42
43
    my $rs = $self->_result->overduerules_transport_types;
44
    return unless $rs;
45
    return Koha::OverdueRules::TransportTypes->_new_from_dbic($rs);
46
}
47
48
=head3 type
49
50
=cut
51
52
sub _type {
53
    return 'Overduerule';
54
}
55
56
1;
(-)a/Koha/OverdueRules.pm (+48 lines)
Line 0 Link Here
1
package Koha::OverdueRules;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::OverdueRule;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::OverdueRules - Koha OverdueRule Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=head3 _type
37
38
=cut
39
40
sub _type {
41
    return 'Overduerule';
42
}
43
44
sub object_class {
45
    return 'Koha::OverdueRule';
46
}
47
48
1;
(-)a/Koha/OverdueRules/TransportType.pm (+42 lines)
Line 0 Link Here
1
package Koha::OverdueRules::TransportType;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::OverdueRules::TransportType - Koha OverdueRules::TransportType Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=head3 _type
35
36
=cut
37
38
sub _type {
39
    return 'OverduerulesTransportType';
40
}
41
42
1;
(-)a/Koha/OverdueRules/TransportTypes.pm (+48 lines)
Line 0 Link Here
1
package Koha::OverdueRules::TransportTypes;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::OverdueRules::TransportType;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::OverdueRules::TransportTypes - Koha OverdueRules::TransportType Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=head3 _type
37
38
=cut
39
40
sub _type {
41
    return 'OverduerulesTransportType';
42
}
43
44
sub object_class {
45
    return 'Koha::OverdueRules::TransportType';
46
}
47
48
1;
(-)a/installer/data/mysql/atomicupdate/bug_18086.perl (+20 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        DELETE overduerules FROM overduerules LEFT JOIN categories USING ( categorycode ) where categories.categorycode IS NULL;
5
    });
6
7
    $dbh->do(q{
8
        DELETE overduerules FROM overduerules LEFT JOIN branches USING ( branchcode ) where branches.branchcode IS NULL;
9
    });
10
11
    $dbh->do(q{
12
        ALTER TABLE overduerules
13
        MODIFY `branchcode` varchar(10) NULL default NULL,
14
        MODIFY `categorycode` varchar(10) NOT NULL,
15
        ADD CONSTRAINT `fk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
16
        ADD CONSTRAINT `fk_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE;
17
    });
18
19
    NewVersion( $DBversion, 18086, "Add FK constraints for branchcode and categorycode");
20
}
(-)a/installer/data/mysql/kohastructure.sql (-3 / +5 lines)
Lines 1224-1231 CREATE TABLE `oai_sets_biblios` ( Link Here
1224
DROP TABLE IF EXISTS `overduerules`;
1224
DROP TABLE IF EXISTS `overduerules`;
1225
CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1225
CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1226
  `overduerules_id` int(11) NOT NULL AUTO_INCREMENT, -- unique identifier for the overduerules
1226
  `overduerules_id` int(11) NOT NULL AUTO_INCREMENT, -- unique identifier for the overduerules
1227
  `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table to define which branch this rule is for (if blank it's all libraries)
1227
  `branchcode` varchar(10) NULL default NULL, -- foreign key from the branches table to define which branch this rule is for (if blank it's all libraries)
1228
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table to define which patron category this rule is for
1228
  `categorycode` varchar(10) NOT NULL, -- foreign key from the categories table to define which patron category this rule is for
1229
  `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
1229
  `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
1230
  `letter1` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the first notice
1230
  `letter1` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the first notice
1231
  `debarred1` varchar(1) default 0, -- is the patron restricted when the first notice is sent (1 for yes, 0 for no)
1231
  `debarred1` varchar(1) default 0, -- is the patron restricted when the first notice is sent (1 for yes, 0 for no)
Lines 1236-1242 CREATE TABLE `overduerules` ( -- overdue notice status and triggers Link Here
1236
  `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1236
  `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1237
  `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1237
  `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1238
  PRIMARY KEY  (`overduerules_id`),
1238
  PRIMARY KEY  (`overduerules_id`),
1239
  UNIQUE KEY `overduerules_branch_cat` (`branchcode`,`categorycode`)
1239
  UNIQUE KEY `overduerules_branch_cat` (`branchcode`,`categorycode`),
1240
  CONSTRAINT `fk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
1241
  CONSTRAINT `fk_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE
1240
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1242
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1241
1243
1242
-- Table structure for table `pending_offline_operations`
1244
-- Table structure for table `pending_offline_operations`
(-)a/tools/overduerules.pl (-51 / +39 lines)
Lines 27-33 use C4::Letters; Link Here
27
use C4::Members;
27
use C4::Members;
28
use C4::Overdues;
28
use C4::Overdues;
29
use Koha::Libraries;
29
use Koha::Libraries;
30
30
use Koha::OverdueRules;
31
use Koha::OverdueRules::TransportTypes;
31
use Koha::Patron::Categories;
32
use Koha::Patron::Categories;
32
33
33
our $input = new CGI;
34
our $input = new CGI;
Lines 76-82 $branch = Link Here
76
  : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch()
77
  : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch()
77
  : Koha::Libraries->search->count() == 1                              ? undef
78
  : Koha::Libraries->search->count() == 1                              ? undef
78
  :                                                                      undef;
79
  :                                                                      undef;
79
$branch ||= q{};
80
$branch ||= undef;
80
81
81
my $op = $input->param('op');
82
my $op = $input->param('op');
82
$op ||= q{};
83
$op ||= q{};
Lines 88-109 my %temphash; Link Here
88
my $input_saved = 0;
89
my $input_saved = 0;
89
if ($op eq 'save') {
90
if ($op eq 'save') {
90
    my @names=$input->multi_param();
91
    my @names=$input->multi_param();
91
    my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM overduerules WHERE branchcode=? AND categorycode=?");
92
93
    my $sth_insert = $dbh->prepare("INSERT INTO overduerules (branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
94
    my $sth_update=$dbh->prepare("UPDATE overduerules SET delay1=?, letter1=?, debarred1=?, delay2=?, letter2=?, debarred2=?, delay3=?, letter3=?, debarred3=? WHERE branchcode=? AND categorycode=?");
95
    my $sth_delete=$dbh->prepare("DELETE FROM overduerules WHERE branchcode=? AND categorycode=?");
96
    my $sth_insert_mtt = $dbh->prepare("
97
        INSERT INTO overduerules_transport_types(
98
            overduerules_id, letternumber, message_transport_type
99
        ) VALUES (
100
            (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?), ?, ?
101
        )
102
    ");
103
    my $sth_delete_mtt = $dbh->prepare("
104
        DELETE FROM overduerules_transport_types
105
        WHERE overduerules_id = (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?)
106
    ");
107
92
108
    foreach my $key (@names){
93
    foreach my $key (@names){
109
            # ISSUES
94
            # ISSUES
Lines 159-199 if ($op eq 'save') { Link Here
159
            if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"}))
144
            if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"}))
160
                or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"}))
145
                or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"}))
161
                or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) {
146
                or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) {
162
                    $sth_search->execute($branch,$bor);
147
                    my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $bor });
163
                    my $res = $sth_search->fetchrow_hashref();
148
                    if ( $overdue_rule ) {
164
                    if ($res->{'total'}>0) {
149
                        $overdue_rule->update({
165
                        $sth_update->execute(
150
                            delay1    => $temphash{$bor}->{"delay1"}    ? $temphash{$bor}->{"delay1"}    : undef,
166
                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:undef),
151
                            letter1   => $temphash{$bor}->{"letter1"}   ? $temphash{$bor}->{"letter1"}   : "",
167
                            ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
152
                            debarred1 => $temphash{$bor}->{"debarred1"} ? $temphash{$bor}->{"debarred1"} : 0,
168
                            ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
153
                            delay2    => $temphash{$bor}->{"delay2"}    ? $temphash{$bor}->{"delay2"}    : undef,
169
                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:undef),
154
                            letter2   => $temphash{$bor}->{"letter2"}   ? $temphash{$bor}->{"letter2"}   : "",
170
                            ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
155
                            debarred2 => $temphash{$bor}->{"debarred2"} ? $temphash{$bor}->{"debarred2"} : 0,
171
                            ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
156
                            delay3    => $temphash{$bor}->{"delay3"}    ? $temphash{$bor}->{"delay3"}    : undef,
172
                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:undef),
157
                            letter3   => $temphash{$bor}->{"letter3"}   ? $temphash{$bor}->{"letter3"}   : "",
173
                            ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
158
                            debarred3 => $temphash{$bor}->{"debarred3"} ? $temphash{$bor}->{"debarred3"} : 0,
174
                            ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0),
159
                        });
175
                            $branch ,$bor
176
                            );
177
                    } else {
160
                    } else {
178
                        $sth_insert->execute($branch,$bor,
161
                        $overdue_rule = Koha::OverdueRule->new({
179
                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
162
                            branchcode => $branch,
180
                            ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
163
                            categorycode => $bor,
181
                            ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
164
                            delay1    => $temphash{$bor}->{"delay1"}    ? $temphash{$bor}->{"delay1"}    : undef ,
182
                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
165
                            letter1   => $temphash{$bor}->{"letter1"}   ? $temphash{$bor}->{"letter1"}   : "" ,
183
                            ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
166
                            debarred1 => $temphash{$bor}->{"debarred1"} ? $temphash{$bor}->{"debarred1"} : 0 ,
184
                            ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
167
                            delay2    => $temphash{$bor}->{"delay2"}    ? $temphash{$bor}->{"delay2"}    : undef ,
185
                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
168
                            letter2   => $temphash{$bor}->{"letter2"}   ? $temphash{$bor}->{"letter2"}   : "" ,
186
                            ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
169
                            debarred2 => $temphash{$bor}->{"debarred2"} ? $temphash{$bor}->{"debarred2"} : 0 ,
187
                            ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0)
170
                            delay3    => $temphash{$bor}->{"delay3"}    ? $temphash{$bor}->{"delay3"}    : undef ,
188
                            );
171
                            letter3   => $temphash{$bor}->{"letter3"}   ? $temphash{$bor}->{"letter3"}   : "" ,
172
                            debarred3 => $temphash{$bor}->{"debarred3"} ? $temphash{$bor}->{"debarred3"} : 0 ,
173
                        })->store();
189
                    }
174
                    }
190
175
191
                    $sth_delete_mtt->execute( $branch, $bor );
176
                    Koha::OverdueRules::TransportTypes->search({ overduerules_id => $overdue_rule->id })->delete();
192
                    for my $letternumber ( 1..3 ) {
177
                    for my $letternumber ( 1..3 ) {
193
                        my @mtt = $input->multi_param( "mtt${letternumber}-$bor" );
178
                        my @mtt = $input->multi_param( "mtt${letternumber}-$bor" );
194
                        next unless @mtt;
179
                        next unless @mtt;
195
                        for my $mtt ( @mtt ) {
180
                        for my $mtt ( @mtt ) {
196
                            $sth_insert_mtt->execute( $branch, $bor, $letternumber, $mtt);
181
                            Koha::OverdueRules::TransportType->new({
182
                                letternumber           => $letternumber,
183
                                message_transport_type => $mtt,
184
                                overduerules_id        => $overdue_rule->id,
185
                            })->store();
197
                        }
186
                        }
198
                    }
187
                    }
199
                }
188
                }
Lines 201-207 if ($op eq 'save') { Link Here
201
    }
190
    }
202
    unless ($err) {
191
    unless ($err) {
203
        for my $category_code (@rows_to_delete) {
192
        for my $category_code (@rows_to_delete) {
204
            $sth_delete->execute($branch, $category_code);
193
            my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $category_code });
194
            $overdue_rule->delete if $overdue_rule;
205
        }
195
        }
206
        $template->param(datasaved => 1);
196
        $template->param(datasaved => 1);
207
        $input_saved = 1;
197
        $input_saved = 1;
Lines 252-260 for my $patron_category (@patron_categories) { Link Here
252
        }
242
        }
253
    } else {
243
    } else {
254
    #getting values from table
244
    #getting values from table
255
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
245
        my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $patron_category->categorycode });
256
        $sth2->execute($branch,$patron_category->categorycode);
246
        my $dat = $overdue_rule ? $overdue_rule->unblessed : {};
257
        my $dat=$sth2->fetchrow_hashref;
258
        for my $i ( 1..3 ){
247
        for my $i ( 1..3 ){
259
            my %row = (
248
            my %row = (
260
                overduename => $patron_category->categorycode,
249
                overduename => $patron_category->categorycode,
261
- 

Return to bug 18086