Bug 32030: ERM - Add vendor to license
[koha-ffzg.git] / Koha / Holds.pm
index 7d070f8..b53b957 100644 (file)
@@ -32,7 +32,7 @@ Koha::Holds - Koha Hold object set class
 
 =head1 API
 
-=head2 Class Methods
+=head2 Class methods
 
 =cut
 
@@ -48,6 +48,18 @@ sub waiting {
     return $self->search( { found => 'W' } );
 }
 
+=head3 processing
+
+returns a set of holds that are processing from an existing set
+
+=cut
+
+sub processing {
+    my ( $self ) = @_;
+
+    return $self->search( { found => 'P' } );
+}
+
 =head3 unfilled
 
 returns a set of holds that are unfilled from an existing set
@@ -85,6 +97,9 @@ sub forced_hold_level {
     my $item_level_count = $self->search( { itemnumber => { '!=' => undef } } )->count();
     return 'item' if $item_level_count > 0;
 
+    my $item_group_level_count = $self->search( { item_group_id => { '!=' => undef } } )->count();
+    return 'item_group' if $item_group_level_count > 0;
+
     my $record_level_count = $self->search( { itemnumber => undef } )->count();
     return 'record' if $record_level_count > 0;
 
@@ -120,12 +135,7 @@ sub get_items_that_can_fill {
     push @bibs_or_items, 'me.itemnumber' => { in => \@itemnumbers } if @itemnumbers;
     push @bibs_or_items, 'me.biblionumber' => { in => \@biblionumbers } if @biblionumbers;
 
-    my @branchtransfers = Koha::Item::Transfers->search(
-        {
-            datearrived => undef,
-            datecancelled => undef,
-        },
-        {
+    my @branchtransfers = Koha::Item::Transfers->filter_by_current->search({}, {
             columns  => ['itemnumber'],
             collapse => 1,
         }
@@ -148,7 +158,39 @@ sub get_items_that_can_fill {
     )->filter_by_for_hold();
 }
 
-=head3 type
+=head3 filter_by_has_cancellation_requests
+
+    my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests;
+
+Returns a filtered resultset only containing holds that have cancellation requests.
+
+=cut
+
+sub filter_by_has_cancellation_requests {
+    my ($self) = @_;
+
+    return $self->search( { 'hold_cancellation_request_id' => { '!=' => undef } },
+        { join => 'cancellation_requests' } );
+}
+
+=head3 filter_out_has_cancellation_requests
+
+    my $holds_without_cancellation_requests = $holds->filter_out_has_cancellation_requests;
+
+Returns a filtered resultset without holds with cancellation requests.
+
+=cut
+
+sub filter_out_has_cancellation_requests {
+    my ($self) = @_;
+
+    return $self->search( { 'hold_cancellation_request_id' => { '=' => undef } },
+        { join => 'cancellation_requests' } );
+}
+
+=head2 Internal methods
+
+=head3 _type
 
 =cut