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

(-)a/C4/Suggestions.pm (-56 lines)
Lines 34-40 use base qw(Exporter); Link Here
34
34
35
our @EXPORT  = qw(
35
our @EXPORT  = qw(
36
  ConnectSuggestionAndBiblio
36
  ConnectSuggestionAndBiblio
37
  CountSuggestion
38
  DelSuggestion
37
  DelSuggestion
39
  GetSuggestion
38
  GetSuggestion
40
  GetSuggestionByStatus
39
  GetSuggestionByStatus
Lines 386-446 sub GetSuggestionByStatus { Link Here
386
    return $results;
385
    return $results;
387
}
386
}
388
387
389
=head2 CountSuggestion
390
391
&CountSuggestion($status)
392
393
Count the number of aqorders with the status given on input argument.
394
the arg status can be :
395
396
=over 2
397
398
=item * ASKED : asked by the user, not dealed by the librarian
399
400
=item * ACCEPTED : accepted by the librarian, but not yet ordered
401
402
=item * REJECTED : rejected by the librarian (definitive status)
403
404
=item * ORDERED : ordered by the librarian (acquisition module)
405
406
=back
407
408
return :
409
the number of suggestion with this status.
410
411
=cut
412
413
sub CountSuggestion {
414
    my ($status) = @_;
415
    my $dbh = C4::Context->dbh;
416
    my $sth;
417
    my $userenv = C4::Context->userenv;
418
    if ( C4::Context->preference("IndependentBranches")
419
        && !C4::Context->IsSuperLibrarian() )
420
    {
421
        my $query = q{
422
            SELECT count(*)
423
            FROM suggestions
424
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
425
            WHERE STATUS=?
426
                AND (suggestions.branchcode='' OR suggestions.branchcode=?)
427
        };
428
        $sth = $dbh->prepare($query);
429
        $sth->execute( $status, $userenv->{branch} );
430
    }
431
    else {
432
        my $query = q{
433
            SELECT count(*)
434
            FROM suggestions
435
            WHERE STATUS=?
436
        };
437
        $sth = $dbh->prepare($query);
438
        $sth->execute($status);
439
    }
440
    my ($result) = $sth->fetchrow;
441
    return $result;
442
}
443
444
=head2 NewSuggestion
388
=head2 NewSuggestion
445
389
446
390
(-)a/t/db_dependent/Suggestions.t (-13 lines)
Lines 159-170 my $my_suggestion_without_suggestedby = { Link Here
159
    quantity      => '', # Insert an empty string into int to catch strict SQL modes errors
159
    quantity      => '', # Insert an empty string into int to catch strict SQL modes errors
160
};
160
};
161
161
162
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
163
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
164
is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
165
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
166
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
167
168
my $my_suggestionid = NewSuggestion($my_suggestion);
162
my $my_suggestionid = NewSuggestion($my_suggestion);
169
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
163
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
170
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
164
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
Lines 181-189 is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef Link Here
181
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
175
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
182
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
176
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
183
177
184
is( CountSuggestion('ASKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
185
186
187
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
178
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
188
my $mod_suggestion1 = {
179
my $mod_suggestion1 = {
189
    title         => 'my modified title',
180
    title         => 'my modified title',
Lines 239-245 $messages = C4::Letters::GetQueuedMessages({ Link Here
239
});
230
});
240
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
231
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
241
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
232
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
242
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
243
233
244
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a smsalertnumber and no email
234
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a smsalertnumber and no email
245
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
235
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
Lines 413-420 my $del_suggestion = { Link Here
413
};
403
};
414
my $del_suggestionid = NewSuggestion($del_suggestion);
404
my $del_suggestionid = NewSuggestion($del_suggestion);
415
405
416
is( CountSuggestion('CHECKED'), 3, 'CountSuggestion returns the correct number of suggestions' );
417
418
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
406
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
419
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
407
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
420
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
408
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
421
- 

Return to bug 25033