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) - INTERVAL ? DAY = 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 21-31 use C4::Context; Link Here
21
use C4::Members;
21
use C4::Members;
22
use C4::Letters;
22
use C4::Letters;
23
use C4::Branch;
23
use C4::Branch;
24
use C4::Budgets;
24
use C4::Budgets qw( AddBudgetPeriod AddBudget );
25
25
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
27
27
28
use Test::More tests => 104;
28
use DateTime::Duration;
29
use Test::More tests => 105;
29
use Test::Warn;
30
use Test::Warn;
30
31
31
BEGIN {
32
BEGIN {
Lines 362-364 $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB Link Here
362
ModSuggestion( $my_suggestion );
363
ModSuggestion( $my_suggestion );
363
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
364
$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
364
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
365
is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
365
- 
366
367
subtest 'GetUnprocessedSuggestions' => sub {
368
    plan tests => 9;
369
    $dbh->do(q|DELETE FROM suggestions|);
370
    my $my_suggestionid         = NewSuggestion($my_suggestion);
371
    my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
372
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' );
373
    my $status     = ModSuggestion($mod_suggestion1);
374
    my $suggestion = GetSuggestion($my_suggestionid);
375
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
376
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
377
    $suggestion = GetSuggestion($my_suggestionid);
378
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
379
380
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
381
    is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
382
383
    ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } );
384
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
385
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
386
387
    ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) } );
388
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
389
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
390
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
391
    is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' );
392
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
393
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' );
394
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
395
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
396
};

Return to bug 13014