Bug 8230: Display acquisition details on the catalogue detail page
authorJonathan Druart <jonathan.druart@biblibre.com>
Wed, 18 Sep 2013 12:30:05 +0000 (14:30 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 13 Dec 2013 23:22:05 +0000 (23:22 +0000)
This patch adds a new tab "Acquitition details" on the catalogue detail
page. It provides a list of order made for this biblio.

New system preference:

AcquisitionDetails: Hide/Show the new tab.  The default for
new and upgraded installations is to display the new tab.

Test plan:
1/ Apply the patch.
2/ Select the "placing an order" value for the AcqCreateItem pref.
3/ Create a new order with X items.
4/ Go on the catalogue detail page for the selected biblio.
5/ Click on the "Acquisition details" tab and check that your order is
displayed. Itemnumbers are present in the last column. Check that links
are not broken.
6/ Close your basket.
7/ Status become "Ordered"
8/ Receive X-1 items.
9/ Come back on the catalogue detail page. There are 2 orders: 1
complete and 1 partial. The complete one has a receive date.
10/ Receive the last item.
11/ Now you have 2 orders with a complete status.
12/ Cancel the last receipt.
13/ You have 1 ordered and 1 complete (2 items).
14/ Cancel the first receipt.
15/ You have 1 ordered (3 items).
16/ Delete your order
17/ You have 1 deleted order.
18/ Switch the AcqCreateItem pref to "receiving an order"
19/ Do again steps 3 to 17.

Signed-off-by: Paola Rossi <paola.rossi@cineca.it>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

C4/Acquisition.pm
catalogue/detail.pl
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt

index dc090b8..cf7e7b7 100644 (file)
@@ -2187,6 +2187,8 @@ sub GetHistory {
     my $basketgroupname = $params{basketgroupname};
     my $budget = $params{budget};
     my $orderstatus = $params{orderstatus};
+    my $biblionumber = $params{biblionumber};
+    my $get_canceled_order = $params{get_canceled_order} || 0;
 
     my @order_loop;
     my $total_qty         = 0;
@@ -2239,10 +2241,16 @@ sub GetHistory {
 
     $query .= " WHERE 1 ";
 
-    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne 'cancelled';
+    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') "
+        if not $get_canceled_order or ( defined $orderstatus and $orderstatus ne 'cancelled' );
 
     my @query_params  = ();
 
+    if ( $biblionumber ) {
+        $query .= " AND biblio.biblionumber = ?";
+        push @query_params, $biblionumber;
+    }
+
     if ( $title ) {
         $query .= " AND biblio.title LIKE ? ";
         $title =~ s/\s+/%/g;
index 955dbf5..6bc0014 100755 (executable)
@@ -20,6 +20,7 @@ use strict;
 use warnings;
 
 use CGI;
+use C4::Acquisition qw( GetHistory GetItemnumbersFromOrder );
 use C4::Auth;
 use C4::Dates qw/format_date/;
 use C4::Koha;
@@ -44,8 +45,6 @@ use C4::HTML5Media;
 use C4::CourseReserves qw(GetItemCourseReservesInfo);
 use C4::Acquisition qw(GetOrdersByBiblionumber);
 
-# use Smart::Comments;
-
 my $query = CGI->new();
 
 my $analyze = $query->param('analyze');
@@ -166,6 +165,19 @@ foreach my $subscription (@subscriptions) {
     push @subs, \%cell;
 }
 
+
+# Get acquisition details
+my ( $orders, $qty, $price, $received ) = C4::Acquisition::GetHistory( biblionumber => $biblionumber, get_canceled_order => 1 );
+if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
+    for my $order ( @$orders ) {
+        $order->{itemnumbers} = [ C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ];
+    }
+}
+$template->param(
+    orders => $orders,
+    AcquisitionDetails => C4::Context->preference('AcquisitionDetails'),
+);
+
 if ( defined $dat->{'itemtype'} ) {
     $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
 }
index 6438483..0de3ac7 100644 (file)
@@ -1,6 +1,7 @@
 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
 ('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'),
 ('AcqItemSetSubfieldsWhenReceived','0','','This syspref set a status for item when items are created when receiving (e.g. 995\$o=5)','Free'),
+('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo'),
 ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'),
 ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'),
 ('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'),
index 19893b4..5258e82 100755 (executable)
@@ -7825,6 +7825,17 @@ if ( CheckVersion($DBversion) ) {
 }
 
 
+
+
+
+$DBversion = "3.13.00.XXX";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo');");
+   print "Upgrade to $DBversion done (Bug 8230: Add AcquisitionDetails)\n";
+   SetVersion ($DBversion);
+}
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 9d15296..5eb493b 100644 (file)
@@ -176,3 +176,9 @@ Cataloging:
             - pref: NotesBlacklist
               class: multi
             - note fields in title notes separator (OPAC record details) and in the description separator (Staff client record details). The fields should appear separated with commas and according with the Koha MARC format (eg 3.. for UNIMARC, 5.. for MARC21)
+        -
+            - pref: AcquisitionDetails
+              choices:
+                  yes: Display
+                  no: "Don't display"
+            - acquisition details on the biblio detail page.
index 26f945c..1bac5a9 100644 (file)
@@ -1,3 +1,4 @@
+[% USE KohaDates %]
 [% USE AuthorisedValues %]
 
 [% ShowCourseReserves = 0 %]
@@ -254,6 +255,18 @@ function verify_images() {
             table.before(link);
             deactivate_filters(id);
         }
+        [% IF AcquisitionDetails %]
+            $("#orders").dataTable($.extend(true, {}, dataTablesDefaults, {
+                'sDom': 't',
+                'bPaginate': false,
+                'bAutoWidth': false,
+                "aaSorting": [[ 2, "desc" ]],
+                "aoColumnDefs": [
+                    { "aTargets": [ 2, 3 ], "sType": "title-string" }
+                ]
+            }));
+
+        [% END %]
     });
 //]]>
 </script>
@@ -482,6 +495,7 @@ function verify_images() {
     [% END %]
 [% IF ( MARCNOTES || notes ) %]<li><a href="#description">Descriptions</a></li>[% END %]
 [% IF ( subscriptionsnumber ) %]<li><a href="#subscriptions">Subscriptions</a></li>[% END %]
+[% IF AcquisitionDetails %]<li><a href="#acq_details">Acquisition details</a></li>[% END %]
 [% IF ( FRBRizeEditions ) %][% IF ( XISBNS ) %]<li><a href="#editions">Editions</a></li>[% END %][% END %]
 [% IF ( LocalCoverImages ) %][% IF ( localimages || CAN_user_tools_upload_local_cover_images ) %]<li><a href="#images">Images</a></li>[% END %][% END %]
 [% IF ( HTML5MediaEnabled ) %][% IF ( HTML5MediaSets ) %]<li><a href="#html5media">Play media</a></li>[% END %][% END %]
@@ -810,6 +824,57 @@ function verify_images() {
 </div>
 [% END %]
 
+[% IF AcquisitionDetails %]
+<div id="acq_details">
+  [% IF orders %]
+    <table id="orders">
+      <thead>
+        <tr>
+          <th>Basket</th>
+          <th>Ordernumber</th>
+          <th>Creation date</th>
+          <th>Receive date</th>
+          <th>Status</th>
+          <th>Quantity / items</th>
+        </tr>
+      </thead>
+      <tbody>
+      [% FOR order IN orders %]
+          <tr>
+            <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% order.basketno %]">[% order.basketname %]</a></td>
+            <td>[% order.ordernumber %]</td>
+            <td><span title="[% order.creationdate %]">[% order.creationdate | $KohaDates%]</span></td>
+            <td><span title="[% order.datereceived %]">[% order.datereceived | $KohaDates%]</span></td>
+            <td>
+              [% SWITCH order.orderstatus %]
+                [% CASE '0' %]New
+                [% CASE '1' %]Ordered
+                [% CASE '2' %]Partial
+                [% CASE '3' %]Complete
+                [% CASE '4' %]Deleted
+              [% END %]
+            </td>
+            <td>
+              [% order.quantity %]
+              [% IF order.itemnumbers.size > 0 && order.orderstatus != '4' %]
+                (
+                  [% FOR itemnumber IN order.itemnumbers %]
+                    <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblionumber %]#item[% itemnumber %]">[% itemnumber %]</a>
+                    [%- UNLESS loop.last %],[% END %]
+                  [% END %]
+                )
+              [% END %]
+            </th>
+          </tr>
+      [% END %]
+      </tbody>
+    </table>
+  [% ELSE %]
+    There is no order for this biblio.
+  [% END %]
+</div>
+[% END %]
+
 [% IF ( FRBRizeEditions ) %][% IF ( XISBNS ) %]
 <div id="editions"><h4>Editions</h4>
 <table>