1 package Koha::IllbatchStatus;
3 # Copyright PTFS Europe 2022
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>.
22 use Koha::Illrequest::Logger;
24 use JSON qw( to_json );
25 use base qw(Koha::Object);
29 Koha::IllbatchStatus - Koha IllbatchStatus Object class
35 $status->create_and_log;
37 Log batch status creation following storage
44 # Ensure code is uppercase and contains only word characters
45 my $fixed_code = uc $self->code;
46 $fixed_code =~ s/\W/_/;
48 # Ensure this status doesn't already exist
49 my $status = Koha::IllbatchStatuses->find({ code => $fixed_code });
52 error => "Duplicate status found"
56 # Ensure system statuses can't be created
62 my $logger = Koha::Illrequest::Logger->new;
64 $logger->log_something({
66 actionname => 'batch_status_create',
67 objectnumber => $self->id,
74 $status->update_and_log;
76 Log batch status update following storage
81 my ( $self, $params ) = @_;
87 # Ensure only the name can be changed
89 name => $params->{name}
91 my $update = $self->store;
97 my $logger = Koha::Illrequest::Logger->new;
99 $logger->log_something({
101 actionname => 'batch_status_update',
102 objectnumber => $self->id,
110 =head3 delete_and_log
112 $batch->delete_and_log;
114 Log batch status delete
121 # Don't permit deletion of system statuses
122 if ($self->is_system) {
126 # Update all batches that use this status to have status UNKNOWN
127 my $affected = Koha::Illbatches->search({ statuscode => $self->code });
128 $affected->update({ statuscode => 'UNKNOWN'});
130 my $logger = Koha::Illrequest::Logger->new;
132 $logger->log_something({
134 actionname => 'batch_status_delete',
135 objectnumber => $self->id,
142 =head2 Internal methods
146 my $type = Koha::IllbatchStatus->_type;
148 Return this object's type
153 return 'IllbatchStatus';
158 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>