1 package Koha
::StockRotationStage
;
3 # Copyright PTFS Europe 2016
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use Koha
::StockRotationRota
;
26 use base
qw(Koha::Object);
30 StockRotationStage - Koha StockRotationStage Object class
34 StockRotationStage class used primarily by stockrotation .pls and the stock
39 Standard Koha::Objects definitions, and additional methods.
52 return 'Stockrotationstage';
56 my ( $self, $method, $type ) = @_;
58 my $rs = $self->_result->$method;
60 my $namespace = 'Koha::' . $type;
61 return $namespace->_new_from_dbic( $rs );
65 =head3 stockrotationitems
67 my $stages = Koha::StockRotationStage->stockrotationitems;
69 Returns the items associated with the current stage.
73 sub stockrotationitems
{
75 return &{$self->_relation(qw
/ stockrotationitems StockRotationItems /)};
80 my $branch = Koha::StockRotationStage->branchcode;
82 Returns the branch associated with the current stage.
88 return &{$self->_relation(qw
/ branchcode Library /)};
93 my $rota = Koha::StockRotationStage->rota;
95 Returns the rota associated with the current stage.
101 return &{$self->_relation(qw
/ rota StockRotationRota /)};
106 my $siblings = $stage->siblings;
108 Koha::Object wrapper around DBIx::Class::Ordered.
114 return &{$self->_relation(qw
/ siblings StockRotationStages /)};
119 my $next_siblings = $stage->next_siblings;
121 Koha::Object wrapper around DBIx::Class::Ordered.
127 return &{$self->_relation(qw
/ next_siblings StockRotationStages /)};
130 =head3 previous_siblings
132 my $previous_siblings = $stage->previous_siblings;
134 Koha::Object wrapper around DBIx::Class::Ordered.
138 sub previous_siblings
{
140 return &{$self->_relation(qw
/ previous_siblings StockRotationStages /)};
145 my $next = $stage->next_sibling;
147 Koha::Object wrapper around DBIx::Class::Ordered.
153 return &{$self->_relation(qw
/ next_sibling StockRotationStage /)};
156 =head3 previous_sibling
158 my $previous = $stage->previous_sibling;
160 Koha::Object Wrapper around DBIx::Class::Ordered.
164 sub previous_sibling
{
166 return &{$self->_relation(qw
/ previous_sibling StockRotationStage /)};
171 my $first = $stage->first_sibling;
173 Koha::Object Wrapper around DBIx::Class::Ordered.
179 return &{$self->_relation(qw
/ first_sibling StockRotationStage /)};
184 my $last = $stage->last_sibling;
186 Koha::Object Wrapper around DBIx::Class::Ordered.
192 return &{$self->_relation(qw
/ last_sibling StockRotationStage /)};
197 1|0 = $stage->move_previous;
199 Koha::Object Wrapper around DBIx::Class::Ordered.
205 return $self->_result->move_previous;
210 1|0 = $stage->move_next;
212 Koha::Object Wrapper around DBIx::Class::Ordered.
218 return $self->_result->move_next;
223 1|0 = $stage->move_first;
225 Koha::Object Wrapper around DBIx::Class::Ordered.
231 return $self->_result->move_first;
236 1|0 = $stage->move_last;
238 Koha::Object Wrapper around DBIx::Class::Ordered.
244 return $self->_result->move_last;
249 1|0 = $stage->move_to($position);
251 Koha::Object Wrapper around DBIx::Class::Ordered.
256 my ( $self, $position ) = @_;
257 return $self->_result->move_to($position)
258 if ( $position le $self->rota->stockrotationstages->count );
264 1|0 = $stage->move_to_group($rota_id, [$position]);
266 Koha::Object Wrapper around DBIx::Class::Ordered.
271 my ( $self, $rota_id, $position ) = @_;
272 return $self->_result->move_to_group($rota_id, $position);
277 1|0 = $stage->delete;
279 Koha::Object Wrapper around DBIx::Class::Ordered.
285 return $self->_result->delete;
290 my $report = $stage->investigate($report_so_far);
292 Return a stage based report. This report will mutate and augment the report
293 that is passed to it. It slots item reports into the branched and temporary
294 rota sections of the report. It also increments a number of counters.
296 For details of intent and context of this procedure, please see
297 Koha::StockRotationRota->investigate.
302 my ( $self, $report ) = @_;
303 my $new_stage = $self->next_sibling;
304 my $duration = $self->duration;
305 # Generate stage items report
306 my $items_report = $self->stockrotationitems->investigate;
308 # Merge into general report
311 ### The branched indexes work as follows:
312 ### - They contain information about the relevant branch
313 ### - They contain an index of actionable items for that branch
314 ### - They contain an index of non-actionable items for that branch
316 ### Items are assigned to a particular branched index as follows:
317 ### - 'advanceable' : assigned to branch of the current stage
318 ### (this should also be the current holding branch)
319 ### - 'log' items are always assigned to branch of current stage.
320 ### - 'indemand' : assigned to branch of current stage
321 ### (this should also be the current holding branch)
322 ### - 'initiable' : assigned to the current holding branch of item
323 ### - 'repatriable' : assigned to the current holding branch of item
325 ### 'Advanceable', 'log', 'indemand':
327 # Set up our stage branch info.
328 my $stagebranch = $self->_result->branchcode;
329 my $stagebranchcode = $stagebranch->branchcode;
331 # Initiate our stage branch index if it does not yet exist.
332 if ( !$report->{branched
}->{$stagebranchcode} ) {
333 $report->{branched
}->{$stagebranchcode} = {
334 code
=> $stagebranchcode,
335 name
=> $stagebranch->branchname,
336 email
=> $stagebranch->branchreplyto
337 ?
$stagebranch->branchreplyto
338 : $stagebranch->branchemail,
339 phone
=> $stagebranch->branchphone,
345 push @
{$report->{branched
}->{$stagebranchcode}->{items
}},
346 @
{$items_report->{advanceable_items
}};
347 push @
{$report->{branched
}->{$stagebranchcode}->{log}},
348 @
{$items_report->{log}};
349 push @
{$report->{branched
}->{$stagebranchcode}->{items
}},
350 @
{$items_report->{indemand_items
}};
352 ### 'Initiable' & 'Repatriable'
353 foreach my $ireport (@
{$items_report->{initiable_items
}}) {
354 my $branch = $ireport->{branch
};
355 my $branchcode = $branch->branchcode;
356 if ( !$report->{branched
}->{$branchcode} ) {
357 $report->{branched
}->{$branchcode} = {
359 name
=> $branch->branchname,
360 email
=> $stagebranch->branchreplyto
361 ?
$stagebranch->branchreplyto
362 : $stagebranch->branchemail,
363 phone
=> $branch->branchphone,
368 push @
{$report->{branched
}->{$branchcode}->{items
}}, $ireport;
371 foreach my $ireport (@
{$items_report->{repatriable_items
}}) {
372 my $branch = $ireport->{branch
};
373 my $branchcode = $branch->branchcode;
374 if ( !$report->{branched
}->{$branchcode} ) {
375 $report->{branched
}->{$branchcode} = {
377 name
=> $branch->branchname,
378 email
=> $stagebranch->branchreplyto
379 ?
$stagebranch->branchreplyto
380 : $stagebranch->branchemail,
381 phone
=> $branch->branchphone,
386 push @
{$report->{branched
}->{$branchcode}->{items
}}, $ireport;
390 ### Per rota indexes are item reports pushed into the index for the
391 ### current rota. We don't know where that index is yet as we don't know
392 ### about the current rota. To resolve this we assign our items and log
393 ### to tmp indexes. They will be merged into the proper rota index at the
395 push @
{$report->{tmp_items
}}, @
{$items_report->{items
}};
396 push @
{$report->{tmp_log
}}, @
{$items_report->{log}};
398 ## Collection of items
399 ### Finally we just add our collection of items to the full item index.
400 push @
{$report->{items
}}, @
{$items_report->{items
}};
403 $report->{actionable
} += $items_report->{actionable
};
404 $report->{indemand
} += scalar @
{$items_report->{indemand_items
}};
405 $report->{advanceable
} += scalar @
{$items_report->{advanceable_items
}};
406 $report->{initiable
} += scalar @
{$items_report->{initiable_items
}};
407 $report->{repatriable
} += scalar @
{$items_report->{repatriable_items
}};
408 $report->{stationary
} += scalar @
{$items_report->{log}};
417 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>