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

(-)a/C4/HoldsQueue.pm (-45 / +35 lines)
Lines 25-31 use warnings; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Circulation qw( GetBranchItemRule );
26
use C4::Circulation qw( GetBranchItemRule );
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::HoldsQueueItems;
28
use Koha::Hold::HoldsQueueItems;
29
use Koha::Items;
29
use Koha::Items;
30
use Koha::Libraries;
30
use Koha::Libraries;
31
use Koha::Patrons;
31
use Koha::Patrons;
Lines 126-177 sub GetHoldsQueueItems { Link Here
126
    my $params = shift;
126
    my $params = shift;
127
    my $dbh   = C4::Context->dbh;
127
    my $dbh   = C4::Context->dbh;
128
128
129
    my @bind_params = ();
129
    my $search_params;
130
    my $query = q/SELECT tmp_holdsqueue.*, biblio.author, items.ccode, items.itype, biblioitems.itemtype, items.location,
130
    $search_params->{'me.holdingbranch'} = $params->{branchlimit} if $params->{branchlimit};
131
                         items.enumchron, items.cn_sort, biblioitems.publishercode,
131
    $search_params->{'itype'} = $params->{itemtypeslimit} if $params->{itemtypeslimit};
132
                         biblio.copyrightdate, biblio.subtitle, biblio.medium,
132
    $search_params->{'ccode'} = $params->{ccodeslimit} if $params->{ccodeslimit};
133
                         biblio.part_number, biblio.part_name,
133
    $search_params->{'location'} = $params->{locationslimit} if $params->{locationslimit};
134
                         biblioitems.publicationyear, biblioitems.pages, biblioitems.size,
134
135
                         biblioitems.isbn, biblioitems.editionstatement, items.copynumber,
135
    my $results = Koha::Hold::HoldsQueueItems->search(
136
                         item_groups.item_group_id, item_groups.description AS item_group_description
136
        $search_params,
137
                  FROM tmp_holdsqueue
137
        {
138
                       JOIN biblio      USING (biblionumber)
138
            join => [
139
                  LEFT JOIN biblioitems USING (biblionumber)
139
                'borrower',
140
                  LEFT JOIN items       USING (  itemnumber)
140
                'biblio',
141
                  LEFT JOIN item_group_items ON ( items.itemnumber =  item_group_items.item_id )
141
                'biblioitem',
142
                  LEFT JOIN item_groups ON ( item_group_items.item_group_id = item_groups.item_group_id )
142
                {
143
                  WHERE 1=1
143
                    'item' => {
144
                /;
144
                        'item_group_item' => 'item_group'
145
    if ($params->{branchlimit}) {
145
                    }
146
        $query .="AND tmp_holdsqueue.holdingbranch = ? ";
146
                },
147
        push @bind_params, $params->{branchlimit};
147
            ],
148
    }
148
            prefetch => [
149
    if( $params->{itemtypeslimit} ) {
149
                'biblio',
150
        $query .=" AND items.itype = ? ";
150
                'biblioitem',
151
        push @bind_params, $params->{itemtypeslimit};
151
                {
152
    }
152
                    'item' => {
153
    if( $params->{ccodeslimit} ) {
153
                        'item_group_item' => 'item_group'
154
        $query .=" AND items.ccode = ? ";
154
                    }
155
        push @bind_params, $params->{ccodeslimit};
155
                }
156
    }
156
            ],
157
    if( $params->{locationslimit} ) {
157
            order_by => [
158
        $query .=" AND items.location = ? ";
158
                'ccode',        'location',   'item.cn_sort', 'author',
159
        push @bind_params, $params->{locationslimit};
159
                'biblio.title', 'pickbranch', 'reservedate'
160
    }
160
            ],
161
    $query .= " ORDER BY ccode, location, cn_sort, author, title, pickbranch, reservedate";
162
    my $sth = $dbh->prepare($query);
163
    $sth->execute(@bind_params);
164
    my $items = [];
165
    while ( my $row = $sth->fetchrow_hashref ){
166
        # return the bib-level or item-level itype per syspref
167
        if (!C4::Context->preference('item-level_itypes')) {
168
            $row->{itype} = $row->{itemtype};
169
        }
161
        }
170
        delete $row->{itemtype};
162
    );
171
163
172
        push @$items, $row;
164
    return $results;
173
    }
174
    return $items;
175
}
165
}
176
166
177
=head2 CreateQueue
167
=head2 CreateQueue
(-)a/Koha/Hold/HoldsQueueItem.pm (+39 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use Koha::Database;
20
use Koha::Database;
21
21
22
use Koha::Items;
23
use Koha::Biblios;
24
use Koha::Patrons;
25
22
use base qw(Koha::Object);
26
use base qw(Koha::Object);
23
27
24
=head1 NAME
28
=head1 NAME
Lines 27-32 Koha::Hold::HoldsQueueItem - Koha hold cancellation request Object class Link Here
27
31
28
=head1 API
32
=head1 API
29
33
34
=head2 Class methods
35
36
=head3 patron
37
38
=cut
39
40
sub patron {
41
    my ( $self ) = @_;
42
    my $rs = $self->_result->borrowernumber;
43
    return unless $rs;
44
    return Koha::Patron->_new_from_dbic( $rs );
45
}
46
47
=head3 biblio
48
49
=cut
50
51
sub biblio {
52
    my ( $self ) = @_;
53
    my $rs = $self->_result->biblionumber;
54
    return unless $rs;
55
    return Koha::Biblio->_new_from_dbic( $rs );
56
}
57
58
=head3 item
59
60
=cut
61
62
sub item {
63
    my ( $self ) = @_;
64
    my $rs = $self->_result->itemnumber;
65
    return unless $rs;
66
    return Koha::Item->_new_from_dbic( $rs );
67
}
68
30
=head2 Internal methods
69
=head2 Internal methods
31
70
32
=head3 _type
71
=head3 _type
(-)a/Koha/Schema/Result/TmpHoldsqueue.pm (+48 lines)
Lines 224-229 __PACKAGE__->add_columns( Link Here
224
    '+item_level_request' => { is_boolean => 1 }
224
    '+item_level_request' => { is_boolean => 1 }
225
);
225
);
226
226
227
__PACKAGE__->belongs_to(
228
  "borrower",
229
  "Koha::Schema::Result::Borrower",
230
  { borrowernumber => "borrowernumber" },
231
  {
232
    is_deferrable => 1,
233
    join_type     => "LEFT",
234
    on_delete     => "CASCADE",
235
    on_update     => "CASCADE",
236
  },
237
);
238
239
__PACKAGE__->belongs_to(
240
  "item",
241
  "Koha::Schema::Result::Item",
242
  { itemnumber => "itemnumber" },
243
  {
244
    is_deferrable => 1,
245
    join_type     => "LEFT",
246
    on_delete     => "CASCADE",
247
    on_update     => "CASCADE",
248
  },
249
);
250
251
__PACKAGE__->belongs_to(
252
  "biblio",
253
  "Koha::Schema::Result::Biblio",
254
  { biblionumber => "biblionumber" },
255
  {
256
    is_deferrable => 1,
257
    join_type     => "LEFT",
258
    on_delete     => "CASCADE",
259
    on_update     => "CASCADE",
260
  },
261
);
262
263
__PACKAGE__->belongs_to(
264
  "biblioitem",
265
  "Koha::Schema::Result::Biblioitem",
266
  { biblionumber => "biblionumber" },
267
  {
268
    is_deferrable => 1,
269
    join_type     => "LEFT",
270
    on_delete     => "CASCADE",
271
    on_update     => "CASCADE",
272
  },
273
);
274
227
sub koha_object_class {
275
sub koha_object_class {
228
    'Koha::HoldsQueueItem';
276
    'Koha::HoldsQueueItem';
229
}
277
}
(-)a/circ/view_holdsqueue.pl (-17 / +17 lines)
Lines 47-70 my $itemtypeslimit = $params->{'itemtypeslimit'}; Link Here
47
my $ccodeslimit = $params->{'ccodeslimit'};
47
my $ccodeslimit = $params->{'ccodeslimit'};
48
my $locationslimit = $params->{'locationslimit'};
48
my $locationslimit = $params->{'locationslimit'};
49
49
50
if ( $run_report ) {
50
if ($run_report) {
51
    my $items = GetHoldsQueueItems({
51
    my $items = GetHoldsQueueItems(
52
        branchlimit => $branchlimit,
52
        {
53
        itemtypeslimit => $itemtypeslimit,
53
            branchlimit    => $branchlimit,
54
        ccodeslimit => $ccodeslimit,
54
            itemtypeslimit => $itemtypeslimit,
55
        locationslimit => $locationslimit
55
            ccodeslimit    => $ccodeslimit,
56
    });
56
            locationslimit => $locationslimit
57
    for my $item ( @$items ) {
57
        }
58
        $item->{patron} = Koha::Patrons->find( $item->{borrowernumber} );
58
    );
59
    }
59
60
    $template->param(
60
    $template->param(
61
        branchlimit     => $branchlimit,
61
        branchlimit    => $branchlimit,
62
        itemtypeslimit     => $itemtypeslimit,
62
        itemtypeslimit => $itemtypeslimit,
63
        ccodeslimit     => $ccodeslimit,
63
        ccodeslimit    => $ccodeslimit,
64
        locationslimit     => $locationslimit,
64
        locationslimit => $locationslimit,
65
        total      => scalar @$items,
65
        total          => $items->count,
66
        itemsloop  => $items,
66
        itemsloop      => $items,
67
        run_report => $run_report,
67
        run_report     => $run_report,
68
    );
68
    );
69
}
69
}
70
70
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt (-18 / +18 lines)
Lines 156-195 Link Here
156
                    <tr>
156
                    <tr>
157
                        <td class="hq-title">
157
                        <td class="hq-title">
158
                            <p>
158
                            <p>
159
                                [% INCLUDE 'biblio-title.inc' biblio=itemsloo link = 1 %]
159
                                [% INCLUDE 'biblio-title.inc' biblio=itemsloo.biblio link = 1 %]
160
                            </p>
160
                            </p>
161
                            <p>
161
                            <p>
162
                                <div class="hq-biblionumber content_hidden">[% itemsloo.biblionumber | html %]</div>
162
                                <div class="hq-biblionumber content_hidden">[% itemsloo.biblionumber | html %]</div>
163
                                <div class="hq-author">[% itemsloo.author | html %]</div>
163
                                <div class="hq-author">[% itemsloo.biblio.author | html %]</div>
164
                                [% IF ( itemsloo.editionstatement ) %]<div class="hq-editionstatement">[% itemsloo.editionstatement | html %]</div>[% END %]
164
                                [% IF ( itemsloo.biblio.biblioitem.editionstatement ) %]<div class="hq-editionstatement">[% itemsloo.biblio.biblioitem.editionstatement | html %]</div>[% END %]
165
                                <div class="hq-pubdata">
165
                                <div class="hq-pubdata">
166
                                    [% IF ( itemsloo.publishercode ) %][% itemsloo.publishercode | html %][% END %]
166
                                    [% IF ( itemsloo.biblio.biblioitem.publishercode ) %][% itemsloo.biblio.biblioitem.publishercode | html %][% END %]
167
167
168
                                    [% IF ( itemsloo.publicationyear ) %]
168
                                    [% IF ( itemsloo.biblio.biblioitem.publicationyear ) %]
169
                                        , [% itemsloo.publicationyear | html %]
169
                                        , [% itemsloo.biblio.biblioitem.publicationyear | html %]
170
                                    [% ELSIF ( itemsloo.copyrightdate ) %]
170
                                    [% ELSIF ( itemsloo.biblio.copyrightdate ) %]
171
                                        , [% itemsloo.copyrightdate | html %]
171
                                        , [% itemsloo.biblio.copyrightdate | html %]
172
                                    [% END %]
172
                                    [% END %]
173
173
174
                                    [% IF ( itemsloo.pages ) %]: [% itemsloo.pages | html %] [% END %]
174
                                    [% IF ( itemsloo.biblio.biblioitem.pages ) %]: [% itemsloo.biblio.biblioitem.pages | html %] [% END %]
175
175
176
                                    [% IF ( itemsloo.item('size') ) %][% itemsloo.item('size') | html %][% END %]
176
                                    [% IF ( itemsloo.biblio.biblioitem.size ) %][% itemsloo.biblio.biblioitem.size | html %][% END %]
177
177
178
                                    [% IF ( itemsloo.isbn ) %]<span>ISBN: [% itemsloo.isbn | html %]</span>[% END %]
178
                                    [% IF ( itemsloo.biblio.biblioitem.isbn ) %]<span>ISBN: [% itemsloo.biblio.biblioitem.isbn | html %]</span>[% END %]
179
                                </div>
179
                                </div>
180
                            </p>
180
                            </p>
181
                        </td>
181
                        </td>
182
                        <td class="hq-holdingbranch">[% Branches.GetName( itemsloo.holdingbranch ) | html %]</td>
182
                        <td class="hq-holdingbranch">[% Branches.GetName( itemsloo.holdingbranch ) | html %]</td>
183
                        <td class="hq-collection">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => itemsloo.ccode ) | html %]</td>
183
                        <td class="hq-collection">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => itemsloo.item.ccode ) | html %]</td>
184
                        <td class="hq-itemtype">[% ItemTypes.GetDescription( itemsloo.itype ) | html %]</td>
184
                        <td class="hq-itemtype">[% ItemTypes.GetDescription( itemsloo.item.effective_itemtype ) | html %]</td>
185
                        <td class="hq-callnumber">[% IF ( itemsloo.location ) %]<em>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => itemsloo.location ) | html %]</em> [% END %][% itemsloo.itemcallnumber | html %]</td>
185
                        <td class="hq-callnumber">[% IF ( itemsloo.item.location ) %]<em>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => itemsloo.item.location ) | html %]</em> [% END %][% itemsloo.item.itemcallnumber | html %]</td>
186
                        <td class="hq-copynumber">[% itemsloo.copynumber | html %]</td>
186
                        <td class="hq-copynumber">[% itemsloo.item.copynumber | html %]</td>
187
                        <td class="hq-enumchron">[% itemsloo.enumchron | html %]</td>
187
                        <td class="hq-enumchron">[% itemsloo.item.enumchron | html %]</td>
188
                        <td class="hq-barcode">
188
                        <td class="hq-barcode">
189
                            [% IF ( itemsloo.item_level_request ) %]
189
                            [% IF ( itemsloo.item_level_request ) %]
190
                                <em>Only item:</em> <strong>[% itemsloo.barcode | html %]</strong>
190
                                <em>Only item:</em> <strong>[% itemsloo.barcode | html %]</strong>
191
                            [% ELSIF itemsloo.item_group_id %]
191
                            [% ELSIF itemsloo.item.item_group %]
192
                                <strong>[% itemsloo.barcode | html %]</strong> <em>or any item from item group <strong>[% itemsloo.item_group_description | html %]</strong></em>
192
                                <strong>[% itemsloo.barcode | html %]</strong> <em>or any item from item group <strong>[% itemsloo.item.item_group.description | html %]</strong></em>
193
                            [% ELSE %]
193
                            [% ELSE %]
194
                                <strong>[% itemsloo.barcode | html %]</strong> <em>or any available</em>
194
                                <strong>[% itemsloo.barcode | html %]</strong> <em>or any available</em>
195
                            [% END %]
195
                            [% END %]
(-)a/t/db_dependent/HoldsQueue.t (-12 / +11 lines)
Lines 163-175 $dbh->do("DELETE FROM items WHERE holdingbranch = '$borrower_branchcode'"); Link Here
163
# Frst branch from StaticHoldsQueueWeight
163
# Frst branch from StaticHoldsQueueWeight
164
test_queue ('take from lowest cost branch', 0, $borrower_branchcode, $other_branches[0]);
164
test_queue ('take from lowest cost branch', 0, $borrower_branchcode, $other_branches[0]);
165
test_queue ('take from lowest cost branch', 1, $borrower_branchcode, $least_cost_branch_code);
165
test_queue ('take from lowest cost branch', 1, $borrower_branchcode, $least_cost_branch_code);
166
my $queue = C4::HoldsQueue::GetHoldsQueueItems({ branchlmit => $least_cost_branch_code}) || [];
166
my $queue = C4::HoldsQueue::GetHoldsQueueItems({ branchlimit => $least_cost_branch_code}) || [];
167
my $queue_item = $queue->[0];
167
my $queue_item = $queue->next;
168
ok( $queue_item
168
ok( $queue_item
169
 && $queue_item->{pickbranch} eq $borrower_branchcode
169
 && $queue_item->pickbranch eq $borrower_branchcode
170
 && $queue_item->{holdingbranch} eq $least_cost_branch_code, "GetHoldsQueueItems" )
170
 && $queue_item->item->holdingbranch eq $least_cost_branch_code, "GetHoldsQueueItems" )
171
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item) );
171
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item->unblessed) );
172
ok( exists($queue_item->{itype}), 'item type included in queued items list (bug 5825)' );
172
ok( $queue_item->item->effective_itemtype, 'item type included in queued items list (bug 5825)' );
173
173
174
ok(
174
ok(
175
    C4::HoldsQueue::least_cost_branch( 'B', [ 'A', 'B', 'C' ] ) eq 'B',
175
    C4::HoldsQueue::least_cost_branch( 'B', [ 'A', 'B', 'C' ] ) eq 'B',
Lines 1944-1968 subtest "GetHoldsQueueItems" => sub { Link Here
1944
     " );
1944
     " );
1945
1945
1946
    my $queue_items = GetHoldsQueueItems();
1946
    my $queue_items = GetHoldsQueueItems();
1947
    is( scalar @$queue_items, $count + 3, 'Three items added to queue' );
1947
    is( $queue_items->count, $count + 3, 'Three items added to queue' );
1948
1948
1949
    $queue_items = GetHoldsQueueItems( { itemtypeslimit => $item_1->itype } );
1949
    $queue_items = GetHoldsQueueItems( { itemtypeslimit => $item_1->itype } );
1950
    is( scalar @$queue_items,
1950
    is( $queue_items->count,
1951
        3, 'Three items of same itemtype found when itemtypeslimit passed' );
1951
        3, 'Three items of same itemtype found when itemtypeslimit passed' );
1952
1952
1953
    $queue_items = GetHoldsQueueItems(
1953
    $queue_items = GetHoldsQueueItems(
1954
        { itemtypeslimit => $item_1->itype, ccodeslimit => $item_2->ccode } );
1954
        { itemtypeslimit => $item_1->itype, ccodeslimit => $item_2->ccode } );
1955
    is( scalar @$queue_items,
1955
    is( $queue_items->count,
1956
        2, 'Two items of same collection found when ccodeslimit passed' );
1956
        2, 'Two items of same collection found when ccodeslimit passed' );
1957
1957
1958
    @$queue_items = GetHoldsQueueItems(
1958
    $queue_items = GetHoldsQueueItems(
1959
        {
1959
        {
1960
            itemtypeslimit => $item_1->itype,
1960
            itemtypeslimit => $item_1->itype,
1961
            ccodeslimit    => $item_2->ccode,
1961
            ccodeslimit    => $item_2->ccode,
1962
            locationslimit => $item_3->location
1962
            locationslimit => $item_3->location
1963
        }
1963
        }
1964
    );
1964
    );
1965
    is( scalar @$queue_items,
1965
    is( scalar $queue_items->count,
1966
        1, 'One item of shleving location found when locationslimit passed' );
1966
        1, 'One item of shleving location found when locationslimit passed' );
1967
1967
1968
    $schema->storage->txn_rollback;
1968
    $schema->storage->txn_rollback;
1969
- 

Return to bug 28966