Bug 24545: Fix license statements
[srvgit] / C4 / Creators / Batch.pm
index 9306263..c579237 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
     }
@@ -199,7 +201,11 @@ sub remove_duplicates {
     my %seen=();
     my $query = "DELETE FROM creator_batches WHERE label_id = ?;"; # ORDER BY timestamp ASC LIMIT ?;";
     my $sth = C4::Context->dbh->prepare($query);
-    my @duplicate_items = grep{$seen{$_->{'item_number'}}++} @{$self->{'items'}};
+    my @duplicate_items = grep{
+        $_->{'item_number'}
+            ? $seen{$_->{'item_number'}}++
+            : $seen{$_->{'borrower_number'}}++
+    } @{$self->{'items'}};
     foreach my $item (@duplicate_items) {
         $sth->execute($item->{'label_id'});
         if ($sth->err) {
@@ -302,11 +308,18 @@ Copyright 2009 Foundations Bible College.
 
 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 2 of the License, or (at your option) any later version.
+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.
+You should have received a copy of the GNU General Public License
+along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 DISCLAIMER OF WARRANTY