From 63f88a574299b3831bf523e5bb8ead52f954864a Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 9 Jun 2021 16:28:51 +0200 Subject: [PATCH] Bug 31254: Add additional fields for accountlines MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test plan: 1. Go to Admin » Additional fields There are two new categories: "Account lines (credit)" and "Account lines (debit)" 2. Create fields for both categories, with and without an authorized value category 3. Go to a user's accounting page 4. Create a manual invoice. Verify that all "debit" fields are there, put a value in them and save 5. Create a manual credit. Verify that all "credit" fields are there, put a value in them and save 6. Make a payment. Verify that all "credit" fields are there, put a value in them and save 7. Go to the transactions tab, click on the "Details" button for the lines you just created and verify that the additional fields are there Signed-off-by: Emmanuel Bétemps Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Account/Line.pm | 2 +- Koha/Schema/Result/Accountline.pm | 16 ++++++++ .../en/includes/additional-fields-entry.inc | 2 +- .../en/modules/admin/additional-fields.tt | 40 ++++++++++++------- .../en/modules/members/accountline-details.tt | 14 +++++++ .../prog/en/modules/members/mancredit.tt | 4 ++ .../prog/en/modules/members/maninvoice.tt | 5 +++ .../prog/en/modules/members/paycollect.tt | 14 +++++++ members/mancredit.pl | 19 ++++++++- members/maninvoice.pl | 17 ++++++++ members/paycollect.pl | 36 +++++++++++++++++ 11 files changed, 152 insertions(+), 17 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index ceb73e7c3e..b940d6acef 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -30,7 +30,7 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::Exceptions::Account; use Koha::Items; -use base qw(Koha::Object); +use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); =encoding utf8 diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index 1dee4ccf20..5ee3aaff3a 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -419,6 +419,22 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->has_many( + "additional_field_values", + "Koha::Schema::Result::AdditionalFieldValue", + sub { + my ($args) = @_; + + return { + "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.accountlines_id" }, + + "$args->{foreign_alias}.field_id" => + { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "accountlines:%")' }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub koha_objects_class { 'Koha::Account::Lines'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc index 775c04d167..24d30b560d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc @@ -9,7 +9,7 @@ [% IF field.authorised_value_category %] [% END %] -
  • - - [% IF field.searchable %] - - [% ELSE %] - - [% END %] -
  • + [% IF show_searchable %] +
  • + + [% IF field.searchable %] + + [% ELSE %] + + [% END %] +
  • + [% END %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt index 1a328dac49..e1fa32f180 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt @@ -71,6 +71,7 @@ [% INCLUDE 'members-toolbar.inc' borrowernumber=patron.borrowernumber %] [% IF accountline %] + [% af_values = accountline.additional_field_values %] [% IF accountline.credit_type_code %]

    Details of credit

    [% ELSIF accountline.debit_type_code %] @@ -86,6 +87,9 @@ Due date Return date Note + [% FOREACH value IN af_values %] + [% value.field.name | html %] + [% END %] Amount Outstanding @@ -134,6 +138,16 @@ [% accountline.note | html_line_break %] + [% FOREACH value IN af_values %] + + [% IF value.field.authorised_value_category %] + [% AuthorisedValues.GetByCode( value.field.authorised_value_category, value.value ) | html %] + [% ELSE %] + [% value.value | html %] + [% END %] + + [% END %] + [% accountline.amount | $Price %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt index 1ef7897747..0303f2a877 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt @@ -74,6 +74,10 @@
    + [% 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/members/maninvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt index b3ddd17c2c..b0a7b6f9f6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt @@ -87,6 +87,11 @@
  • Example: 5.00
  • + + [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 125ccc6e10..71465bd757 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -211,6 +211,10 @@
    +[% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] +[% END %] +
    Cancel @@ -263,6 +267,11 @@ + + [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
    Cancel @@ -346,6 +355,11 @@ + + [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
    Cancel diff --git a/members/mancredit.pl b/members/mancredit.pl index 58a8e9b3f3..0652471493 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -34,6 +34,7 @@ use Koha::Items; use Koha::Patrons; use Koha::Patron::Categories; use Koha::Account::CreditTypes; +use Koha::AdditionalFields; use Koha::Token; @@ -90,7 +91,7 @@ if ($add) { my $amount = $input->param('amount') || 0; my $type = $input->param('type'); - $patron->account->add_credit( + my $line = $patron->account->add_credit( { amount => $amount, description => $description, @@ -103,6 +104,21 @@ if ($add) { } ); + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' }); + while ( my $field = $accountline_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + if (defined $value) { + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + } + if (@additional_fields) { + $line->set_additional_fields(\@additional_fields); + } + if ( C4::Context->preference('AccountAutoReconcile') ) { $patron->account->reconcile_balance; } @@ -124,6 +140,7 @@ else { csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID') } ), + available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'accountlines:credit' })->as_list ], ); output_html_with_http_headers $input, $cookie, $template->output; } diff --git a/members/maninvoice.pl b/members/maninvoice.pl index 4bee132645..01464cf3a4 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -41,6 +41,7 @@ use Koha::Old::Checkouts; use Koha::Patron::Categories; use Koha::Account::DebitTypes; +use Koha::AdditionalFields; my $input = CGI->new; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -165,6 +166,21 @@ if ($add) { } ); + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:debit' }); + while ( my $field = $accountline_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + if (defined $value) { + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + } + if (@additional_fields) { + $line->set_additional_fields(\@additional_fields); + } + if ( C4::Context->preference('AccountAutoReconcile') ) { $patron->account->reconcile_balance; } @@ -216,5 +232,6 @@ $template->param( ), patron => $patron, finesview => 1, + available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'accountlines:debit' })->as_list ], ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/members/paycollect.pl b/members/paycollect.pl index e8301a7660..b189107f25 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -32,6 +32,8 @@ use Koha::Patrons; use Koha::Patron::Categories; use Koha::AuthorisedValues; use Koha::Account; +use Koha::Account::Lines; +use Koha::AdditionalFields; use Koha::Token; use Koha::DateUtils qw( output_pref ); @@ -170,6 +172,23 @@ if ( $total_paid and $total_paid ne '0.00' ) { ); $payment_id = $pay_result->{payment_id}; + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' }); + while ( my $field = $accountline_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 $payment = Koha::Account::Lines->find($payment_id); + $payment->set_additional_fields(\@additional_fields); + } + + $url = "/cgi-bin/koha/members/pay.pl"; } else { if ($selected_accts) { @@ -213,6 +232,22 @@ if ( $total_paid and $total_paid ne '0.00' ) { } $payment_id = $pay_result->{payment_id}; + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' }); + while ( my $field = $accountline_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 $payment = Koha::Account::Lines->find($payment_id); + $payment->set_additional_fields(\@additional_fields); + } + $url = "/cgi-bin/koha/members/boraccount.pl"; } # It's possible renewals took place, parse any renew results @@ -249,6 +284,7 @@ $template->param( total => $total_due, csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID') } ), + available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'accountlines:credit' })->as_list ], ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5