Bugzilla – Attachment 61830 Details for
Bug 11897
Stock Rotation for Koha
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11897: Add Utils library for Stockrotation module
Bug-11897-Add-Utils-library-for-Stockrotation-modu.patch (text/plain), 5.80 KB, created by
Alex Sassmannshausen
on 2017-04-04 13:50:41 UTC
(
hide
)
Description:
Bug 11897: Add Utils library for Stockrotation module
Filename:
MIME Type:
Creator:
Alex Sassmannshausen
Created:
2017-04-04 13:50:41 UTC
Size:
5.80 KB
patch
obsolete
>From 28f35da25a5d2db12e7ec0e783fda62e4a22041b Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 13 Dec 2016 15:57:43 +0000 >Subject: [PATCH] Bug 11897: Add Utils library for Stockrotation module > >* Koha/Util/Stockrotation.pm: new file >--- > Koha/Util/Stockrotation.pm | 247 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 247 insertions(+) > create mode 100644 Koha/Util/Stockrotation.pm > >diff --git a/Koha/Util/Stockrotation.pm b/Koha/Util/Stockrotation.pm >new file mode 100644 >index 0000000000..481e45af5e >--- /dev/null >+++ b/Koha/Util/Stockrotation.pm >@@ -0,0 +1,247 @@ >+package Koha::Util::Stockrotation; >+ >+# Module contains subroutines used with Stock Rotation >+# >+# Copyright 2016 PTFS-Europe Ltd >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Items; >+use Koha::Stockrotationitems; >+use Koha::Database; >+ >+our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); >+BEGIN { >+ require Exporter; >+ @ISA = qw( Exporter ); >+ @EXPORT = qw( ); >+ @EXPORT_OK = qw( >+ get_branches >+ get_stages >+ toggle_indemand >+ remove_from_stage >+ get_barcodes_status >+ add_items_to_rota >+ move_to_next_stage >+ ); >+ %EXPORT_TAGS = ( ALL => [ @EXPORT_OK, @EXPORT ] ); >+} >+ >+=head1 NAME >+ >+Koha::Util::Stockrotation - utility class with routines for Stock Rotation >+ >+=head1 FUNCTIONS >+ >+=head2 get_branches >+ >+ returns all branches ordered by branchname as an array, each element >+ contains a hashref containing branch details >+ >+=cut >+ >+sub get_branches { >+ >+ return Koha::Libraries->search( >+ {}, >+ { order_by => ['branchname'] } >+ )->unblessed; >+ >+} >+ >+=head2 get_stages >+ >+ returns an arrayref of Stockrotationstage objects representing >+ all stages for a passed rota >+ >+=cut >+ >+sub get_stages { >+ >+ my $rota = shift; >+ >+ my @out = (); >+ >+ if ($rota->stockrotationstages->count > 0) { >+ >+ push @out, $rota->first_stage->unblessed; >+ >+ push @out, @{$rota->first_stage->siblings->unblessed}; >+ >+ } >+ >+ return \@out; >+} >+ >+=head2 toggle_indemand >+ >+ given an item's ID & stage ID toggle that item's in_demand >+ status on that stage >+ >+=cut >+ >+sub toggle_indemand { >+ >+ my ($item_id, $stage_id) = @_; >+ >+ # Get the item object >+ my $item = Koha::Stockrotationitems->find( >+ { >+ itemnumber_id => $item_id, >+ stage_id => $stage_id >+ } >+ ); >+ >+ # Toggle the item's indemand flag >+ my $new_indemand = ($item->indemand == 1) ? 0 : 1; >+ >+ $item->indemand($new_indemand)->store; >+ >+} >+ >+=head2 move_to_next_stage >+ >+ given an item's ID and stage ID, move it >+ to the next stage on the rota >+ >+=cut >+ >+sub move_to_next_stage { >+ >+ my ($item_id, $stage_id) = shift; >+ >+ # Get the item object >+ my $item = Koha::Stockrotationitems->find( >+ { >+ itemnumber_id => $item_id, >+ stage_id => $stage_id >+ } >+ ); >+ >+ $item->advance; >+ >+} >+ >+=head2 remove_from_stage >+ >+ given an item's ID & stage ID, remove that item from that stage >+ >+=cut >+ >+sub remove_from_stage { >+ >+ my ($item_id, $stage_id) = @_; >+ >+ # Get the item object and delete it >+ Koha::Stockrotationitems->find( >+ { >+ itemnumber_id => $item_id, >+ stage_id => $stage_id >+ } >+ )->delete; >+ >+} >+ >+=head2 get_barcodes_status >+ >+ take an arrayref of barcodes and a status hashref and populate it >+ >+=cut >+ >+sub get_barcodes_status { >+ >+ my ($rota_id, $barcodes, $status) = @_; >+ >+ # Get the items associated with these barcodes >+ my $items = Koha::Items->search( >+ { >+ barcode => { '-in' => $barcodes } >+ }, >+ { >+ prefetch => 'stockrotationitem' >+ } >+ ); >+ # Get an array of barcodes that were found >+ # Assign each barcode's status >+ my @found = (); >+ while (my $item = $items->next) { >+ >+ push @found, $item->barcode if $item->barcode; >+ >+ # Check if it's on a rota >+ my $on_rota = $item->stockrotationitem; >+ >+ # It is on a rota >+ if ($on_rota) { >+ >+ # Check if it's on this rota >+ if ($on_rota->stage->rota->rota_id == $rota_id) { >+ >+ # It's on this rota >+ push @{$status->{on_this}}, $item; >+ >+ } else { >+ >+ # It's on another rota >+ push @{$status->{on_other}}, $item; >+ >+ } >+ >+ } else { >+ >+ # Item is not on a rota >+ push @{$status->{ok}}, $item; >+ >+ } >+ >+ } >+ >+ # Create an array of barcodes supplied in the file that >+ # were not found in the catalogue >+ my %found_in_cat = map{ $_ => 1 } @found; >+ push @{$status->{not_found}}, grep( >+ !defined $found_in_cat{$_}, @{$barcodes} >+ ); >+ >+} >+ >+=head2 add_items_to_rota >+ >+ take an arrayref of Koha::Item objects and add them to the passed rota >+ >+=cut >+ >+sub add_items_to_rota { >+ >+ my ($rota_id, $items) = @_; >+ >+ foreach my $item(@{$items}) { >+ >+ $item->add_to_rota($rota_id); >+ >+ } >+ >+} >+ >+1; >+ >+=head1 AUTHOR >+ >+Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >+ >+=cut >-- >2.11.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11897
:
25887
|
58207
|
58208
|
58209
|
58210
|
58211
|
58212
|
58213
|
58214
|
58215
|
58216
|
58217
|
58218
|
58219
|
58280
|
58281
|
58687
|
58692
|
58693
|
58694
|
58695
|
58696
|
60175
|
60715
|
61825
|
61826
|
61827
|
61828
|
61829
|
61830
|
61831
|
61832
|
61833
|
61834
|
61835
|
61836
|
61837
|
61838
|
61839
|
61885
|
62730
|
62750
|
62751
|
62752
|
62753
|
62754
|
62755
|
62756
|
62757
|
62758
|
62759
|
62760
|
62761
|
62762
|
62763
|
62764
|
62765
|
62766
|
62767
|
63063
|
63064
|
63065
|
63066
|
63067
|
63068
|
63069
|
63070
|
63071
|
63072
|
63073
|
63074
|
63075
|
63076
|
63077
|
63078
|
63079
|
63080
|
63114
|
64850
|
64851
|
65715
|
65716
|
65717
|
65718
|
65719
|
65720
|
65721
|
65722
|
65723
|
65724
|
65725
|
65726
|
65727
|
65728
|
65729
|
65730
|
65731
|
65732
|
65733
|
65734
|
65735
|
65736
|
65737
|
65738
|
65739
|
65740
|
65741
|
65742
|
65743
|
65744
|
65745
|
65746
|
65747
|
65748
|
65749
|
65750
|
65751
|
65752
|
65753
|
65754
|
65755
|
65756
|
65757
|
65758
|
66381
|
70496
|
70497
|
70498
|
70499
|
70500
|
70501
|
70502
|
70503
|
70504
|
70505
|
70506
|
70507
|
70508
|
70509
|
70510
|
70511
|
70512
|
70513
|
70514
|
70515
|
70516
|
70517
|
70518
|
70519
|
70520
|
70521
|
70522
|
70523
|
70524
|
72124
|
72125
|
72126
|
72127
|
72128
|
74003
|
74004
|
74005
|
74006
|
74007
|
74008
|
74010
|
74011
|
74012
|
74013
|
74014
|
74015
|
74016
|
74017
|
74197
|
74198
|
74199
|
74200
|
74201
|
74202
|
74203
|
74204
|
74205
|
74206
|
74319
|
74320
|
74360
|
74459
|
74460
|
74461
|
74462
|
74463
|
74464
|
74465
|
74466
|
74467
|
74468
|
74469
|
74470
|
75409
|
75410
|
75411
|
75412
|
75413
|
75414
|
75415
|
75416
|
75417
|
75418
|
75419
|
75420
|
76121
|
76122
|
76123
|
76124
|
76125
|
76126
|
76127
|
76128
|
76129
|
76130
|
76131
|
76132
|
76133
|
76134
|
76135
|
76144
|
76706
|
76707
|
76708
|
76709
|
76710
|
77623
|
77624
|
77625
|
77626
|
78387
|
78388
|
78389
|
78390
|
78391
|
78392
|
78393
|
78394
|
78404
|
78405
|
78406
|
78407
|
78408
|
79040
|
79041
|
79042
|
79043
|
79044
|
79738
|
79739
|
79740
|
79741
|
79742
|
79746
|
79747
|
79748
|
79749
|
79750
|
79964
|
79965
|
79966
|
79967
|
79968
|
79969
|
79970
|
79971
|
79972
|
79973
|
79974
|
79975
|
80068
|
80087
|
80088
|
80089
|
80090
|
80091
|
80092
|
80093
|
80094
|
80095
|
80096
|
80097
|
80098
|
80099
|
80100
|
80118
|
80260
|
80261
|
80262
|
80263
|
80264
|
80265
|
80266
|
80267
|
80268
|
80269
|
80270
|
80271
|
80272
|
80273
|
80274
|
80275
|
80289
|
80298
|
80299
|
80300