From bb8819ec3842725032cc236f1e20b5e500acf369 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Tue, 24 Jul 2012 11:12:53 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 8443: Suggestions publication year and copyright date Signed-off-by: Katrin Fischer Tested: - Copyright date is saved on creating suggestions from OPAC and staff - Copyright filter works - Form and filter labelling match - Budget filter works - When ordering an accepted suggestion the publication year is filled with the copyright date. I noted some problems I found while testing this on the bug. This patch is still an improvement to reach more consistency. Signing off. --- C4/Acquisition.pm | 4 +- C4/Serials.pm | 2 +- C4/Suggestions.pm | 79 ++++++++++++-------- .../prog/en/modules/suggestion/suggestion.tt | 14 ++-- suggestion/suggestion.pl | 26 +++++-- 5 files changed, 77 insertions(+), 48 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 9678ffc..1047017 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1000,7 +1000,7 @@ Else, the upcoming July 1st is used. =item defaults entrydate to Now -The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid". +The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id". =back @@ -1338,7 +1338,7 @@ C<@results> is an array of references-to-hash with the following keys: =item C -=item C +=item C =back diff --git a/C4/Serials.pm b/C4/Serials.pm index 98660e9..17f5215 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -298,7 +298,7 @@ $subs = GetSubscription($subscriptionid) this function returns the subscription which has $subscriptionid as id. return : a hashref. This hash containts -subscription, subscriptionhistory, aqbudget.bookfundid, biblio.title +subscription, subscriptionhistory, aqbooksellers.name, biblio.title =cut diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 0cb484a..87c8214 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -93,7 +93,7 @@ sub SearchSuggestion { my $dbh = C4::Context->dbh; my @sql_params; my @query = ( - q{ SELECT suggestions.*, + q/SELECT suggestions.*, U1.branchcode AS branchcodesuggestedby, B1.branchname AS branchnamesuggestedby, U1.surname AS surnamesuggestedby, @@ -115,49 +115,61 @@ sub SearchSuggestion { LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber LEFT JOIN branches AS B2 ON B2.branchcode=U2.branchcode LEFT JOIN categories AS C2 ON C2.categorycode = U2.categorycode - WHERE 1=1 - } , map { - if ( my $s = $suggestion->{$_} ) { - push @sql_params,'%'.$s.'%'; - " and suggestions.$_ like ? "; - } else { () } - } qw( title author isbn publishercode collectiontitle ) + WHERE 1=1/ ); + # filter on biblio informations + foreach my $field ( + grep { + my $fieldname = $_; + any { $fieldname eq $_ } qw/title author isbn publishercode copyrightdate collectiontitle/ + } keys %$suggestion + ) + { + if ( $suggestion->{$field} ) { + push @sql_params, $suggestion->{$field}; + push @query, " AND suggestions.$field = ?"; + } + } + + # filter on user branch my $userenv = C4::Context->userenv; if (C4::Context->preference('IndependantBranches')) { - if ($userenv) { - if (($userenv->{flags} % 2) != 1 && !$suggestion->{branchcode}){ - push @sql_params,$$userenv{branch}; - push @query,q{ and (suggestions.branchcode = ? or suggestions.branchcode ='')}; - } + if ($userenv) { + if (($userenv->{flags} % 2) != 1 && !$suggestion->{branchcode}){ + push @sql_params, $userenv->{branch}; + push @query, q/ AND (suggestions.branchcode = ? or suggestions.branchcode = '')/; } + } } - foreach my $field (grep { my $fieldname=$_; - any {$fieldname eq $_ } qw< - STATUS branchcode itemtype suggestedby managedby acceptedby - bookfundid biblionumber - >} keys %$suggestion - ) { - if ($$suggestion{$field}){ - push @sql_params,$suggestion->{$field}; - push @query, " and suggestions.$field=?"; - } + # filter on nillable fields + foreach my $field ( + grep { + my $fieldname = $_; + any { $fieldname eq $_ } qw/STATUS branchcode itemtype suggestedby managedby acceptedby budgetid biblionumber/ + } keys %$suggestion + ) + { + if ( $suggestion->{$field} ) { + push @sql_params, $suggestion->{$field}; + push @query, " AND suggestions.$field = ?"; + } else { - push @query, " and (suggestions.$field='' OR suggestions.$field IS NULL)"; + push @query, " AND (suggestions.$field = '' OR suggestions.$field IS NULL)"; } } + # filter on date fields my $today = C4::Dates->today('iso'); - - foreach ( qw( suggesteddate manageddate accepteddate ) ) { - my $from = $_ . "_from"; - my $to = $_ . "_to"; - if ($$suggestion{$from} || $$suggestion{$to}) { - push @query, " AND suggestions.suggesteddate BETWEEN '" - . (format_date_in_iso($$suggestion{$from}) || 0000-00-00) . "' AND '" . (format_date_in_iso($$suggestion{$to}) || $today) . "'"; - } + foreach my $field ( qw/suggesteddate manageddate accepteddate/ ) { + my $from = $field."_from"; + my $to = $field."_to"; + if ($suggestion->{$from} || $suggestion->{$to}) { + push @query, " AND suggestions.$field BETWEEN ? AND ?"; + push @sql_params, format_date_in_iso($suggestion->{$from}) || '0000-00-00'; + push @sql_params, format_date_in_iso($suggestion->{$to}) || $today; + } } $debug && warn "@query"; @@ -165,7 +177,8 @@ sub SearchSuggestion { $sth->execute(@sql_params); my @results; while ( my $data=$sth->fetchrow_hashref ){ - $$data{$$data{STATUS}} = 1; + # add status as field + $data->{$data->{STATUS}} = 1; push(@results,$data); } return (\@results); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index edaea79..aa026dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -493,7 +493,7 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • -
  • +
  • Suggestion information

    @@ -514,10 +514,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% suggesteddate %] - + - +
  • @@ -527,10 +527,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% manageddate %] - + - +
  • @@ -540,10 +540,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% accepteddate %] - + - +
  • diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 99f38eb..bf53c83 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -188,12 +188,24 @@ elsif ( $op eq 'show' ) { if ($op=~/else/) { $op='else'; - $displayby||="STATUS"; + $displayby||="STATUS"; # by default, organize by status delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode"); my $criteria_list=GetDistinctValues("suggestions.".$displayby); + my %criteria_dv; + foreach (@$criteria_list) { + my $criteria_key; + if ($_->{value}) { + $criteria_key = $_->{value}; + } else { + # agregate null and empty values under empty value + $criteria_key = ''; + } + my $criteria_cnt = $criteria_dv{$criteria_key} || 0; + $criteria_dv{$criteria_key} = $criteria_cnt + $_->{cnt}; + } my @allsuggestions; my $reasonsloop = GetAuthorisedValues("SUGGEST"); - foreach my $criteriumvalue ( map { $$_{'value'} } @$criteria_list ) { + foreach my $criteriumvalue (keys %criteria_dv) { # By default, display suggestions from current working branch if(not defined $branchfilter) { $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'}; @@ -356,16 +368,20 @@ $template->param( total => sprintf("%.2f", $$suggestion_ref{'total'}||0), ); +# lists of distinct values (without empty) for filters my %hashlists; foreach my $field ( qw(managedby acceptedby suggestedby budgetid) ) { my $values_list; - $values_list = GetDistinctValues( "suggestions." . $field ); - my @codes_list = map { + $values_list = GetDistinctValues( "suggestions.$field" ); + my @codes_list = + map { { 'code' => $$_{'value'}, 'desc' => GetCriteriumDesc( $$_{'value'}, $field ), 'selected' => ($$suggestion_ref{$field}) ? $$_{'value'} eq $$suggestion_ref{$field} : 0, } - } @$values_list; + } + grep { $$_{'value'} } + @$values_list; $hashlists{ lc($field) . "_loop" } = \@codes_list; } $template->param(%hashlists); -- 1.7.9.5