View | Details | Raw Unified | Return to bug 6679
Collapse All | Expand All

(-)a/C4/Barcodes.pm (-14 / +13 lines)
Lines 56-76 sub initial { Link Here
56
sub width {
56
sub width {
57
	return undef;
57
	return undef;
58
}
58
}
59
sub process_head($$;$$) {	# (self,head,whole,specific)
59
sub process_head {	# (self,head,whole,specific)
60
	my $self = shift;
60
	my $self = shift;
61
	return shift;			# Default: just return the head unchanged.
61
	return shift;			# Default: just return the head unchanged.
62
}
62
}
63
sub process_tail($$;$$) {	# (self,tail,whole,specific)
63
sub process_tail {	# (self,tail,whole,specific)
64
	my $self = shift;
64
	my $self = shift;
65
	return shift;			# Default: just return the tail unchanged.
65
	return shift;			# Default: just return the tail unchanged.
66
}
66
}
67
sub is_max ($;$) {
67
sub is_max {
68
	my $self = shift;
68
	my $self = shift;
69
	ref($self) or carp "Called is_max on a non-object: '$self'";
69
	ref($self) or carp "Called is_max on a non-object: '$self'";
70
	(@_) and $self->{is_max} = shift;
70
	(@_) and $self->{is_max} = shift;
71
	return $self->{is_max} || 0;
71
	return $self->{is_max} || 0;
72
}
72
}
73
sub value ($;$) {
73
sub value {
74
	my $self = shift;
74
	my $self = shift;
75
	if (@_) {
75
	if (@_) {
76
		my $value = shift;
76
		my $value = shift;
Lines 83-96 sub value ($;$) { Link Here
83
	}
83
	}
84
	return $self->{value};
84
	return $self->{value};
85
}
85
}
86
sub autoBarcode (;$) {
86
sub autoBarcode {
87
	(@_) or return _prefformat;
87
	(@_) or return _prefformat;
88
	my $self = shift;
88
	my $self = shift;
89
	my $value = $self->{autoBarcode} or return _prefformat;
89
	my $value = $self->{autoBarcode} or return _prefformat;
90
	$value =~ s/^.*:://;	# in case we get C4::Barcodes::incremental, we just want 'incremental'
90
	$value =~ s/^.*:://;	# in case we get C4::Barcodes::incremental, we just want 'incremental'
91
	return $value;
91
	return $value;
92
}
92
}
93
sub parse ($;$) {	# return 3 parts of barcode: non-incrementing, incrementing, non-incrementing
93
sub parse {	# return 3 parts of barcode: non-incrementing, incrementing, non-incrementing
94
	my $self = shift;
94
	my $self = shift;
95
	my $barcode = (@_) ? shift : $self->value;
95
	my $barcode = (@_) ? shift : $self->value;
96
	unless ($barcode =~ /(.*?)(\d+)$/) {	# non-greedy match in first part
96
	unless ($barcode =~ /(.*?)(\d+)$/) {	# non-greedy match in first part
Lines 100-106 sub parse ($;$) { # return 3 parts of barcode: non-incrementing, incrementing, n Link Here
100
	$debug and warn "Barcode '$barcode' parses into: '$1', '$2', ''";
100
	$debug and warn "Barcode '$barcode' parses into: '$1', '$2', ''";
101
	return ($1,$2,'');	# the third part is in anticipation of barcodes that include checkdigits
101
	return ($1,$2,'');	# the third part is in anticipation of barcodes that include checkdigits
102
}
102
}
103
sub max ($;$) {
103
sub max {
104
	my $self = shift;
104
	my $self = shift;
105
	if ($self->{is_max}) {
105
	if ($self->{is_max}) {
106
		$debug and print STDERR "max taken from Barcodes value $self->value\n";
106
		$debug and print STDERR "max taken from Barcodes value $self->value\n";
Lines 109-122 sub max ($;$) { Link Here
109
	$debug and print STDERR "Retrieving max database query.\n";
109
	$debug and print STDERR "Retrieving max database query.\n";
110
	return $self->db_max;
110
	return $self->db_max;
111
}
111
}
112
sub db_max () {
112
sub db_max {
113
	my $self = shift;
113
	my $self = shift;
114
	my $query = "SELECT max(abs(barcode)) FROM items LIMIT 1"; # Possible problem if multiple barcode types populated
114
	my $query = "SELECT max(abs(barcode)) FROM items LIMIT 1"; # Possible problem if multiple barcode types populated
115
	my $sth = C4::Context->dbh->prepare($query);
115
	my $sth = C4::Context->dbh->prepare($query);
116
	$sth->execute();
116
	$sth->execute();
117
	return $sth->fetchrow_array || $self->initial;
117
	return $sth->fetchrow_array || $self->initial;
118
}
118
}
119
sub next_value ($;$) {
119
sub next_value {
120
	my $self = shift;
120
	my $self = shift;
121
	my $specific = (scalar @_) ? 1 : 0;
121
	my $specific = (scalar @_) ? 1 : 0;
122
	my $max = $specific ? shift : $self->max;		# optional argument, i.e. next_value after X
122
	my $max = $specific ? shift : $self->max;		# optional argument, i.e. next_value after X
Lines 143-164 sub next_value ($;$) { Link Here
143
	$debug and print STDERR "(  next ) max barcode found: $next_value\n";
143
	$debug and print STDERR "(  next ) max barcode found: $next_value\n";
144
	return $next_value;
144
	return $next_value;
145
}
145
}
146
sub next ($;$) {
146
sub next {
147
	my $self = shift or return undef;
147
	my $self = shift or return undef;
148
	(@_) and $self->{next} = shift;
148
	(@_) and $self->{next} = shift;
149
	return $self->{next};
149
	return $self->{next};
150
}
150
}
151
sub previous ($;$) {
151
sub previous {
152
	my $self = shift or return undef;
152
	my $self = shift or return undef;
153
	(@_) and $self->{previous} = shift;
153
	(@_) and $self->{previous} = shift;
154
	return $self->{previous};
154
	return $self->{previous};
155
}
155
}
156
sub serial ($;$) {
156
sub serial {
157
	my $self = shift or return undef;
157
	my $self = shift or return undef;
158
	(@_) and $self->{serial} = shift;
158
	(@_) and $self->{serial} = shift;
159
	return $self->{serial};
159
	return $self->{serial};
160
}
160
}
161
sub default_self (;$) {
161
sub default_self {
162
	(@_) or carp "default_self called with no argument.  Reverting to _prefformat.";
162
	(@_) or carp "default_self called with no argument.  Reverting to _prefformat.";
163
	my $autoBarcode = (@_) ? shift : _prefformat;
163
	my $autoBarcode = (@_) ? shift : _prefformat;
164
	$autoBarcode =~ s/^.*:://;  # in case we get C4::Barcodes::incremental, we just want 'incremental'
164
	$autoBarcode =~ s/^.*:://;  # in case we get C4::Barcodes::incremental, we just want 'incremental'
165
- 

Return to bug 6679