Koha/svc/cataloguing/control_num_sequences
Jesse Weaver 36d46cf997 Bug 19263: Rancor - Add auto-001 widget
To test:

1 - Define a new authorised valued category "CONTROL_NUM_SEQUENCE"
2 - Add a value/sequence
    The authorised_value is the starting value - shoudl end in a number
    that can be incremented e.g. "control_sequence_001"
    The description field is the name for the seqeuence
    Opac description is unused
3 - Edit a record in rancor
4 - Note the new widget and option to increment or assign manually

Signed-off-by: Claire Gravely <claire.gravely@bsz-bw.de>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2018-10-27 13:26:08 +00:00

59 lines
1.7 KiB
Perl
Executable file

#!/usr/bin/perl
#
# Copyright 2015 ByWater Solutions
#
# 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 C4::Service;
use Koha::Database;
use MARC::Record;
our ( $query, $response ) = C4::Service->init( editcatalogue => 'edit_catalogue' );
sub get_and_increment {
my ( $control_num_sequence ) = @_;
my $schema = Koha::Database->new->schema();
my $authval = $schema->resultset( 'AuthorisedValue' )->find(
{
category => 'CONTROL_NUM_SEQUENCE',
lib => $control_num_sequence
}
);
if ( !$authval ) {
C4::Service->return_error( 'not_found' );
}
my $value = $authval->authorised_value;
$response->param( next_value => $value );
my ( $prefix, $num ) = ( $value =~ /(.+?)(\d+)$/ );
$value = $prefix . sprintf( '%0*d', length( $num ), $num + 1 );
$authval->authorised_value( $value );
$authval->update();
C4::Service->return_success( $response );
}
C4::Service->dispatch(
[ 'POST /(.*)', [], \&get_and_increment ],
);