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

(-)a/C4/Overdues.pm (-14 / +12 lines)
Lines 707-727 returns a list of branch codes for branches with overdue rules defined. Link Here
707
=cut
707
=cut
708
708
709
sub GetBranchcodesWithOverdueRules {
709
sub GetBranchcodesWithOverdueRules {
710
    my $dbh         = C4::Context->dbh;
710
    my @branchcodes = Koha::CirculationRules->search(
711
    my $branchcodes = $dbh->selectcol_arrayref(
711
        { rule_name => 'overdue_1_delay' },
712
        q|
712
        {
713
        SELECT DISTINCT(branchcode)
713
            order_by => 'branchcode',
714
        FROM overduerules
714
            columns  => ['branchcode'],
715
        WHERE delay1 IS NOT NULL
715
            distinct => 1,
716
        ORDER BY branchcode
716
        }
717
    |
717
    )->get_column('branchcode');
718
    );
718
    if ( !$branchcodes[0] ) {
719
    if ( defined $branchcodes->[0] && $branchcodes->[0] eq '' ) {
719
        @branchcodes = Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
720
721
        # If a default rule exists, all branches should be returned
722
        return Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
723
    }
720
    }
724
    return @$branchcodes;
721
722
    return @branchcodes;
725
}
723
}
726
724
727
=head2 GetOverduesForBranch
725
=head2 GetOverduesForBranch
(-)a/t/db_dependent/Overdues.t (-17 / +16 lines)
Lines 96-102 is_deeply( Link Here
96
);
96
);
97
97
98
# Test GetBranchcodesWithOverdueRules
98
# Test GetBranchcodesWithOverdueRules
99
$dbh->do(q|DELETE FROM overduerules|);
99
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
100
100
101
my @overdue_branches;
101
my @overdue_branches;
102
warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); } [],
102
warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); } [],
Lines 104-113 warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules( Link Here
104
104
105
$dbh->do(
105
$dbh->do(
106
    q|
106
    q|
107
    INSERT INTO overduerules
107
    INSERT INTO circulation_rules
108
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
108
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
109
        VALUES
109
        VALUES
110
        ( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
110
        ( NULL, NULL, NULL, 'overdue_1_delay', 1 )
111
|
111
|
112
);
112
);
113
113
Lines 121-130 is_deeply( Link Here
121
121
122
$dbh->do(
122
$dbh->do(
123
    q|
123
    q|
124
    INSERT INTO overduerules
124
    INSERT INTO circulation_rules
125
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
125
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
126
        VALUES
126
        VALUES
127
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
127
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
128
|
128
|
129
);
129
);
130
130
Lines 134-160 is_deeply( Link Here
134
    'If a default rule exists and a specific rule exists, all branches should be returned'
134
    'If a default rule exists and a specific rule exists, all branches should be returned'
135
);
135
);
136
136
137
$dbh->do(q|DELETE FROM overduerules|);
137
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
138
$dbh->do(
138
$dbh->do(
139
    q|
139
    q|
140
    INSERT INTO overduerules
140
    INSERT INTO circulation_rules
141
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
141
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
142
        VALUES
142
        VALUES
143
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
143
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
144
|
144
|
145
);
145
);
146
146
147
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
147
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
148
is_deeply( \@overdue_branches, ['CPL'], 'If only a specific rule exist, only 1 branch should be returned' );
148
is_deeply( \@overdue_branches, ['CPL'], 'If only a specific rule exist, only 1 branch should be returned' );
149
149
150
$dbh->do(q|DELETE FROM overduerules|);
150
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
151
$dbh->do(
151
$dbh->do(
152
    q|
152
    q|
153
    INSERT INTO overduerules
153
    INSERT INTO circulation_rules
154
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
154
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
155
        VALUES
155
        VALUES
156
        ( 'CPL', '', 1, 'LETTER_CODE1_CPL', 1, 5, 'LETTER_CODE2_CPL', 1, 10, 'LETTER_CODE3_CPL', 1 ),
156
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 ),
157
        ( 'MPL', '', 1, 'LETTER_CODE1_MPL', 1, 5, 'LETTER_CODE2_MPL', 1, 10, 'LETTER_CODE3_MPL', 1 )
157
        ( 'MPL', NULL, NULL, 'overdue_1_delay', 1 )
158
|
158
|
159
);
159
);
160
160
161
- 

Return to bug 10190