From 70de0532845b2c12ef5ac1294e9a68906c5c58e1 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 13 Jun 2024 00:14:57 +0000 Subject: [PATCH] Bug 27063: Link different record to order from existing records This patch adds the ability to link an order to a different record. This applies to: * orders in open baskets (not closed) * unreceived orders in standing baskets Orders can be linked: * from an existing record * from a suggestion * from a subscription * from a new (empty) record * from existing orders (copy) * from an external source To test: 1. Apply the patches and restart services 2. Create a normal basket (do not check 'orders are standing'). Add an order to the basket. 3. Notice there is a 'Link to different record' option in the Modify column. 4. Close the basket. 5. Create another basket, this time do check the 'orders are standing' option. Add two orders to the basket. 6. Click 'Link to different record' for one of the orders. 7. Create a suggestion. Create a subscription. Have a MARC record available to stage/import. 8. Loop through each option, linking: * from an existing record * from a suggestion * from a subscription * from a new (empty) record * from existing orders (copy) * from an external source Make sure that the accounting information is always kept, and just the record details of the order are changed. 9. Go to the vendor page and click 'Receive shipments'. Fill in invoice details. 10. On the receiving page, 'Receive' one of your standing orders. Increment the quantity and finish receiving. 11. Go to the standing basket. Confirm there is no 'Link to different record' option for the received order. Sponsored-by: Auckland University of Technology --- C4/Breeding.pm | 5 +-- Koha/Acquisition/Order.pm | 9 ++++- acqui/duplicate_orders.pl | 8 +++++ acqui/neworderempty.pl | 22 +++++++++++++ acqui/newordersubscription.pl | 2 ++ acqui/newordersuggestion.pl | 16 +++++---- acqui/z3950_search.pl | 33 ++++++++++--------- .../prog/en/includes/subscriptions-search.inc | 3 ++ .../prog/en/modules/acqui/basket.tt | 8 ++++- .../prog/en/modules/acqui/duplicate_orders.tt | 24 ++++++++++++++ .../en/modules/acqui/newordersubscription.tt | 4 +++ .../en/modules/acqui/newordersuggestion.tt | 12 +++++-- .../prog/en/modules/acqui/z3950_search.tt | 9 ++++- 13 files changed, 126 insertions(+), 29 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 8dbaae9fff3..50ae4fb5ea5 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -215,8 +215,9 @@ sub Z3950Search { $template->param( breeding_loop => \@breeding_loop, - servers => \@servers, - errconn => \@errconn + servers => \@servers, + errconn => \@errconn, + ordernumber => $pars->{ordernumber}, ); } diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index b8399e3524c..a9aac284e53 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -443,6 +443,8 @@ sub duplicate_to { my ( $self, $basket, $default_values ) = @_; my $new_order; $default_values //= {}; + my $linking_ordernumber = $default_values->{linking_ordernumber} || undef; + delete $default_values->{linking_ordernumber}; Koha::Database->schema->txn_do( sub { my $order_info = $self->unblessed; @@ -471,7 +473,12 @@ sub duplicate_to { $order_info->{created_by} = $userenv->{number}; $order_info->{basketno} = $basket->basketno; - $new_order = Koha::Acquisition::Order->new($order_info)->store; + if ($linking_ordernumber) { + delete $order_info->{ordernumber}; + $new_order = Koha::Acquisition::Orders->find($linking_ordernumber)->update($order_info); + } else { + $new_order = Koha::Acquisition::Order->new($order_info)->store; + } if ( ! $self->subscriptionid && $self->basket->effective_create_items eq 'ordering') { # Do copy items if not a subscription order AND if items are created on ordering my $items = $self->items; diff --git a/acqui/duplicate_orders.pl b/acqui/duplicate_orders.pl index 05b6b28628c..80913acdbb0 100755 --- a/acqui/duplicate_orders.pl +++ b/acqui/duplicate_orders.pl @@ -67,6 +67,8 @@ my $filters = { created_by => [$input->multi_param('created_by')] }; +my $linking_ordernumber = scalar $input->param('linking_ordernumber'); + my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string; my $to_placed_on = @@ -124,6 +126,7 @@ elsif ( $op eq 'cud-batch_edit' ) { $template->param( currencies => Koha::Acquisition::Currencies->search, budget_loop => $budget_loop, + linking_ordernumber => $linking_ordernumber, ); } elsif ( $op eq 'cud-do_duplicate' ) { @@ -137,6 +140,10 @@ elsif ( $op eq 'cud-do_duplicate' ) { $default_values->{$field} = $input->param("all_$field"); } + if ( $linking_ordernumber ) { + $default_values->{linking_ordernumber} = $linking_ordernumber; + } + @ordernumbers = $input->multi_param('ordernumber'); my @new_ordernumbers; for my $ordernumber (@ordernumbers) { @@ -173,6 +180,7 @@ $template->param( bp_loop => $bp_loop, ordernumbers => \@ordernumbers, op => $op, + linking_ordernumber => $linking_ordernumber, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 95c31d9aa85..f4b1566491c 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -146,6 +146,28 @@ $booksellerid = $basket->{booksellerid} unless $booksellerid; my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); $data = GetOrder($ordernumber) if $ordernumber; +my $newdata; + +# re-linking order to a different record +if ( $biblionumber and $biblionumber != $data->{biblionumber} ) { + $newdata = GetBiblioData($biblionumber); +} elsif ( $suggestionid and $ordernumber ) { + $newdata = GetSuggestion($suggestionid); +} elsif ( $ordernumber and $input->param('relink') ) { + $newdata = {}; +} +if ($newdata) { + $data->{biblionumber} = $biblionumber; + $data->{title} = $newdata->{title} || ""; + $data->{author} = $newdata->{author} || ""; + $data->{publishercode} = $newdata->{publishercode} || ""; + $data->{editionstatement} = $newdata->{editionstatement} || ""; + $data->{publicationyear} = $newdata->{publicationyear} || ""; + $data->{isbn} = $newdata->{isbn} || ""; + $data->{seriestitle} = $newdata->{seriestitle} || ""; + $data->{copyrightdate} = $newdata->{copyrightdate} || ""; +} + output_and_exit( $input, $cookie, $template, 'unknown_basket') unless $basketobj; output_and_exit( $input, $cookie, $template, 'unknown_vendor') unless $bookseller; diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl index e8d776598bf..f6be8009e7f 100755 --- a/acqui/newordersubscription.pl +++ b/acqui/newordersubscription.pl @@ -37,6 +37,7 @@ my $branch = $query->param('branch_filter'); my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); my $searched = $query->param('searched'); my $biblionumber = $query->param('biblionumber'); +my $ordernumber = $query->param('ordernumber'); my $basketno = $query->param('basketno'); my $booksellerid = $query->param('booksellerid'); @@ -88,5 +89,6 @@ $template->param( basketno => $basket->{basketno}, basketname => $basket->{basketname}, booksellername => $bookseller->name, + ordernumber => $ordernumber, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl index 9d35ec48def..964b88c0181 100755 --- a/acqui/newordersuggestion.pl +++ b/acqui/newordersuggestion.pl @@ -103,14 +103,15 @@ my $input = CGI->new; # getting the CGI params my $basketno = $input->param('basketno'); -my $booksellerid = $input->param('booksellerid'); +my $booksellerid = $input->param('booksellerid'); my $author = $input->param('author'); my $title = $input->param('title'); my $publishercode = $input->param('publishercode'); my $op = $input->param('op'); my $suggestionid = $input->param('suggestionid'); my $duplicateNumber = $input->param('duplicateNumber'); -my $uncertainprice = $input->param('uncertainprice'); +my $uncertainprice = $input->param('uncertainprice'); +my $ordernumber = $input->param('ordernumber') || undef; $op = 'else' unless $op; @@ -140,11 +141,12 @@ my $suggestions = [ Koha::Suggestions->search_limited( my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid ); $template->param( - suggestions => $suggestions, - basketno => $basketno, - booksellerid => $booksellerid, - name => $vendor->name, - "op_$op" => 1, + suggestions => $suggestions, + basketno => $basketno, + booksellerid => $booksellerid, + name => $vendor->name, + "op_$op" => 1, + ordernumber => $ordernumber, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/z3950_search.pl b/acqui/z3950_search.pl index 6913adeceea..42803c994cb 100755 --- a/acqui/z3950_search.pl +++ b/acqui/z3950_search.pl @@ -50,6 +50,7 @@ my $booksellerid = $input->param('booksellerid'); my $basketno = $input->param('basketno'); my $page = $input->param('current_page') || 1; $page = $input->param('goto_page') if $input->param('changepage_goto'); +my $ordernumber = $input->param('ordernumber'); # get framework list my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); @@ -99,6 +100,7 @@ if ( $op ne "cud-do_search" ) { $template->param( serverloop => [ $rs->all ], opsearch => "cud-search", + ordernumber => $ordernumber, ); output_html_with_http_headers $input, $cookie, $template->output; exit; @@ -111,21 +113,22 @@ if (@id==0) { exit; } -my $pars= { - biblionumber => $biblionumber, - page => $page, - id => \@id, - isbn => $isbn, - issn => $issn, - title => $title, - author => $author, - dewey => $dewey, - subject => $subject, - lccall => $lccall, - controlnumber => $controlnumber, - stdid => $stdid, - srchany => $srchany, - publicationyear => $publicationyear, +my $pars = { + biblionumber => $biblionumber, + page => $page, + id => \@id, + isbn => $isbn, + issn => $issn, + title => $title, + author => $author, + dewey => $dewey, + subject => $subject, + lccall => $lccall, + controlnumber => $controlnumber, + stdid => $stdid, + srchany => $srchany, + publicationyear => $publicationyear, + ordernumber => $ordernumber, }; Z3950Search($pars, $template); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc index 5e1275d249c..362133cf4c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc @@ -43,6 +43,9 @@ [% IF (basketno) %] [% END %] + [% IF ordernumber %] + + [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index cb920e3bfb5..270e946912d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -910,7 +910,7 @@
  • From a suggestion
  • From a subscription
  • -
  • From a new (empty) record
  • +
  • From a new (empty) record
  • From existing orders (copy)
  • From an external source
  • @@ -1160,6 +1160,12 @@ $("#relinkOrder").find("input[id='searchtoorder']").attr("data-ordernumber", ordernumber); $("#relinkOrder a").each(function() { var link = $(this).attr("href"); + if ( link.indexOf("&linking_ordernumber") >= 0 ) { + link = link.substring( 0, link.indexOf("&linking_ordernumber") ); + } + if ( link.indexOf("&ordernumber") >= 0 ) { + link = link.substring( 0, link.indexOf("&ordernumber") ); + } if ( link.indexOf("duplicate_orders") >= 0 ) { $(this).attr("href", link + "&linking_ordernumber=" + ordernumber); } else { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt index 7657df8bff4..da58a632fa0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt @@ -71,6 +71,9 @@ + [% IF linking_ordernumber %] + + [% END %]
    @@ -139,6 +142,9 @@
    [% INCLUDE 'csrf-token.inc' %]
    + [% IF linking_ordernumber %] +
    Only one order can be selected for duplication when linking to an existing order.
    + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt index 1556470c563..0b91e35ba81 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt @@ -128,6 +128,7 @@ tr.selected td { +

    Search targets

    @@ -220,7 +221,13 @@ tr.selected td {
    -- 2.39.2
    Select all @@ -178,6 +184,9 @@
    + [% IF linking_ordernumber %] + + [% END %]
    @@ -259,6 +268,9 @@ + [% IF linking_ordernumber %] + + [% END %] Cancel @@ -435,6 +447,18 @@ $("input[name='copy_existing_value']").each(function(){ render_disabled(this); }); + + [% IF linking_ordernumber %] + $("input[type='checkbox'][name='ordernumber']").on("click", function() { + var checkbox_count = $("input[type='checkbox'][name='ordernumber']:checked").length; + if ( checkbox_count < 1 ) { + $("input[type='checkbox'][name='ordernumber']").removeAttr("disabled"); + } else { + $("input[type='checkbox'][name='ordernumber']").prop("disabled","disabled"); + $("input[type='checkbox'][name='ordernumber']:checked").removeAttr("disabled"); + } + }); + [% END %] }); function render_disabled (elt) { var field = $(elt).val(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt index b164248092e..d40bb8f7848 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt @@ -91,7 +91,11 @@ Outstanding order [% END %] [% IF not sub.aqbooksellerid || booksellerid == sub.aqbooksellerid %] + [% IF ordernumber %] + + [% ELSE %] + [% END %] [% tp('verb', 'Order') | html %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt index 0a0b968b57a..1d1b37e0399 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt @@ -101,9 +101,17 @@
    [% IF ( suggestion.biblionumber ) %] - [% tp('verb', 'Order') | html %] + [% IF ordernumber %] + [% tp('verb', 'Order') | html %] + [% ELSE %] + [% tp('verb', 'Order') | html %] + [% END %] [% ELSE %] - [% tp('verb', 'Order') | html %] + [% IF ordernumber %] + [% tp('verb', 'Order') | html %] + [% ELSE %] + [% tp('verb', 'Order') | html %] + [% END %] [% END %]