View | Details | Raw Unified | Return to bug 17678
Collapse All | Expand All

(-)a/C4/Circulation.pm (-73 / +10 lines)
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);
(-)a/t/db_dependent/Circulation/GetIssues.t (-23 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 10;
20
use Test::More tests => 2;
21
use Test::MockModule;
21
use Test::MockModule;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 72-98 AddIssue($borrower, '0101'); Link Here
72
AddIssue($borrower, '0203');
72
AddIssue($borrower, '0203');
73
73
74
# Begin tests...
74
# Begin tests...
75
my $issues;
76
$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
77
is(scalar @$issues, 1, "Biblio $biblionumber1 has 1 item issued");
78
is($issues->[0]->{itemnumber}, $itemnumber1, "First item of biblio $biblionumber1 is issued");
79
80
$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber2});
81
is(scalar @$issues, 1, "Biblio $biblionumber2 has 1 item issued");
82
is($issues->[0]->{itemnumber}, $itemnumber3, "First item of biblio $biblionumber2 is issued");
83
84
$issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber});
85
is(scalar @$issues, 2, "Borrower $borrowernumber checked out 2 items");
86
87
$issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber, biblionumber => $biblionumber1});
88
is(scalar @$issues, 1, "One of those is an item from biblio $biblionumber1");
89
90
$issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber, biblionumber => $biblionumber2});
91
is(scalar @$issues, 1, "The other is an item from biblio $biblionumber2");
92
93
$issues = C4::Circulation::GetIssues({itemnumber => $itemnumber2});
94
is(scalar @$issues, 0, "No one has issued the second item of biblio $biblionumber2");
95
96
my $onsite_checkouts = GetPendingOnSiteCheckouts;
75
my $onsite_checkouts = GetPendingOnSiteCheckouts;
97
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
76
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
98
77
99
- 

Return to bug 17678