From d470352c9b22d12aa5d76dc5072a36734b8473fc 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 checkbox to 'ignore fund from incoming record?' Leave this unchecked for now and click the 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 checkbox to 'ignore fund from incoming record?' 11) Repeat step 8 and confirm there is no fund pre-selected, for both the staged record and under the Default accounting details tab. Sponsored-by: Friends of Round Rock Library --- acqui/addorderiso2709.pl | 70 +++++++++++++------ .../prog/en/modules/acqui/addorderiso2709.tt | 2 +- .../en/modules/tools/stage-marc-import.tt | 9 +++ 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index e777e64c176..695d5eaff96 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/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 12abc2f71b9..b7f382d16e5 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 072ce87ff8b..a623343e8dd 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 @@ -429,6 +429,7 @@ }) }); [% IF job_enqueued %] + $("#job_callback").after($('')); updateProgress([% job_id | html %], { finish_callback : function(){ $.getJSON('/api/v1/jobs/[% job_id | html %]', function(job){ @@ -442,6 +443,14 @@ }); } }); + $("#clear_fund").change(function(){ + var addbasketlink = $("#addtobasket").prop("href"); + if (this.checked) { + $("#addtobasket").prop("href",addbasketlink+"&clear_fund=1"); + } else { + $("#addtobasket").prop("href",addbasketlink.substring(0,addbasketlink.indexOf("&clear_fund=1"))); + } + }); [% END %] }); -- 2.39.2