Bug 21637: Fixed upercase letter in EasyAnalyticalRecords syspref
[koha.git] / Koha / StockRotationRota.pm
blobfdf52fccd94ae9a308164b7a163c12573bbc9d60
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
10 # version.
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.
20 use Modern::Perl;
22 use Koha::Database;
23 use Koha::StockRotationStages;
24 use Koha::StockRotationItem;
25 use Koha::StockRotationItems;
27 use base qw(Koha::Object);
29 =head1 NAME
31 StockRotationRota - Koha StockRotationRota Object class
33 =head1 SYNOPSIS
35 StockRotationRota class used primarily by stockrotation .pls and the stock
36 rotation cron script.
38 =head1 DESCRIPTION
40 Standard Koha::Objects definitions, and additional methods.
42 =head1 API
44 =head2 Class Methods
46 =cut
48 =head3 stockrotationstages
50 my $stages = Koha::StockRotationRota->stockrotationstages;
52 Returns the stages associated with the current rota.
54 =cut
56 sub stockrotationstages {
57 my ( $self ) = @_;
58 my $rs = $self->_result->stockrotationstages;
59 return Koha::StockRotationStages->_new_from_dbic( $rs );
62 =head3 add_item
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.
70 =cut
72 sub add_item {
73 my ( $self, $itemnumber ) = @_;
74 my $sritem = Koha::StockRotationItems->find($itemnumber);
75 if ($sritem) {
76 $sritem->stage_id($self->first_stage->stage_id)
77 ->indemand(0)->fresh(1)->store;
78 } else {
79 $sritem = Koha::StockRotationItem->new({
80 itemnumber_id => $itemnumber,
81 stage_id => $self->first_stage->stage_id,
82 indemand => 0,
83 fresh => 1,
84 })->store;
86 return $self;
89 =head3 first_stage
91 my $stage = $rota->first_stage;
93 Return the first stage attached to this rota (the one that has an undefined
94 `stagebefore`).
96 =cut
98 sub first_stage {
99 my ( $self ) = @_;
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.
111 =cut
113 sub stockrotationitems {
114 my ( $self ) = @_;
115 my $rs = Koha::StockRotationItems->search(
116 { 'stage.rota_id' => $self->rota_id }, { join => [ qw/stage/ ] }
118 return $rs;
121 =head3 investigate
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
131 & compare results.
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.
139 =cut
141 sub investigate {
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;
165 return $report;
168 =head3 _type
170 =cut
172 sub _type {
173 return 'Stockrotationrota';
178 =head1 AUTHOR
180 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
182 =cut