|
Lines 1064-1077
sub CanBookBeIssued {
Link Here
|
| 1064 |
require C4::Serials; |
1064 |
require C4::Serials; |
| 1065 |
my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber); |
1065 |
my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber); |
| 1066 |
unless ($is_a_subscription) { |
1066 |
unless ($is_a_subscription) { |
| 1067 |
my $issues = GetIssues( { |
1067 |
my $issues = Koha::Issues->search( |
| 1068 |
borrowernumber => $borrower->{borrowernumber}, |
1068 |
{ |
| 1069 |
biblionumber => $biblionumber, |
1069 |
borrowernumber => $borrower->{borrowernumber}, |
| 1070 |
} ); |
1070 |
biblionumber => $biblionumber, |
| 1071 |
my @issues = $issues ? @$issues : (); |
1071 |
}, |
|
|
1072 |
{ |
| 1073 |
join => 'item', |
| 1074 |
} |
| 1075 |
); |
| 1072 |
# if we get here, we don't already have a loan on this item, |
1076 |
# if we get here, we don't already have a loan on this item, |
| 1073 |
# so if there are any loans on this bib, ask for confirmation |
1077 |
# so if there are any loans on this bib, ask for confirmation |
| 1074 |
if (scalar @issues > 0) { |
1078 |
if ( $issues->count ) { |
| 1075 |
$needsconfirmation{BIBLIO_ALREADY_ISSUED} = 1; |
1079 |
$needsconfirmation{BIBLIO_ALREADY_ISSUED} = 1; |
| 1076 |
} |
1080 |
} |
| 1077 |
} |
1081 |
} |
|
Lines 2506-2578
sub GetOpenIssue {
Link Here
|
| 2506 |
|
2510 |
|
| 2507 |
} |
2511 |
} |
| 2508 |
|
2512 |
|
| 2509 |
=head2 GetIssues |
|
|
| 2510 |
|
| 2511 |
$issues = GetIssues({}); # return all issues! |
| 2512 |
$issues = GetIssues({ borrowernumber => $borrowernumber, biblionumber => $biblionumber }); |
| 2513 |
|
| 2514 |
Returns all pending issues that match given criteria. |
| 2515 |
Returns a arrayref or undef if an error occurs. |
| 2516 |
|
| 2517 |
Allowed criteria are: |
| 2518 |
|
| 2519 |
=over 2 |
| 2520 |
|
| 2521 |
=item * borrowernumber |
| 2522 |
|
| 2523 |
=item * biblionumber |
| 2524 |
|
| 2525 |
=item * itemnumber |
| 2526 |
|
| 2527 |
=back |
| 2528 |
|
| 2529 |
=cut |
| 2530 |
|
| 2531 |
sub GetIssues { |
| 2532 |
my ($criteria) = @_; |
| 2533 |
|
| 2534 |
# Build filters |
| 2535 |
my @filters; |
| 2536 |
my @allowed = qw(borrowernumber biblionumber itemnumber); |
| 2537 |
foreach (@allowed) { |
| 2538 |
if (defined $criteria->{$_}) { |
| 2539 |
push @filters, { |
| 2540 |
field => $_, |
| 2541 |
value => $criteria->{$_}, |
| 2542 |
}; |
| 2543 |
} |
| 2544 |
} |
| 2545 |
|
| 2546 |
# Do we need to join other tables ? |
| 2547 |
my %join; |
| 2548 |
if (defined $criteria->{biblionumber}) { |
| 2549 |
$join{items} = 1; |
| 2550 |
} |
| 2551 |
|
| 2552 |
# Build SQL query |
| 2553 |
my $where = ''; |
| 2554 |
if (@filters) { |
| 2555 |
$where = "WHERE " . join(' AND ', map { "$_->{field} = ?" } @filters); |
| 2556 |
} |
| 2557 |
my $query = q{ |
| 2558 |
SELECT issues.* |
| 2559 |
FROM issues |
| 2560 |
}; |
| 2561 |
if (defined $join{items}) { |
| 2562 |
$query .= q{ |
| 2563 |
LEFT JOIN items ON (issues.itemnumber = items.itemnumber) |
| 2564 |
}; |
| 2565 |
} |
| 2566 |
$query .= $where; |
| 2567 |
|
| 2568 |
# Execute SQL query |
| 2569 |
my $dbh = C4::Context->dbh; |
| 2570 |
my $sth = $dbh->prepare($query); |
| 2571 |
my $rv = $sth->execute(map { $_->{value} } @filters); |
| 2572 |
|
| 2573 |
return $rv ? $sth->fetchall_arrayref({}) : undef; |
| 2574 |
} |
| 2575 |
|
| 2576 |
=head2 GetItemIssues |
2513 |
=head2 GetItemIssues |
| 2577 |
|
2514 |
|
| 2578 |
$issues = &GetItemIssues($itemnumber, $history); |
2515 |
$issues = &GetItemIssues($itemnumber, $history); |