|
Lines 26-31
use Koha::Biblioitems;
Link Here
|
| 26 |
use Koha::Items; |
26 |
use Koha::Items; |
| 27 |
use Koha::ItemTypes; |
27 |
use Koha::ItemTypes; |
| 28 |
use Koha::Patrons; |
28 |
use Koha::Patrons; |
|
|
29 |
use Koha::Patron::Relationship; |
| 30 |
use Koha::Patron::Relationships; |
| 29 |
use C4::Biblio qw( GetMarcFromKohaField ); |
31 |
use C4::Biblio qw( GetMarcFromKohaField ); |
| 30 |
|
32 |
|
| 31 |
{ |
33 |
{ |
|
Lines 326-331
use C4::Biblio qw( GetMarcFromKohaField );
Link Here
|
| 326 |
} |
328 |
} |
| 327 |
} |
329 |
} |
| 328 |
|
330 |
|
|
|
331 |
{ |
| 332 |
my @loop_borrowers_relationships; |
| 333 |
my $relationships = Koha::Patron::Relationships->search(); |
| 334 |
my @patrons_guarantors = Koha::Patron::Relationships::guarantors($relationships)->as_list; |
| 335 |
my @patrons_guarantees = Koha::Patron::Relationships::guarantees($relationships)->as_list; |
| 336 |
|
| 337 |
foreach my $patron_guarantor (@patrons_guarantors) { |
| 338 |
foreach my $patron_guarantee (@patrons_guarantees) { |
| 339 |
if ($patron_guarantor->borrowernumber == $patron_guarantee->borrowernumber) { |
| 340 |
|
| 341 |
my $guarantor_id; |
| 342 |
my $guarantee_id; |
| 343 |
my $size_list; |
| 344 |
my $tmp_garantor_id = $patron_guarantor->borrowernumber; |
| 345 |
my @guarantor_ids; |
| 346 |
|
| 347 |
do { |
| 348 |
my @relationship_for_go = Koha::Patron::Relationships->search( |
| 349 |
{ |
| 350 |
-or => [ |
| 351 |
'guarantor_id' => { '=', $tmp_garantor_id }, |
| 352 |
] |
| 353 |
}, |
| 354 |
)->as_list; |
| 355 |
$size_list = scalar @relationship_for_go; |
| 356 |
|
| 357 |
foreach my $relation (@relationship_for_go) { |
| 358 |
$guarantor_id = $relation->guarantor_id; |
| 359 |
unless (grep { $_ == $guarantor_id } @guarantor_ids) { |
| 360 |
push @guarantor_ids, $guarantor_id; |
| 361 |
} |
| 362 |
$guarantee_id = $relation->guarantee_id; |
| 363 |
|
| 364 |
my @relationship_for_go = Koha::Patron::Relationships->search( |
| 365 |
{ |
| 366 |
-or => [ |
| 367 |
'guarantor_id' => { '=', $guarantee_id }, |
| 368 |
] |
| 369 |
}, |
| 370 |
)->as_list; |
| 371 |
$size_list = scalar @relationship_for_go; |
| 372 |
|
| 373 |
if ($patron_guarantor->borrowernumber == $guarantee_id) { |
| 374 |
last; |
| 375 |
} |
| 376 |
|
| 377 |
foreach my $relation (@relationship_for_go) { |
| 378 |
$guarantor_id = $relation->guarantor_id; |
| 379 |
unless (grep { $_ == $guarantor_id } @guarantor_ids) { |
| 380 |
push @guarantor_ids, $guarantor_id; |
| 381 |
} |
| 382 |
$guarantee_id = $relation->guarantee_id; |
| 383 |
|
| 384 |
if ($patron_guarantor->borrowernumber == $guarantee_id) { |
| 385 |
last; |
| 386 |
} |
| 387 |
} |
| 388 |
if ($patron_guarantor->borrowernumber == $guarantee_id) { |
| 389 |
last; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
$tmp_garantor_id = $guarantee_id; |
| 394 |
} while ($patron_guarantor->borrowernumber != $guarantee_id && $size_list > 0); |
| 395 |
|
| 396 |
if ($patron_guarantor->borrowernumber == $guarantee_id) { |
| 397 |
unless (grep { join("", sort @$_) eq join("", sort @guarantor_ids) } @loop_borrowers_relationships) { |
| 398 |
push @loop_borrowers_relationships, \@guarantor_ids; |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
if (scalar @loop_borrowers_relationships > 0) { |
| 406 |
new_section("The list of guarantors who are also guarantee."); |
| 407 |
my $count = 0; |
| 408 |
foreach my $table (@loop_borrowers_relationships) { |
| 409 |
$count++; |
| 410 |
print "Loop $count, borrowers id : "; |
| 411 |
foreach my $borrower_id (@$table) { |
| 412 |
print "$borrower_id | "; |
| 413 |
} |
| 414 |
print "\n"; |
| 415 |
} |
| 416 |
new_hint("Relationships that form guarantor loops must be deleted"); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 329 |
sub new_section { |
420 |
sub new_section { |
| 330 |
my ( $name ) = @_; |
421 |
my ( $name ) = @_; |
| 331 |
say "\n== $name =="; |
422 |
say "\n== $name =="; |
| 332 |
- |
|
|