|
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 273-305
if (@delete_guarantor) {
Link Here
|
| 273 |
if ( C4::Context->preference('ChildNeedsGuarantor') && $will_remove_last ) { |
275 |
if ( C4::Context->preference('ChildNeedsGuarantor') && $will_remove_last ) { |
| 274 |
push @errors, 'ERROR_cannot_delete_guarantor'; |
276 |
push @errors, 'ERROR_cannot_delete_guarantor'; |
| 275 |
} else { |
277 |
} else { |
|
|
278 |
my @deleted_guarantors; |
| 276 |
foreach my $id (@delete_guarantor) { |
279 |
foreach my $id (@delete_guarantor) { |
| 277 |
my $r = Koha::Patron::Relationships->find($id); |
280 |
my $r = Koha::Patron::Relationships->find($id); |
| 278 |
$r->delete() if $r; |
281 |
if ($r) { |
|
|
282 |
$r->delete(); |
| 283 |
push @deleted_guarantors, $id; |
| 284 |
} |
| 285 |
} |
| 286 |
foreach my $deleted_guarantor_id (@deleted_guarantors) { |
| 287 |
@guarantors = grep { ref($_) eq 'Koha::Patron' && $_->id ne $deleted_guarantor_id } @guarantors; |
| 279 |
} |
288 |
} |
| 280 |
} |
289 |
} |
| 281 |
} |
290 |
} |
| 282 |
|
291 |
|
| 283 |
#Check if guarantor requirements are met |
292 |
#Check if guarantor requirements are met |
| 284 |
if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) ) { |
293 |
my $guarantors_to_be_validated = |
| 285 |
unless ( $patron && $patron->is_guarantor ) { |
294 |
@guarantors ? \@guarantors : $newdata{'contactname'} ? [ $newdata{'contactname'} ] : []; |
| 286 |
try { |
295 |
if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && $guarantors_to_be_validated ) { |
| 287 |
Koha::Patron->validate_guarantor( \@guarantors, $newdata{'contactname'}, $category ); |
296 |
try { |
| 288 |
} catch { |
297 |
if ($patron) { |
| 289 |
if ( ref($_) eq "Koha::Exceptions::Patron::Relationship::NoGuarantor" ) { |
298 |
if ( $patron->categorycode eq $categorycode ) { |
|
|
299 |
$patron->can_be_guaranteed_by($guarantors_to_be_validated); |
| 300 |
} else { |
| 301 |
# If $patron's categorycode is about to change, check guarantor requirements against |
| 302 |
# the new category but keep the original $patron object intact |
| 303 |
# (this clone()s the $patron) |
| 304 |
( bless {%$patron}, ref $patron )->categorycode($categorycode) |
| 305 |
->can_be_guaranteed_by($guarantors_to_be_validated); |
| 306 |
} |
| 307 |
} else { |
| 308 |
Koha::Patron->new( { categorycode => $categorycode } )->can_be_guaranteed_by($guarantors_to_be_validated); |
| 309 |
} |
| 310 |
} catch { |
| 311 |
unless ( blessed($_) ) { |
| 312 |
$logger->error($_); |
| 313 |
} else { |
| 314 |
if ( $_->isa("Koha::Exceptions::Patron::Relationship::NoGuarantor") ) { |
| 290 |
push @errors, "ERROR_child_no_guarantor"; |
315 |
push @errors, "ERROR_child_no_guarantor"; |
| 291 |
} elsif ( ref($_) eq "Koha::Exceptions::Patron::Relationship::InvalidRelationship" ) { |
316 |
} elsif ( $_->isa("Koha::Exceptions::Patron::Relationship::InvalidRelationship") ) { |
| 292 |
if ( $_->full_message eq "Guarantee patron cannot be a guarantor." ) { |
317 |
if ( $_->invalid_guarantor ) { |
| 293 |
push @errors, "ERROR_guarantor_is_guarantee"; |
318 |
push @errors, "ERROR_guarantor_is_guarantee"; |
| 294 |
} elsif ( $_->full_message eq "Child patron cannot be a guarantor." ) { |
319 |
$template->param( guarantor_is_guarantee => $_->guarantor ); |
|
|
320 |
} elsif ( $_->child_guarantor ) { |
| 295 |
push @errors, "ERROR_child_is_guarantor"; |
321 |
push @errors, "ERROR_child_is_guarantor"; |
|
|
322 |
} elsif ( $_->guarantor_cant_have_guarantors ) { |
| 323 |
push @errors, "ERROR_guarantor_cant_have_guarantors"; |
| 296 |
} |
324 |
} |
|
|
325 |
} else { |
| 326 |
$logger->error( $_->error ); |
| 327 |
$_->rethrow; |
| 297 |
} |
328 |
} |
| 298 |
return; |
329 |
} |
| 299 |
}; |
330 |
return; |
| 300 |
} else { |
331 |
}; |
| 301 |
push @errors, "ERROR_guarantee_is_guarantor"; |
|
|
| 302 |
} |
| 303 |
} |
332 |
} |
| 304 |
|
333 |
|
| 305 |
my @valid_relationships = split( /\|/, C4::Context->preference('borrowerRelationship'), -1 ); |
334 |
my @valid_relationships = split( /\|/, C4::Context->preference('borrowerRelationship'), -1 ); |