From ad2240b0cf924fdd3cbcdeadbee4e4fa46bb5b56 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 7 Aug 2018 13:09:22 +0000 Subject: [PATCH] Bug 14850: Use optgroups to display active/inactive budgets This is incomplete, some issues: 1 - It doesn't match current use of checkbox on other pages 2 - It should use a block instead of repeating code 3 - All of the dropdowns for funds should probably be moved to a single include file and/or use a template plugin Leaving this here rather for future work https://bugs.koha-community.org/show_bug.cgi?id=14580 --- Koha/Acquisition/Fund.pm | 15 ++++ acqui/invoice.pl | 25 ++++--- .../intranet-tmpl/prog/en/modules/acqui/invoice.tt | 87 ++++++++++++++++------ t/db_dependent/Koha/Acquisition/Funds.t | 19 ++++- 4 files changed, 114 insertions(+), 32 deletions(-) diff --git a/Koha/Acquisition/Fund.pm b/Koha/Acquisition/Fund.pm index 20cc26e..5b6f0ef 100644 --- a/Koha/Acquisition/Fund.pm +++ b/Koha/Acquisition/Fund.pm @@ -18,6 +18,7 @@ package Koha::Acquisition::Fund; use Modern::Perl; use Koha::Database; +use Koha::Acquisition::Budgets; use base qw(Koha::Object); @@ -37,4 +38,18 @@ sub _type { return 'Aqbudget'; } +=head3 budget + +my $budget = $fund->budget; + +Return the budget this fund belongs to + +=cut + +sub budget { + my ( $self ) = @_; + my $budget = Koha::Acquisition::Budgets->find( $self->budget_period_id); + return $budget; +} + 1; diff --git a/acqui/invoice.pl b/acqui/invoice.pl index bdf9485..5463233 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -36,6 +36,7 @@ use C4::Budgets; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; +use Koha::Acquisition::Funds; use Koha::DateUtils; use Koha::Misc::Files; use Koha::Acquisition::Invoice::Adjustments; @@ -187,18 +188,23 @@ foreach my $order (@$orders) { push @foot_loop, map {$_} values %foot; -my $budgets = GetBudgets(); -my @budgets_loop; +my @funds = Koha::Acquisition::Funds->search(); +my @active_funds_loop; +my @inactive_funds_loop; my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; -foreach my $budget (@$budgets) { - next unless CanUserUseBudget( $loggedinuser, $budget, $flags ); - my %line = %{$budget}; +foreach my $fund (@funds) { + my $line = $fund->unblessed; + next unless CanUserUseBudget( $loggedinuser, $fund, $flags ); if ( $shipmentcost_budgetid - and $budget->{budget_id} == $shipmentcost_budgetid ) + and $fund->budget_id == $shipmentcost_budgetid ) { - $line{selected} = 1; + $line->{selected} = 1; + } + if ( $fund->budget->budget_period_active ){ + push @active_funds_loop, \%$line; + } else { + push @inactive_funds_loop, \%$line; } - push @budgets_loop, \%line; } my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} }); @@ -223,7 +229,8 @@ $template->param( total_tax_included_shipment => $total_tax_included + $shipmentcost, invoiceincgst => $bookseller->invoiceincgst, currency => Koha::Acquisition::Currencies->get_active, - budgets_loop => \@budgets_loop, + active_funds_loop => \@active_funds_loop, + inactive_funds_loop => \@inactive_funds_loop, ); defined( $invoice_files ) && $template->param( files => $invoice_files->GetFilesInfo() ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt index 85a23c5..48369b6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -50,15 +50,28 @@
  • [% IF ( invoiceclosedate ) %] @@ -132,16 +145,29 @@ [% IF adjustment.encumber_open %] @@ -201,11 +227,28 @@
  • diff --git a/t/db_dependent/Koha/Acquisition/Funds.t b/t/db_dependent/Koha/Acquisition/Funds.t index 4232571..b32e7e5 100644 --- a/t/db_dependent/Koha/Acquisition/Funds.t +++ b/t/db_dependent/Koha/Acquisition/Funds.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Koha::Acquisition::Funds; use Koha::Database; @@ -45,5 +45,22 @@ is( $retrieved_fund_1->budget_name, $new_fund->budget_name, 'Find a fund by budg $retrieved_fund_1->delete; is( Koha::Acquisition::Funds->search->count, $nb_of_funds, 'Delete should have deleted the fund' ); +subtest 'budget method tests' => sub { + + plan tests => 1; + + my $budget = $builder->build({ + source => 'Aqbudgetperiod' + }); + my $fund = $builder->build({ + source => 'Aqbudget', + value => { budget_period_id => $budget->{budget_period_id} } + }); + my $retrieved_fund = Koha::Acquisition::Funds->find( $fund->{budget_id} ); + + is( $retrieved_fund->budget->budget_period_id, $budget->{budget_period_id},"The budget retrieved is the same as the one created"); + +}; + $schema->storage->txn_rollback; -- 2.1.4