|
Lines 24-29
use Try::Tiny;
Link Here
|
| 24 |
|
24 |
|
| 25 |
# external modules |
25 |
# external modules |
| 26 |
use CGI qw ( -utf8 ); |
26 |
use CGI qw ( -utf8 ); |
|
|
27 |
use Scalar::Util qw( blessed ); |
| 27 |
|
28 |
|
| 28 |
# internal modules |
29 |
# internal modules |
| 29 |
use C4::Auth qw( get_template_and_user haspermission ); |
30 |
use C4::Auth qw( get_template_and_user haspermission ); |
|
Lines 53-58
my $input = CGI->new;
Link Here
|
| 53 |
my %data; |
54 |
my %data; |
| 54 |
|
55 |
|
| 55 |
my $dbh = C4::Context->dbh; |
56 |
my $dbh = C4::Context->dbh; |
|
|
57 |
my $logger = Koha::Logger->get({ interface => 'intranet '}); |
| 56 |
|
58 |
|
| 57 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
59 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
| 58 |
{ |
60 |
{ |
|
Lines 278-310
if (@delete_guarantor) {
Link Here
|
| 278 |
if ( C4::Context->preference('ChildNeedsGuarantor') && $will_remove_last ) { |
280 |
if ( C4::Context->preference('ChildNeedsGuarantor') && $will_remove_last ) { |
| 279 |
push @errors, 'ERROR_cannot_delete_guarantor'; |
281 |
push @errors, 'ERROR_cannot_delete_guarantor'; |
| 280 |
} else { |
282 |
} else { |
|
|
283 |
my @deleted_guarantors; |
| 281 |
foreach my $id (@delete_guarantor) { |
284 |
foreach my $id (@delete_guarantor) { |
| 282 |
my $r = Koha::Patron::Relationships->find($id); |
285 |
my $r = Koha::Patron::Relationships->find($id); |
| 283 |
$r->delete() if $r; |
286 |
if ($r) { |
|
|
287 |
$r->delete(); |
| 288 |
push @deleted_guarantors, $id; |
| 289 |
} |
| 290 |
} |
| 291 |
foreach my $deleted_guarantor_id (@deleted_guarantors) { |
| 292 |
@guarantors = grep { ref($_) eq 'Koha::Patron' && $_->id ne $deleted_guarantor_id } @guarantors; |
| 284 |
} |
293 |
} |
| 285 |
} |
294 |
} |
| 286 |
} |
295 |
} |
| 287 |
|
296 |
|
| 288 |
#Check if guarantor requirements are met |
297 |
#Check if guarantor requirements are met |
| 289 |
if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) ) { |
298 |
my $guarantors_to_be_validated = |
| 290 |
unless ( $patron && $patron->is_guarantor ) { |
299 |
@guarantors ? \@guarantors : $newdata{'contactname'} ? [ $newdata{'contactname'} ] : []; |
| 291 |
try { |
300 |
if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && $guarantors_to_be_validated ) { |
| 292 |
Koha::Patron->validate_guarantor( \@guarantors, $newdata{'contactname'}, $category ); |
301 |
try { |
| 293 |
} catch { |
302 |
if ($patron) { |
| 294 |
if ( ref($_) eq "Koha::Exceptions::Patron::Relationship::NoGuarantor" ) { |
303 |
if ( $patron->categorycode eq $categorycode ) { |
|
|
304 |
$patron->can_be_guaranteed_by($guarantors_to_be_validated); |
| 305 |
} else { |
| 306 |
# If $patron's categorycode is about to change, check guarantor requirements against |
| 307 |
# the new category but keep the original $patron object intact |
| 308 |
# (this clone()s the $patron) |
| 309 |
( bless {%$patron}, ref $patron )->categorycode($categorycode) |
| 310 |
->can_be_guaranteed_by($guarantors_to_be_validated); |
| 311 |
} |
| 312 |
} else { |
| 313 |
Koha::Patron->new( { categorycode => $categorycode } )->can_be_guaranteed_by($guarantors_to_be_validated); |
| 314 |
} |
| 315 |
} catch { |
| 316 |
unless ( blessed($_) ) { |
| 317 |
$logger->error($_); |
| 318 |
} else { |
| 319 |
if ( $_->isa("Koha::Exceptions::Patron::Relationship::NoGuarantor") ) { |
| 295 |
push @errors, "ERROR_child_no_guarantor"; |
320 |
push @errors, "ERROR_child_no_guarantor"; |
| 296 |
} elsif ( ref($_) eq "Koha::Exceptions::Patron::Relationship::InvalidRelationship" ) { |
321 |
} elsif ( $_->isa("Koha::Exceptions::Patron::Relationship::InvalidRelationship") ) { |
| 297 |
if ( $_->full_message eq "Guarantee patron cannot be a guarantor." ) { |
322 |
if ( $_->invalid_guarantor ) { |
| 298 |
push @errors, "ERROR_guarantor_is_guarantee"; |
323 |
push @errors, "ERROR_guarantor_is_guarantee"; |
| 299 |
} elsif ( $_->full_message eq "Child patron cannot be a guarantor." ) { |
324 |
$template->param( guarantor_is_guarantee => $_->guarantor ); |
|
|
325 |
} elsif ( $_->child_guarantor ) { |
| 300 |
push @errors, "ERROR_child_is_guarantor"; |
326 |
push @errors, "ERROR_child_is_guarantor"; |
|
|
327 |
} elsif ( $_->guarantor_cant_have_guarantors ) { |
| 328 |
push @errors, "ERROR_guarantor_cant_have_guarantors"; |
| 301 |
} |
329 |
} |
|
|
330 |
} else { |
| 331 |
$logger->error( $_->error ); |
| 332 |
$_->rethrow; |
| 302 |
} |
333 |
} |
| 303 |
return; |
334 |
} |
| 304 |
}; |
335 |
return; |
| 305 |
} else { |
336 |
}; |
| 306 |
push @errors, "ERROR_guarantee_is_guarantor"; |
|
|
| 307 |
} |
| 308 |
} |
337 |
} |
| 309 |
|
338 |
|
| 310 |
my @valid_relationships = split( /\|/, C4::Context->preference('borrowerRelationship'), -1 ); |
339 |
my @valid_relationships = split( /\|/, C4::Context->preference('borrowerRelationship'), -1 ); |