|
Lines 425-491
if ( $op eq 'else' ) {
Link Here
|
| 425 |
$suggestion_ref->{branchcode} = C4::Context->userenv->{'branch'}; |
425 |
$suggestion_ref->{branchcode} = C4::Context->userenv->{'branch'}; |
| 426 |
} |
426 |
} |
| 427 |
|
427 |
|
|
|
428 |
my $search_params = {%$suggestion_ref}; |
| 429 |
|
| 430 |
# filter on date fields |
| 431 |
foreach my $field (qw( suggesteddate manageddate accepteddate )) { |
| 432 |
my $from = delete $search_params->{"${field}_from"}; |
| 433 |
my $to = delete $search_params->{"${field}_to"}; |
| 434 |
|
| 435 |
my $from_dt = $from && eval { dt_from_string($from) }; |
| 436 |
my $to_dt = $to && eval { dt_from_string($to) }; |
| 437 |
|
| 438 |
if ( $from_dt || $to_dt ) { |
| 439 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 440 |
if ( $from_dt && $to_dt ) { |
| 441 |
$search_params->{$field} = |
| 442 |
{ -between => [ $dtf->format_date($from_dt), $dtf->format_date($to_dt) ] }; |
| 443 |
} elsif ($from_dt) { |
| 444 |
$search_params->{$field} = { '>=' => $dtf->format_date($from_dt) }; |
| 445 |
} elsif ($to_dt) { |
| 446 |
$search_params->{$field} = { '<=' => $dtf->format_date($to_dt) }; |
| 447 |
} |
| 448 |
} |
| 449 |
} |
| 450 |
if ( $search_params->{budgetid} && $search_params->{budgetid} eq '__NONE__' ) { |
| 451 |
$search_params->{budgetid} = [ undef, '' ]; |
| 452 |
} |
| 453 |
for my $f (qw (branchcode budgetid)) { |
| 454 |
delete $search_params->{$f} |
| 455 |
if $search_params->{$f} eq '__ANY__' |
| 456 |
|| $search_params->{$f} eq ''; |
| 457 |
} |
| 458 |
for my $bi (qw (title author isbn publishercode copyrightdate collectiontitle)) { |
| 459 |
$search_params->{$bi} = { 'LIKE' => "%" . $search_params->{$bi} . "%" } if $search_params->{$bi}; |
| 460 |
} |
| 461 |
|
| 462 |
$search_params->{archived} = 0 if !$filter_archived; |
| 463 |
foreach my $key ( keys %$search_params ) { |
| 464 |
if ( $key eq 'branchcode' ) { |
| 465 |
my $branch_param = delete $search_params->{$key}; |
| 466 |
$search_params->{"me.branchcode"} = $branch_param; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
# Retrieve the count to display on each tab |
| 471 |
my $suggestion_tabs = Koha::Suggestions->search_limited( |
| 472 |
$search_params, |
| 473 |
{ |
| 474 |
select => [ $displayby, { count => $displayby, -as => 'count' } ], |
| 475 |
as => [ $displayby, 'count' ], |
| 476 |
group_by => [$displayby], |
| 477 |
} |
| 478 |
); |
| 479 |
my $tab_counts = { map { $_->get_column($displayby) => $_->get_column('count') } $suggestion_tabs->as_list }; |
| 480 |
|
| 428 |
my @allsuggestions; |
481 |
my @allsuggestions; |
| 429 |
foreach my $criteriumvalue (@criteria_dv) { |
482 |
foreach my $criteriumvalue (@criteria_dv) { |
| 430 |
my $search_params = {%$suggestion_ref}; |
|
|
| 431 |
|
483 |
|
|
|
484 |
# By default, display suggestions from current working branch |
| 485 |
my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; |
| 432 |
next |
486 |
next |
| 433 |
if $search_params->{STATUS} |
487 |
if $search_params->{STATUS} |
| 434 |
&& $displayby eq 'STATUS' |
488 |
&& $displayby eq 'STATUS' |
| 435 |
&& $criteriumvalue ne $search_params->{STATUS}; |
489 |
&& $criteriumvalue ne $search_params->{STATUS}; |
| 436 |
|
490 |
|
| 437 |
# By default, display suggestions from current working branch |
|
|
| 438 |
my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; |
| 439 |
|
| 440 |
next |
491 |
next |
| 441 |
if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) |
492 |
if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) |
| 442 |
and ( $displayby ne 'branchcode' && $branchfilter ne '__ANY__' ); |
493 |
and ( $displayby ne 'branchcode' && $branchfilter ne '__ANY__' ); |
| 443 |
|
494 |
|
| 444 |
$search_params->{$displayby} = $criteriumvalue; |
495 |
my $criterium_search_params = {%$search_params}; |
| 445 |
|
496 |
$criterium_search_params->{"me.$displayby"} = $criteriumvalue; |
| 446 |
# filter on date fields |
|
|
| 447 |
foreach my $field (qw( suggesteddate manageddate accepteddate )) { |
| 448 |
my $from = delete $search_params->{"${field}_from"}; |
| 449 |
my $to = delete $search_params->{"${field}_to"}; |
| 450 |
|
| 451 |
my $from_dt = $from && eval { dt_from_string($from) }; |
| 452 |
my $to_dt = $to && eval { dt_from_string($to) }; |
| 453 |
|
| 454 |
if ( $from_dt || $to_dt ) { |
| 455 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 456 |
if ( $from_dt && $to_dt ) { |
| 457 |
$search_params->{$field} = |
| 458 |
{ -between => [ $dtf->format_date($from_dt), $dtf->format_date($to_dt) ] }; |
| 459 |
} elsif ($from_dt) { |
| 460 |
$search_params->{$field} = { '>=' => $dtf->format_date($from_dt) }; |
| 461 |
} elsif ($to_dt) { |
| 462 |
$search_params->{$field} = { '<=' => $dtf->format_date($to_dt) }; |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
if ( $search_params->{budgetid} && $search_params->{budgetid} eq '__NONE__' ) { |
| 467 |
$search_params->{budgetid} = [ undef, '' ]; |
| 468 |
} |
| 469 |
for my $f (qw (branchcode budgetid)) { |
| 470 |
delete $search_params->{$f} |
| 471 |
if $search_params->{$f} eq '__ANY__' |
| 472 |
|| $search_params->{$f} eq ''; |
| 473 |
} |
| 474 |
for my $bi (qw (title author isbn publishercode copyrightdate collectiontitle)) { |
| 475 |
$search_params->{$bi} = { 'LIKE' => "%" . $search_params->{$bi} . "%" } if $search_params->{$bi}; |
| 476 |
} |
| 477 |
|
| 478 |
$search_params->{archived} = 0 if !$filter_archived; |
| 479 |
my @suggestions = Koha::Suggestions->search_limited($search_params)->as_list; |
| 480 |
|
497 |
|
| 481 |
push @allsuggestions, |
498 |
push @allsuggestions, |
| 482 |
{ |
499 |
{ |
| 483 |
"suggestiontype" => $criteriumvalue || "suggest", |
500 |
"suggestiontype" => $criteriumvalue || "suggest", |
| 484 |
"suggestiontypelabel" => GetCriteriumDesc( $criteriumvalue, $displayby ) || "", |
501 |
"suggestiontypelabel" => GetCriteriumDesc( $criteriumvalue, $displayby ) || "", |
| 485 |
'suggestions' => \@suggestions, |
|
|
| 486 |
'reasonsloop' => $reasonsloop, |
502 |
'reasonsloop' => $reasonsloop, |
|
|
503 |
'search_params' => $criterium_search_params, |
| 504 |
'tab_count' => $tab_counts->{$criteriumvalue}, |
| 487 |
} |
505 |
} |
| 488 |
if scalar @suggestions > 0; |
506 |
if $tab_counts->{$criteriumvalue} > 0; |
| 489 |
|
507 |
|
| 490 |
delete $$suggestion_ref{$displayby} unless $definedvalue; |
508 |
delete $$suggestion_ref{$displayby} unless $definedvalue; |
| 491 |
} |
509 |
} |
| 492 |
- |
|
|