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

(-)a/C4/Overdues.pm (-14 / +12 lines)
Lines 710-730 returns a list of branch codes for branches with overdue rules defined. Link Here
710
=cut
710
=cut
711
711
712
sub GetBranchcodesWithOverdueRules {
712
sub GetBranchcodesWithOverdueRules {
713
    my $dbh         = C4::Context->dbh;
713
    my @branchcodes = Koha::CirculationRules->search(
714
    my $branchcodes = $dbh->selectcol_arrayref(
714
        { rule_name => 'overdue_1_delay' },
715
        q|
715
        {
716
        SELECT DISTINCT(branchcode)
716
            order_by => 'branchcode',
717
        FROM overduerules
717
            columns  => ['branchcode'],
718
        WHERE delay1 IS NOT NULL
718
            distinct => 1,
719
        ORDER BY branchcode
719
        }
720
    |
720
    )->get_column('branchcode');
721
    );
721
    if ( !$branchcodes[0] ) {
722
    if ( defined $branchcodes->[0] && $branchcodes->[0] eq '' ) {
722
        @branchcodes = Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
723
724
        # If a default rule exists, all branches should be returned
725
        return Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
726
    }
723
    }
727
    return @$branchcodes;
724
725
    return @branchcodes;
728
}
726
}
729
727
730
=head2 GetOverduesForBranch
728
=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