Kemnersaker.pm 1.4 KB
Newer Older
Benjamin Rokseth's avatar
Benjamin Rokseth committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package Koha::Kemnersaker;

use Modern::Perl;
use Koha::Database;
use C4::Context;

=pod
Oslo Public Library specific module for handling kemnersaker
=cut

# Get all ongoing kemnersaker for a patron
sub GetActiveCases {
    my ( $self, $borrowernumber ) = @_;

    return unless $borrowernumber;

    my $dbh = C4::Context->dbh;

    my @results;
    my $query = "
        SELECT ks.issue_id, ks.itemnumber, ks.timestamp, ks.status, bib.title, it.barcode, ks.date_due, ks.issuedate, ks.returndate
        FROM (
          SELECT k.issue_id, k.itemnumber, k.timestamp, k.status, iss.date_due, iss.issuedate, iss.returndate
          FROM kemnersaker k
          JOIN issues iss USING(issue_id)
          WHERE k.borrowernumber = ?
27
          AND k.status IN ('new', 'sent')
Benjamin Rokseth's avatar
Benjamin Rokseth committed
28
29
30
31
32
          UNION
          SELECT k.issue_id, k.itemnumber, k.timestamp, k.status, iss.date_due, iss.issuedate, iss.returndate
          FROM kemnersaker k
          JOIN old_issues iss USING(issue_id)
          WHERE k.borrowernumber = ?
33
          AND k.status IN ('new', 'sent')
Benjamin Rokseth's avatar
Benjamin Rokseth committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        ) ks
        JOIN items it ON (it.itemnumber=ks.itemnumber)
        JOIN biblio bib ON (bib.biblionumber=it.biblionumber);
    ";

    my $sth = $dbh->prepare($query);
    $sth->execute($borrowernumber, $borrowernumber) or die "Error running query: $sth";

    while ( my $row = $sth->fetchrow_hashref() ) {
        push @results, $row;
    }

    return \@results;
}

1;