@@ -, +, @@ be asssigned to several batches --- C4/Creators/Batch.pm | 12 +++++++----- .../prog/en/modules/labels/label-edit-batch.tt | 2 +- labels/label-edit-batch.pl | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) --- a/C4/Creators/Batch.pm +++ a/C4/Creators/Batch.pm @@ -51,10 +51,6 @@ sub new { batch_stat => 0, # False if any data has changed and the db has not been updated @_, }; - my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;"); - $sth->execute(); - my $batch_id = $sth->fetchrow_array; - $self->{'batch_id'} = ++$batch_id unless $self->{'batch_id'} != 0; # this allows batch_id to be passed in for individual label printing bless ($self, $type); return $self; } @@ -64,12 +60,18 @@ sub add_item { my $number = shift; ref($self) =~ m/C4::(.+)::.+$/; my $number_type = ($1 eq 'Patroncards' ? 'borrower_number' : 'item_number'); + if ($self->{'batch_id'} == 0){ #if this is a new batch batch_id must be created + my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;"); + $sth->execute(); + my $batch_id = $sth->fetchrow_array; + $self->{'batch_id'}= ++$batch_id; + } my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);"; my $sth = C4::Context->dbh->prepare($query); # $sth->{'TraceLevel'} = 3; $sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1); if ($sth->err) { - warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr); + warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr); return -1; } $query = "SELECT max(label_id) FROM creator_batches WHERE batch_id=? AND $number_type=? AND branch_code=?;"; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt @@ -262,7 +262,7 @@
  1. -

    There are no items in Batch [% batch_id %] yet

    +

    There are no items in this batch yet

    Add items by barcode using the text area above or leave empty to add via item search.

--- a/labels/label-edit-batch.pl +++ a/labels/label-edit-batch.pl @@ -95,6 +95,7 @@ elsif ($op eq 'add') { foreach my $item_number (@item_numbers) { $err = $batch->add_item($item_number); } + $batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch $errstr = "item(s) not added to batch $batch_id." if $err; } else { --