1 package Koha::StockRotationRota;
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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Koha::StockRotationStages;
24 use Koha::StockRotationItem;
25 use Koha::StockRotationItems;
27 use base qw(Koha::Object);
31 StockRotationRota - Koha StockRotationRota Object class
35 StockRotationRota class used primarily by stockrotation .pls and the stock
40 Standard Koha::Objects definitions, and additional methods.
48 =head3 stockrotationstages
50 my $stages = Koha::StockRotationRota->stockrotationstages;
52 Returns the stages associated with the current rota.
56 sub stockrotationstages {
58 my $rs = $self->_result->stockrotationstages;
59 return Koha::StockRotationStages->_new_from_dbic( $rs );
64 my $rota = $rota->add_item($itemnumber);
66 Add item identified by $ITEMNUMBER to this rota, which means we associate it
67 with the first stage of this rota. Should the item already be associated with
68 a rota, move it from that rota to this rota.
73 my ( $self, $itemnumber ) = @_;
74 my $sritem = Koha::StockRotationItems->find($itemnumber);
76 $sritem->stage_id($self->first_stage->stage_id)
77 ->indemand(0)->fresh(1)->store;
79 $sritem = Koha::StockRotationItem->new({
80 itemnumber_id => $itemnumber,
81 stage_id => $self->first_stage->stage_id,
91 my $stage = $rota->first_stage;
93 Return the first stage attached to this rota (the one that has an undefined
100 my $guess = $self->stockrotationstages->next;
101 my $stage = $guess->first_sibling;
102 return ( $stage ) ? $stage : $guess;
105 =head3 stockrotationitems
107 my $items = $rota->stockrotationitems;
109 Return all items associated with this rota via its stages.
113 sub stockrotationitems {
115 my $rs = Koha::StockRotationItems->search(
116 { 'stage.rota_id' => $self->rota_id }, { join => [ qw/stage/ ] }
123 my $report = $rota->investigate($report_so_far);
125 Aim here is to return $report augmented with content for this rota. We
126 delegate to $stage->investigate.
128 The report will include some basic information and 2 primary reports:
130 - per rota report in 'rotas'. This report is mainly used by admins to do check
133 - branched report in 'branched'. This is the workhorse: emails to libraries
134 are compiled from these reports, and they will have the actionable work.
136 Both reports are generated in stage based investigations; the rota report is
137 then glued into place at this stage.
142 my ( $self, $report ) = @_;
143 my $count = $self->stockrotationitems->count;
144 $report->{sum_items} += $count;
146 if ( $self->active ) {
147 $report->{rotas_active}++;
148 # stockrotationstages->investigate augments $report with the stage's
149 # content. This is how 'branched' slowly accumulates all items.
150 $report = $self->stockrotationstages->investigate($report);
151 # Add our rota report to the full report.
152 push @{$report->{rotas}}, {
153 name => $self->title,
154 id => $self->rota_id,
155 items => $report->{tmp_items} || [],
156 log => $report->{tmp_log} || [],
158 delete $report->{tmp_items};
159 delete $report->{tmp_log};
160 } else { # Rota is not active.
161 $report->{rotas_inactive}++;
162 $report->{items_inactive} += $count;
173 return 'Stockrotationrota';
180 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>