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

(-)a/C4/Overdues.pm (-7 / +11 lines)
Lines 752-765 returns a list of branch codes for branches with overdue rules defined. Link Here
752
752
753
sub GetBranchcodesWithOverdueRules {
753
sub GetBranchcodesWithOverdueRules {
754
    my $dbh               = C4::Context->dbh;
754
    my $dbh               = C4::Context->dbh;
755
    my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode");
755
    my $branchcodes = $dbh->selectcol_arrayref(q|
756
    $rqoverduebranches->execute;
756
        SELECT DISTINCT(branchcode)
757
    my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref };
757
        FROM overduerules
758
    if (!$branches[0]) {
758
        WHERE delay1 IS NOT NULL
759
       my $availbranches = C4::Branch::GetBranches();
759
        ORDER BY branchcode
760
       @branches = keys %$availbranches;
760
    |);
761
    if ( $branchcodes->[0] eq '' ) {
762
        # If a default rule exists, all branches should be returned
763
        my $availbranches = C4::Branch::GetBranches();
764
        return keys %$availbranches;
761
    }
765
    }
762
    return @branches;
766
    return @$branchcodes;
763
}
767
}
764
768
765
=head2 CheckItemNotify
769
=head2 CheckItemNotify
(-)a/t/db_dependent/Overdues.t (-3 / +49 lines)
Lines 1-11 Link Here
1
#!/usr/bin/perl;
1
#!/usr/bin/perl;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More;# tests => 3;
4
use Test::More tests => 16;
5
5
6
use C4::Context;
6
use C4::Context;
7
use C4::Branch;
7
use_ok('C4::Overdues');
8
use_ok('C4::Overdues');
8
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes');
9
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes');
10
can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules');
9
11
10
my $dbh = C4::Context->dbh;
12
my $dbh = C4::Context->dbh;
11
$dbh->{AutoCommit} = 0;
13
$dbh->{AutoCommit} = 0;
Lines 73-77 is_deeply( $mtts, ['email', 'sms'], 'GetOverdueMessageTransportTypes: second ove Link Here
73
$mtts = C4::Overdues::GetOverdueMessageTransportTypes('', 'PT', 3);
75
$mtts = C4::Overdues::GetOverdueMessageTransportTypes('', 'PT', 3);
74
is_deeply( $mtts, ['print', 'sms', 'email'], 'GetOverdueMessageTransportTypes: third overdue is by print, sms and email for PT (default). With print in first.' );
76
is_deeply( $mtts, ['print', 'sms', 'email'], 'GetOverdueMessageTransportTypes: third overdue is by print, sms and email for PT (default). With print in first.' );
75
77
78
# Test GetBranchcodesWithOverdueRules
79
$dbh->do(q|DELETE FROM overduerules|);
80
$dbh->do(q|
81
    INSERT INTO overduerules
82
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
83
        VALUES
84
        ( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
85
|);
86
87
my $all_branches = C4::Branch::GetBranches;
88
my @branchcodes = keys %$all_branches;
89
90
my @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
91
is_deeply( [ sort @overdue_branches ], [ sort @branchcodes ], 'If a default rule exists, all branches should be returned' );
92
93
$dbh->do(q|
94
    INSERT INTO overduerules
95
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
96
        VALUES
97
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
98
|);
99
100
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
101
is_deeply( [ sort @overdue_branches ], [ sort @branchcodes ], 'If a default rule exists and a specific rule exists, all branches should be returned' );
102
103
$dbh->do(q|DELETE FROM overduerules|);
104
$dbh->do(q|
105
    INSERT INTO overduerules
106
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
107
        VALUES
108
        ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
109
|);
110
111
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
112
is_deeply( \@overdue_branches, ['CPL'] , 'If only a specific rule exist, only 1 branch should be returned' );
113
114
$dbh->do(q|DELETE FROM overduerules|);
115
$dbh->do(q|
116
    INSERT INTO overduerules
117
        ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
118
        VALUES
119
        ( 'CPL', '', 1, 'LETTER_CODE1_CPL', 1, 5, 'LETTER_CODE2_CPL', 1, 10, 'LETTER_CODE3_CPL', 1 ),
120
        ( 'MPL', '', 1, 'LETTER_CODE1_MPL', 1, 5, 'LETTER_CODE2_MPL', 1, 10, 'LETTER_CODE3_MPL', 1 )
121
|);
76
122
77
done_testing;
123
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
124
is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' );
78
- 

Return to bug 9180