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

(-)a/C4/Overdues.pm (-14 / +12 lines)
Lines 687-707 returns a list of branch codes for branches with overdue rules defined. Link Here
687
=cut
687
=cut
688
688
689
sub GetBranchcodesWithOverdueRules {
689
sub GetBranchcodesWithOverdueRules {
690
    my $dbh         = C4::Context->dbh;
690
    my @branchcodes = Koha::CirculationRules->search(
691
    my $branchcodes = $dbh->selectcol_arrayref(
691
        { rule_name => 'overdue_1_delay' },
692
        q|
692
        {
693
        SELECT DISTINCT(branchcode)
693
            order_by => 'branchcode',
694
        FROM overduerules
694
            columns  => ['branchcode'],
695
        WHERE delay1 IS NOT NULL
695
            distinct => 1,
696
        ORDER BY branchcode
696
        }
697
    |
697
    )->get_column('branchcode');
698
    );
698
    if ( !$branchcodes[0] ) {
699
    if ( defined $branchcodes->[0] && $branchcodes->[0] eq '' ) {
699
        @branchcodes = Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
700
701
        # If a default rule exists, all branches should be returned
702
        return Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
703
    }
700
    }
704
    return @$branchcodes;
701
702
    return @branchcodes;
705
}
703
}
706
704
707
=head2 GetOverduesForBranch
705
=head2 GetOverduesForBranch
(-)a/t/db_dependent/Overdues.t (-17 / +16 lines)
Lines 95-101 is_deeply( Link Here
95
);
95
);
96
96
97
# Test GetBranchcodesWithOverdueRules
97
# Test GetBranchcodesWithOverdueRules
98
$dbh->do(q|DELETE FROM overduerules|);
98
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
99
99
100
my @overdue_branches;
100
my @overdue_branches;
101
warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); } [],
101
warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); } [],
Lines 103-112 warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules( Link Here
103
103
104
$dbh->do(
104
$dbh->do(
105
    q|
105
    q|
106
    INSERT INTO overduerules
106
    INSERT INTO circulation_rules
107
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
107
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
108
        VALUES
108
        VALUES
109
        ( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
109
        ( NULL, NULL, NULL, 'overdue_1_delay', 1 )
110
|
110
|
111
);
111
);
112
112
Lines 120-129 is_deeply( Link Here
120
120
121
$dbh->do(
121
$dbh->do(
122
    q|
122
    q|
123
    INSERT INTO overduerules
123
    INSERT INTO circulation_rules
124
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
124
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
125
        VALUES
125
        VALUES
126
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
126
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
127
|
127
|
128
);
128
);
129
129
Lines 133-159 is_deeply( Link Here
133
    'If a default rule exists and a specific rule exists, all branches should be returned'
133
    'If a default rule exists and a specific rule exists, all branches should be returned'
134
);
134
);
135
135
136
$dbh->do(q|DELETE FROM overduerules|);
136
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
137
$dbh->do(
137
$dbh->do(
138
    q|
138
    q|
139
    INSERT INTO overduerules
139
    INSERT INTO circulation_rules
140
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
140
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
141
        VALUES
141
        VALUES
142
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
142
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
143
|
143
|
144
);
144
);
145
145
146
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
146
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
147
is_deeply( \@overdue_branches, ['CPL'], 'If only a specific rule exist, only 1 branch should be returned' );
147
is_deeply( \@overdue_branches, ['CPL'], 'If only a specific rule exist, only 1 branch should be returned' );
148
148
149
$dbh->do(q|DELETE FROM overduerules|);
149
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
150
$dbh->do(
150
$dbh->do(
151
    q|
151
    q|
152
    INSERT INTO overduerules
152
    INSERT INTO circulation_rules
153
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
153
        ( branchcode, categorycode, itemtype, rule_name, rule_value )
154
        VALUES
154
        VALUES
155
        ( 'CPL', '', 1, 'LETTER_CODE1_CPL', 1, 5, 'LETTER_CODE2_CPL', 1, 10, 'LETTER_CODE3_CPL', 1 ),
155
        ( 'CPL', NULL, NULL, 'overdue_1_delay', 1 ),
156
        ( 'MPL', '', 1, 'LETTER_CODE1_MPL', 1, 5, 'LETTER_CODE2_MPL', 1, 10, 'LETTER_CODE3_MPL', 1 )
156
        ( 'MPL', NULL, NULL, 'overdue_1_delay', 1 )
157
|
157
|
158
);
158
);
159
159
160
- 

Return to bug 10190