From c633d990c7b0d7303087e5ab7d5f3c3a89067042 Mon Sep 17 00:00:00 2001 From: Roch D'Amour Date: Wed, 28 Feb 2018 17:54:53 -0500 Subject: [PATCH] Bug 12446: Enable an adult to have a guarantor Concflicts has been fixed. Also attributes in system preference : AdditionalGuarantorField are now displayed correctly in all scenerios. I have rebased every patch. This includes all the features from the previous patches. Removed the dollar signs and stopped using C4::Category On the patron category page, there is a new field to specify whether patrons can be guarantee or not. The atomic update SQL script adds this new field and sets it to true for categories of type "C" and "P". 1) Apply the patch 2) Run updatedatabase.pl to add AdditionalGuarantorField to preferences and canbeguarantee to categories. 3) Go to patron category administration, edit a category and change the value of Can Be Guarantee to yes (for Child and Professional mostly to set it by default) 4) See below to test various scenarios - Enable an adult to have a guarantor: 0.0) Create or edit a patron category of type 'A'. 0.1) Set the "Can be guarantee" field to "Yes" and save. 1) Select an adult patron -> details tab; 2) Click edit button; 3) validate "guarantor information" fieldset; - Shows guarantees' fines in the guarantor's page: 4) Click Set to patron button and select a guarantor; 5) Generate a fine; 6) Select guarantor patron -> details tab; 7) Validate guarantee's fine information. - Transfer some guarantor's information to the guarantee while adding a guarantiee: 0) Select an adult patron; 1) Insert all information; 2) Click Add guarantiee bouton; 3) Validade Garantor information/Main address/Contact fieldsets filled; - Transfer some guarantor's information to the guarantee while creating a new patron 0) Select an adult patron; 1) Insert all information; 2) Add a new adult patron; 3) Click "Set to patron" button; 4) Select the adult patron from 0); 5) Validade Garantor information/Main address/Contact fieldsets filled; - Transfer guarantor's alternate address/contact to the guarantee while creating a new patron: 0) Search AdditionalGuarantorField preference; 1) Insert some additional database columns from alternate address/contact to be transferred from guarantor; 2) Select an adult patron; 3) Insert all information; 4) Add a new adult patron; 5) Click "Set to patron" button; 6) Select the adult patron from 0); 7) Validade Garantor information/Main address/Contact fieldsets filled; 8) Validade Garantor additional alternate address/contact filled; - Transfer guarantor's alternate address/contact to the guarantee while adding a guarantiee: 0) Search AdditionalGuarantorField preference; 1) Insert some additional database columns from alternate address/contact to be transferred from guarantor; 3) Select an adult patron; 4) Insert all information; 5) Click Add guarantiee bouton; 6) Validade Garantor information/Main address/Contact fieldsets filled; 7) Validade Garantor additional alternate address/contact filled; --- C4/Members/Attributes.pm | 19 ++++++++++++- C4/Utils/DataTables/Members.pm | 32 +++++++++++++++++----- Koha/Schema/Result/Category.pm | 8 ++++++ admin/categories.pl | 3 ++ .../atomicupdate/bug_12446-EnableAdultGarantee.sql | 11 ++++++++ installer/data/mysql/kohastructure.sql | 3 +- installer/data/mysql/sysprefs.sql | 4 ++- .../en/includes/member-main-address-style-us.inc | 18 ++++++------ .../prog/en/includes/members-toolbar.inc | 2 +- .../prog/en/modules/admin/categories.tt | 15 ++++++++++ .../prog/en/modules/admin/preferences/patrons.pref | 5 ++++ .../prog/en/modules/common/patron_search.tt | 7 +++-- .../prog/en/modules/members/memberentrygen.tt | 6 ++-- .../prog/en/modules/members/moremember.tt | 15 +++++++--- .../en/modules/members/tables/guarantor_search.tt | 2 +- koha-tmpl/intranet-tmpl/prog/js/members.js | 20 ++++++-------- members/memberentry.pl | 15 +++++----- members/moremember.pl | 29 +++++++++++++++++--- svc/members/search | 2 ++ 19 files changed, 161 insertions(+), 55 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_12446-EnableAdultGarantee.sql diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index cf9051d..41490a1 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -32,7 +32,7 @@ BEGIN { @EXPORT_OK = qw(GetBorrowerAttributes GetBorrowerAttributeValue CheckUniqueness SetBorrowerAttributes DeleteBorrowerAttribute UpdateBorrowerAttribute extended_attributes_code_value_arrayref extended_attributes_merge - SearchIdMatchingAttribute); + SearchIdMatchingAttribute get_guarantor_shared_attributes); %EXPORT_TAGS = ( all => \@EXPORT_OK ); } @@ -365,6 +365,23 @@ sub _sort_by_code { return $x->{code} cmp $y->{code} || $x->{value} cmp $y->{value}; } +=head2 get_guarantor_shared_attributes + + $guarantor_attributes = get_guarantor_attributes(); + + returns an array reference containing attributes to be shared between guarantor and guarantee. + +=cut + +sub get_guarantor_shared_attributes{ + my @attributes = qw( streetnumber address address2 city state zipcode country branchcode phone phonepro mobile email emailpro fax ); + if( my @additional = split(/\|/, C4::Context->preference("AdditionalGuarantorField")) ){ + $_ =~ s/(?:^\s+)|(?:\s+$)//g for (@additional); # Trim whitespaces + @attributes = ( @attributes, @additional); + } + return \@attributes; +} + =head1 AUTHOR Koha Development Team diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index caf7a92..2f01120 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -2,6 +2,8 @@ package C4::Utils::DataTables::Members; use Modern::Perl; use C4::Context; +use C4::Members; +use C4::Members::Attributes qw/get_guarantor_shared_attributes/; use C4::Utils::DataTables; use Koha::DateUtils; use C4::Members::Attributes qw(SearchIdMatchingAttribute ); @@ -56,13 +58,29 @@ sub search { } } - my $select = "SELECT - borrowers.borrowernumber, borrowers.surname, borrowers.firstname, - 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, + # If branches are independent and user is not superlibrarian + # The search has to be only on the user branch + if ( C4::Context::only_my_library ) { + my $userenv = C4::Context->userenv; + $branchcode = $userenv->{'branch'}; + + } + + $dbh = C4::Context->dbh; + my @columns = qw( borrowernumber surname firstname streetnumber streettype address address2 city state zipcode country cardnumber dateexpiry borrowernotes branchcode email userid dateofbirth categorycode phone phonepro mobile fax email emailpro); + if( my @guarantor_attributes = @{ get_guarantor_shared_attributes() }){ + foreach my $item (@guarantor_attributes) { + if (! grep {$_ eq $item} @columns) { + push @columns, $item; + } + } + }; + 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/Schema/Result/Category.pm b/Koha/Schema/Result/Category.pm index b32b967..c7a9c50 100644 --- a/Koha/Schema/Result/Category.pm +++ b/Koha/Schema/Result/Category.pm @@ -109,6 +109,12 @@ __PACKAGE__->table("categories"); default_value: -1 is_nullable: 0 +=head2 canbeguarantee + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + =head2 default_privacy data_type: 'enum' @@ -171,6 +177,8 @@ __PACKAGE__->add_columns( default_value => -1, is_nullable => 0, }, + "canbeguarantee", + { data_type => "tinyint", default_value => 0, is_nullable => 0}, "default_privacy", { data_type => "enum", diff --git a/admin/categories.pl b/admin/categories.pl index f9144e7..92b75a0 100755 --- a/admin/categories.pl +++ b/admin/categories.pl @@ -95,6 +95,7 @@ elsif ( $op eq 'add_validate' ) { my $reset_password = $input->param('reset_password'); my $change_password = $input->param('change_password'); my @branches = grep { $_ ne q{} } $input->multi_param('branches'); + my $canbeguarantee = $input->param('canbeguarantee'); $reset_password = undef if $reset_password eq -1; $change_password = undef if $change_password eq -1; @@ -124,6 +125,7 @@ elsif ( $op eq 'add_validate' ) { $category->hidelostitems($hidelostitems); $category->overduenoticerequired($overduenoticerequired); $category->category_type($category_type); + $category->canbeguarantee($canbeguarantee); $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions); $category->checkprevcheckout($checkPrevCheckout); $category->default_privacy($default_privacy); @@ -152,6 +154,7 @@ elsif ( $op eq 'add_validate' ) { hidelostitems => $hidelostitems, overduenoticerequired => $overduenoticerequired, category_type => $category_type, + canbeguarantee => $canbeguarantee, BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions, checkprevcheckout => $checkPrevCheckout, default_privacy => $default_privacy, diff --git a/installer/data/mysql/atomicupdate/bug_12446-EnableAdultGarantee.sql b/installer/data/mysql/atomicupdate/bug_12446-EnableAdultGarantee.sql new file mode 100644 index 0000000..56462a7 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12446-EnableAdultGarantee.sql @@ -0,0 +1,11 @@ +-- ******** -- +-- SYSPREFS -- +-- ******** -- +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) +VALUES ('AdditionalGuarantorField','',NULL,'Additional fields name to be transfer from guarantor to guarantee.','free'); + +-- ********* -- +-- STRUCTURE -- +-- ********* -- +ALTER TABLE categories ADD COLUMN `canbeguarantee` tinyint(1) NOT NULL default '0'; +UPDATE categories SET canbeguarantee = 1 WHERE category_type = 'P' OR category_type = 'C'; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 7b78a87..9db1a4b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -316,10 +316,11 @@ CREATE TABLE `categories` ( -- this table shows information related to Koha patr `hidelostitems` tinyint(1) NOT NULL default '0', -- are lost items shown to this category (1 for yes, 0 for no) `category_type` varchar(1) NOT NULL default 'A', -- type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff) `BlockExpiredPatronOpacActions` tinyint(1) NOT NULL default '-1', -- wheither or not a patron of this category can renew books or place holds once their card has expired. 0 means they can, 1 means they cannot, -1 means use syspref BlockExpiredPatronOpacActions - `default_privacy` ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default', -- Default privacy setting for this patron category + `default_privacy` ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default', -- Default privacy setting for this patron category, `checkprevcheckout` varchar(7) NOT NULL default 'inherit', -- produce a warning for this patron category if this item has previously been checked out to this patron if 'yes', not if 'no', defer to syspref setting if 'inherit'. `reset_password` TINYINT(1) NULL DEFAULT NULL, -- if patrons of this category can do the password reset flow, `change_password` TINYINT(1) NULL DEFAULT NULL, -- if patrons of this category can change their passwords in the OAPC + `canbeguarantee` tinyint(1) NOT NULL default '0' PRIMARY KEY (`categorycode`), UNIQUE KEY `categorycode` (`categorycode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 35c9ff0..8ac7037 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -8,7 +8,9 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'), ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), ('AdditionalFieldsInZ3950ResultSearch', '', NULL, 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free'), -('AddressFormat','us','us|de|fr','Choose format to display postal addresses', 'Choice'), +('AdditionalGuarantorField','',NULL,'Additional fields name to be transfer from guarantor to guarantee.','free'), +('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'), +('AddressFormat','us','','Choose format to display postal addresses', 'Choice'), ('AdlibrisCoversEnabled','0',NULL,'Display cover images in OPAC results and detail listing from Swedish retailer Adlibris.','YesNo'), ('AdlibrisCoversURL','http://www.adlibris.com/se/organisationer/showimagesafe.aspx',NULL,'Base URL for Adlibris cover image web service.','Free'), ('advancedMARCeditor','0','','If ON, the MARC editor won\'t display field/subfield descriptions','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc index 0db6e83..15893cb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc @@ -8,7 +8,7 @@ - + [% IF ( mandatorystreetnumber ) %]Required[% END %] [% END %] @@ -24,7 +24,7 @@ + [% IF ( mandatoryaddress ) %]Required[% END %] [% END %] @@ -55,7 +55,7 @@ - + [% IF ( mandatoryaddress2 ) %]Required[% END %] [% END %] @@ -67,12 +67,12 @@ - + [% IF cities.count %]or choose + [% IF ( mandatorystate ) %]Required[% END %] [% END %] @@ -105,7 +105,7 @@ - + [% IF ( mandatoryzipcode ) %]Required[% END %] [% END %] @@ -117,7 +117,7 @@ - + [% IF ( mandatorycountry ) %]Required[% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc index a86c976..4695a14 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -16,7 +16,7 @@ [% IF CAN_user_borrowers_edit_borrowers %] [% IF patron.is_adult AND Koha.Preference("borrowerRelationship") %] - Add child + Add guarantee [% END %] [% IF CAN_user_borrowers_edit_borrowers %] Change password diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt index f2704e9..ef91dba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -151,6 +151,18 @@ Required +
  • + + +
  • [% END %]
  • - [% END %] - [% UNLESS nocontactfirstname %] -
  • + [% UNLESS nocontactfirstname %] +
  • [% IF ( guarantorid ) %] [% contactfirstname | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index fc93db3..90fe0c5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -245,15 +245,22 @@ [% IF guarantees %]
  • Guarantees: -
      + [% FOREACH guarantee IN guarantees %] + [% IF logged_in_user.can_see_patron_infos( guarantee ) %] -
    • [% guarantee.firstname | html %] [% guarantee.surname | html %]
    • + + [% ELSE %] -
    • [% guarantee.firstname | html %] [% guarantee.surname | html %]
    • + [% END %] + [% END %] - + [% IF logged_in_user.can_see_patron_infos( guarantee ) %] + + + [% END %] +
      [% guarantee.firstname | html %] [% guarantee.surname | html %][% guarantee.account.balance %][% guarantee.firstname | html %] [% guarantee.surname | html %]
      Total[% amounttot %]
      [% ELSIF guarantor %]
    • 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 a82f0e8..6cba09c 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 bcca8ef..33344b0 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -169,7 +169,7 @@ function update_category_code(category_code) { $(mytables).find(" li[data-category_code='']").show(); } -function select_user(borrowernumber, borrower) { +function select_user(borrowernumber, borrower, attributes) { var form = $('#entryform').get(0); if (form.guarantorid.value) { $("#contact-details, #quick_add_form #contact-details").find('a').remove(); @@ -192,14 +192,13 @@ function select_user(borrowernumber, borrower) { .before('' + borrower.firstname + '').get(0).type = 'hidden'; $("#quick_add_form #contactfirstname").val(borrower.firstname).before(''+borrower.firstname+'{'firstname'}; $newdata{'contactname'} = $guarantordata->{'surname'}; $newdata{'contacttitle'} = $guarantordata->{'title'}; + if ( $op eq 'add' ) { - 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{$_} = $guarantordata->{$_}; - } + my @attributes = @{C4::Members::Attributes::get_guarantor_shared_attributes()}; + foreach my $attribute (@attributes) { + $newdata{$attribute} = $guarantordata->{$attribute}; + } } } } @@ -761,7 +760,9 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) { $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification")); } -$template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are +$template->param( "showguarantor" => $categorycode ? Koha::Patron::Categories->find($categorycode)->canbeguarantee : 1); # associate with step to know where you are + +$template->param( "guarantor_attributes" => C4::Members::Attributes::get_guarantor_shared_attributes() ); $debug and warn "memberentry step: $step"; $template->param(%data); $template->param( "step_$step" => 1) if $step; # associate with step to know where u are diff --git a/members/moremember.pl b/members/moremember.pl index be365a3..96ed91e 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -67,7 +67,7 @@ use Koha::Token; use vars qw($debug); BEGIN { - $debug = $ENV{DEBUG} || 0; + $debug = $ENV{DEBUG} || 0; } my $dbh = C4::Context->dbh; @@ -143,7 +143,7 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) { # FIXME This should be remov } for (qw(gonenoaddress lost borrowernotes)) { - $data->{$_} and $template->param(flagged => 1) and last; + $data->{$_} and $template->param(flagged => 1) and last; } if ( $patron->is_debarred ) { @@ -163,7 +163,6 @@ $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex}; my @relatives; if ( my $guarantor = $patron->guarantor ) { - $template->param( guarantor => $guarantor ); push @relatives, $guarantor->borrowernumber; push @relatives, $_->borrowernumber for $patron->siblings; } elsif ( $patron->contactname || $patron->contactfirstname ) { @@ -175,13 +174,35 @@ if ( my $guarantor = $patron->guarantor ) { ); } else { my @guarantees = $patron->guarantees; - $template->param( guarantees => \@guarantees ); push @relatives, $_->borrowernumber for @guarantees; } my $relatives_issues_count = Koha::Database->new()->schema()->resultset('Issue') ->count( { borrowernumber => \@relatives } ); +my @guarantees = $patron->guarantees; +my $count = scalar @guarantees; +if ( $count ) { + $template->param( isguarantee => 1 ); + + my @guaranteedata; + my $amount; + my $totalmount = 0; + + foreach my $guarantee (@guarantees){ + + $totalmount += $guarantee->account->balance; + + } + $template->param( guarantees => @guarantees); + $template->param( amounttot => sprintf("%.2f",$totalmount)); +} +( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' || $category_type eq 'I' ); + +if (my $guarantor = $patron->guarantor){ + $template->param(isguarantor => 1); + $template->param(guarantor => $guarantor); +} my %bor; $bor{'borrowernumber'} = $borrowernumber; diff --git a/svc/members/search b/svc/members/search index abb5716..cd72114 100755 --- a/svc/members/search +++ b/svc/members/search @@ -109,12 +109,14 @@ if ($has_permission) { $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission ); } +my @attributes = C4::Members::Attributes::get_guarantor_shared_attributes(); $template->param( sEcho => $sEcho, iTotalRecords => $results->{iTotalRecords}, iTotalDisplayRecords => $results->{iTotalDisplayRecords}, aaData => $results->{patrons}, selection_type => $selection_type, + attributes => @attributes ); output_with_http_headers $input, $cookie, $template->output, 'json'; -- 2.7.4