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

(-)a/C4/Overdues.pm (-11 / +16 lines)
Lines 765-782 sub GetOverduesForBranch { Link Here
765
sub GetOverdueMessageTransportTypes {
765
sub GetOverdueMessageTransportTypes {
766
    my ( $branchcode, $categorycode, $letternumber ) = @_;
766
    my ( $branchcode, $categorycode, $letternumber ) = @_;
767
    return unless $categorycode and $letternumber;
767
    return unless $categorycode and $letternumber;
768
    my $dbh = C4::Context->dbh;
768
    my $rule = Koha::OverdueRules->search(
769
    my $sth = $dbh->prepare("
769
        {
770
        SELECT message_transport_type
770
            branchcode   => $branchcode,
771
        FROM overduerules odr LEFT JOIN overduerules_transport_types ott USING (overduerules_id)
771
            categorycode => $categorycode,
772
        WHERE branchcode = ?
772
            letternumber => $letternumber,
773
          AND categorycode = ?
773
        },
774
          AND letternumber = ?
774
        {
775
    ");
775
            join => 'overduerules_transport_types',
776
    $sth->execute( $branchcode, $categorycode, $letternumber );
776
        }
777
    )->next;
778
779
    return [] unless $rule;
780
781
    my $transport_types = $rule->transport_types;
777
    my @mtts;
782
    my @mtts;
778
    while ( my $mtt = $sth->fetchrow ) {
783
    while ( my $mtt = $transport_types->next ) {
779
        push @mtts, $mtt;
784
        push @mtts, $mtt->message_transport_type;
780
    }
785
    }
781
786
782
    # Put 'print' in first if exists
787
    # Put 'print' in first if exists
(-)a/Koha/OverdueRule.pm (+28 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object);
23
23
24
use Koha::Database;
25
24
=head1 NAME
26
=head1 NAME
25
27
26
Koha::OverdueRule - Koha Overdue rule object class
28
Koha::OverdueRule - Koha Overdue rule object class
Lines 37-40 sub _type { Link Here
37
    return 'Overduerule';
39
    return 'Overduerule';
38
}
40
}
39
41
42
=head3 object_class
43
44
=cut
45
46
sub object_class {
47
    return 'Koha::OverdueRule';
48
}
49
50
51
52
=head3 transport_types
53
54
my $transport_types = $rule->transport_types;
55
56
=cut
57
58
59
sub transport_types {
60
    my ( $self ) = @_;
61
62
    my $rs = $self->_result->overduerules_transport_types;
63
    return unless $rs;
64
    return Koha::OverdueRules::TransportTypes->_new_from_dbic($rs);
65
}
66
67
40
1;
68
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 (+52 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
=head3 object_class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::OverdueRules::TransportType';
50
}
51
52
1;
(-)a/installer/data/mysql/atomicupdate/bug_18086.perl (+38 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        UPDATE overduerules SET categorycode = NULL WHERE categorycode = "";
5
    });
6
7
    $dbh->do(q{
8
        DELETE overduerules FROM overduerules
9
        LEFT JOIN categories USING ( categorycode )
10
        WHERE
11
            overduerules.categorycode IS NOT NULL
12
          AND
13
            categories.categorycode IS NULL;
14
    });
15
16
    $dbh->do(q{
17
        UPDATE overduerules SET branchcode = NULL WHERE branchcode = "";
18
    });
19
20
    $dbh->do(q{
21
        DELETE overduerules FROM overduerules
22
        LEFT JOIN branches USING ( branchcode )
23
        WHERE
24
            branches.branchcode IS NULL
25
          AND
26
            overduerules.branchcode IS NOT NULL
27
    });
28
29
    $dbh->do(q{
30
        ALTER TABLE overduerules
31
        MODIFY `branchcode` varchar(10) NULL default NULL,
32
        MODIFY `categorycode` varchar(10) NOT NULL,
33
        ADD CONSTRAINT `fk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
34
        ADD CONSTRAINT `fk_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE;
35
    });
36
37
    NewVersion( $DBversion, 18086, "Add FK constraints for branchcode and categorycode");
38
}
(-)a/installer/data/mysql/kohastructure.sql (-3 / +5 lines)
Lines 4962-4969 DROP TABLE IF EXISTS `overduerules`; Link Here
4962
/*!40101 SET character_set_client = utf8 */;
4962
/*!40101 SET character_set_client = utf8 */;
4963
CREATE TABLE `overduerules` (
4963
CREATE TABLE `overduerules` (
4964
  `overduerules_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier for the overduerules',
4964
  `overduerules_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier for the overduerules',
4965
  `branchcode` varchar(10) NOT NULL DEFAULT '' COMMENT 'foreign key from the branches table to define which branch this rule is for (if blank it''s all libraries)',
4965
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'foreign key from the branches table to define which branch this rule is for (if blank it''s all libraries)',
4966
  `categorycode` varchar(10) NOT NULL DEFAULT '' COMMENT 'foreign key from the categories table to define which patron category this rule is for',
4966
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'foreign key from the categories table to define which patron category this rule is for',
4967
  `delay1` int(4) DEFAULT NULL COMMENT 'number of days after the item is overdue that the first notice is sent',
4967
  `delay1` int(4) DEFAULT NULL COMMENT 'number of days after the item is overdue that the first notice is sent',
4968
  `letter1` varchar(20) DEFAULT NULL COMMENT 'foreign key from the letter table to define which notice should be sent as the first notice',
4968
  `letter1` varchar(20) DEFAULT NULL COMMENT 'foreign key from the letter table to define which notice should be sent as the first notice',
4969
  `debarred1` varchar(1) DEFAULT '0' COMMENT 'is the patron restricted when the first notice is sent (1 for yes, 0 for no)',
4969
  `debarred1` varchar(1) DEFAULT '0' COMMENT 'is the patron restricted when the first notice is sent (1 for yes, 0 for no)',
Lines 4974-4980 CREATE TABLE `overduerules` ( Link Here
4974
  `letter3` varchar(20) DEFAULT NULL COMMENT 'foreign key from the letter table to define which notice should be sent as the third notice',
4974
  `letter3` varchar(20) DEFAULT NULL COMMENT 'foreign key from the letter table to define which notice should be sent as the third notice',
4975
  `debarred3` int(1) DEFAULT 0 COMMENT 'is the patron restricted when the third notice is sent (1 for yes, 0 for no)',
4975
  `debarred3` int(1) DEFAULT 0 COMMENT 'is the patron restricted when the third notice is sent (1 for yes, 0 for no)',
4976
  PRIMARY KEY (`overduerules_id`),
4976
  PRIMARY KEY (`overduerules_id`),
4977
  UNIQUE KEY `overduerules_branch_cat` (`branchcode`,`categorycode`)
4977
  UNIQUE KEY `overduerules_branch_cat` (`branchcode`,`categorycode`),
4978
  CONSTRAINT `fk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
4979
  CONSTRAINT `fk_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE
4978
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4980
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4979
/*!40101 SET character_set_client = @saved_cs_client */;
4981
/*!40101 SET character_set_client = @saved_cs_client */;
4980
4982
(-)a/tools/overduerules.pl (-51 / +39 lines)
Lines 26-32 use C4::Letters; Link Here
26
use C4::Members;
26
use C4::Members;
27
use C4::Overdues qw( GetOverdueMessageTransportTypes );
27
use C4::Overdues qw( GetOverdueMessageTransportTypes );
28
use Koha::Libraries;
28
use Koha::Libraries;
29
29
use Koha::OverdueRules;
30
use Koha::OverdueRules::TransportTypes;
30
use Koha::Patron::Categories;
31
use Koha::Patron::Categories;
31
32
32
our $input = CGI->new;
33
our $input = CGI->new;
Lines 73-79 $branch = Link Here
73
  : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch()
74
  : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch()
74
  : Koha::Libraries->search->count() == 1                              ? undef
75
  : Koha::Libraries->search->count() == 1                              ? undef
75
  :                                                                      undef;
76
  :                                                                      undef;
76
$branch ||= q{};
77
$branch ||= undef;
77
78
78
my $op = $input->param('op');
79
my $op = $input->param('op');
79
$op ||= q{};
80
$op ||= q{};
Lines 85-106 my %temphash; Link Here
85
my $input_saved = 0;
86
my $input_saved = 0;
86
if ($op eq 'cud-save') {
87
if ($op eq 'cud-save') {
87
    my @names=$input->multi_param();
88
    my @names=$input->multi_param();
88
    my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM overduerules WHERE branchcode=? AND categorycode=?");
89
90
    my $sth_insert = $dbh->prepare("INSERT INTO overduerules (branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
91
    my $sth_update=$dbh->prepare("UPDATE overduerules SET delay1=?, letter1=?, debarred1=?, delay2=?, letter2=?, debarred2=?, delay3=?, letter3=?, debarred3=? WHERE branchcode=? AND categorycode=?");
92
    my $sth_delete=$dbh->prepare("DELETE FROM overduerules WHERE branchcode=? AND categorycode=?");
93
    my $sth_insert_mtt = $dbh->prepare("
94
        INSERT INTO overduerules_transport_types(
95
            overduerules_id, letternumber, message_transport_type
96
        ) VALUES (
97
            (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?), ?, ?
98
        )
99
    ");
100
    my $sth_delete_mtt = $dbh->prepare("
101
        DELETE FROM overduerules_transport_types
102
        WHERE overduerules_id = (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?)
103
    ");
104
89
105
    foreach my $key (@names){
90
    foreach my $key (@names){
106
            # ISSUES
91
            # ISSUES
Lines 156-196 if ($op eq 'cud-save') { Link Here
156
            if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"}))
141
            if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"}))
157
                or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"}))
142
                or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"}))
158
                or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) {
143
                or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) {
159
                    $sth_search->execute($branch,$bor);
144
                    my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $bor });
160
                    my $res = $sth_search->fetchrow_hashref();
145
                    if ( $overdue_rule ) {
161
                    if ($res->{'total'}>0) {
146
                        $overdue_rule->update({
162
                        $sth_update->execute(
147
                            delay1    => $temphash{$bor}->{"delay1"}    ? $temphash{$bor}->{"delay1"}    : undef,
163
                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:undef),
148
                            letter1   => $temphash{$bor}->{"letter1"}   ? $temphash{$bor}->{"letter1"}   : "",
164
                            ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
149
                            debarred1 => $temphash{$bor}->{"debarred1"} ? $temphash{$bor}->{"debarred1"} : 0,
165
                            ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
150
                            delay2    => $temphash{$bor}->{"delay2"}    ? $temphash{$bor}->{"delay2"}    : undef,
166
                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:undef),
151
                            letter2   => $temphash{$bor}->{"letter2"}   ? $temphash{$bor}->{"letter2"}   : "",
167
                            ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
152
                            debarred2 => $temphash{$bor}->{"debarred2"} ? $temphash{$bor}->{"debarred2"} : 0,
168
                            ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
153
                            delay3    => $temphash{$bor}->{"delay3"}    ? $temphash{$bor}->{"delay3"}    : undef,
169
                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:undef),
154
                            letter3   => $temphash{$bor}->{"letter3"}   ? $temphash{$bor}->{"letter3"}   : "",
170
                            ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
155
                            debarred3 => $temphash{$bor}->{"debarred3"} ? $temphash{$bor}->{"debarred3"} : 0,
171
                            ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0),
156
                        });
172
                            $branch ,$bor
173
                            );
174
                    } else {
157
                    } else {
175
                        $sth_insert->execute($branch,$bor,
158
                        $overdue_rule = Koha::OverdueRule->new({
176
                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
159
                            branchcode => $branch,
177
                            ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
160
                            categorycode => $bor,
178
                            ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
161
                            delay1    => $temphash{$bor}->{"delay1"}    ? $temphash{$bor}->{"delay1"}    : undef ,
179
                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
162
                            letter1   => $temphash{$bor}->{"letter1"}   ? $temphash{$bor}->{"letter1"}   : "" ,
180
                            ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
163
                            debarred1 => $temphash{$bor}->{"debarred1"} ? $temphash{$bor}->{"debarred1"} : 0 ,
181
                            ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
164
                            delay2    => $temphash{$bor}->{"delay2"}    ? $temphash{$bor}->{"delay2"}    : undef ,
182
                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
165
                            letter2   => $temphash{$bor}->{"letter2"}   ? $temphash{$bor}->{"letter2"}   : "" ,
183
                            ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
166
                            debarred2 => $temphash{$bor}->{"debarred2"} ? $temphash{$bor}->{"debarred2"} : 0 ,
184
                            ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0)
167
                            delay3    => $temphash{$bor}->{"delay3"}    ? $temphash{$bor}->{"delay3"}    : undef ,
185
                            );
168
                            letter3   => $temphash{$bor}->{"letter3"}   ? $temphash{$bor}->{"letter3"}   : "" ,
169
                            debarred3 => $temphash{$bor}->{"debarred3"} ? $temphash{$bor}->{"debarred3"} : 0 ,
170
                        })->store();
186
                    }
171
                    }
187
172
188
                    $sth_delete_mtt->execute( $branch, $bor );
173
                    Koha::OverdueRules::TransportTypes->search({ overduerules_id => $overdue_rule->id })->delete();
189
                    for my $letternumber ( 1..3 ) {
174
                    for my $letternumber ( 1..3 ) {
190
                        my @mtt = $input->multi_param( "mtt${letternumber}-$bor" );
175
                        my @mtt = $input->multi_param( "mtt${letternumber}-$bor" );
191
                        next unless @mtt;
176
                        next unless @mtt;
192
                        for my $mtt ( @mtt ) {
177
                        for my $mtt ( @mtt ) {
193
                            $sth_insert_mtt->execute( $branch, $bor, $letternumber, $mtt);
178
                            Koha::OverdueRules::TransportType->new({
179
                                letternumber           => $letternumber,
180
                                message_transport_type => $mtt,
181
                                overduerules_id        => $overdue_rule->id,
182
                            })->store();
194
                        }
183
                        }
195
                    }
184
                    }
196
                }
185
                }
Lines 198-204 if ($op eq 'cud-save') { Link Here
198
    }
187
    }
199
    unless ($err) {
188
    unless ($err) {
200
        for my $category_code (@rows_to_delete) {
189
        for my $category_code (@rows_to_delete) {
201
            $sth_delete->execute($branch, $category_code);
190
            my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $category_code });
191
            $overdue_rule->delete if $overdue_rule;
202
        }
192
        }
203
        $template->param(datasaved => 1);
193
        $template->param(datasaved => 1);
204
        $input_saved = 1;
194
        $input_saved = 1;
Lines 247-255 for my $patron_category (@patron_categories) { Link Here
247
        }
237
        }
248
    } else {
238
    } else {
249
    #getting values from table
239
    #getting values from table
250
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
240
        my $overdue_rule = Koha::OverdueRules->find({ branchcode => $branch, categorycode => $patron_category->categorycode });
251
        $sth2->execute($branch,$patron_category->categorycode);
241
        my $dat = $overdue_rule ? $overdue_rule->unblessed : {};
252
        my $dat=$sth2->fetchrow_hashref;
253
        for my $i ( 1..3 ){
242
        for my $i ( 1..3 ){
254
            my %row = (
243
            my %row = (
255
                overduename => $patron_category->categorycode,
244
                overduename => $patron_category->categorycode,
256
- 

Return to bug 18086