MT 1443 : better reports on items
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Tue, 15 Sep 2009 14:59:37 +0000 (16:59 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 30 Sep 2009 09:30:32 +0000 (11:30 +0200)
C4/Reports/Guided.pm
koha-tmpl/intranet-tmpl/prog/en/columns.def
koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
reports/guided_reports.pl

index 3c655c4..a2efd53 100644 (file)
@@ -29,6 +29,7 @@ use C4::Output;
 use C4::Dates;
 use XML::Simple;
 use XML::Dumper;
+use Switch;
 use C4::Debug;
 # use Smart::Comments;
 # use Data::Dumper;
@@ -81,7 +82,7 @@ $criteria{'1'} = [
     'items.dateaccessioned|date'
 ];
 $criteria{'2'} =
-  [ 'items.holdingbranch', 'items.homebranch' ,'items.itemlost', 'items.location', 'items.ccode'];
+  [ 'items.itemnumber|textrange', 'items.biblionumber|textrange', 'items.barcode|textrange', 'items.holdingbranch', 'items.homebranch', 'items.onloan|daterange', 'items.ccode', 'items.itemcallnumber|textrange', 'items.itype', 'items.itemlost', 'items.location' ];
 $criteria{'3'} = ['borrowers.branchcode'];
 $criteria{'4'} = ['aqorders.datereceived|date'];
 $criteria{'5'} = ['borrowers.branchcode'];
@@ -305,31 +306,57 @@ sub get_criteria {
     foreach my $localcrit (@$crit) {
         my ( $value, $type )   = split( /\|/, $localcrit );
         my ( $table, $column ) = split( /\./, $value );
-        if ( $type eq 'date' ) {
-                       my %temp;
-            $temp{'name'}   = $value;
-            $temp{'date'}   = 1;
-                       $temp{'description'} = $column_defs->{$value};
-            push @criteria_array, \%temp;
-        }
-        else {
-
-            my $query =
-              "SELECT distinct($column) as availablevalues FROM $table";
-            my $sth = $dbh->prepare($query);
-            $sth->execute();
-            my @values;
-            while ( my $row = $sth->fetchrow_hashref() ) {
-                push @values, $row;
-                ### $row;
-            }
-            $sth->finish();
-            my %temp;
-            $temp{'name'}   = $value;
-                       $temp{'description'} = $column_defs->{$value};
-            $temp{'values'} = \@values;
-            push @criteria_array, \%temp;
-        }
+       switch ($type) {
+           case 'textrange' {
+               my %temp;
+               $temp{'name'}        = $value;
+               $temp{'from'}        = "from_" . $value;
+               $temp{'to'}          = "to_" . $value;
+               $temp{'textrange'}   = 1;
+               $temp{'description'} = $column_defs->{$value};
+               push @criteria_array, \%temp;
+           }
+
+           case 'date' {
+               my %temp;
+               $temp{'name'}        = $value;
+               $temp{'date'}        = 1;
+               $temp{'description'} = $column_defs->{$value};
+               push @criteria_array, \%temp;
+           }
+
+           case 'daterange' {
+               my %temp;
+               $temp{'name'}        = $value;
+               $temp{'from'}        = "from_" . $value;
+               $temp{'to'}          = "to_" . $value;
+               $temp{'daterange'}   = 1;
+               $temp{'description'} = $column_defs->{$value};
+               push @criteria_array, \%temp;
+           }
+
+
+           else {
+               my $query =
+                 "SELECT distinct($column) as availablevalues FROM $table";
+               my $sth = $dbh->prepare($query);
+               $sth->execute();
+               my @values;
+               while ( my $row = $sth->fetchrow_hashref() ) {
+                   push @values, $row;
+               }
+               $sth->finish();
+
+               my %temp;
+               $temp{'name'}        = $value;
+               $temp{'description'} = $column_defs->{$value};
+               $temp{'values'}      = \@values;
+               
+               push @criteria_array, \%temp;
+     
+           }
+
+       }
     }
     return ( \@criteria_array );
 }
index d53685a..2b7cf82 100644 (file)
@@ -64,6 +64,7 @@ items.datelastborrowed        Date Item last issued
 items.datelastseen     Date Item was last seen by Koha
 items.multivolume      Volume Number (if part of a multivolume work)
 items.stack    Is the item in the stack?
+items.onloan   On loan
 items.notforloan       Item Not for loan
 items.itemlost Item Lost
 items.wthdrawn Item Cancelled
index a172fb4..a2b333d 100644 (file)
@@ -158,8 +158,10 @@ canned reports and writing custom SQL reports.</p>
 </li></ol></fieldset>
 
 <fieldset class="action">
-<input type="hidden" name="phase" value="Choose this type" />
-<input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
+    <input type="hidden" name="phase" value="Choose this type" />
+    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="submit" name="submit" value="Next &gt;&gt;" />
+</fieldset>
 </form>
 </div>
 <div class="yui-gb"><div class="yui-u first"></div>
@@ -213,8 +215,9 @@ canned reports and writing custom SQL reports.</p>
 </fieldset>
 <div class="yui-g">
 <fieldset class="action">
-<input type="hidden" name="phase" value="Choose these columns" />
-<input type="submit" name="submit" value="Next &gt;&gt;" />
+    <input type="hidden" name="phase" value="Choose these columns" />
+    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="submit" name="submit" value="Next &gt;&gt;" />
 </fieldset>
 </div>
 </form>
@@ -223,39 +226,79 @@ canned reports and writing custom SQL reports.</p>
 
 <!-- TMPL_IF NAME="build4" -->
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" >
-<input type="hidden" name="area" value="<!-- TMPL_VAR NAME="area" -->" />
-<input type="hidden" name="type" value="<!-- TMPL_VAR NAME="type" -->" />
-<input type="hidden" name="column" value="<!-- TMPL_VAR NAME="column" -->" />
-<fieldset><legend>Step 4 of 6: Select Criteria to Limit on</legend><table>
-<!-- TMPL_LOOP NAME="criteria" -->
-<tr><td><input type="checkbox" name="criteria_column" id="<!-- TMPL_VAR
-NAME="name" -->" value="<!-- TMPL_VAR
-NAME="name" -->" /> <label for="<!-- TMPL_VAR
-NAME="name" -->"><!-- TMPL_VAR NAME="description" --> </label>
-</td>
-<!-- TMPL_IF NAME="date" -->
-<td><input type="text" size="10" id="<!-- TMPL_VAR NAME="name"
--->_value" name="<!-- TMPL_VAR NAME="name" -->_value" value=""
-/><img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfrom<!-- TMPL_VAR NAME="name" -->" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />                 
-<script type="text/javascript">   
-Calendar.setup({  
-inputField     : "<!-- TMPL_VAR NAME="name" -->_value",
-ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
-button         : "buttonfrom<!-- TMPL_VAR NAME="name" -->",
-align          : "Tl" 
-});     
-</script>          
-</td></tr>
-<!-- TMPL_ELSE -->
-<td><select name="<!-- TMPL_VAR NAME="name" -->_value">
-<!-- TMPL_LOOP NAME="values" -->
-<option value="<!-- TMPL_VAR NAME="availablevalues"-->"><!-- TMPL_VAR NAME="availablevalues" --></option>
-<!-- /TMPL_LOOP -->
-</select>
-</td></tr>
-<!-- /TMPL_IF -->
-<!-- /TMPL_LOOP -->
-</table></fieldset>
+    <input type="hidden" name="area" value="<!-- TMPL_VAR NAME="area" -->" />
+    <input type="hidden" name="type" value="<!-- TMPL_VAR NAME="type" -->" />
+    <input type="hidden" name="column" value="<!-- TMPL_VAR NAME="column" -->" />
+    <fieldset><legend>Step 4 of 6: Select Criteria to Limit on</legend>
+       <table>
+           <!-- TMPL_LOOP NAME="criteria" -->
+           <tr>
+               <td>
+                   <input type="checkbox" name="criteria_column" id="<!-- TMPL_VAR NAME="name" -->" value="<!-- TMPL_VAR NAME="name" -->" /> 
+                   <label for="<!-- TMPL_VAR NAME="name" -->"><!-- TMPL_VAR NAME="description" --> </label>
+               </td>
+               <!-- TMPL_IF NAME="date" -->
+               <td>
+                   <input type="text" size="10" id="<!-- TMPL_VAR NAME="name" -->_value" name="<!-- TMPL_VAR NAME="name" -->_value" value="" />
+                   <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfrom<!-- TMPL_VAR NAME="name" -->" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />                 
+                   <script type="text/javascript">   
+                       Calendar.setup({  
+                       inputField     : "<!-- TMPL_VAR NAME="name" -->_value",
+                       ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+                       button         : "buttonfrom<!-- TMPL_VAR NAME="name" -->",
+                       align          : "Tl" 
+                       });     
+                   </script>          
+               </td>
+           </tr>
+           <!-- TMPL_ELSE -->
+               <!-- TMPL_IF NAME="textrange" -->
+                   <td>from
+                       <input type="text" size="10" id="<!-- TMPL_VAR NAME="from" -->_value" name="<!-- TMPL_VAR NAME="from" -->_value" value="" /> to 
+                       <input type="text" size="10" id="<!-- TMPL_VAR NAME="to" -->_value" name="<!-- TMPL_VAR NAME="to" -->_value" value="" />
+                   </td>
+                   </tr>
+               <!-- TMPL_ELSE -->
+                   <!-- TMPL_IF NAME="daterange" -->
+                   <td>from 
+                       <input type="text" size="10" id="from_<!-- TMPL_VAR NAME="name" -->_value" name="from_<!-- TMPL_VAR NAME="name" -->_value" value="" />
+                       <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfromfrom_<!-- TMPL_VAR NAME="name" -->" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />                 
+                       <script type="text/javascript">   
+                           Calendar.setup({  
+                           inputField     : "from_<!-- TMPL_VAR NAME="name" -->_value",
+                           ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+                           button         : "buttonfromfrom_<!-- TMPL_VAR NAME="name" -->",
+                           align          : "Tl" 
+                           });     
+                       </script>         
+                       to
+                       <input type="text" size="10" id="to_<!-- TMPL_VAR NAME="name" -->_value" name="to_<!-- TMPL_VAR NAME="name" -->_value" value="" />
+                       <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfromto_<!-- TMPL_VAR NAME="name" -->" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />                 
+                       <script type="text/javascript">   
+                           Calendar.setup({  
+                           inputField     : "to_<!-- TMPL_VAR NAME="name" -->_value",
+                           ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+                           button         : "buttonfromto_<!-- TMPL_VAR NAME="name" -->",
+                           align          : "Tl" 
+                           });     
+                       </script>        
+                   </td>
+               </tr>
+                   <!-- TMPL_ELSE -->
+                       <td>
+                           <select name="<!-- TMPL_VAR NAME="name" -->_value">
+                               <!-- TMPL_LOOP NAME="values" -->
+                               <option value="<!-- TMPL_VAR NAME="availablevalues"-->"><!-- TMPL_VAR NAME="availablevalues" --></option>
+                               <!-- /TMPL_LOOP -->
+                           </select>
+                      </td>
+                      </tr>
+                   <!-- /TMPL_IF -->
+               <!-- /TMPL_IF -->
+           <!-- /TMPL_IF -->
+       <!-- /TMPL_LOOP -->
+       </table>
+    </fieldset>
 
 <!-- TMPL_IF NAME="definitions" -->
 <fieldset><legend>Dictionary Definitions</legend><table>
@@ -267,7 +310,8 @@ TMPL_VAR NAME="id" -->" /> <!-- TMPL_VAR NAME="name" --></td></tr>
 <!-- /TMPL_IF -->
 
 <fieldset class="action"><input type="hidden" name="phase" value="Choose these criteria" />
-<input type="submit" name="submit" value="Next &gt;&gt;" /> </fieldset>
+    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="submit" name="submit" value="Next &gt;&gt;" /> </fieldset>
 </form>
 <!-- /TMPL_IF -->
 
@@ -298,7 +342,8 @@ NAME="name" -->"><!-- TMPL_VAR NAME="name" --></label></td>
 </table></fieldset>
 
 <fieldset class="action"><input type="hidden" name="phase" value="Choose These Operations" />
-<input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
+    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
 </form>
 <!-- /TMPL_IF -->
 
index 913e317..d0910de 100755 (executable)
@@ -193,11 +193,32 @@ elsif ( $phase eq 'Choose these criteria' ) {
        my $query_criteria;
     foreach my $crit (@criteria) {
         my $value = $input->param( $crit . "_value" );
-        ($value) or next;
-        if ($value =~ C4::Dates->regexp('syspref')) { 
-            $value = C4::Dates->new($value)->output("iso");
-        }
-        $query_criteria .= " AND $crit='$value'";
+       
+       # If value is not defined, then it may be range values
+       if (!$value) {
+
+           my $fromvalue = $input->param( "from_" . $crit . "_value" );
+           my $tovalue   = $input->param( "to_"   . $crit . "_value" );
+           
+           # If the range values are dates
+           if ($fromvalue =~ C4::Dates->regexp('syspref') && $tovalue =~ C4::Dates->regexp('syspref')) { 
+               $fromvalue = C4::Dates->new($fromvalue)->output("iso");
+               $tovalue = C4::Dates->new($tovalue)->output("iso");
+           }
+
+           if ($fromvalue && $tovalue) {
+               $query_criteria .= " AND $crit >= '$fromvalue' AND $crit <= '$tovalue'";
+           }
+
+       } else {
+
+           # If value is a date
+           if ($value =~ C4::Dates->regexp('syspref')) { 
+               $value = C4::Dates->new($value)->output("iso");
+           }
+           $query_criteria .= " AND $crit='$value'";
+       }
+       warn $query_criteria;
     }
 
     $template->param(