@@ -, +, @@ adding guarantors --- .../prog/en/modules/members/memberentrygen.tt | 4 ++-- members/memberentry.pl | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -573,7 +573,7 @@ legend:hover { - [% UNLESS nocontactname && nocontactfirstname && norelationship %] + [% UNLESS nocontactname && nocontactfirstname && norelationship || Koha.Preference('GuarantorHasToBePatron') %]
Non-patron guarantor
    @@ -637,7 +637,7 @@ legend:hover { [% PROCESS 'main-address-style' %] [% END # /UNLESS nostreet && nocity etc group%] - [% UNLESS nophone && nophonepro && nomobile && noemail && noemailpro && nofax || Koha.Preference('GuarantorHasToBePatron') %] + [% UNLESS nophone && nophonepro && nomobile && noemail && noemailpro && nofax %]
    Contact information
      --- a/members/memberentry.pl +++ a/members/memberentry.pl @@ -110,19 +110,25 @@ $template->param( relationships => scalar $patron->guarantor_relationships ) if my @relations = split /,|\|/, C4::Context->preference('borrowerRelationship'); my $empty_relationship_allowed = grep {$_ eq ""} @relations; $template->param( empty_relationship_allowed => $empty_relationship_allowed ); - -my $guarantorinfo = $input->param('guarantorinfo'); my $guarantor_id = $input->param('new_guarantor_id'); my $guarantor = undef; $guarantor = Koha::Patrons->find( $guarantor_id ) if $guarantor_id; $template->param( guarantor => $guarantor ); - my @delete_guarantor = $input->multi_param('delete_guarantor'); foreach my $id ( @delete_guarantor ) { my $r = Koha::Patron::Relationships->find( $id ); $r->delete() if $r; } +#Search existing guarantor id(s) and new ones from params +my @guarantor_ids; +my @guarantors = $patron->guarantor_relationships()->guarantors unless !$patron; +foreach my $guarantor (@guarantors){ + push @guarantor_ids, $guarantor->id; +}; +my @new_guarantor_ids = grep { $_ ne '' } $input->multi_param('new_guarantor_id'); +push (@guarantor_ids, @new_guarantor_ids); + ## Deal with debarments $template->param( debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) ); @@ -287,15 +293,16 @@ if ( ( $op eq 'insert' ) and !$nodouble ) { } } -if ( $guarantor_id ) { - if (my $guarantor = Koha::Patrons->find( $guarantor_id )) { - my $guarantor_category = $guarantor->category->category_type; - push @errors, 'ERROR_guarantor_is_guarantee' if ( ($guarantor_category eq 'C') && +if ( @guarantor_ids ) { + foreach my $guarantor_id ( @guarantor_ids ){ + if (my $guarantor = Koha::Patrons->find( $guarantor_id )){ + push @errors, 'ERROR_guarantor_is_guarantee' if ( ($guarantor->is_child) && ($op eq 'save' || $op eq 'insert') ); + } } } -my $valid_guarantor = $guarantor_id ? $guarantor_id : $newdata{'contactname'}; +my $valid_guarantor = @guarantor_ids or $newdata{'contactname'} ? 1 : 0; if($category_type eq 'C' && ($op eq 'save' || $op eq 'insert') && C4::Context->preference('ChildNeedsGuarantor')){ if(!$valid_guarantor){ --