From 88a7b8df45e1324675aaf0d080b4c4b3e1218831 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 17 Jul 2018 08:18:27 -0400 Subject: [PATCH] Bug 14570 [QA Followup]: Add Koha::Patron::add_gurarantor --- Koha/Patron.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ members/memberentry.pl | 35 +++++++++++++---------------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 141eb2a6c8..366be8684c 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1053,6 +1053,51 @@ sub generate_userid { } + +=head3 add_guarantor + + my @relationships = $patron->add_guarantor( + { + borrowernumber => $borrowernumber, + surname => $surname, + firstname => $firstname, + relationships => $relationship, + } + ); + + Adds a new guarantor to a patron, requires either an id ( borrowernumber ) or surname. + +=cut + +sub add_guarantor { + my ( $self, $params ) = @_; + + my $guarantor_id = $params->{guarantor_id}; + my $surname = $params->{surname}; + my $firstname = $params->{firstname}; + my $relationship = $params->{relationship}; + + if ($guarantor_id) { + return Koha::Patron::Relationship->new( + { + guarantee_id => $self->id, + guarantor_id => $guarantor_id, + relationship => $relationship + } + )->store(); + } + elsif ($surname) { + return Koha::Patron::Relationship->new( + { + guarantee_id => $self->id, + surname => $surname, + firstname => $firstname, + relationship => $relationship + } + )->store(); + } +} + =head2 Internal methods =head3 _type diff --git a/members/memberentry.pl b/members/memberentry.pl index 331e7e147f..24dd969719 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -414,7 +414,8 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ if ($op eq 'insert'){ # we know it's not a duplicate borrowernumber or there would already be an error $borrowernumber = &AddMember(%newdata); - add_guarantors( $borrowernumber, $input ); + $patron = Koha::Patrons->find( $borrowernumber ); + add_guarantors( $patron, $input ); $newdata{'borrowernumber'} = $borrowernumber; # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. @@ -512,7 +513,7 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ # updating any columns in the borrowers table, # which can happen if we're only editing the # patron attributes or messaging preferences sections - add_guarantors( $borrowernumber, $input ); + add_guarantors( $patron, $input ); if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); } @@ -892,7 +893,7 @@ sub patron_attributes_form { } sub add_guarantors { - my ( $borrowernumber, $input ) = @_; + my ( $patron, $input ) = @_; my @new_guarantor_id = $input->multi_param('new_guarantor_id'); my @new_guarantor_surname = $input->multi_param('new_guarantor_surname'); @@ -905,25 +906,15 @@ sub add_guarantors { my $firstname = $new_guarantor_firstname[$i]; my $relationship = $new_guarantor_relationship[$i]; - if ($guarantor_id) { - Koha::Patron::Relationship->new( - { - guarantee_id => $borrowernumber, - guarantor_id => $guarantor_id, - relationship => $relationship - } - )->store(); - } - elsif ($surname) { - Koha::Patron::Relationship->new( - { - guarantee_id => $borrowernumber, - surname => $surname, - firstname => $firstname, - relationship => $relationship - } - )->store(); - } + $patron->add_guarantor( + { + guarantee_id => $patron->id, + guarantor_id => $guarantor_id, + surname => $surname, + firstname => $firstname, + relationship => $relationship + } + ); } } -- 2.11.0