From 5c5f8f98069d9993cee6f7f5c80df40f7517e575 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 19 Oct 2022 17:12:38 -0300 Subject: [PATCH] Bug 31115: Add support for additional fields for invoices This patch adds support for additional fields for invoices. A new option is added to the 'Additional fields' admin page, for the 'aqinvoices' table. Adding/editing invoices now supports this additional fields. To test: 1. Apply this patches 2. Verify the original test plan works => SUCCESS: It does! 3. Sign off :-D Sponsored-by: The Research University in the Helmholtz Association (KIT) Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Invoice.pm | 2 +- Koha/Acquisition/Invoices.pm | 2 +- Koha/Schema/Result/Aqinvoice.pm | 16 ++++++++++++ acqui/invoice.pl | 22 ++++++++++++++++ acqui/parcels.pl | 25 ++++++++++++++++++- .../prog/en/modules/acqui/invoice.tt | 5 ++++ .../prog/en/modules/acqui/parcels.tt | 5 ++++ .../en/modules/admin/additional-fields.tt | 5 +++- 8 files changed, 78 insertions(+), 4 deletions(-) diff --git a/Koha/Acquisition/Invoice.pm b/Koha/Acquisition/Invoice.pm index df46b65a30..be36b5d718 100644 --- a/Koha/Acquisition/Invoice.pm +++ b/Koha/Acquisition/Invoice.pm @@ -19,7 +19,7 @@ use Modern::Perl; use Koha::Database; -use base qw(Koha::Object); +use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); =head1 NAME diff --git a/Koha/Acquisition/Invoices.pm b/Koha/Acquisition/Invoices.pm index 4fb1d92f9b..3c530d73e0 100644 --- a/Koha/Acquisition/Invoices.pm +++ b/Koha/Acquisition/Invoices.pm @@ -21,7 +21,7 @@ use Koha::Database; use Koha::Acquisition::Invoice; -use base qw(Koha::Objects); +use base qw(Koha::Objects Koha::Objects::Mixin::AdditionalFields); =head1 NAME diff --git a/Koha/Schema/Result/Aqinvoice.pm b/Koha/Schema/Result/Aqinvoice.pm index e27cbfa20a..89fea491df 100644 --- a/Koha/Schema/Result/Aqinvoice.pm +++ b/Koha/Schema/Result/Aqinvoice.pm @@ -220,6 +220,22 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LkekSbup37Z2WVnU/c9K+g +__PACKAGE__->has_many( + "additional_field_values", + "Koha::Schema::Result::AdditionalFieldValue", + sub { + my ($args) = @_; + + return { + "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.invoiceid" }, + + "$args->{foreign_alias}.field_id" => + { -in => \'(SELECT id FROM additional_fields WHERE tablename="aqinvoices")' }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub koha_object_class { 'Koha::Acquisition::Invoice'; } diff --git a/acqui/invoice.pl b/acqui/invoice.pl index f283f9721c..0f8f57b6f6 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -38,9 +38,11 @@ use C4::Log qw(logaction); use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies qw( get_active ); +use Koha::AdditionalFields; use Koha::DateUtils qw( output_pref ); use Koha::Misc::Files; use Koha::Acquisition::Invoice::Adjustments; +use Koha::Acquisition::Invoices; my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -125,6 +127,18 @@ elsif ( $op && $op eq 'mod' ) { MergeInvoices($invoiceid, \@sources); defined($invoice_files) && $invoice_files->MergeFileRecIds(@sources); } + + my @additional_fields; + my $invoice_fields = Koha::AdditionalFields->search({ tablename => 'aqinvoices' }); + while ( my $field = $invoice_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + Koha::Acquisition::Invoices->find($invoiceid)->set_additional_fields(\@additional_fields); + $template->param( modified => 1 ); } elsif ( $op && $op eq 'delete' ) { @@ -298,6 +312,14 @@ foreach my $r ( @{$budgets} ) { my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} }); if ( $adjustments ) { $template->param( adjustments => $adjustments ); } +my $invoice = Koha::Acquisition::Invoices->find($invoiceid); +$template->param( + available_additional_fields => Koha::AdditionalFields->search( { tablename => 'aqinvoices' } ), + additional_field_values => { map { + $_->field->id => $_->value + } $invoice->additional_field_values->as_list }, +); + $template->param( invoiceid => $details->{'invoiceid'}, invoicenumber => $details->{'invoicenumber'}, diff --git a/acqui/parcels.pl b/acqui/parcels.pl index 9fa697a179..985947ef56 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -75,6 +75,8 @@ use C4::Acquisition qw( GetInvoices GetInvoice AddInvoice ); use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget ); use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Invoices; +use Koha::AdditionalFields; use Koha::DateUtils qw( dt_from_string ); my $input = CGI->new; @@ -118,6 +120,7 @@ if ( $op and $op eq 'new' ) { } $op = 'confirm' unless $template->{'VARS'}->{'duplicate_invoices'}; } + if ($op and $op eq 'confirm') { my $invoiceid = AddInvoice( invoicenumber => $invoicenumber, @@ -126,7 +129,23 @@ if ($op and $op eq 'confirm') { shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipmentcost_budgetid, ); - if(defined $invoiceid) { + if (defined $invoiceid) { + + my @additional_fields; + my $invoice_fields = Koha::AdditionalFields->search({ tablename => 'aqinvoices' }); + while ( my $field = $invoice_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + if (defined $value) { + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + } + if (@additional_fields) { + my $invoice = Koha::Acquisition::Invoices->find( $invoiceid ); + $invoice->set_additional_fields(\@additional_fields); + } # Successful 'Add' print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid"); exit 0; @@ -135,6 +154,10 @@ if ($op and $op eq 'confirm') { } } +$template->param( + available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'aqinvoices' })->as_list ] +); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my @parcels = GetInvoices( supplierid => $booksellerid, 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 0cab159113..8356da2b09 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -140,6 +140,11 @@ [% END %] [% END %] +
+ [% IF available_additional_fields.count %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
[% UNLESS readonly %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt index ff359efbcc..ffe58aac4c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt @@ -191,6 +191,11 @@ +
+ [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
Cancel
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt index e3efdaf184..31acd80d05 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt @@ -12,7 +12,7 @@ [% marcfield_tables = ['subscription'] %] -[% searchable_tables = ['subscription', 'aqbasket'] %] +[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices'] %] [% show_marcfield = marcfield_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %] [% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %] @@ -117,6 +117,9 @@ [% IF CAN_user_acquisition_order_manage %] [% WRAPPER table_option value="aqbasket" %]Order baskets[% END %] [% END %] + [% IF CAN_user_acquisition_edit_invoices %] + [% WRAPPER table_option value="aqinvoices" %]Invoices[% END %] + [% END %] [% IF CAN_user_serials_edit_subscription %] [% WRAPPER table_option value="subscription" %]Subscriptions[% END %] [% END %] -- 2.39.5