@@ -, +, @@
guarantor to an existing patron
---
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(-)
--- a/C4/Utils/DataTables/Members.pm
+++ a/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
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
+++ a/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"
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
+++ a/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 %]
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ a/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 %]
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt
+++ a/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 %]
]
--- a/koha-tmpl/intranet-tmpl/prog/js/members.js
+++ a/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;
--- a/svc/members/search
+++ a/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';
--