Bug 14669: Add search option for managing library to orders search
authorKatrin Fischer <katrin.fischer.83@web.de>
Sat, 11 May 2019 21:08:11 +0000 (21:08 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 8 Oct 2019 13:04:48 +0000 (14:04 +0100)
Currently the order search can't be limited by managing library.
The patch adds the search option to the order history search form
and a column for the managing library to the search results table.

To test:
- Create some baskets with orders
  - Set managing library for some, but also have some without
- Apply patch
- prove t/db_dependent/Acquisition.t
- Go to Aquisition > Orders search tab on top > Advanced search link
- Search for orders without limiting
  Orders with and without managing library set should show up
- Limit search to a specific managing library
- Verify results match expectations

Signed-off-by: Alex Sassmannshausen <alex@komputilo.eu>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Acquisition.pm
acqui/histsearch.pl
koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt
t/db_dependent/Acquisition.t

index 4122c5d..75429e7 100644 (file)
@@ -2276,6 +2276,7 @@ params:
   budget
   orderstatus (note that orderstatus '' will retrieve orders
                of any status except cancelled)
+  managing_library
   biblionumber
   get_canceled_order (if set to a true value, cancelled orders will
                       be included)
@@ -2296,7 +2297,8 @@ returns:
                 'ordernumber'      => '1',
                 'quantity'         => 1,
                 'quantityreceived' => undef,
-                'title'            => 'The Adventures of Huckleberry Finn'
+                'title'            => 'The Adventures of Huckleberry Finn',
+                'managing_library' => 'CPL'
             }
 
 =cut
@@ -2322,6 +2324,7 @@ sub GetHistory {
     my $ordernumber = $params{ordernumber};
     my $search_children_too = $params{search_children_too} || 0;
     my $created_by = $params{created_by} || [];
+    my $managing_library = $params{managing_library};
     my $ordernumbers = $params{ordernumbers} || [];
     my $additional_fields = $params{additional_fields} // [];
 
@@ -2358,6 +2361,7 @@ sub GetHistory {
             aqbasket.basketgroupid,
             aqbasket.authorisedby,
             concat( borrowers.firstname,' ',borrowers.surname) AS authorisedbyname,
+            branch as managing_library,
             aqbasketgroups.name as groupname,
             aqbooksellers.name,
             aqbasket.creationdate,
@@ -2484,6 +2488,11 @@ sub GetHistory {
         push @query_params, @$created_by;
     }
 
+    if ( $managing_library ) {
+        $query .= " AND aqbasket.branch = ? ";
+        push @query_params, $managing_library;
+    }
+
     if ( @$ordernumbers ) {
         $query .= ' AND (aqorders.ordernumber IN ( ' . join (',', ('?') x @$ordernumbers ) . '))';
         push @query_params, @$ordernumbers;
index 93bca34..1f097d8 100755 (executable)
@@ -89,15 +89,17 @@ my $filters = {
     ordernumber             => scalar $input->param('ordernumber'),
     search_children_too     => scalar $input->param('search_children_too'),
     created_by              => [ $input->multi_param('created_by') ],
+    managing_library        => scalar $input->param('managing_library'),
 };
+
 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
 my $to_placed_on   = eval { dt_from_string( scalar $input->param('to')   ) } || dt_from_string;
 unless ( $input->param('from') ) {
     # Fill the form with year-1
     $from_placed_on->set_time_zone('floating')->subtract( years => 1 );
 }
-$filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
-$filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
+$filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } );
+$filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } );
 my @additional_fields = Koha::AdditionalFields->search( { tablename => 'aqbasket', searchable => 1 } );
 $template->param( available_additional_fields => \@additional_fields );
 my @additional_field_filters;
index 8cc68b5..ec62b1a 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% USE KohaDates %]
 <ol>
     <li><label for="title">Title: </label> <input type="text" name="title" id="title" value="[% filters.title | html %]" /></li>
             <div id="basket_creators" style="float:left;"></div>
         </div>
     </li>
+    <li>
+        <label for="managing_library">Managing library: </label>
+        <select name="managing_library" id="managing_library">
+            <option value="">Any library</option>
+            [% PROCESS options_for_libraries libraries => Branches.all(selected => '') %]
+        </select>
+    </li>
     <li><label for="booksellerinvoicenumber ">Bookseller invoice no: </label> <input type="text" name="booksellerinvoicenumber" id="booksellerinvoicenumber" value="[% filters.booksellerinvoicenumber | html %]" /></li>
     <li>
         <label for="basketgroupname">Basket group:</label>
index 8a227a1..805a6d2 100644 (file)
@@ -2,6 +2,7 @@
 [% USE Asset %]
 [% USE KohaDates %]
 [% USE ColumnsSettings %]
+[% USE Branches %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; [% IF ( order_loop ) %]Orders search &rsaquo; Search results[% ELSE %]Order search[% END %]</title>
@@ -38,7 +39,8 @@
                 <th>Status</th>
                                <th>Basket</th>
                 <th>Basket creator</th>
-                               <th>Basket group</th>
+                <th>Basket group</th>
+                <th>Managing library</th>
                 <th>Invoice number</th>
                 <th class="anti-the">Summary</th>
                                <th>Vendor</th>
@@ -75,6 +77,7 @@
                             &nbsp;
                         [% END %]
                     </td>
+                    <td>[% Branches.GetName(order.managing_library) | html %]</td>
                     <td>[% IF ( order.invoicenumber ) %]
                             <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% order.invoiceid | uri %]">[% order.invoicenumber | html %]</a>
                         [% ELSE %]
index b6fe38d..781a235 100755 (executable)
@@ -19,7 +19,7 @@ use Modern::Perl;
 
 use POSIX qw(strftime);
 
-use Test::More tests => 77;
+use Test::More tests => 78;
 use t::lib::Mocks;
 use Koha::Database;
 use Koha::Acquisition::Basket;
@@ -838,4 +838,42 @@ subtest 'Test for get_rounded_price' => sub {
     is( $rounded_result3,     $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" );
 
 };
+
+subtest 'GetHistory - managing library' => sub {
+
+    plan tests => 1;
+
+    my $orders = GetHistory(managing_library => 'CPL');
+
+    my $builder = t::lib::TestBuilder->new;
+
+    my $order_basket1 = $builder->build({ source => 'Aqbasket', value => { branch => 'CPL' } });
+    my $orderinfo1 ={
+        basketno => $order_basket1->{basketno},
+        rrp => 19.99,
+        replacementprice => undef,
+        quantity => 1,
+        quantityreceived => 0,
+        datereceived => undef,
+        datecancellationprinted => undef,
+    };
+    my $order1 = $builder->build({ source => 'Aqorder', value => $orderinfo1 });
+
+    my $order_basket2 = $builder->build({ source => 'Aqbasket', value => { branch => 'LIB' } });
+    my $orderinfo2 ={
+        basketno => $order_basket2->{basketno},
+        rrp => 19.99,
+        replacementprice => undef,
+        quantity => 1,
+        quantityreceived => 0,
+        datereceived => undef,
+        datecancellationprinted => undef,
+    };
+    my $order2 = $builder->build({ source => 'Aqorder', value => $orderinfo2 });
+
+    my $history = GetHistory(managing_library => 'CPL');
+    is( scalar( @$history), scalar ( @$orders ) +1, "GetHistory returns number of orders");
+
+};
+
 $schema->storage->txn_rollback();