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

(-)a/C4/Suggestions.pm (+18 lines)
Lines 49-54 our @EXPORT = qw( Link Here
49
  NewSuggestion
49
  NewSuggestion
50
  SearchSuggestion
50
  SearchSuggestion
51
  DelSuggestionsOlderThan
51
  DelSuggestionsOlderThan
52
  GetUnprocessedSuggestions
52
);
53
);
53
54
54
=head1 NAME
55
=head1 NAME
Lines 596-601 sub DelSuggestionsOlderThan { Link Here
596
    $sth->execute("-$days");
597
    $sth->execute("-$days");
597
}
598
}
598
599
600
sub GetUnprocessedSuggestions {
601
    my ( $number_of_days_since_the_last_modification ) = @_;
602
603
    $number_of_days_since_the_last_modification ||= 0;
604
605
    my $dbh = C4::Context->dbh;
606
607
    my $s = $dbh->selectall_arrayref(q|
608
        SELECT *
609
        FROM suggestions
610
        WHERE STATUS = 'ASKED'
611
            AND budgetid IS NOT NULL
612
            AND CAST(NOW() AS DATE) - CAST(suggesteddate AS DATE) = ?
613
    |, { Slice => {} }, $number_of_days_since_the_last_modification );
614
    return $s;
615
}
616
599
1;
617
1;
600
__END__
618
__END__
601
619
(-)a/t/db_dependent/Suggestions.t (-3 / +44 lines)
Lines 18-29 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Context;
20
use C4::Context;
21
use C4::Budgets qw( AddBudgetPeriod AddBudget );
21
use C4::Members;
22
use C4::Members;
22
use C4::Letters;
23
use C4::Letters;
23
24
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
25
26
26
use Test::More tests => 100;
27
use DateTime::Duration;
28
use Test::More tests => 109;
27
use Test::Warn;
29
use Test::Warn;
28
30
29
BEGIN {
31
BEGIN {
Lines 65-70 my $my_suggestion = { Link Here
65
    note          => 'my note',
67
    note          => 'my note',
66
};
68
};
67
69
70
# Create a fund for the budgetid value
71
my $bpid = C4::Budgets::AddBudgetPeriod({
72
    budget_period_startdate => '2008-01-01',
73
});
74
my $my_budget = {
75
    budget_code      => 'ABCD',
76
    budget_amount    => '123.132000',
77
    budget_name      => 'Periodiques',
78
    budget_notes     => 'This is a note',
79
    budget_period_id => $bpid,
80
};
81
my $budget_id = C4::Budgets::AddBudget($my_budget);
82
83
my $unprocessed_suggestions;
68
84
69
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
85
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
70
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
86
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
Lines 89-96 is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL i Link Here
89
105
90
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
106
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
91
107
108
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
109
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' );
110
92
111
93
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
112
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
113
94
my $mod_suggestion1 = {
114
my $mod_suggestion1 = {
95
    title         => 'my modified title',
115
    title         => 'my modified title',
96
    author        => 'my modified author',
116
    author        => 'my modified author',
Lines 112-117 is( $suggestion->{managedby}, undef, 'ModSuggestion stores empty string as undef Link Here
112
is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
132
is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
113
isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
133
isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
114
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
134
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
135
is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
136
137
ModSuggestion({ suggestionid => $my_suggestionid, budgetid => $budget_id });
138
$suggestion = GetSuggestion($my_suggestionid);
139
is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
140
141
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
142
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
143
144
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } );
145
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
146
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
147
148
ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration(DateTime::Duration->new(days => -4) ) } );
149
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
150
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
151
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
152
is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' );
153
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
154
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' );
155
$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
156
is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
115
157
116
my $messages = C4::Letters::GetQueuedMessages({
158
my $messages = C4::Letters::GetQueuedMessages({
117
    borrowernumber => $borrowernumber,
159
    borrowernumber => $borrowernumber,
Lines 121-126 is( @$messages, 0, 'ModSuggestions does not send an email if the status is not u Link Here
121
my $mod_suggestion2 = {
163
my $mod_suggestion2 = {
122
    STATUS       => 'STALLED',
164
    STATUS       => 'STALLED',
123
    suggestionid => $my_suggestionid,
165
    suggestionid => $my_suggestionid,
166
124
};
167
};
125
warning_is { $status = ModSuggestion($mod_suggestion2) }
168
warning_is { $status = ModSuggestion($mod_suggestion2) }
126
           "No suggestions STALLED letter transported by email",
169
           "No suggestions STALLED letter transported by email",
Lines 143-149 is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); Link Here
143
186
144
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
187
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
145
188
146
147
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
189
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
148
$suggestion = GetSuggestionInfo($my_suggestionid);
190
$suggestion = GetSuggestionInfo($my_suggestionid);
149
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' );
191
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' );
150
- 

Return to bug 13014