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

(-)a/C4/Overdues.pm (-7 / +11 lines)
Lines 749-762 returns a list of branch codes for branches with overdue rules defined. Link Here
749
749
750
sub GetBranchcodesWithOverdueRules {
750
sub GetBranchcodesWithOverdueRules {
751
    my $dbh               = C4::Context->dbh;
751
    my $dbh               = C4::Context->dbh;
752
    my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode");
752
    my @branchcodes = $dbh->selectrow_array(q|
753
    $rqoverduebranches->execute;
753
        SELECT DISTINCT(branchcode)
754
    my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref };
754
        FROM overduerules
755
    if (!$branches[0]) {
755
        WHERE delay1 IS NOT NULL
756
       my $availbranches = C4::Branch::GetBranches();
756
        ORDER BY branchcode
757
       @branches = keys %$availbranches;
757
    |);
758
    if ( $branchcodes[0] eq '' ) {
759
        # If a default rule exists, all branches should be returned
760
        my $availbranches = C4::Branch::GetBranches();
761
        return keys %$availbranches;
758
    }
762
    }
759
    return @branches;
763
    return @branchcodes;
760
}
764
}
761
765
762
=head2 CheckBorrowerDebarred
766
=head2 CheckBorrowerDebarred
(-)a/t/db_dependent/Overdues.pl (-1 / +47 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 3;
5
6
use C4::Branch;
7
use C4::Context;
8
use C4::Overdues;
9
10
my $dbh = C4::Context->dbh;
11
$dbh->{AutoCommit} = 0;
12
$dbh->{RaiseError} = 1;
13
14
$dbh->do(q|DELETE FROM overduerules|);
15
$dbh->do(q|
16
    INSERT INTO overduerules
17
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
18
        VALUES
19
        ( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
20
|);
21
22
my $all_branches = C4::Branch::GetBranches;
23
my @branchcodes = keys %$all_branches;
24
25
my @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules;
26
is_deeply( \@overdue_branches, \@branchcodes, 'If a default rule exists, all branches should be returned' );
27
28
$dbh->do(q|
29
    INSERT INTO overduerules
30
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
31
        VALUES
32
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
33
|);
34
35
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules;
36
is_deeply( \@overdue_branches, \@branchcodes, 'If a default rule exists and a specific rule exists, all branches should be returned' );
37
38
$dbh->do(q|DELETE FROM overduerules|);
39
$dbh->do(q|
40
    INSERT INTO overduerules
41
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
42
        VALUES
43
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
44
|);
45
46
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules;
47
is_deeply( \@overdue_branches, ['CPL'] , 'If only a specific rule exist, only 1 branch should be returned' );

Return to bug 9180