From 81eb0ebcef4374f29263160f7347265172116502 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
---
Koha/MarcOrder.pm | 29 ++++++++++++++++---
acqui/addorderiso2709.pl | 6 ++--
.../background_jobs/stage_marc_for_import.inc | 6 ++++
.../prog/en/modules/acqui/addorderiso2709.tt | 2 +-
.../en/modules/tools/stage-marc-import.tt | 2 +-
5 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/Koha/MarcOrder.pm b/Koha/MarcOrder.pm
index 13053c588d9..33c81df8f24 100644
--- a/Koha/MarcOrder.pm
+++ b/Koha/MarcOrder.pm
@@ -52,7 +52,7 @@ use C4::Biblio qw(
GetMarcPrice
);
use C4::Items qw( AddItemFromMarc );
-use C4::Budgets qw( GetBudgetByCode );
+use C4::Budgets qw( GetBudgetByCode GetBudgetHierarchy );
use Koha::Database;
use Koha::ImportBatchProfiles;
@@ -651,12 +651,12 @@ sub import_batches_list {
For an import batch, this function reads the files and creates all the relevant data pertaining to that file
It then returns this to the template to be shown in the UI
-Koha::MarcOrder->import_biblios_list( $cgiparams->{'import_batch_id'} );
+ Koha::MarcOrder->import_biblios_list( $cgiparams->{'import_batch_id'}, $clear_fund );
=cut
sub import_biblios_list {
- my ( $self, $import_batch_id ) = @_;
+ my ( $self, $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(
@@ -733,13 +733,34 @@ sub import_biblios_list {
my $sort2 = $infos->{sort2} || undef;
my $budget_id;
- if ($budget_code) {
+ 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/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl
index 7cfa45776ac..3826bb060d6 100755
--- a/acqui/addorderiso2709.pl
+++ b/acqui/addorderiso2709.pl
@@ -71,6 +71,7 @@ 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",
@@ -116,7 +117,7 @@ if ( $op eq "" ) {
bookseller => $bookseller,
"allmatch" => $allmatch,
);
- my $biblios_list = Koha::MarcOrder->import_biblios_list( $cgiparams->{'import_batch_id'} );
+ my $biblios_list = Koha::MarcOrder->import_biblios_list( $cgiparams->{'import_batch_id'}, $clear_fund );
my $overlay_action = $biblios_list->{overlay_action};
my $nomatch_action = $biblios_list->{nomatch_action};
my $item_action = $biblios_list->{item_action};
@@ -307,11 +308,10 @@ if ( $op eq "" ) {
}
my $budgets = GetBudgets();
-my $budget_id = @$budgets[0]->{'budget_id'};
+my $budget_id = $clear_fund ? "" : @$budgets[0]->{'budget_id'};
# build bookfund list
my $patron = Koha::Patrons->find($loggedinuser)->unblessed;
-my $budget = GetBudget($budget_id);
# build budget list
my %budget_loops;
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 f3d88312218..2cd0fde645b 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
@@ -42,6 +42,12 @@
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 684751f1627..b69c35283f0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt
@@ -273,7 +273,7 @@
Required
[% 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 e42fde81c6b..452d5a6c6ad 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
@@ -436,7 +436,7 @@
let basket_id = job.data.report.basket_id;
let vendor_id = job.data.report.vendor_id;
if ( basket_id && vendor_id ) {
- $('