From bcf675e782f160d43d7c6d171819e1a510f18b23 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Wed, 30 Sep 2020 17:13:42 -0400 Subject: [PATCH] Bug 26597: Transfer informations from guarantor when adding a guarantor to an existing patron When creating a new guarantee from the guarantor, the preference PrefillGuaranteeField dictates some fields to be transfered from guarantor to guarantee. This patch makes it so those informations are also transfered when adding a new guarantor relationship to an existing patron. To test: 1) Apply patch 2) Search PrefillGuaranteeField preference and make sure some fields are selected 3) Select a user that can have a guarantor 4) In the edit form, click on "Search to add" in "Patron guarantor" fieldset 5) Choose a patron who has at least one of the fields in 1) set 6) Click "Select" 7) Confirm guarantee's information is filled from the guarantor's record 8) Check that any preexisting information is not overwritten Signed-off-by: David Nind Signed-off-by: Kyle M Hall --- C4/Utils/DataTables/Members.pm | 27 ++++++++++++------- .../en/modules/admin/preferences/patrons.pref | 2 +- .../prog/en/modules/common/patron_search.tt | 10 ++++--- .../prog/en/modules/members/memberentrygen.tt | 2 +- .../members/tables/guarantor_search.tt | 2 +- koha-tmpl/intranet-tmpl/prog/js/members.js | 11 +++++++- svc/members/search | 4 +++ 7 files changed, 42 insertions(+), 16 deletions(-) diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index a718a9633e..04a1995719 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -77,15 +77,24 @@ sub search { } } - my $select = "SELECT - borrowers.borrowernumber, borrowers.surname, borrowers.firstname, - borrowers.othernames, - borrowers.flags, - borrowers.streetnumber, borrowers.streettype, borrowers.address, - borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode, - borrowers.country, cardnumber, borrowers.dateexpiry, - borrowers.borrowernotes, borrowers.branchcode, borrowers.email, - borrowers.userid, borrowers.dateofbirth, borrowers.categorycode, + my @columns = qw( borrowernumber surname firstname othernames flags streetnumber streettype address address2 city state zipcode country cardnumber dateexpiry borrowernotes branchcode email userid dateofbirth categorycode phone phonepro mobile fax email emailpro); + + my $prefillguarantorfields = C4::Context->preference("PrefillGuaranteeField"); + my @prefill_fields = split(/\,/,$prefillguarantorfields); + if ( @prefill_fields ) { + foreach my $field (@prefill_fields) { + if (! grep {$_ eq $field} @columns) { + push @columns, $field; + } + } + }; + + my $borrowers_columns = ""; + foreach my $item (@columns) { + $borrowers_columns .= "borrowers." . $item . ", "; + } + + my $select = "SELECT " . $borrowers_columns . " categories.description AS category_description, categories.category_type, branches.branchname, borrowers.phone"; my $from = "FROM borrowers diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index fc8e8b6c7e..509fbdbdd2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -249,7 +249,7 @@ Patrons: class: multi - (input multiple choices separated by |). Leave empty to deactivate. - - - "When adding a guarantee to a guarantor patron fill the following fields in the guarantee's member entry form from the guarantors record:" + - "When adding a guarantor relationship to a patron fill the following unfilled fields in the guarantee's member entry form from the guarantors record:" - pref: PrefillGuaranteeField multiple: B_address: "Alternate address - Address" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt index b78ec9bd31..46b2e7d090 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt @@ -225,7 +225,11 @@ e.preventDefault(); var borrowernumber = $(this).data("borrowernumber"); var borrower_data = $("#borrower_data"+borrowernumber).val(); - select_user( borrowernumber, JSON.parse(borrower_data) ); + var guarantor_attributes = $("#guarantor_attributes"+borrowernumber).val(); + if ( !guarantor_attributes ) { + guarantor_attributes = "{}"; + } + select_user( borrowernumber, JSON.parse(borrower_data), JSON.parse(guarantor_attributes) ); }); $("body").on("click",".patron_preview", function( e ){ @@ -283,9 +287,9 @@ wait_for_opener(); } [% ELSIF selection_type == 'select' %] - function select_user(borrowernumber, data) { + function select_user(borrowernumber, data, attributes) { var p = window.opener; - p.select_user(borrowernumber, data); + p.select_user(borrowernumber, data, null, attributes); window.close(); } [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 738afd604b..6d461a7736 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1581,7 +1581,7 @@ legend:hover { [% IF new_guarantors %] [% FOREACH g IN new_guarantors %] - select_user( '[% g.patron.borrowernumber | html %]', [% To.json( g.patron.unblessed ) | $raw %], '[% g.relationship | html %]' ); + select_user( '[% g.patron.borrowernumber | html %]', [% To.json( g.patron.unblessed ) | $raw %], '[% g.relationship | html %]' [% IF guarantor_attributes %], [% To.json( guarantor_attributes ) | $raw %][% END %] ); [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt index 38ec5aa9e0..d451aec944 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt @@ -18,7 +18,7 @@ "dt_address": "[% INCLUDE escape_address data=data %]", "dt_action": - "Select" + "Select" }[% UNLESS loop.last %],[% END %] [% END %] ] diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index f38870cc48..cdbb813759 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -75,7 +75,7 @@ function update_category_code(category_code) { $(mytables).find(" li[data-category_code='']").show(); } -function select_user(borrowernumber, borrower, relationship) { +function select_user(borrowernumber, borrower, relationship, attributes) { let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrower.borrowernumber}]`).length; if ( is_guarantor ) { @@ -120,6 +120,15 @@ function select_user(borrowernumber, borrower, relationship) { if ( relationship ) { fieldset.find('.new_guarantor_relationship').val(relationship); } + + if ( attributes ) { + for (var i = 0; i < parseInt(attributes.length, 10); i++) { + var attribute = attributes[i]; + if ( borrower[attribute] != null && document.forms.entryform[attribute].value == "" ) { + document.forms.entryform[attribute].value = borrower[attribute]; + } + } + } } return 0; diff --git a/svc/members/search b/svc/members/search index 7cad0e8ab0..a95cad1fa8 100755 --- a/svc/members/search +++ b/svc/members/search @@ -90,12 +90,16 @@ $results = C4::Utils::DataTables::Members::search( } ) unless $results; +my $prefillguarantorfields = C4::Context->preference("PrefillGuaranteeField"); +my @prefill_fields = split(/\,/,$prefillguarantorfields); + $template->param( sEcho => $sEcho, iTotalRecords => $results->{iTotalRecords}, iTotalDisplayRecords => $results->{iTotalDisplayRecords}, aaData => $results->{patrons}, selection_type => $selection_type, + guarantor_attributes => \@prefill_fields, ); output_with_http_headers $input, $cookie, $template->output, 'json'; -- 2.24.1 (Apple Git-126)