Lines 51-60
sub new {
Link Here
|
51 |
batch_stat => 0, # False if any data has changed and the db has not been updated |
51 |
batch_stat => 0, # False if any data has changed and the db has not been updated |
52 |
@_, |
52 |
@_, |
53 |
}; |
53 |
}; |
54 |
my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;"); |
|
|
55 |
$sth->execute(); |
56 |
my $batch_id = $sth->fetchrow_array; |
57 |
$self->{'batch_id'} = ++$batch_id unless $self->{'batch_id'} != 0; # this allows batch_id to be passed in for individual label printing |
58 |
bless ($self, $type); |
54 |
bless ($self, $type); |
59 |
return $self; |
55 |
return $self; |
60 |
} |
56 |
} |
Lines 64-75
sub add_item {
Link Here
|
64 |
my $number = shift; |
60 |
my $number = shift; |
65 |
ref($self) =~ m/C4::(.+)::.+$/; |
61 |
ref($self) =~ m/C4::(.+)::.+$/; |
66 |
my $number_type = ($1 eq 'Patroncards' ? 'borrower_number' : 'item_number'); |
62 |
my $number_type = ($1 eq 'Patroncards' ? 'borrower_number' : 'item_number'); |
|
|
63 |
if ($self->{'batch_id'} == 0){ #if this is a new batch batch_id must be created |
64 |
my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;"); |
65 |
$sth->execute(); |
66 |
my $batch_id = $sth->fetchrow_array; |
67 |
$self->{'batch_id'}= ++$batch_id; |
68 |
} |
67 |
my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);"; |
69 |
my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);"; |
68 |
my $sth = C4::Context->dbh->prepare($query); |
70 |
my $sth = C4::Context->dbh->prepare($query); |
69 |
# $sth->{'TraceLevel'} = 3; |
71 |
# $sth->{'TraceLevel'} = 3; |
70 |
$sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1); |
72 |
$sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1); |
71 |
if ($sth->err) { |
73 |
if ($sth->err) { |
72 |
warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr); |
74 |
warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr); |
73 |
return -1; |
75 |
return -1; |
74 |
} |
76 |
} |
75 |
$query = "SELECT max(label_id) FROM creator_batches WHERE batch_id=? AND $number_type=? AND branch_code=?;"; |
77 |
$query = "SELECT max(label_id) FROM creator_batches WHERE batch_id=? AND $number_type=? AND branch_code=?;"; |