Lines 150-166
that it may return to it's stage.branch to continue its rota as normal.
Link Here
|
150 |
|
150 |
|
151 |
sub repatriate { |
151 |
sub repatriate { |
152 |
my ( $self, $msg ) = @_; |
152 |
my ( $self, $msg ) = @_; |
|
|
153 |
|
153 |
# Create the transfer. |
154 |
# Create the transfer. |
154 |
my $transfer_stored = Koha::Item::Transfer->new({ |
155 |
my $transfer = $self->itemnumber->request_transfer( |
155 |
'itemnumber' => $self->itemnumber_id, |
156 |
{ |
156 |
'frombranch' => $self->itemnumber->holdingbranch, |
157 |
to => $self->stage->branchcode, |
157 |
'tobranch' => $self->stage->branchcode_id, |
158 |
reason => "StockrotationRepatriation", |
158 |
'datesent' => dt_from_string(), |
159 |
comment => $msg |
159 |
'comments' => $msg, |
160 |
} |
160 |
'reason' => "StockrotationRepatriation" |
161 |
); |
161 |
})->store; |
162 |
|
162 |
$self->itemnumber->homebranch($self->stage->branchcode_id)->store; |
163 |
# Ensure the homebranch is still in sync with the rota stage |
163 |
return $transfer_stored; |
164 |
$self->itemnumber->homebranch( $self->stage->branchcode_id )->store; |
|
|
165 |
|
166 |
return $transfer; |
164 |
} |
167 |
} |
165 |
|
168 |
|
166 |
=head3 advance |
169 |
=head3 advance |
Lines 180-228
advance the item as per usual.
Link Here
|
180 |
=cut |
183 |
=cut |
181 |
|
184 |
|
182 |
sub advance { |
185 |
sub advance { |
183 |
my ( $self ) = @_; |
186 |
my ($self) = @_; |
184 |
my $item = $self->itemnumber; |
187 |
my $item = $self->itemnumber; |
185 |
my $transfer = Koha::Item::Transfer->new({ |
188 |
my $current_branch = $item->holdingbranch; |
186 |
'itemnumber' => $self->itemnumber_id, |
189 |
my $transfer; |
187 |
'frombranch' => $item->holdingbranch, |
190 |
|
188 |
'datesent' => dt_from_string(), |
191 |
# Find and interpret our stage |
189 |
'reason' => "StockrotationAdvance" |
192 |
my $stage = $self->stage; |
190 |
}); |
193 |
my $new_stage; |
191 |
|
|
|
192 |
if ( $self->indemand && !$self->fresh ) { |
194 |
if ( $self->indemand && !$self->fresh ) { |
193 |
$self->indemand(0)->store; # De-activate indemand |
195 |
$self->indemand(0)->store; # De-activate indemand |
194 |
$transfer->tobranch($self->stage->branchcode_id); |
196 |
$new_stage = $stage; |
195 |
$transfer->datearrived(dt_from_string()); |
197 |
} |
196 |
} else { |
198 |
else { |
197 |
# Find and update our stage. |
199 |
# New to rota? |
198 |
my $stage = $self->stage; |
200 |
if ( $self->fresh ) { |
199 |
my $new_stage; |
|
|
200 |
if ( $self->fresh ) { # Just added to rota |
201 |
$new_stage = $self->stage->first_sibling || $self->stage; |
201 |
$new_stage = $self->stage->first_sibling || $self->stage; |
202 |
$transfer->tobranch($new_stage->branchcode_id); |
202 |
$self->fresh(0)->store; # Reset fresh |
203 |
$transfer->datearrived(dt_from_string()) # Already at first branch |
203 |
} |
204 |
if $item->holdingbranch eq $new_stage->branchcode_id; |
204 |
# Last stage? |
205 |
$self->fresh(0)->store; # Reset fresh |
205 |
elsif ( !$stage->last_sibling ) { |
206 |
} elsif ( !$stage->last_sibling ) { # Last stage |
206 |
# Cyclical rota? |
207 |
if ( $stage->rota->cyclical ) { # Cyclical rota? |
207 |
if ( $stage->rota->cyclical ) { |
208 |
# Revert to first stage. |
208 |
$new_stage = |
209 |
$new_stage = $stage->first_sibling || $stage; |
209 |
$stage->first_sibling || $stage; # Revert to first stage. |
210 |
$transfer->tobranch($new_stage->branchcode_id); |
210 |
} |
211 |
$transfer->datearrived(dt_from_string()); |
211 |
else { |
212 |
} else { |
212 |
$self->delete; # StockRotationItem is done. |
213 |
$self->delete; # StockRotationItem is done. |
|
|
214 |
return 1; |
213 |
return 1; |
215 |
} |
214 |
} |
216 |
} else { |
|
|
217 |
# Just advance. |
218 |
$new_stage = $self->stage->next_sibling; |
219 |
} |
215 |
} |
220 |
$self->stage_id($new_stage->stage_id)->store; # Set new stage |
216 |
else { |
221 |
$item->homebranch($new_stage->branchcode_id)->store; # Update homebranch |
217 |
$new_stage = $self->stage->next_sibling; # Just advance |
222 |
$transfer->tobranch($new_stage->branchcode_id); # Send to new branch |
218 |
} |
223 |
} |
219 |
} |
224 |
|
220 |
|
225 |
return $transfer->store; |
221 |
# Update stage and record transfer |
|
|
222 |
$self->stage_id( $new_stage->stage_id )->store; # Set new stage |
223 |
$item->homebranch( $new_stage->branchcode_id )->store; # Update homebranch |
224 |
$transfer = $item->request_transfer( |
225 |
{ |
226 |
to => $new_stage->branchcode, |
227 |
reason => "StockrotationAdvance", |
228 |
ignore_limits => 1 |
229 |
} |
230 |
); # Add transfer |
231 |
$transfer->receive |
232 |
if $item->holdingbranch eq $new_stage->branchcode_id; # Already at branch |
233 |
|
234 |
return $transfer; |
226 |
} |
235 |
} |
227 |
|
236 |
|
228 |
=head3 investigate |
237 |
=head3 investigate |
229 |
- |
|
|