From 73dde5c10d12b40e6f1fe20c53de6ebc2966279d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sat, 7 Feb 2015 12:49:29 -0500 Subject: [PATCH] Bug 12911 - batch_id for new labels batches can be asssigned to several batches Currently batch_id is assigned upon creation of a new batch object. This patch leaves batch_id as 0 at creation and adds a check when adding items. If batch is new then batch_id is created then Test plan: 1 -In one browser window, go to tools->label creator and click the new batch button 2 - Before adding items, open a new browser, and go tools->label creator and click the new batch button 3 - Note that both batches have the same number listed 4 - Add an item to the first batch - you should now see one item in the batch 5 - Add an item to the second batch, you should see two items in the batch 6 - Apply patch and repeat steps 1&2 7 - Note that neither batch lists a batch number 8 - Add an item to the first batch, you should see one item and a batch number 9 - Add an item to the second batch, you should see one item and a new batch number --- 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(-) diff --git a/C4/Creators/Batch.pm b/C4/Creators/Batch.pm index 28beeb7..13fc436 100644 --- a/C4/Creators/Batch.pm +++ b/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=?;"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt index f9f7b55..6832d56 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt +++ b/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.

diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index 60d7b43..9c009e2 100755 --- a/labels/label-edit-batch.pl +++ b/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 { -- 1.7.10.4