From 45180c01c9ddd21bc54458ce4513aaf0e277a536 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 13 Jun 2024 00:14:57 +0000 Subject: [PATCH] Bug 27063: [WIP] Link different record to order from existing records So far this works for * from an existing record * from a suggestion * from a new (empty) record * from a subscription * from existing orders (copy) Working on: * from an external source --- 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 | 32 ++++++++++--------- .../prog/en/includes/subscriptions-search.inc | 3 ++ .../prog/en/modules/acqui/basket.tt | 2 +- .../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 | 7 +++- 13 files changed, 117 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..55fdb1eebb5 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'] }); @@ -111,21 +112,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 fae6c01d890..84aa26e399d 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
  • [% IF ( CAN_user_tools_stage_marc_import ) %]
  • From a new file
  • [% END %] 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..67437d5fe68 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 @@ -220,7 +220,12 @@ 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 %]