[Koha-patches] [PATCH] Bug 8443: Suggestions publication year and copyright date

Fridolyn SOMERS fridolyn.somers at biblibre.com
Wed Aug 22 14:23:13 CEST 2012


---
 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 ccb488b..47bb7d2 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -922,7 +922,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
 
@@ -1260,7 +1260,7 @@ C<@results> is an array of references-to-hash with the following keys:
 
 =item C<branchcode>
 
-=item C<bookfundid>
+=item C<budget_id>
 
 =back
 
diff --git a/C4/Serials.pm b/C4/Serials.pm
index 58b6078..913320e 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -297,7 +297,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..610d161 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(); });
                     <li><label for="author"> Author:</label><input type="text" id="author" name="author" value="[% author %]" /></li>
                     <li><label for="isbn"> ISBN:</label><input type="text" id="isbn"  name="isbn" value="[% isbn %]" /></li>
                     <li><label for="publishercode"> Publisher:</label><input type="text" id="publishercode" name="publishercode" value="[% publishercode %]" /></li>
-                    <li><label for="publicationyear"> Publication year:</label><input type="text" id="publicationyear" name="publicationyear" value="[% publicationyear %]" /></li>
+                    <li><label for="copyrightdate_filter"> Copyright date:</label><input type="text" id="copyrightdate_filter" name="copyrightdate" value="[% copyrightdate %]" /></li>
                     <li><label for="collectiontitle"> Collection title:</label><input type="text" id="collectiontitle" name="collectiontitle" value="[% collectiontitle %]" /></li><li><input type="submit" value="Go" /></li></ol>
                 </fieldset>
 				 <fieldset class="brief"><h4 class="collapse"><a href="#">Suggestion information</a></h4>
@@ -514,10 +514,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
                     <li><label for="suggesteddate_from"> Suggested on:</label>[% suggesteddate %]
                         <table class="invis">
                         <tr>
-                        <td><label for="suggesteddate_from">from:</label></td><td><input type="text" id="suggesteddate_from" name="suggesteddate_from" style="width:80px;" /></td>
+                        <td><label for="suggesteddate_from">from:</label></td><td><input type="text" id="suggesteddate_from" name="suggesteddate_from" style="width:76px;" /></td>
                         </tr>
                         <tr>
-                        <td><label for="suggesteddate_to">to:</label></td><td><input type="text" id="suggesteddate_to" name="suggesteddate_to" style="width:80px;" /></td>
+                        <td><label for="suggesteddate_to">to:</label></td><td><input type="text" id="suggesteddate_to" name="suggesteddate_to" style="width:76px;" /></td>
                         </tr>
                         </table>
                     </li>
@@ -527,10 +527,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
                     <li><label for="manageddate_from"> Management date:</label>[% manageddate %]
                         <table class="invis">
                         <tr>
-                        <td><label for="manageddate_from">from:</label></td><td><input type="text" id="manageddate_from" name="manageddate_from" style="width:80px;" /></td>
+                        <td><label for="manageddate_from">from:</label></td><td><input type="text" id="manageddate_from" name="manageddate_from" style="width:76px;" /></td>
                         </tr>
                         <tr>
-                        <td><label for="manageddate_to">to:</label></td><td><input type="text" id="manageddate_to" name="manageddate_to" style="width:80px;" /></td>
+                        <td><label for="manageddate_to">to:</label></td><td><input type="text" id="manageddate_to" name="manageddate_to" style="width:76px;" /></td>
                         </tr>
                         </table>
                     </li>
@@ -540,10 +540,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
                     <li><label for="accepteddate_from"> Accepted on:</label>[% accepteddate %]
                         <table class="invis">
                         <tr>
-                        <td><label for="accepteddate_from">from:</label></td><td><input type="text" id="accepteddate_from" name="accepteddate_from" style="width:80px;" /></td>
+                        <td><label for="accepteddate_from">from:</label></td><td><input type="text" id="accepteddate_from" name="accepteddate_from" style="width:76px;" /></td>
                         </tr>
                         <tr>
-                        <td><label for="accepteddate_to">to:</label></td><td><input type="text" id="accepteddate_to" name="accepteddate_to" style="width:80px;" /></td>
+                        <td><label for="accepteddate_to">to:</label></td><td><input type="text" id="accepteddate_to" name="accepteddate_to" style="width:76px;" /></td>
                         </tr>
                         </table>
                     </li>
diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl
index 6bf188f..d96fe38 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'};
@@ -363,16 +375,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



More information about the Koha-patches mailing list