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

(-)a/C4/Acquisition.pm (-25 / +11 lines)
Lines 1283-1312 Returns a reference-to-hash describing the last order received for a subscriptio Link Here
1283
1283
1284
sub GetLastOrderReceivedFromSubscriptionid {
1284
sub GetLastOrderReceivedFromSubscriptionid {
1285
    my ( $subscriptionid ) = @_;
1285
    my ( $subscriptionid ) = @_;
1286
    my $dbh                = C4::Context->dbh;
1286
    my $lastOrderReceived = Koha::Acquisition::Orders->search(
1287
    my $query              = qq|
1287
        {
1288
        SELECT * FROM aqorders
1288
            subscriptionid => $subscriptionid,
1289
        LEFT JOIN subscription
1289
            datereceived   => { '!=' => undef }
1290
            ON ( aqorders.subscriptionid = subscription.subscriptionid )
1290
        },
1291
        WHERE aqorders.subscriptionid = ?
1291
        {
1292
            AND aqorders.datereceived =
1292
            order_by =>
1293
                (
1293
              [ { -desc => 'datereceived' }, { -desc => 'ordernumber' } ]
1294
                    SELECT MAX( aqorders.datereceived )
1294
        }
1295
                    FROM aqorders
1295
    );
1296
                    LEFT JOIN subscription
1296
    return $lastOrderReceived->count ? $lastOrderReceived->next->unblessed : undef;
1297
                        ON ( aqorders.subscriptionid = subscription.subscriptionid )
1298
                        WHERE aqorders.subscriptionid = ?
1299
                            AND aqorders.datereceived IS NOT NULL
1300
                )
1301
        ORDER BY ordernumber DESC
1302
        LIMIT 1
1303
    |;
1304
    my $result_set =
1305
      $dbh->selectall_arrayref( $query, { Slice => {} }, $subscriptionid, $subscriptionid );
1306
1307
    # result_set assumed to contain 1 match
1308
    return $result_set->[0];
1309
1310
}
1297
}
1311
1298
1312
#------------------------------------------------------------#
1299
#------------------------------------------------------------#
1313
- 

Return to bug 20728