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 597-602 sub DelSuggestionsOlderThan { Link Here
597
    $sth->execute("-$days");
598
    $sth->execute("-$days");
598
}
599
}
599
600
601
sub GetUnprocessedSuggestions {
602
    my ( $number_of_days_since_the_last_modification ) = @_;
603
604
    $number_of_days_since_the_last_modification ||= 0;
605
606
    my $dbh = C4::Context->dbh;
607
608
    my $s = $dbh->selectall_arrayref(q|
609
        SELECT *
610
        FROM suggestions
611
        WHERE STATUS = 'ASKED'
612
            AND budgetid IS NOT NULL
613
            AND CAST(NOW() AS DATE) - CAST(suggesteddate AS DATE) = ?
614
    |, { Slice => {} }, $number_of_days_since_the_last_modification );
615
    return $s;
616
}
617
600
1;
618
1;
601
__END__
619
__END__
602
620
(-)a/t/db_dependent/Suggestions.t (-3 / +34 lines)
Lines 20-30 use Modern::Perl; Link Here
20
use C4::Context;
20
use C4::Context;
21
use C4::Members;
21
use C4::Members;
22
use C4::Letters;
22
use C4::Letters;
23
use C4::Budgets;
23
use C4::Budgets qw( AddBudgetPeriod AddBudget );
24
24
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
26
27
use Test::More tests => 104;
27
use DateTime::Duration;
28
use Test::More tests => 105;
28
use Test::Warn;
29
use Test::Warn;
29
30
30
BEGIN {
31
BEGIN {
Lines 328-330 $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB Link Here
328
ModSuggestion( $my_suggestion );
329
ModSuggestion( $my_suggestion );
329
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
330
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
330
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
331
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
331
- 
332
333
subtest 'GetUnprocessedSuggestions' => sub {
334
    plan tests => 9;
335
    $dbh->do(q|DELETE FROM suggestions|);
336
    my $my_suggestionid         = NewSuggestion($my_suggestion);
337
    my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
338
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' );
339
    my $status     = ModSuggestion($mod_suggestion1);
340
    my $suggestion = GetSuggestion($my_suggestionid);
341
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
342
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
343
    $suggestion = GetSuggestion($my_suggestionid);
344
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
345
346
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
347
    is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
348
349
    ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } );
350
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
351
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
352
353
    ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) } );
354
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
355
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
356
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
357
    is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' );
358
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
359
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' );
360
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
361
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
362
};

Return to bug 13014