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 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.
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>