Lines 116-142
Return 1 if this item is ready to be moved on to the next stage in its rota.
Link Here
|
116 |
=cut |
116 |
=cut |
117 |
|
117 |
|
118 |
sub needs_advancing { |
118 |
sub needs_advancing { |
119 |
my ( $self ) = @_; |
119 |
my ($self) = @_; |
120 |
return 0 if $self->item->get_transfer; # intransfer: don't advance. |
120 |
return 0 if $self->item->get_transfer; # intransfer: don't advance. |
121 |
return 1 if $self->fresh; # Just on rota: advance. |
121 |
return 1 if $self->fresh; # Just on rota: advance. |
122 |
my $completed = $self->item->_result->branchtransfers->search( |
122 |
my $completed = $self->item->_result->branchtransfers->search( |
123 |
{ 'reason' => "StockrotationAdvance" }, |
123 |
{ 'reason' => "StockrotationAdvance" }, |
124 |
{ order_by => { -desc => 'datearrived' } } |
124 |
{ order_by => { -desc => 'datearrived' } } |
125 |
); |
125 |
); |
|
|
126 |
|
126 |
# Do maths on whether we need to be moved on. |
127 |
# Do maths on whether we need to be moved on. |
127 |
if ( $completed->count ) { |
128 |
if ( $completed->count ) { |
128 |
my $arrival = dt_from_string( |
129 |
my $arrival = dt_from_string( $completed->next->datearrived ); |
129 |
$completed->next->datearrived, 'iso' |
130 |
my $duration = $arrival->delta_days( dt_from_string() ); |
130 |
); |
131 |
if ( $duration->in_units('days') >= $self->stage->duration ) { |
131 |
my $duration = DateTime::Duration |
|
|
132 |
->new( days => $self->stage->duration ); |
133 |
if ( $arrival + $duration le dt_from_string() ) { |
134 |
return 1; |
132 |
return 1; |
135 |
} else { |
133 |
} |
|
|
134 |
else { |
136 |
return 0; |
135 |
return 0; |
137 |
} |
136 |
} |
138 |
} else { |
137 |
} |
139 |
warn "We have no historical branch transfer for item " . $self->item->itemnumber . "; This should not have happened!"; |
138 |
else { |
|
|
139 |
warn "We have no historical branch transfer for item " |
140 |
. $self->item->itemnumber |
141 |
. "; This should not have happened!"; |
140 |
} |
142 |
} |
141 |
} |
143 |
} |
142 |
|
144 |
|
143 |
- |
|
|