|
Lines 105-110
my @relations = split /\|/, C4::Context->preference('borrowerRelationship'), -1;
Link Here
|
| 105 |
my $empty_relationship_allowed = grep {$_ eq ""} @relations; |
105 |
my $empty_relationship_allowed = grep {$_ eq ""} @relations; |
| 106 |
$template->param( empty_relationship_allowed => $empty_relationship_allowed ); |
106 |
$template->param( empty_relationship_allowed => $empty_relationship_allowed ); |
| 107 |
|
107 |
|
|
|
108 |
#Search existing guarantor id(s) and new ones from params |
| 109 |
my @guarantors; |
| 110 |
my @new_guarantor_ids = grep { $_ ne '' } $input->multi_param('new_guarantor_id'); |
| 111 |
|
| 112 |
foreach my $new_guarantor_id (@new_guarantor_ids) { |
| 113 |
my $new_guarantor = Koha::Patrons->find( { borrowernumber => $new_guarantor_id } ); |
| 114 |
push @guarantors, $new_guarantor; |
| 115 |
} |
| 116 |
|
| 117 |
my @existing_guarantors = $patron->guarantor_relationships()->guarantors->as_list unless !$patron; |
| 118 |
push @guarantors, @existing_guarantors; |
| 119 |
|
| 108 |
my $guarantor_id = $input->param('guarantor_id'); |
120 |
my $guarantor_id = $input->param('guarantor_id'); |
| 109 |
my $guarantor = undef; |
121 |
my $guarantor = undef; |
| 110 |
$guarantor = Koha::Patrons->find( $guarantor_id ) if $guarantor_id; |
122 |
$guarantor = Koha::Patrons->find( $guarantor_id ) if $guarantor_id; |
|
Lines 265-270
if ( ( $op eq 'insert' ) and !$nodouble ) {
Link Here
|
| 265 |
} |
277 |
} |
| 266 |
} |
278 |
} |
| 267 |
|
279 |
|
|
|
280 |
#Check if guarantor requirements are met |
| 281 |
my $valid_guarantor = @guarantors ? @guarantors : $newdata{'contactname'}; |
| 282 |
if ( C4::Context->preference('ChildNeedsGuarantor') |
| 283 |
&& $category->category_type eq 'C' |
| 284 |
&& !$valid_guarantor |
| 285 |
&& ( $op eq 'save' || $op eq 'insert' ) ) |
| 286 |
{ |
| 287 |
push @errors, 'ERROR_child_no_guarantor'; |
| 288 |
} |
| 289 |
|
| 290 |
foreach my $guarantor (@guarantors) { |
| 291 |
if ( $guarantor->is_child && ( $op eq 'save' || $op eq 'insert' ) ) { |
| 292 |
push @errors, 'ERROR_guarantor_is_guarantee'; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 268 |
###############test to take the right zipcode, country and city name ############## |
296 |
###############test to take the right zipcode, country and city name ############## |
| 269 |
# set only if parameter was passed from the form |
297 |
# set only if parameter was passed from the form |
| 270 |
$newdata{'city'} = $input->param('city') if defined($input->param('city')); |
298 |
$newdata{'city'} = $input->param('city') if defined($input->param('city')); |
|
Lines 428-434
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
| 428 |
if ($op eq 'insert'){ |
456 |
if ($op eq 'insert'){ |
| 429 |
# we know it's not a duplicate borrowernumber or there would already be an error |
457 |
# we know it's not a duplicate borrowernumber or there would already be an error |
| 430 |
delete $newdata{password2}; |
458 |
delete $newdata{password2}; |
| 431 |
$patron = eval { Koha::Patron->new(\%newdata)->store }; |
459 |
$patron = eval { Koha::Patron->new(\%newdata)->store({ guarantors => \@guarantors }) }; |
| 432 |
if ( $@ ) { |
460 |
if ( $@ ) { |
| 433 |
# FIXME Urgent error handling here, we cannot fail without relevant feedback |
461 |
# FIXME Urgent error handling here, we cannot fail without relevant feedback |
| 434 |
# Lot of code will need to be removed from this script to handle exceptions raised by Koha::Patron->store |
462 |
# Lot of code will need to be removed from this script to handle exceptions raised by Koha::Patron->store |
|
Lines 514-520
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
| 514 |
delete $newdata{password2}; |
542 |
delete $newdata{password2}; |
| 515 |
|
543 |
|
| 516 |
eval { |
544 |
eval { |
| 517 |
$patron->set(\%newdata)->store if scalar(keys %newdata) > 1; # bug 4508 - avoid crash if we're not |
545 |
$patron->set(\%newdata)->store({ guarantors => \@guarantors }) if scalar(keys %newdata) > 1; # bug 4508 - avoid crash if we're not |
| 518 |
# updating any columns in the borrowers table, |
546 |
# updating any columns in the borrowers table, |
| 519 |
# which can happen if we're only editing the |
547 |
# which can happen if we're only editing the |
| 520 |
# patron attributes or messaging preferences sections |
548 |
# patron attributes or messaging preferences sections |