From 6a8843146259c0a86607f5ec92ac37d038774bea Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 22 Jul 2024 05:13:52 +0000 Subject: [PATCH] Bug 31606: Add option to ignore the incoming fund on newly staged files This enhancement adds the option to ignore the fund specified in newly staged records when adding orders to a basket. To test: 1) Configure the MarcFieldsToOrder syspref so that Koha knows to map a MARC field in the staged record to a budget. It may look something like this: budget_code: 942$e 2) Make sure you have a MARC file where your configured MARC field contains a fund code that exists in your Koha. You could follow these steps: a) Create an active budget b) Attach a fund with code FUND c) Edit a record d) If using the mapping configured in MarcFieldsToOrder above, add FUND to the 942$e of your record e) Download the record in MARCXML format 3) Go to Acquisitions. Create a vendor and a basket if you don't already have them. 4) Add an order to the basket 5) Choose 'From a new file' 6) Upload the MARCXML you just downloaded and stage for import 7) In the 'job enqueued' box, notice there is a sceond button to 'Add staged files and ignore incoming fund'. Click the normal button to Add staged files to basket 8) Open the record you just staged by clicking on it/the checkbox. Confirm the fund pre-selected is the FUND from your budget_code field i.e. 942$e. Go to the Default accounting details tab, there may or may not be a different fund selected there. 9) Click Cancel, you'll be redirected back to the basket. 10) Repeat steps 4-7, except this time, check the new second button to 'Add staged files and ignore incoming fund' 11) Repeat step 8 and confirm there is no fund pre-selected, for both the staged record and under the Default accounting details tab. 12) Click Cancel, you'll be redirected back to the basket. 13) Repeat steps 4-7, except this time, click the 'View detail of the enqueued job' link 14) Confirm both buttons are there to add staged files to basket, with or without incoming fund, and they work as expected. Sponsored-by: Friends of Round Rock Library Signed-off-by: Rhonda Kuiper --- acqui/addorderiso2709.pl | 70 +++++++++++++------ .../background_jobs/stage_marc_for_import.inc | 1 + .../prog/en/modules/acqui/addorderiso2709.tt | 2 +- .../en/modules/tools/stage-marc-import.tt | 2 +- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index e777e64c17..695d5eaff9 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -63,11 +63,12 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ flagsrequired => { acquisition => 'order_manage' }, }); -my $cgiparams = $input->Vars; -my $op = $cgiparams->{'op'} || ''; -my $booksellerid = $input->param('booksellerid'); -my $allmatch = $input->param('allmatch'); -my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); +my $cgiparams = $input->Vars; +my $op = $cgiparams->{'op'} || ''; +my $booksellerid = $input->param('booksellerid'); +my $allmatch = $input->param('allmatch'); +my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); +my $clear_fund = $input->param('clear_fund'); $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", booksellerid => $booksellerid, @@ -104,7 +105,7 @@ if ($op eq ""){ bookseller => $bookseller, "allmatch" => $allmatch, ); - import_biblios_list($template, $cgiparams->{'import_batch_id'}); + import_biblios_list( $template, $cgiparams->{'import_batch_id'}, $clear_fund ); if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { # prepare empty item form my $cell = PrepareItemrecordDisplay( '', '', undef, 'ACQ' ); @@ -393,11 +394,11 @@ if ($op eq ""){ exit; } -my $budgets = GetBudgets(); -my $budget_id = @$budgets[0]->{'budget_id'}; +my $budgets = GetBudgets(); +my $budget_id = $clear_fund ? "" : @$budgets[0]->{'budget_id'}; + # build bookfund list -my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; -my $budget = GetBudget($budget_id); +my $patron = Koha::Patrons->find($loggedinuser)->unblessed; # build budget list my %budget_loops; @@ -461,7 +462,7 @@ sub import_batches_list { } sub import_biblios_list { - my ($template, $import_batch_id) = @_; + my ( $template, $import_batch_id, $clear_fund ) = @_; my $batch = GetImportBatch($import_batch_id,'staged'); return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/; my $import_records = Koha::Import::Records->search({ @@ -508,23 +509,50 @@ sub import_biblios_list { ); my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; - my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']); - my $price = looks_like_number($infos->{price}) ? $infos->{price} : GetMarcPrice( $marcrecord, C4::Context->preference('marcflavour') ); + my $infos = get_infos_syspref( + 'MarcFieldsToOrder', $marcrecord, + [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice' ] + ); + my $price = + looks_like_number( $infos->{price} ) + ? $infos->{price} + : GetMarcPrice( $marcrecord, C4::Context->preference('marcflavour') ); my $replacementprice = $infos->{replacementprice}; - my $quantity = $infos->{quantity}; - my $budget_code = $infos->{budget_code}; - my $discount = $infos->{discount}; - my $sort1 = $infos->{sort1}; - my $sort2 = $infos->{sort2}; - my $budget_id; - - if ($budget_code) { + my $quantity = $infos->{quantity}; + my $budget_code = $infos->{budget_code}; + my $discount = $infos->{discount}; + my $sort1 = $infos->{sort1}; + my $sort2 = $infos->{sort2}; + my $budget_id = ""; + + if ( $budget_code and not $clear_fund ) { my $biblio_budget = GetBudgetByCode($budget_code); if ($biblio_budget) { $budget_id = $biblio_budget->{budget_id}; } } + my %budget_loops; + my $budgets_hierarchy = GetBudgetHierarchy; + foreach my $r ( @{$budgets_hierarchy} ) { + unless ( defined $budget_loops{ $r->{budget_period_id} } ) { + $budget_loops{ $r->{budget_period_id} }->{description} = $r->{budget_period_description}; + $budget_loops{ $r->{budget_period_id} }->{active} = $r->{budget_period_active}; + $budget_loops{ $r->{budget_period_id} }->{funds} = []; + } + push @{ $budget_loops{ $r->{budget_period_id} }->{funds} }, { + b_id => $r->{budget_id}, + b_txt => $r->{budget_name}, + b_code => $r->{budget_code}, + b_sort1_authcat => $r->{'sort1_authcat'}, + b_sort2_authcat => $r->{'sort2_authcat'}, + b_active => $r->{budget_period_active}, + b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0, + b_level => $r->{budget_level}, + }; + } + $cellrecord{budget_loop} = \%budget_loops; + # Items my @itemlist = (); my $all_items_quantity = 0; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc index 1ecc6747d7..e0b743bed0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc @@ -41,6 +41,7 @@ [% IF report.basket_id && report.vendor_id %]

Add staged files to basket + Add staged files to basket and ignore incoming fund

[% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 12abc2f71b..b7f382d16e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -213,7 +213,7 @@ [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt index 072ce87ff8..c62dde75af 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt @@ -437,7 +437,7 @@ let basket_id = job.data.report.basket_id; let vendor_id = job.data.report.vendor_id; if ( basket_id && vendor_id ) { - $('

%s

'.format(import_batch_id, basket_id, vendor_id, _("Add staged files to basket"))).appendTo("#job_callback"); + $('

%s %s

'.format(import_batch_id, basket_id, vendor_id, _("Add staged files to basket"), import_batch_id, basket_id, vendor_id, _("Add staged files to basket and ignore incoming fund"))).appendTo("#job_callback"); } }); } -- 2.39.2