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

(-)a/C4/Circulation.pm (-7 / +81 lines)
Lines 123-128 use Koha::Exceptions::Checkout; Link Here
123
use Koha::Plugins;
123
use Koha::Plugins;
124
use Koha::Recalls;
124
use Koha::Recalls;
125
use Koha::Library::Hours;
125
use Koha::Library::Hours;
126
use Koha::DisplayItems;
126
use Carp            qw( carp );
127
use Carp            qw( carp );
127
use List::MoreUtils qw( any );
128
use List::MoreUtils qw( any );
128
use Scalar::Util    qw( looks_like_number blessed );
129
use Scalar::Util    qw( looks_like_number blessed );
Lines 2753-2758 sub AddReturn { Link Here
2753
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
2754
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
2754
    $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2755
    $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2755
2756
2757
    if ( my $display_item = $item->active_display_item ) {
2758
        my $display       = $display_item->display;
2759
        my $return_over   = $display->display_return_over;
2760
        my $should_remove = 0;
2761
2762
        if ( $return_over eq 'yes - any library' ) {
2763
            $should_remove = 1;
2764
        } elsif ( $return_over eq 'yes - except at home library' ) {
2765
            my $homebranch = $item->homebranch;
2766
            $should_remove = 1 if $branch ne $homebranch;
2767
        }
2768
2769
        if ($should_remove) {
2770
            $display_item->delete;
2771
            $messages->{RemovedFromDisplay} = {
2772
                display_id   => $display->display_id,
2773
                display_name => $display->display_name,
2774
            };
2775
        }
2776
    }
2777
2756
    if ( $doreturn and $issue ) {
2778
    if ( $doreturn and $issue ) {
2757
        my $checkin = Koha::Old::Checkouts->find( $issue->id );
2779
        my $checkin = Koha::Old::Checkouts->find( $issue->id );
2758
2780
Lines 4778-4785 sub GetAgeRestriction { Link Here
4778
4800
4779
sub GetPendingOnSiteCheckouts {
4801
sub GetPendingOnSiteCheckouts {
4780
    my $dbh = C4::Context->dbh;
4802
    my $dbh = C4::Context->dbh;
4781
    return $dbh->selectall_arrayref(
4803
4782
        q|
4804
    my $use_display_module = C4::Context->preference('UseDisplayModule');
4805
4806
    my $sql = q|
4783
        SELECT
4807
        SELECT
4784
          items.barcode,
4808
          items.barcode,
4785
          items.biblionumber,
4809
          items.biblionumber,
Lines 4795-4808 sub GetPendingOnSiteCheckouts { Link Here
4795
          borrowers.firstname,
4819
          borrowers.firstname,
4796
          borrowers.surname,
4820
          borrowers.surname,
4797
          borrowers.cardnumber,
4821
          borrowers.cardnumber,
4798
          borrowers.borrowernumber
4822
          borrowers.borrowernumber|;
4823
4824
    if ($use_display_module) {
4825
        $sql .= q|,
4826
          COALESCE(active_display.display_location, items.location) AS effective_location,
4827
          active_display.display_name,
4828
          active_display.display_location AS raw_display_location|;
4829
    } else {
4830
        $sql .= q|,
4831
          items.location AS effective_location,
4832
          NULL AS display_name,
4833
          NULL AS raw_display_location|;
4834
    }
4835
4836
    $sql .= q|
4799
        FROM items
4837
        FROM items
4800
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
4838
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
4801
        LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
4839
        LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
4802
        LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
4840
        LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber|;
4803
        WHERE issues.onsite_checkout = 1
4841
4804
    |, { Slice => {} }
4842
    if ($use_display_module) {
4805
    );
4843
        $sql .= q|
4844
        LEFT JOIN (
4845
          SELECT 
4846
            di.itemnumber,
4847
            d.display_location,
4848
            d.display_name,
4849
            ROW_NUMBER() OVER (PARTITION BY di.itemnumber ORDER BY di.date_added DESC) as rn
4850
          FROM display_items di
4851
          JOIN displays d ON di.display_id = d.display_id
4852
          WHERE d.enabled = 1
4853
            AND (d.start_date IS NULL OR d.start_date <= CURDATE())
4854
            AND (d.end_date IS NULL OR d.end_date >= CURDATE())
4855
            AND (di.date_remove IS NULL OR di.date_remove >= CURDATE())
4856
        ) active_display ON items.itemnumber = active_display.itemnumber AND active_display.rn = 1|;
4857
    }
4858
4859
    $sql .= q|
4860
        WHERE issues.onsite_checkout = 1|;
4861
4862
    my $results = $dbh->selectall_arrayref( $sql, { Slice => {} } );
4863
4864
    # Add effective location description for each item
4865
    foreach my $checkout (@$results) {
4866
        if ( $checkout->{display_name} && !$checkout->{raw_display_location} ) {
4867
4868
            # Item is on display with no specific display location
4869
            $checkout->{effective_location_description} = "DISPLAY: " . $checkout->{display_name};
4870
        } else {
4871
4872
            # Use AuthorisedValues to get effective location description
4873
            my $av = Koha::AuthorisedValues->get_description_by_koha_field(
4874
                { kohafield => 'items.location', authorised_value => $checkout->{effective_location} } );
4875
            $checkout->{effective_location_description} = $av->{lib} || '';
4876
        }
4877
    }
4878
4879
    return $results;
4806
}
4880
}
4807
4881
4808
=head2 GetTopIssues
4882
=head2 GetTopIssues
(-)a/C4/Search.pm (-4 / +52 lines)
Lines 46-51 use C4::XSLT qw( XSLTParse4Display ); Link Here
46
use C4::Reserves qw( GetReserveStatus );
46
use C4::Reserves qw( GetReserveStatus );
47
use C4::Charset  qw( SetUTF8Flag );
47
use C4::Charset  qw( SetUTF8Flag );
48
use Koha::AuthorisedValues;
48
use Koha::AuthorisedValues;
49
use Koha::Displays;
50
use Koha::Items;
49
use Koha::ItemTypes;
51
use Koha::ItemTypes;
50
use Koha::Libraries;
52
use Koha::Libraries;
51
use Koha::Logger;
53
use Koha::Logger;
Lines 1687-1692 sub searchResults { Link Here
1687
        )
1689
        )
1688
    };
1690
    };
1689
1691
1692
    # Cache for display lookups to avoid repeated queries
1693
    my $display_cache = {};
1694
1695
    # Helper function to get effective location for search results
1696
    my $get_effective_location_display = sub {
1697
        my ($item) = @_;
1698
        return $shelflocations->{ $item->{location} } unless C4::Context->preference('UseDisplayModule');
1699
1700
        my $item_obj = Koha::Items->find( $item->{itemnumber} );
1701
        return $shelflocations->{ $item->{location} } unless $item_obj;
1702
1703
        my $effective_loc = $item_obj->effective_location;
1704
1705
        # If it starts with "DISPLAY:", validate against displays table
1706
        if ( $effective_loc =~ /^DISPLAY:\s*(.+)$/ ) {
1707
            my $display_name = $1;
1708
1709
            # Use cache to avoid repeated database queries
1710
            if ( !exists $display_cache->{$display_name} ) {
1711
                my $display = Koha::Displays->search( { display_name => $display_name } )->next;
1712
                $display_cache->{$display_name} = $display ? $display->display_name : undef;
1713
            }
1714
            return $display_cache->{$display_name} ? "DISPLAY: " . $display_cache->{$display_name} : $effective_loc;
1715
        } else {
1716
            return $shelflocations->{$effective_loc};
1717
        }
1718
    };
1719
1690
    # get notforloan authorised value list (see $shelflocations  FIXME)
1720
    # get notforloan authorised value list (see $shelflocations  FIXME)
1691
    my $av = Koha::MarcSubfieldStructures->search(
1721
    my $av = Koha::MarcSubfieldStructures->search(
1692
        {
1722
        {
Lines 1891-1896 sub searchResults { Link Here
1891
                $item->{'branchcode'} = $item->{$otherbranch};
1921
                $item->{'branchcode'} = $item->{$otherbranch};
1892
            }
1922
            }
1893
1923
1924
            # items on display
1925
            my @displays;
1926
            my @display_items = Koha::DisplayItems->search(
1927
                { itemnumber => $item->{itemnumber} },
1928
                {
1929
                    order_by => { '-desc' => 'date_added' },
1930
                }
1931
            )->as_list;
1932
1933
            foreach my $display_item (@display_items) {
1934
                push @displays, $display_item->display;
1935
            }
1936
1937
            $item->{displays} = \@displays
1938
                unless $#displays < 0;
1939
1894
            my $prefix =
1940
            my $prefix =
1895
                  ( $item->{$hbranch}       ? $item->{$hbranch} . '--' : q{} )
1941
                  ( $item->{$hbranch}       ? $item->{$hbranch} . '--' : q{} )
1896
                . ( $item->{location}       ? $item->{location}        : q{} )
1942
                . ( $item->{location}       ? $item->{location}        : q{} )
Lines 1912-1918 sub searchResults { Link Here
1912
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
1958
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
1913
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
1959
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
1914
                $onloan_items->{$key}->{branchcode}     = $item->{branchcode};
1960
                $onloan_items->{$key}->{branchcode}     = $item->{branchcode};
1915
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} } if $item->{location};
1961
                $onloan_items->{$key}->{location}       = $get_effective_location_display->($item) if $item->{location};
1916
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
1962
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
1917
                $onloan_items->{$key}->{description}    = $item->{description};
1963
                $onloan_items->{$key}->{description}    = $item->{description};
1918
                $onloan_items->{$key}->{imageurl}       = getitemtypeimagelocation(
1964
                $onloan_items->{$key}->{imageurl}       = getitemtypeimagelocation(
Lines 1921-1926 sub searchResults { Link Here
1921
                );
1967
                );
1922
                $onloan_items->{$key}->{collectioncode} =
1968
                $onloan_items->{$key}->{collectioncode} =
1923
                    GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
1969
                    GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
1970
                $onloan_items->{$key}->{displays} = $item->{displays};
1924
1971
1925
                # if something's checked out and lost, mark it as 'long overdue'
1972
                # if something's checked out and lost, mark it as 'long overdue'
1926
                if ( $item->{itemlost} ) {
1973
                if ( $item->{itemlost} ) {
Lines 2030-2036 sub searchResults { Link Here
2030
                        GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value )
2077
                        GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value )
2031
                        if $notforloan_authorised_value and $item->{notforloan};
2078
                        if $notforloan_authorised_value and $item->{notforloan};
2032
                    $other_items->{$key}->{count}++ if $item->{$hbranch};
2079
                    $other_items->{$key}->{count}++ if $item->{$hbranch};
2033
                    $other_items->{$key}->{location}    = $shelflocations->{ $item->{location} } if $item->{location};
2080
                    $other_items->{$key}->{location}    = $get_effective_location_display->($item) if $item->{location};
2034
                    $other_items->{$key}->{description} = $item->{description};
2081
                    $other_items->{$key}->{description} = $item->{description};
2035
                    $other_items->{$key}->{imageurl}    = getitemtypeimagelocation(
2082
                    $other_items->{$key}->{imageurl}    = getitemtypeimagelocation(
2036
                        $search_context->{'interface'},
2083
                        $search_context->{'interface'},
Lines 2038-2043 sub searchResults { Link Here
2038
                    );
2085
                    );
2039
                    $other_items->{$key}->{collectioncode} =
2086
                    $other_items->{$key}->{collectioncode} =
2040
                        GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
2087
                        GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
2088
                    $other_items->{$key}->{displays} = $item->{displays};
2041
                }
2089
                }
2042
2090
2043
                # item is available
2091
                # item is available
Lines 2051-2057 sub searchResults { Link Here
2051
                    }
2099
                    }
2052
                    $available_items->{$prefix}->{branchavailablecount} = $branch_available_count;
2100
                    $available_items->{$prefix}->{branchavailablecount} = $branch_available_count;
2053
                    $available_items->{$prefix}->{branchcode}           = $item->{branchcode};
2101
                    $available_items->{$prefix}->{branchcode}           = $item->{branchcode};
2054
                    $available_items->{$prefix}->{location}             = $shelflocations->{ $item->{location} }
2102
                    $available_items->{$prefix}->{location}             = $get_effective_location_display->($item)
2055
                        if $item->{location};
2103
                        if $item->{location};
2056
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation(
2104
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation(
2057
                        $search_context->{'interface'},
2105
                        $search_context->{'interface'},
Lines 2059-2064 sub searchResults { Link Here
2059
                    );
2107
                    );
2060
                    $available_items->{$prefix}->{collectioncode} =
2108
                    $available_items->{$prefix}->{collectioncode} =
2061
                        GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
2109
                        GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' );
2110
                    $available_items->{$prefix}->{displays} = $item->{displays};
2062
                }
2111
                }
2063
            }
2112
            }
2064
        }    # notforloan, item level and biblioitem level
2113
        }    # notforloan, item level and biblioitem level
2065
- 

Return to bug 14962