From c09f59b610df6f8a9909d04fa4e7981590dac899 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 23 Mar 2020 04:14:39 +0000 Subject: [PATCH] Bug 22534: Added syspref for defining what guarantee fields are pre filled Librarians should be able to define what fields in 'Main address', 'Contact' and 'Alternate contact' in member entry form for guarantee's are pre-filled from guarantor's record The 'Guarantor surname, 'Guarantor first name' and 'relationship' fields in the 'Contact' section should not be filled from guarantor patron record as those fields are intended for guarantor's without patron records in Koha. Test plan: 1. On an adult patron's record (which has all fields filled out in the 'Main address', 'Contact' (Except for 'Guarantor surname', 'Guarantor first name', and 'relationship')) select 'Add guarantee' 2. Observe: * Fields in 'Main address' are all automatically pre-filled from guarantor record * Fields in 'Contact' (except 'Guarantor surname', 'Guarantor firstname' and 'relationship') are all automatically pre-filled from guarantor record * None of the fields in 'Alternate contact' are pre-filled from guarantor 4. Apply patch 5. Run database updates cd installer/data/mysql sudo koha-shell ./updatedatabase.pl 6. Go to Administration > Global system preferences and search for the new PrefillGuaranteeField system preference 7. Observe this syspref is empty 8. Repeat step 1 and observe none of the fields in 'Main address' , 'Contact' or 'Alternate address' are prefilled from guarantor 9. Add the following content into PrefillGuaranteeField syspref and save: phone|phonepro|mobile|email|emailpro|fax|streetnumber|address|address2|city|state|zipcode|country|altcontactfirstname|altcontactsurname|altcontactaddress1|altcontactaddress2|altcontactaddress3|altcontactstate|altcontactzipcode|altcontactcountry|altcontactphone 10. Repeat step 1 and observe all fields in 'Main address', 'Alternate contact', and (except 'Guarantor surname', 'Guarantor first name', and 'relationship') in 'Contact' are pre-filled from guarantor 11. Change a few of the prefilled field values and 'Save' and observe your changes have been saved as have the values you haven't altered 12. Amend PrefillGuaranteeField syspref to be: phone|phonepro|mobile|email|emailpro|fax|streetnumber|address|address2|city|state|zipcode|country|altcontactfirstname|altcontactsurname|drfregfre|altcontactaddress1|altcontactaddress2|altcontactaddress3|altcontactstate|altcontactzipcode|altcontactcountry|altcontactphone (Note: Have added a invalid column field 'drfregfre') 13. Repeat step 1 and observe no internal server errors and all fields listed in step 10 are still pre-filled 14. Amend PrefillGuarantee field syspref to be: phone|phonepro|mobile|email|contactfirstname|emailpro|fax|streetnumber|address|address2|city|state|zipcode|country|altcontactfirstname|altcontactsurname|altcontactaddress1|altcontactaddress2|altcontactaddress3|altcontactstate|altcontactzipcode|altcontactcountry|altcontactphone (Note: Have added contactfirstname which is what the 'Guarantor first name' field in 'Contact' section of member entry form is) 15. Repeat step 1 and observe all fields defined in step 10 are filled and 'Guarantor first name' is not filled even though it was listed in PrefillGuarantorField because contactfirstname (along with contactsurname and relationship are meant for non Koha patrons and so should not pre-fill from a Koha patron) 16. Run tests: sudo koha-shell prove xt prove t Sponsored-by: Waitaki Distict Council, NZ --- ...bug_22534-add_PreFillGuaranteeField_syspref.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/patrons.pref | 5 +++ members/memberentry.pl | 40 ++++++++++++++++------ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22534-add_PreFillGuaranteeField_syspref.sql diff --git a/installer/data/mysql/atomicupdate/bug_22534-add_PreFillGuaranteeField_syspref.sql b/installer/data/mysql/atomicupdate/bug_22534-add_PreFillGuaranteeField_syspref.sql new file mode 100644 index 0000000000..946b14a112 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22534-add_PreFillGuaranteeField_syspref.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('PrefillGuaranteeField', 'phone|email|streetnumber|address|city|state|zipcode|country', NULL, 'Choose which guarantee fields are pre-filled from guarantor record', 'free'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 612dcc20c6..44ef5e5965 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -500,6 +500,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('PayPalSandboxMode', '1', NULL , 'If enabled, the system will use PayPal''s sandbox server for testing, rather than the production server.', 'YesNo'), ('PayPalSignature', '', NULL , 'Your PayPal API signature', 'Free'), ('PayPalUser', '', NULL , 'Your PayPal API username ( email address )', 'Free'), +('PrefillGuaranteeField', 'phone|email|streetnumber|address|city|state|zipcode|country', NULL, 'Choose which guarantee fields are pre-filled from guarantor record', 'free'), ('PrefillItem','0','','When a new item is added, should it be prefilled with last created item values?','YesNo'), ('PreserveSerialNotes','1','','When a new "Expected" issue is generated, should it be prefilled with last created issue notes?','YesNo'), ('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'), 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 48bc763cc3..b861710e86 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 @@ -140,6 +140,11 @@ Patrons: no: "Don't allow" - images to be uploaded and shown for patrons on the staff client. - + - "The following database columns will be pre-filled in guarantee entry screen from guarantor redord:" + - pref: PrefillGuaranteeField + class: multi + - (seperate columns with |) + - - By default, show - pref: PatronsPerPage class: integer diff --git a/members/memberentry.pl b/members/memberentry.pl index 052dbe28aa..b1c8c21f59 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -594,18 +594,38 @@ if (C4::Context->preference("IndependentBranches")) { } } } + +# Define the fields to be pre-filled in guarantee records +my $prefillguarantorfields=C4::Context->preference("PrefillGuaranteeField"); +my @prefill_fields=split(/\|/,$prefillguarantorfields); + if ($op eq 'add'){ if ($guarantor_id) { - foreach ( - qw( - streetnumber address streettype address2 zipcode country city state phone phonepro mobile - fax email emailpro branchcode - B_streetnumber B_streettype B_address B_address2 - B_city B_state B_zipcode B_country B_email B_phone - ) - ) - { - $newdata{$_} = $guarantor->$_; + foreach (@prefill_fields) { + if ($_ eq 'altcontactfirstname') { + $newdata{altcontactfirstname} = $guarantor->firstname; + } elsif ($_ eq 'altcontactsurname') { + $newdata{altcontactsurname} = $guarantor->surname; + } elsif ($_ eq 'altcontactaddress1') { + $newdata{altcontactaddress1} = $guarantor->address; + } elsif ($_ eq 'altcontactaddress2') { + $newdata{altcontactaddress2} = $guarantor->address2; + } elsif ($_ eq 'altcontactaddress3') { + $newdata{altcontactaddress3} = $guarantor->city; + } elsif ($_ eq 'altcontactstate') { + $newdata{altcontactstate} = $guarantor->state; + } elsif ($_ eq 'altcontactzipcode') { + $newdata{altcontactzipcode} = $guarantor->zipcode; + } elsif ($_ eq 'altcontactcountry') { + $newdata{altcontactcountry} = $guarantor->country; + } elsif ($_ eq 'altcontactphone') { + $newdata{altcontactphone} = $guarantor->phone; + } else { + eval { $newdata{$_} = $guarantor->$_; }; + if ($@) { + push @errors, $@; + } + } } } $template->param( updtype => 'I', step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1, step_7 => 1); -- 2.11.0