Bug 22878: Do not pass layout_id on creating a layout
[koha-ffzg.git] / C4 / Creators / Batch.pm
index 28beeb7..9b9a0f2 100644 (file)
@@ -8,9 +8,6 @@ use autouse 'Data::Dumper' => qw(Dumper);
 use C4::Context;
 use C4::Debug;
 
-BEGIN {
-    use version; our $VERSION = qv('3.07.00.049');
-}
 
 sub _check_params {
     my $given_params = {};
@@ -18,6 +15,7 @@ sub _check_params {
     my @valid_template_params = (
         'label_id',
         'batch_id',
+        'description',
         'item_number',
         'card_number',
         'branch_code',
@@ -46,15 +44,12 @@ sub new {
     my $type = ref($invocant) || $invocant;
     my $self = {
         batch_id        => 0,
+        description     => '',
         items           => [],
         branch_code     => 'NB',
         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 +59,18 @@ sub add_item {
     my $number = shift;
     ref($self) =~ m/C4::(.+)::.+$/;
     my $number_type = ($1 eq 'Patroncards' ? 'borrower_number' : 'item_number');
-    my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);";
+    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, description, $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);
+    $sth->execute($self->{'batch_id'}, $self->{'description'}, $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=?;";
@@ -103,8 +104,8 @@ sub remove_item {
 }
 
 # FIXME: This method is effectively useless the way the current add_item method is written. Ideally, the items should be added to the object
-#       and then the save method called. This does not work well in practice due to the inability to pass objects accross cgi script calls.
-#       I'm leaving it here because it should be here and for consistency's sake and once memcached support is fully implimented this should be as well. -cnighswonger
+#       and then the save method called. This does not work well in practice due to the inability to pass objects across cgi script calls.
+#       I'm leaving it here because it should be here and for consistency's sake and once memcached support is fully implemented this should be as well. -cnighswonger
 #
 #=head2 $batch->save()
 #
@@ -150,6 +151,7 @@ sub retrieve {
     while (my $record = $sth->fetchrow_hashref) {
         $self->{'branch_code'} = $record->{'branch_code'};
         $self->{'creator'} = $record->{'creator'};
+        $self->{'description'} = $record->{'description'};
         push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
         $record_flag = 1;       # true if one or more rows were retrieved
     }